Tk Img Extensions
Check-in [88f406c8e9]
Not logged in
Tcl 2014 Conference, Portland/OR, US, Nov 10-14
Send your abstracts to tclconference@googlegroups.com by Sep 8.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use xerrorhandler on all platforms, not only UNIX.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:88f406c8e9f3621056d2b295805ad954f9d07484
User & Date: nijtmans 2013-10-03 09:38:24
Context
2013-10-03
09:48
Some unused variables check-in: c9bd7a43a8 user: nijtmans tags: trunk
09:38
Use xerrorhandler on all platforms, not only UNIX. check-in: 88f406c8e9 user: nijtmans tags: trunk
2013-10-02
18:12
Replaced workaround for adding alpha channel with png_set_add_alpha for lower memory consumption. check-in: c8336949ad user: obermeier tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to window/window.c.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32


33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include "X11/Xutil.h"
#ifndef	__WIN32__
#  ifndef MAC_OSX_TK
#   include "X11/Xproto.h"
#  else
#   include "X11/Xlib.h"
#   include "X11/Xfuncproto.h"
#   undef X_GetImage
#  endif
#else
/*#   include <windows.h>*/
#   include "X11/Xlib.h"
#   include "tkInt.h"
#   include "tkWinInt.h"
#   include "X11/Xfuncproto.h"


#   undef X_GetImage

#endif

/*
 * The format record for the Win data format:
 */

#ifdef X_GetImage
static int xerrorhandler(ClientData clientData, XErrorEvent *e);
#endif

typedef struct ColormapData {	/* Hold color information for a window */
    int separated;		/* Whether to use separate color bands */
    int color;			/* Whether window is color or black/white */
    int ncolors;		/* Number of color values stored */
    XColor *colors;		/* Pixel value -> RGB mappings */
    int red_mask, green_mask, blue_mask;	/* Masks and shifts for each */
................................................................................
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

#ifdef X_GetImage
static int
xerrorhandler(clientData, e)
    ClientData clientData;
    XErrorEvent *e;
{
    return 0;
}
#endif

/* OPA TODO: Must be a better way to specify non-existing format functions. */
static int
ChnRead (interp, chan, fileName, format, imageHandle,
         destX, destY, width, height, srcX, srcY)
    Tcl_Interp *interp;
    Tcl_Channel chan;
................................................................................
#   undef XGetPixel
#   define XGetPixel(P,X,Y) GetPixel(P, X, Y)
    TkWinDCState DCi;
    HDC			ximage;
#endif
    Visual *visual;
    unsigned char *p;
#ifdef X_GetImage
    Tk_ErrorHandler	handle;
#endif
    int green, blue;
    int result = TCL_OK;

    name = tkimg_GetStringFromObj(data, NULL);

    tkwin = Tk_NameToWindow(interp, name, Tk_MainWindow(interp));

................................................................................
    }

    /*
     * If the window is off the screen it will generate an BadMatch/XError
     * We catch any BadMatch errors here
     */

#ifdef X_GetImage
    handle = Tk_CreateErrorHandler(Tk_Display(tkwin), BadMatch,
	    X_GetImage, -1, xerrorhandler, (ClientData) tkwin);
#endif

#ifndef	__WIN32__
    /*
     * Generate an XImage from the window.  We can then read pixel
     * values out of the XImage.
     */

    ximage = XGetImage(Tk_Display(tkwin), Tk_WindowId(tkwin), srcX, srcY,
	width, height, AllPlanes, ZPixmap);

#ifdef X_GetImage
    Tk_DeleteErrorHandler(handle);
#endif

    if (ximage == (XImage*) NULL) {
	Tcl_AppendResult(interp, "Window \"", name,
		"\" cannot be transformed into a pixmap (possibly obscured?)",
		(char *) NULL);
	return TCL_ERROR;
    }







<


<




>
>
|
>






<

<







 







<







<







 







<

<







 







<


<










<

<







18
19
20
21
22
23
24

25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40

41

42
43
44
45
46
47
48
..
67
68
69
70
71
72
73

74
75
76
77
78
79
80

81
82
83
84
85
86
87
...
228
229
230
231
232
233
234

235

236
237
238
239
240
241
242
...
264
265
266
267
268
269
270

271
272

273
274
275
276
277
278
279
280
281
282

283

284
285
286
287
288
289
290
#include "X11/Xutil.h"
#ifndef	__WIN32__
#  ifndef MAC_OSX_TK
#   include "X11/Xproto.h"
#  else
#   include "X11/Xlib.h"
#   include "X11/Xfuncproto.h"

#  endif
#else

#   include "X11/Xlib.h"
#   include "tkInt.h"
#   include "tkWinInt.h"
#   include "X11/Xfuncproto.h"
#endif

#ifndef X_GetImage
#   define X_GetImage 73
#endif

/*
 * The format record for the Win data format:
 */


static int xerrorhandler(ClientData clientData, XErrorEvent *e);


typedef struct ColormapData {	/* Hold color information for a window */
    int separated;		/* Whether to use separate color bands */
    int color;			/* Whether window is color or black/white */
    int ncolors;		/* Number of color values stored */
    XColor *colors;		/* Pixel value -> RGB mappings */
    int red_mask, green_mask, blue_mask;	/* Masks and shifts for each */
................................................................................
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */


static int
xerrorhandler(clientData, e)
    ClientData clientData;
    XErrorEvent *e;
{
    return 0;
}


/* OPA TODO: Must be a better way to specify non-existing format functions. */
static int
ChnRead (interp, chan, fileName, format, imageHandle,
         destX, destY, width, height, srcX, srcY)
    Tcl_Interp *interp;
    Tcl_Channel chan;
................................................................................
#   undef XGetPixel
#   define XGetPixel(P,X,Y) GetPixel(P, X, Y)
    TkWinDCState DCi;
    HDC			ximage;
#endif
    Visual *visual;
    unsigned char *p;

    Tk_ErrorHandler	handle;

    int green, blue;
    int result = TCL_OK;

    name = tkimg_GetStringFromObj(data, NULL);

    tkwin = Tk_NameToWindow(interp, name, Tk_MainWindow(interp));

................................................................................
    }

    /*
     * If the window is off the screen it will generate an BadMatch/XError
     * We catch any BadMatch errors here
     */


    handle = Tk_CreateErrorHandler(Tk_Display(tkwin), BadMatch,
	    X_GetImage, -1, xerrorhandler, (ClientData) tkwin);


#ifndef	__WIN32__
    /*
     * Generate an XImage from the window.  We can then read pixel
     * values out of the XImage.
     */

    ximage = XGetImage(Tk_Display(tkwin), Tk_WindowId(tkwin), srcX, srcY,
	width, height, AllPlanes, ZPixmap);


    Tk_DeleteErrorHandler(handle);


    if (ximage == (XImage*) NULL) {
	Tcl_AppendResult(interp, "Window \"", name,
		"\" cannot be transformed into a pixmap (possibly obscured?)",
		(char *) NULL);
	return TCL_ERROR;
    }