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.
18 #include <Xw_Extension.h>
21 // GG PRO4521 05/08/96
22 // Capture an image across all the window memory plans.
23 // GG PRO6633 21/08/97
24 // Avoid crash when image size is NULL.
26 // Capture an image from any pixmap.
32 #ifdef HAVE_X11_EXTENSIONS_READDISPLAY_H
33 #include <X11/extensions/readdisplay.h>
36 #ifdef HAVE_X11_EXTENSIONS_TRANSOLV_H
37 #include <X11/extensions/transovl.h>
40 /* ifdef then trace on */
42 #define TRACE_GET_IMAGE
46 XW_EXT_IMAGEDATA* Xw_get_image (awindow,aimageinfo,xc,yc,width,height):
47 XW_EXT_WINDOW *awindow
48 XW_USERDATA *aimageinfo Image Informations Address
49 int xc,yc Image center location in pixels
50 int width,height Image size in pixels
52 Get an image from the window at the required Center location
53 NOTE than current Window position and size are taken.
55 returns The image descriptor address if successful
56 returns NULL if BadAllocation or Image is outside of the window
58 XW_EXT_IMAGEDATA* Xw_get_image_from_pixmap (awindow,aimageinfo,pixmap,xc,yc,width,height):
59 XW_EXT_WINDOW *awindow
60 XW_USERDATA *aimageinfo Image Informations Address
62 int xc,yc Image center location in pixels
63 int width,height Image size in pixels
65 Get an image from any pixmap at the required Center location and size
67 returns The image descriptor address if successful
68 returns NULL if BadAllocation or Image is outside of the pixmap
73 void* Xw_get_image (void* awindow, void *aimageinfo,
74 int xc,int yc,int width,int height)
76 void* Xw_get_image (awindow,aimageinfo,xc,yc,width,height)
81 #endif // XW_PROTOTYPE
83 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
84 XW_EXT_DISPLAY *pdisplay = pwindow->connexion ;
85 XW_EXT_IMAGEDATA *pimage ;
87 #if defined(HAVE_X11_EXTENSIONS_READDISPLAY_H) || defined(HAVE_X11_EXTENSIONS_TRANSOLV_H)
88 int mOptCode,fEvent,fError;
91 if( !Xw_isdefine_window(pwindow) ) {
92 /*ERROR*Bad EXT_WINDOW Address*/
93 Xw_set_error(24,"Xw_get_image",pwindow) ;
97 if( width <= 0 || height <= 0 ) return NULL;
105 if( !(pimage = Xw_add_imagedata_structure(sizeof(XW_EXT_IMAGEDATA))) )
108 pimage->pimageinfo = aimageinfo ;
111 wx += _X ; wy += _Y ;
112 if( (wx + width) < 0 || wx > _DWIDTH ||
113 (wy + height) < 0 || wy > _DHEIGHT ) {
114 Xw_del_imagedata_structure(pimage) ;
115 /*WARNING*Try to Get Image from outside the display*/
116 Xw_set_error(45,"Xw_get_image",0) ;
120 if( width > _DWIDTH ) width = _DWIDTH;
121 if( height > _DHEIGHT ) height = _DHEIGHT;
122 if( wx + width > _DWIDTH ) width = _DWIDTH - wx;
123 if( wy + height > _DHEIGHT ) height = _DHEIGHT - wy;
127 #ifdef HAVE_X11_EXTENSIONS_READDISPLAY_H
128 if( XQueryExtension(_DISPLAY,"ReadDisplay",&mOptCode,&fEvent,&fError) ) {
129 XGrabServer(_DISPLAY);
130 XSync(_DISPLAY,False);
131 _IIMAGE = XReadDisplay(_DISPLAY,_DROOT,wx,wy,width,height,0,0);
132 XUngrabServer(_DISPLAY);
133 XSync(_DISPLAY,False);
135 #endif // HAVE_X11_EXTENSIONS_READDISPLAY_H
136 #ifdef HAVE_X11_EXTENSIONS_TRANSOLV_H
137 if( XQueryExtension(_DISPLAY,"SUN_OVL",&mOptCode,&fEvent,&fError) ) {
138 XGrabServer(_DISPLAY);
139 XSync(_DISPLAY,False);
140 _IIMAGE = XReadScreen(_DISPLAY,_DROOT,wx,wy,width,height,False);
141 XUngrabServer(_DISPLAY);
142 XSync(_DISPLAY,False);
144 #endif // HAVE_X11_EXTENSIONS_TRANSOLV_H
146 _IIMAGE = XGetImage(_DISPLAY,_DROOT,wx,wy,
147 width,height,AllPlanes,ZPixmap) ;
149 if( (wx + width) < 0 || wx > _WIDTH ||
150 (wy + height) < 0 || wy > _HEIGHT ) {
151 Xw_del_imagedata_structure(pimage) ;
152 /*WARNING*Try to Get Image from outside the window*/
153 Xw_set_error(45,"Xw_get_image",0) ;
157 if( width > _WIDTH ) width = _WIDTH;
158 if( height > _HEIGHT ) height = _HEIGHT;
159 if( wx + width > _WIDTH ) width = _WIDTH - wx;
160 if( wy + height > _HEIGHT ) height = _HEIGHT - wy;
162 _ICOLORMAP = _COLORMAP ;
164 #ifdef HAVE_X11_EXTENSIONS_READDISPLAY_H
165 if( XQueryExtension(_DISPLAY,"ReadDisplay",&mOptCode,&fEvent,&fError) )
167 unsigned int flag = XRD_IGNORE_LAYER_1 | XRD_IGNORE_LAYER_2 |
168 XRD_IGNORE_LAYER_MINUS_1;
171 XGrabServer(_DISPLAY);
172 XSync(_DISPLAY,False);
173 XTranslateCoordinates(_DISPLAY,_WINDOW,_DROOT,wx,wy,&rx,&ry,&child);
174 _IIMAGE = XReadDisplay(_DISPLAY,_WINDOW,rx,ry,width,height,flag,0);
175 XUngrabServer(_DISPLAY);
176 XSync(_DISPLAY,False);
178 #endif // HAVE_X11_EXTENSIONS_READDISPLAY_H
179 #ifdef HAVE_X11_EXTENSIONS_TRANSOLV_H
180 if( XQueryExtension(_DISPLAY,"SUN_OVL",&mOptCode,&fEvent,&fError) )
182 XGrabServer(_DISPLAY);
183 XSync(_DISPLAY,False);
184 _IIMAGE = XReadScreen(_DISPLAY,_WINDOW,wx,wy,width,height,False);
185 XUngrabServer(_DISPLAY);
186 XSync(_DISPLAY,False);
188 #endif // HAVE_X11_EXTENSIONS_TRANSOLV_H
190 _IIMAGE = XGetImage(_DISPLAY,_WINDOW,wx,wy,
191 width,height,AllPlanes,ZPixmap) ;
195 Xw_del_imagedata_structure(pimage) ;
196 /*WARNING*XImage allocation failed*/
197 Xw_set_error(60,"Xw_get_image",0) ;
200 else if( _IIMAGE->depth > 24 ) _IIMAGE->depth = 24;
202 #ifdef TRACE_GET_IMAGE
203 if( Xw_get_trace() ) {
204 printf (" %lx = Xw_get_image(%lx,%lx,%d,%d,%d,%d)\n",
205 (long ) pimage,(long ) pwindow,(long ) aimageinfo,xc,yc,width,height);
213 void* Xw_get_image_from_pixmap (void* awindow, void *aimageinfo,
214 Aspect_Handle pixmap, int xc,int yc,int width,int height)
216 void* Xw_get_image_from_pixmap (awindow,aimageinfo,pixmap,xc,yc,width,height)
219 Aspect_Handle pixmap;
222 #endif /*XW_PROTOTYPE*/
224 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
225 // XW_EXT_DISPLAY *pdisplay = pwindow->connexion ;
226 XW_EXT_IMAGEDATA *pimage ;
229 if( !Xw_isdefine_window(pwindow) ) {
230 /*ERROR*Bad EXT_WINDOW Address*/
231 Xw_set_error(24,"Xw_get_image_from_pixmap",pwindow) ;
235 if( pixmap == 0 || width <= 0 || height <= 0 ) return NULL;
243 if( !(pimage = Xw_add_imagedata_structure(sizeof(XW_EXT_IMAGEDATA))) )
245 pimage->pimageinfo = aimageinfo ;
247 _IIMAGE = XGetImage(_DISPLAY,pixmap,wx,wy,
248 width,height,AllPlanes,ZPixmap) ;
251 Xw_del_imagedata_structure(pimage) ;
252 /*WARNING*XImage allocation failed*/
253 Xw_set_error(60,"Xw_get_image_from_pixmap",0) ;
256 _IIMAGE->red_mask = _VISUAL->red_mask;
257 _IIMAGE->green_mask = _VISUAL->green_mask;
258 _IIMAGE->blue_mask = _VISUAL->blue_mask;
259 if( _IIMAGE->depth > 24 ) _IIMAGE->depth = 24;
262 #ifdef TRACE_GET_IMAGE
263 if( Xw_get_trace() ) {
264 printf (" %lx = Xw_get_image_from_pixmap(%lx,%lx,%lx,%d,%d,%d,%d)\n",
265 (long ) pimage,(long ) pwindow,(long ) aimageinfo, pixmap,xc,yc,width,height);