summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXXStubs.c
diff options
context:
space:
mode:
authordas <das>2004-02-23 10:48:09 (GMT)
committerdas <das>2004-02-23 10:48:09 (GMT)
commit424068d0e8dd6fcb04ef498c011262dd8466f3b5 (patch)
tree8af091f49a419ae3eaa1eefd6d0e21df85524f33 /macosx/tkMacOSXXStubs.c
parent326d3447f96c8bbd0e2f1956eddfc532ab6a0853 (diff)
downloadtk-424068d0e8dd6fcb04ef498c011262dd8466f3b5.zip
tk-424068d0e8dd6fcb04ef498c011262dd8466f3b5.tar.gz
tk-424068d0e8dd6fcb04ef498c011262dd8466f3b5.tar.bz2
* macosx/tkMacOSXDraw.c:
* macosx/tkMacOSXXStubs.c: * xlib/ximage.c: fixed MacOSX XGetImage/XPutImage and related functions to deal properly with XImages copied from screen. * generic/tkCanvPs.c (TkImageGetColor): MacOSX fix. [Bug 809157]
Diffstat (limited to 'macosx/tkMacOSXXStubs.c')
-rw-r--r--macosx/tkMacOSXXStubs.c86
1 files changed, 64 insertions, 22 deletions
diff --git a/macosx/tkMacOSXXStubs.c b/macosx/tkMacOSXXStubs.c
index 8d9aee7..fa21bce 100644
--- a/macosx/tkMacOSXXStubs.c
+++ b/macosx/tkMacOSXXStubs.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXXStubs.c,v 1.4 2004/01/13 02:06:01 davygrvy Exp $
+ * RCS: @(#) $Id: tkMacOSXXStubs.c,v 1.5 2004/02/23 10:48:11 das Exp $
*/
#include "tkInt.h"
@@ -142,7 +142,7 @@ TkpOpenDisplay(
screen->root_visual->green_mask = 0x0000FF00;
screen->root_visual->blue_mask = 0x000000FF;
screen->root_visual->bits_per_rgb = 24;
- screen->root_visual->map_entries = 2 ^ 8;
+ screen->root_visual->map_entries = 256;
gMacDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay));
@@ -328,19 +328,45 @@ XGetImage(display, d, x, y, width, height, plane_mask, format)
unsigned long plane_mask;
int format;
{
- XImage * imagePtr;
- Visual * visual = NULL;
- int depth = 0;
- int offset = 0;
- char * data = NULL;
- int bitmap_pad = 0;
- int bytes_per_line = 0;
- CGrafPtr grafPtr;
-
- imagePtr = XCreateImage(display,visual,depth,format, offset, data,
- width, height, bitmap_pad, bytes_per_line );
- grafPtr = TkMacOSXGetDrawablePort(d);
- imagePtr->data = (char *) grafPtr;
+ XImage * imagePtr = NULL;
+ Pixmap pixmap = NULL;
+ Tk_Window win = (Tk_Window) ((MacDrawable *) d)->winPtr;
+ GC gc;
+ int depth = 32;
+ int offset = 0;
+ int bitmap_pad = 32;
+ int bytes_per_line = 0;
+
+ if (TkMacOSXGetDrawablePort(d)) {
+ if (format == ZPixmap) {
+ if (width > 0 && height > 0) {
+ /* Tk_GetPixmap fails for zero width or height */
+ pixmap = Tk_GetPixmap(display, d, width, height, depth);
+ }
+ if (win) {
+ XGCValues values;
+ gc = Tk_GetGC(win, 0, &values);
+ } else {
+ gc = XCreateGC(display, pixmap, 0, NULL);
+ }
+ if (pixmap) {
+ XCopyArea(display, d, pixmap, gc, x, y, width, height, 0, 0);
+ }
+ imagePtr = XCreateImage(display, NULL, depth, format, offset,
+ (char*)TkMacOSXGetDrawablePort(pixmap),
+ width, height, bitmap_pad, bytes_per_line);
+ /* Track Pixmap underlying the XImage in the unused obdata field *
+ * so that we can treat XImages coming from XGetImage specially. */
+ imagePtr->obdata = (XPointer) pixmap;
+ if (!win) {
+ XFreeGC(display, gc);
+ }
+ } else {
+ TkpDisplayWarning(
+ "XGetImage: only ZPixmap types are implemented",
+ "XGetImage Failure");
+ }
+ }
return imagePtr;
}
@@ -459,6 +485,7 @@ XCreateImage(
ximage->green_mask = 0x0000FF00;
ximage->blue_mask = 0x000000FF;
+ ximage->obdata = NULL;
ximage->f.destroy_image = TkMacOSXXDestroyImage;
ximage->f.get_pixel = TkMacOSXXGetPixel;
ximage->f.put_pixel = TkMacOSXXPutPixel;
@@ -667,7 +694,8 @@ int
TkMacOSXXDestroyImage(
XImage *image)
{
- Debugger();
+ if (image->obdata)
+ Tk_FreePixmap((Display*)gMacDisplay,(Pixmap)image->obdata);
return 0;
}
@@ -683,9 +711,16 @@ TkMacOSXXGetPixel(
grafPtr = (CGrafPtr)image->data;
SetPort(grafPtr);
GetCPixel(x,y,&cPix);
- r = cPix . red;
- g = cPix . green;
- b = cPix . blue;
+ if (image->obdata) {
+ /* Image from XGetImage, 16 bit color values */
+ r = (cPix . red) >> 8;
+ g = (cPix . green) >> 8;
+ b = (cPix . blue) >> 8;
+ } else {
+ r = cPix . red;
+ g = cPix . green;
+ b = cPix . blue;
+ }
c = (r<<16)|(g<<8)|(b);
return c;
}
@@ -705,9 +740,16 @@ TkMacOSXXPutPixel(
r = (pixel & image->red_mask)>>16;
g = (pixel & image->green_mask)>>8;
b = (pixel & image->blue_mask);
- cPix . red = r;
- cPix . green = g;
- cPix . blue = b;
+ if (image->obdata) {
+ /* Image from XGetImage, 16 bit color values */
+ cPix . red = r << 8;
+ cPix . green = g << 8;
+ cPix . blue = b << 8;
+ } else {
+ cPix . red = r;
+ cPix . green = g;
+ cPix . blue = b;
+ }
SetCPixel(x,y,&cPix);
return 0;
}