Tk Source Code

Artifact [48975bea]
Login

Artifact 48975bea2dbd2b0494d61589491e8349895e7f5a:

Attachment "XGetPutImage-core-8-4-branch.patch" to ticket [809157ff] added by das 2004-02-23 17:49:18.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tktoolkit/tk/ChangeLog,v
retrieving revision 1.758.2.109
diff -u -p -r1.758.2.109 ChangeLog
--- ChangeLog	18 Feb 2004 20:56:44 -0000	1.758.2.109
+++ ChangeLog	23 Feb 2004 10:27:38 -0000
@@ -1,7 +1,18 @@
-2004-02-18  Peter Spjuth  <[email protected]>
+2004-02-23  Daniel Steffen  <[email protected]>
 
 	*** 8.4.6 TAGGED FOR RELEASE ***
 
+	* 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.
+	* generic/tkImgPhoto.c (ImgPhotoDisplay): enabled alpha blending
+	for images with partial transparency on MacOSX.
+	[Bug 809157]
+
+2004-02-18  Peter Spjuth  <[email protected]>
+
 	* tests/grid.test:
 	* generic/tkGrid.c: Fixed a bug in grid geometry calculations for
 	a shrinking grid. [Bug 899246]
Index: changes
===================================================================
RCS file: /cvsroot/tktoolkit/tk/changes,v
retrieving revision 1.64.2.6
diff -u -p -r1.64.2.6 changes
--- changes	20 Feb 2004 19:54:34 -0000	1.64.2.6
+++ changes	23 Feb 2004 10:27:38 -0000
@@ -5616,4 +5616,7 @@ with spaces in their names.
 
 2004-02-18 (bug fix)[899246] fix shrinking grid geometry calculations
 
+2003-02-23 (platform support)[809157] Mac OS X: Add alpha blending for
+images with partial transparency.
+
 --- Released 8.4.6, February 27, 2004 --- See ChangeLog for details ---
