1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
19 #include <Xw_Extension.h>
21 /* ifdef then trace on */
23 #define TRACE_OPEN_IMAGE
27 XW_EXT_IMAGEDATA Xw_open_image (awindow,aimageinfo,width,height):
28 XW_EXT_WINDOW *awindow ;
29 XW_USERDATA *aimageinfo ; Image identifier
30 int width,height Image size in pixels
32 Open an Image in the same Window visual as defined
33 NOTE than this image can be filled with Xw_put_pixel
35 Returns The image extension address if Successful
36 returns NULL if BadAllocation
38 XW_STATUS Xw_close_image (aimage):
39 XW_EXT_IMAGEDATA *aimage Extended Image address
43 returns SUCCESS always
45 XW_EXT_IMAGEDATA* Xw_get_image_handle (awindow,aimageinfo):
46 XW_EXT_WINDOW *awindow ;
47 XW_USERDATA aimageinfo Image identifier
49 returns the Image handle associated to the image ID
50 or NULL if no image exist.
55 void* Xw_open_image (void *awindow,void *aimageinfo,int width,int height)
57 void* Xw_open_image (awindow,aimageinfo,width,height)
61 #endif /*XW_PROTOTYPE*/
63 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
64 XW_EXT_IMAGEDATA *pimage ;
65 XW_EXT_COLORMAP *pcolormap ;
70 if( !Xw_isdefine_window(pwindow) ) {
71 /*ERROR*Bad EXT_WINDOW Address*/
72 Xw_set_error(24,"Xw_open_image",pwindow) ;
92 /*ERROR*Unimplemented Image Visual depth*/
93 Xw_set_error(64,"Xw_open_image",&_DEPTH) ;
97 if( !(cdata = (char*) Xw_calloc(width*height,pad)) ) {
98 /*ERROR*XImage Allocation failed*/
99 Xw_set_error(60,"Xw_open_image",0) ;
103 if( !(pimage = Xw_add_imagedata_structure(sizeof(XW_EXT_IMAGEDATA))) ) {
108 pimage->pimageinfo = aimageinfo ;
109 pimage->pcolormap = pcolormap = _COLORMAP ;
110 _IIMAGE = XCreateImage(_CDISPLAY,_CVISUAL,_DEPTH,
111 ZPixmap,0,cdata,width,height,pad*8,width*pad) ;
113 /*ERROR*XImage Creation failed*/
114 Xw_set_error(62,"Xw_open_image",0) ;
115 Xw_del_imagedata_structure(pimage) ;
118 #ifdef TRACE_OPEN_IMAGE
119 if( Xw_get_trace() ) {
120 printf (" %lx = Xw_open_image(%lx,%lx,%d,%d)\n",(long ) pimage,(long ) pwindow,(long ) aimageinfo,
128 static XW_EXT_IMAGEDATA *PimageList =NULL ;
131 XW_EXT_IMAGEDATA* Xw_add_imagedata_structure(int size)
133 XW_EXT_IMAGEDATA* Xw_add_imagedata_structure(size)
135 #endif /*XW_PROTOTYPE*/
137 Create and Insert one Extended image structure in the
140 returns Extended image address if successful
141 or NULL if Bad Allocation
144 XW_EXT_IMAGEDATA *pimage ;
147 pimage = (XW_EXT_IMAGEDATA*) Xw_malloc(size) ;
150 pimage->type = IMAGE_TYPE ;
151 pimage->link = PimageList ;
152 PimageList = pimage ;
153 pimage->pcolormap = NULL ;
155 pimage->pximage = NULL ;
156 pimage->zximage = NULL ;
157 pimage->maxwindow = 0 ;
159 /*ERROR*EXT_IMAGE allocation failed*/
160 Xw_set_error(27,"Xw_open_image",0) ;
167 XW_STATUS Xw_close_image (void* aimage)
169 XW_STATUS Xw_close_image (aimage)
171 #endif /*XW_PROTOTYPE*/
173 XW_EXT_IMAGEDATA *pimage = (XW_EXT_IMAGEDATA*) aimage ;
175 Xw_del_imagedata_structure(pimage) ;
177 #ifdef TRACE_CLOSE_IMAGE
178 if( Xw_get_trace() ) {
179 printf (" Xw_close_image(%x)\n",pimage);
187 void* Xw_get_image_handle (void* awindow,void *aimageinfo)
189 void* Xw_get_image_handle (awindow,aimageinfo)
192 #endif /*XW_PROTOTYPE*/
194 #ifdef TRACE_OPEN_IMAGE
195 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
197 XW_EXT_IMAGEDATA *pimage ;
199 for( pimage = PimageList ; pimage ;
200 pimage = (XW_EXT_IMAGEDATA*) pimage->link ) {
201 if( pimage->pimageinfo == aimageinfo ) break ;
204 #ifdef TRACE_OPEN_IMAGE
205 if( Xw_get_trace() ) {
206 printf (" %lx = Xw_get_image_handle(%lx,%lx)\n",(long ) pimage,(long ) pwindow,(long ) aimageinfo);
214 XW_STATUS Xw_del_imagedata_structure(XW_EXT_IMAGEDATA *aimage)
216 XW_STATUS Xw_del_imagedata_structure(aimage)
217 XW_EXT_IMAGEDATA *aimage;
218 #endif /*XW_PROTOTYPE*/
220 Remove the Extended image address from the Extended List and
221 Free the Extended Image
223 returns ERROR if the image address is not Found in the list
224 returns XW_SUCCESS if successful
227 XW_EXT_IMAGEDATA *pimage = aimage ;
230 if( !pimage ) return (XW_ERROR) ;
232 if( pimage->maxwindow ) --pimage->maxwindow ;
234 if( pimage->maxwindow ) {
237 if( _IIMAGE ) XDestroyImage(_IIMAGE) ;
238 if( _ZIMAGE ) XDestroyImage(_ZIMAGE) ;
239 if( pimage == PimageList ) {
240 PimageList = (XW_EXT_IMAGEDATA*) pimage->link ;
242 for( pimage = PimageList ; pimage ;
243 pimage = (XW_EXT_IMAGEDATA*) pimage->link ) {
244 if( pimage->link == aimage ) {
245 pimage->link = aimage->link ;
252 return (XW_SUCCESS) ;