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))) )
106 pimage->pimageinfo = aimageinfo ;
107 pimage->pcolormap = pcolormap = _COLORMAP ;
108 _IIMAGE = XCreateImage(_CDISPLAY,_CVISUAL,_DEPTH,
109 ZPixmap,0,cdata,width,height,pad*8,width*pad) ;
111 /*ERROR*XImage Creation failed*/
112 Xw_set_error(62,"Xw_open_image",0) ;
113 Xw_del_imagedata_structure(pimage) ;
116 #ifdef TRACE_OPEN_IMAGE
117 if( Xw_get_trace() ) {
118 printf (" %lx = Xw_open_image(%lx,%lx,%d,%d)\n",(long ) pimage,(long ) pwindow,(long ) aimageinfo,
126 static XW_EXT_IMAGEDATA *PimageList =NULL ;
129 XW_EXT_IMAGEDATA* Xw_add_imagedata_structure(int size)
131 XW_EXT_IMAGEDATA* Xw_add_imagedata_structure(size)
133 #endif /*XW_PROTOTYPE*/
135 Create and Insert one Extended image structure in the
138 returns Extended image address if successful
139 or NULL if Bad Allocation
142 XW_EXT_IMAGEDATA *pimage ;
145 pimage = (XW_EXT_IMAGEDATA*) Xw_malloc(size) ;
148 pimage->type = IMAGE_TYPE ;
149 pimage->link = PimageList ;
150 PimageList = pimage ;
151 pimage->pcolormap = NULL ;
153 pimage->pximage = NULL ;
154 pimage->zximage = NULL ;
155 pimage->maxwindow = 0 ;
157 /*ERROR*EXT_IMAGE allocation failed*/
158 Xw_set_error(27,"Xw_open_image",0) ;
165 XW_STATUS Xw_close_image (void* aimage)
167 XW_STATUS Xw_close_image (aimage)
169 #endif /*XW_PROTOTYPE*/
171 XW_EXT_IMAGEDATA *pimage = (XW_EXT_IMAGEDATA*) aimage ;
173 Xw_del_imagedata_structure(pimage) ;
175 #ifdef TRACE_CLOSE_IMAGE
176 if( Xw_get_trace() ) {
177 printf (" Xw_close_image(%x)\n",pimage);
185 void* Xw_get_image_handle (void* awindow,void *aimageinfo)
187 void* Xw_get_image_handle (awindow,aimageinfo)
190 #endif /*XW_PROTOTYPE*/
192 #ifdef TRACE_OPEN_IMAGE
193 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
195 XW_EXT_IMAGEDATA *pimage ;
197 for( pimage = PimageList ; pimage ;
198 pimage = (XW_EXT_IMAGEDATA*) pimage->link ) {
199 if( pimage->pimageinfo == aimageinfo ) break ;
202 #ifdef TRACE_OPEN_IMAGE
203 if( Xw_get_trace() ) {
204 printf (" %lx = Xw_get_image_handle(%lx,%lx)\n",(long ) pimage,(long ) pwindow,(long ) aimageinfo);
212 XW_STATUS Xw_del_imagedata_structure(XW_EXT_IMAGEDATA *aimage)
214 XW_STATUS Xw_del_imagedata_structure(aimage)
215 XW_EXT_IMAGEDATA *aimage;
216 #endif /*XW_PROTOTYPE*/
218 Remove the Extended image address from the Extended List and
219 Free the Extended Image
221 returns ERROR if the image address is not Found in the list
222 returns XW_SUCCESS if successful
225 XW_EXT_IMAGEDATA *pimage = aimage ;
228 if( !pimage ) return (XW_ERROR) ;
230 if( pimage->maxwindow ) --pimage->maxwindow ;
232 if( pimage->maxwindow ) {
235 if( _IIMAGE ) XDestroyImage(_IIMAGE) ;
236 if( _ZIMAGE ) XDestroyImage(_ZIMAGE) ;
237 if( pimage == PimageList ) {
238 PimageList = (XW_EXT_IMAGEDATA*) pimage->link ;
240 for( pimage = PimageList ; pimage ;
241 pimage = (XW_EXT_IMAGEDATA*) pimage->link ) {
242 if( pimage->link == aimage ) {
243 pimage->link = aimage->link ;
250 return (XW_SUCCESS) ;