Index: generic/tkCanvPs.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkCanvPs.c,v
retrieving revision 1.13
diff -u -p -r1.13 tkCanvPs.c
--- generic/tkCanvPs.c	18 Feb 2003 21:54:18 -0000	1.13
+++ generic/tkCanvPs.c	23 Feb 2004 10:27:38 -0000
@@ -1137,7 +1137,13 @@ GetPostscriptPoints(interp, string, doub
  #define GetGValue(rgb)	((BYTE)(((WORD)(rgb)) >> 8))
  #define GetBValue(rgb)	((BYTE)((rgb)>>16))
 */
+#else
+#define GetRValue(rgb)	((rgb & cdata->red_mask) >> cdata->red_shift)
+#define GetGValue(rgb)	((rgb & cdata->green_mask) >> cdata->green_shift)
+#define GetBValue(rgb)	((rgb & cdata->blue_mask) >> cdata->blue_shift)
+#endif
 
+#if defined(WIN32) || defined(MAC_OSX_TK)
 static void
 TkImageGetColor(cdata, pixel, red, green, blue)
     TkColormapData *cdata;              /* Colormap data */
@@ -1156,9 +1162,9 @@ TkImageGetColor(cdata, pixel, red, green
     double *red, *green, *blue;         /* Color data to return */
 {
     if (cdata->separated) {
-	int r = (pixel & cdata->red_mask) >> cdata->red_shift;
-	int g = (pixel & cdata->green_mask) >> cdata->green_shift;
-	int b = (pixel & cdata->blue_mask) >> cdata->blue_shift;
+	int r = GetRValue(pixel);
+	int g = GetGValue(pixel);
+	int b = GetBValue(pixel);
 	*red   = cdata->colors[r].red / 65535.0;
 	*green = cdata->colors[g].green / 65535.0;
 	*blue  = cdata->colors[b].blue / 65535.0;
Index: generic/tkImgPhoto.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkImgPhoto.c,v
retrieving revision 1.36.2.4
diff -u -p -r1.36.2.4 tkImgPhoto.c
--- generic/tkImgPhoto.c	9 Feb 2004 14:40:31 -0000	1.36.2.4
+++ generic/tkImgPhoto.c	23 Feb 2004 10:27:38 -0000
@@ -2678,10 +2678,10 @@ ImgPhotoDisplay(clientData, display, dra
     }
 
     if (
-#if defined(MAC_TCL) || defined(MAC_OSX_TK)
+#if defined(MAC_TCL)
 	/*
-	 * The retrieval of bgImg is currently not functional on OSX
-	 * (and likely not OS9 either), so skip attempts to alpha blend.
+	 * The retrieval of bgImg is currently not functional on OS9
+	 * so skip attempts to alpha blend.
 	 */
 	0 &&
 #endif
Index: macosx/tkMacOSXDraw.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXDraw.c,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 tkMacOSXDraw.c
--- macosx/tkMacOSXDraw.c	16 Feb 2004 00:42:34 -0000	1.2.2.1
+++ macosx/tkMacOSXDraw.c	23 Feb 2004 10:27:39 -0000
@@ -347,13 +347,15 @@ TkPutImage(
     GDHandle saveDevice;
     GWorldPtr destPort;
     const BitMap * destBits;
+    MacDrawable *dstDraw = (MacDrawable *) d;
     int i, j;
     BitMap bitmap;
     char *newData = NULL;
     Rect destRect, srcRect;
 
     destPort = TkMacOSXGetDrawablePort(d);
-    SetRect(&destRect, dest_x, dest_y, dest_x + width, dest_y + height);
+    SetRect(&destRect, dstDraw->xOff + dest_x, dstDraw->yOff + dest_y, 
+            dstDraw->xOff + dest_x + width, dstDraw->yOff + dest_y + height);
     SetRect(&srcRect, src_x, src_y, src_x + width, src_y + height);
 
     display->request++;
@@ -362,7 +364,13 @@ TkPutImage(
 
     TkMacOSXSetUpClippingRgn(d);
 
-    if (image->depth == 1) {
+    if (image->obdata) {
+        /* Image from XGetImage, copy from containing GWorld directly */
+        GWorldPtr srcPort = TkMacOSXGetDrawablePort((Drawable)image->obdata);
+        CopyBits(GetPortBitMapForCopyBits(srcPort),
+                GetPortBitMapForCopyBits (destPort),
+                &srcRect, &destRect, srcCopy, NULL);
+    } else if (image->depth == 1) {
 
         /* 
          * This code assumes a pixel depth of 1 
@@ -400,15 +408,15 @@ TkPutImage(
                 &srcRect, &destRect, srcCopy, NULL);
 
     } else {
-            /* Color image */
-            PixMap pixmap;
+        /* Color image */
+        PixMap pixmap;
             
         pixmap.bounds.left = 0;
         pixmap.bounds.top = 0;
         pixmap.bounds.right = (short) image->width;
         pixmap.bounds.bottom = (short) image->height;
         pixmap.pixelType = RGBDirect;
-        pixmap.pmVersion = 4;        /* 32bit clean */
+        pixmap.pmVersion = baseAddr32;        /* 32bit clean */
         pixmap.packType = 0;
         pixmap.packSize = 0;
         pixmap.hRes = 0x00480000;
@@ -416,7 +424,7 @@ TkPutImage(
         pixmap.pixelSize = 32;
         pixmap.cmpCount = 3;
         pixmap.cmpSize = 8;
-        pixmap.pixelFormat = 0;
+        pixmap.pixelFormat = k32ARGBPixelFormat;
         pixmap.pmTable = NULL;
         pixmap.pmExt = 0;
         pixmap.baseAddr = image->data;
Index: macosx/tkMacOSXXStubs.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXXStubs.c,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 tkMacOSXXStubs.c
--- macosx/tkMacOSXXStubs.c	18 Mar 2003 13:55:51 -0000	1.2.2.1
+++ macosx/tkMacOSXXStubs.c	23 Feb 2004 10:27:39 -0000
@@ -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, heigh
     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;
 }
Index: xlib/ximage.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/xlib/ximage.c,v
retrieving revision 1.4
diff -u -p -r1.4 ximage.c
--- xlib/ximage.c	6 Jul 2000 03:17:45 -0000	1.4
+++ xlib/ximage.c	23 Feb 2004 10:27:39 -0000
@@ -64,6 +64,9 @@ XCreateBitmapFromData(display, d, data, 
     ximage.bitmap_bit_order = LSBFirst;
     ximage.bitmap_pad = 8;
     ximage.bytes_per_line = (width+7)/8;
+#ifdef MAC_OSX_TK
+    ximage.obdata = NULL;
+#endif
 
     TkPutImage(NULL, 0, display, pix, gc, &ximage, 0, 0, 0, 0, width, height);
     XFreeGC(display, gc);