Hello!

Since 8.4.4 Tk support alpha blending for images with partial
transparency.
This patch added alpha-channel support for ImageTk.

== patch ==
--- Tk/tkImaging.c.orig 2007-02-26 22:33:45.000000000 +0300
+++ Tk/tkImaging.c      2007-02-27 15:30:31.000000000 +0300
@@ -39,10 +39,7 @@
  * See the README file for information on usage and redistribution.
  */
 
-/* This is needed for (at least) Tk 8.4.1, otherwise the signature of
-** Tk_PhotoPutBlock changes.
-*/
-#define USE_COMPOSITELESS_PHOTO_PUT_BLOCK
+#define TKMAJORMINOR (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION)
 
 /* This is needed for (at least) Tk 8.4.6 and later, to avoid warnings
    for the Tcl_CreateCommand command. */
@@ -125,7 +122,7 @@
        block.offset[0] = 0;
        block.offset[1] = 1;
        block.offset[2] = 2;
-       block.offset[3] = 0; /* no alpha (or reserved, under 8.2) */
+       block.offset[3] = 3; /* alpha (or reserved, under 8.2) */
     } else {
         Tcl_AppendResult(interp, "Bad mode", (char*) NULL);
        return TCL_ERROR;
@@ -141,6 +138,7 @@
                     src_xoffset * im->pixelsize;
 #endif
 
+#if TKMAJORMINOR < 8004 /* Tk < 8.4.0 */
     if (strcmp(im->mode, "RGBA") == 0) {
         /* Copy non-transparent pixels to photo image */
         int x, y;
@@ -193,6 +191,15 @@
         /* Copy opaque block to photo image, and leave the rest to TK */
         Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height);
 
+#else /* Tk >= 8.4.0 */
+    Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height,
+                     TK_PHOTO_COMPOSITE_SET);
+    if (strcmp(im->mode, "RGBA") == 0)
+        /* Tk workaround: we need apply ToggleComplexAlphaIfNeeded */
+        /* (fixed in Tk 8.5a3) */
+        Tk_PhotoSetSize(photo, block.width, block.height);
+#endif
+
     return TCL_OK;
 }
== end == 

-- 
wbr, con

Today is Pungenday, the 58th day of Chaos in the YOLD 3173

--- Tk/tkImaging.c.orig	2007-02-26 22:33:45.000000000 +0300
+++ Tk/tkImaging.c	2007-02-27 15:30:31.000000000 +0300
@@ -39,10 +39,7 @@
  * See the README file for information on usage and redistribution.
  */
 
-/* This is needed for (at least) Tk 8.4.1, otherwise the signature of
-** Tk_PhotoPutBlock changes.
-*/
-#define USE_COMPOSITELESS_PHOTO_PUT_BLOCK
+#define TKMAJORMINOR (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION)
 
 /* This is needed for (at least) Tk 8.4.6 and later, to avoid warnings
    for the Tcl_CreateCommand command. */
@@ -125,7 +122,7 @@
 	block.offset[0] = 0;
 	block.offset[1] = 1;
 	block.offset[2] = 2;
-	block.offset[3] = 0; /* no alpha (or reserved, under 8.2) */
+	block.offset[3] = 3; /* alpha (or reserved, under 8.2) */
     } else {
         Tcl_AppendResult(interp, "Bad mode", (char*) NULL);
 	return TCL_ERROR;
@@ -141,6 +138,7 @@
 	             src_xoffset * im->pixelsize;
 #endif
 
+#if TKMAJORMINOR < 8004 /* Tk < 8.4.0 */
     if (strcmp(im->mode, "RGBA") == 0) {
         /* Copy non-transparent pixels to photo image */
         int x, y;
@@ -193,6 +191,15 @@
         /* Copy opaque block to photo image, and leave the rest to TK */
         Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height);
 
+#else /* Tk >= 8.4.0 */
+    Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height,
+                     TK_PHOTO_COMPOSITE_SET);
+    if (strcmp(im->mode, "RGBA") == 0)
+        /* Tk workaround: we need apply ToggleComplexAlphaIfNeeded */
+        /* (fixed in Tk 8.5a3) */
+        Tk_PhotoSetSize(photo, block.width, block.height);
+#endif
+
     return TCL_OK;
 }
 
_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to