0023533: Unitialized variables used, IntTools_TopolTool.cxx
[occt.git] / src / Xw / Xw_save_image.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18/*
19 * Modified: zov : 17-Apr-1998 : Saves an image as .BMP, .GIF or .XWD file
20 *
21
22 XW_STATUS Xw_save_image (awindow,aimage,filename):
23 XW_EXT_WINDOW *awindow
24 XW_EXT_IMAGEDATA *aimage
25 char *filename XWD Image name
26
27 Saves an image to an XWD, BMP or GIF file depending on given filename.
28
29 returns SUCCESS if successfull;
30 otherwise returns ERROR
31 */
32
33#ifdef HAVE_CONFIG_H
34# include <config.h>
35#endif
36
692613e5 37#include <Image_AlienPixMap.hxx>
38#include <TCollection_AsciiString.hxx>
39
7fd59977 40#include <Xw_Extension.h>
41#ifdef HAVE_STRINGS_H
42# include <strings.h>
43#endif
44
7fd59977 45#ifdef XW_PROTOTYPE
46XW_STATUS Xw_save_image_adv (Display *aDisplay,Window aWindow,XWindowAttributes aWinAttr,XImage *aPximage,Colormap aColormap,int aNcolors,char *filename)
47#else
48XW_STATUS Xw_save_image_adv (aDisplay,aWindow,aWinAttr,aPximage,aColormap,aNcolors,filename)
49Display *aDisplay;
50Window aWindow;
51XWindowAttributes aWinAttr;
52XImage *aPximage;
53Colormap aColormap;
54int ncolors;
55char *filename;
56#endif /*XW_PROTOTYPE*/
57{
692613e5 58 if (aWinAttr.visual->c_class != TrueColor)
7fd59977 59 {
60 std::cerr << "Visual Type not supported!";
692613e5 61 return XW_ERROR;
7fd59977 62 }
692613e5 63
64 const bool isBigEndian = (aPximage->byte_order == MSBFirst);
65 Image_PixMap::ImgFormat aFormat = (aPximage->bits_per_pixel == 32)
66 ? (isBigEndian ? Image_PixMap::ImgRGB32 : Image_PixMap::ImgBGR32)
67 : (isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR);
68 Image_PixMap aWrapper;
69 aWrapper.InitWrapper (aFormat, (Standard_Byte* )aPximage->data, aPximage->width, aPximage->height, aPximage->bytes_per_line);
70 aWrapper.SetTopDown (true);
71
72 Image_AlienPixMap anAlienImage;
73 return (anAlienImage.InitCopy (aWrapper) && anAlienImage.Save (filename)) ? XW_SUCCESS : XW_ERROR;
7fd59977 74}
75
76#ifdef XW_PROTOTYPE
77XW_STATUS Xw_save_image (void *awindow,void *aimage,char *filename)
78#else
79XW_STATUS Xw_save_image (awindow,aimage,filename)
80void *awindow;
81void *aimage;
82char *filename ;
83#endif /*XW_PROTOTYPE*/
84{
85 XW_EXT_WINDOW* pwindow = (XW_EXT_WINDOW* )awindow;
86 if (!Xw_isdefine_window (pwindow))
87 { // ERROR Bad EXT_WINDOW Address
88 Xw_set_error (24, "Xw_save_image", pwindow);
89 return (XW_ERROR);
90 }
91
92 XW_EXT_IMAGEDATA* pimage = (XW_EXT_IMAGEDATA* )aimage;
93 if (!Xw_isdefine_image (pimage))
94 { // ERROR Bad EXT_IMAGEDATA Address
95 Xw_set_error (25, "Xw_save_image", pimage);
96 return (XW_ERROR);
97 }
98
99 XImage* pximage = (_ZIMAGE) ? _ZIMAGE : _IIMAGE;
100 return Xw_save_image_adv (_DISPLAY, _WINDOW, _ATTRIBUTES, pximage,
101 _COLORMAP->info.colormap, _COLORMAP->maxhcolor,
102 filename);
103}