diff options
Diffstat (limited to 'Build/source/utils/asymptote/patches/TkAlpha-Imaging-1.1.6.patch')
-rw-r--r-- | Build/source/utils/asymptote/patches/TkAlpha-Imaging-1.1.6.patch | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/patches/TkAlpha-Imaging-1.1.6.patch b/Build/source/utils/asymptote/patches/TkAlpha-Imaging-1.1.6.patch new file mode 100644 index 00000000000..30ee1ffa31a --- /dev/null +++ b/Build/source/utils/asymptote/patches/TkAlpha-Imaging-1.1.6.patch @@ -0,0 +1,156 @@ +diff -ru Imaging-1.1.6/Tk/tkImaging.c Imaging-1.1.6J/Tk/tkImaging.c +--- Imaging-1.1.6/Tk/tkImaging.c 2006-12-03 04:37:29.000000000 -0700 ++++ Imaging-1.1.6J/Tk/tkImaging.c 2007-11-14 20:22:02.000000000 -0700 +@@ -48,6 +48,9 @@ + for the Tcl_CreateCommand command. */ + #define USE_COMPAT_CONST + ++#define CONST84 const ++#define CONST84_RETURN const ++ + #include "tk.h" + + #include "Imaging.h" +@@ -76,6 +79,13 @@ + Imaging im; + Tk_PhotoHandle photo; + Tk_PhotoImageBlock block; ++ int renderalpha; ++ char *max_alpha_area; ++ int maxarea; ++ Tk_PhotoImageBlock run; ++ ++ unsigned char back[3]={255,255,255}; ++ char *background=getenv("PIL_BACKGROUND"); + + if (argc != 3) { + Tcl_AppendResult(interp, "usage: ", argv[0], +@@ -117,6 +127,15 @@ + + /* Mode */ + ++#ifndef MAX_ALPHA_AREA ++#define MAX_ALPHA_AREA 10000; ++#endif ++ ++ maxarea=MAX_ALPHA_AREA; ++ max_alpha_area=getenv("PIL_MAX_ALPHA_AREA"); ++ if(max_alpha_area != NULL) maxarea=atoi(max_alpha_area); ++ renderalpha=(maxarea < 0) ? 1 : (im->xsize*im->ysize < maxarea); ++ + if (strcmp(im->mode, "1") == 0 || strcmp(im->mode, "L") == 0) { + block.pixelSize = 1; + block.offset[0] = block.offset[1] = block.offset[2] = 0; +@@ -125,7 +144,10 @@ + block.offset[0] = 0; + block.offset[1] = 1; + block.offset[2] = 2; +- block.offset[3] = 0; /* no alpha (or reserved, under 8.2) */ ++ if(renderalpha && strcmp(im->mode,"RGBA") == 0) ++ block.offset[3] = 3; /* alpha (or reserved, under 8.2) */ ++ else ++ block.offset[3] = 0; /* no alpha */ + } else { + Tcl_AppendResult(interp, "Bad mode", (char*) NULL); + return TCL_ERROR; +@@ -140,15 +162,30 @@ + src_yoffset * im->linesize + + src_xoffset * im->pixelsize; + #endif +- +- if (strcmp(im->mode, "RGBA") == 0) { +- /* Copy non-transparent pixels to photo image */ ++ if (!renderalpha && strcmp(im->mode, "RGBA") == 0) { ++ int bytes =block.height*block.pitch; ++ unsigned char *pixelPtr; + int x, y; +- Tk_PhotoImageBlock run; ++ int j; ++ ++ /* Buffer image block for pseudo-antialiasing */ ++ if (bytes <= 0) ++ bytes=1; ++ pixelPtr=(unsigned char *) malloc(bytes); ++ if (!pixelPtr) { ++ Tcl_AppendResult(interp, "bad display memory", (char*) NULL); ++ return TCL_ERROR; ++ } + +- /* Clear current contents */ +- Tk_PhotoBlank(photo); ++ /* Copy non-transparent pixels to photo image */ + ++ if(background && strlen(background) == 6) { ++ for(j=0; j < 3; ++j) { ++ char h[3]={background[2*j],background[2*j+1],0}; ++ back[j]=strtol(h,NULL,16); ++ } ++ } ++ + /* Setup run descriptor */ + run.height = 1; + run.pitch = block.pitch; +@@ -161,13 +198,19 @@ + /* Copy opaque runs to photo image */ + for (y = 0; y < block.height; y++) { + unsigned char* p = block.pixelPtr + y*block.pitch; +- unsigned char* s = p; ++ unsigned char* q = pixelPtr + y*block.pitch; ++ unsigned char* s = q; + int w = 0; + for (x = 0; x < block.width; x++) { + if (p[3]) { + /* opaque: add pixel to current run */ +- if (w == 0) +- s = p; ++ double opacity=p[3]/255.0; ++ double transparency=1.0-opacity; ++ q[0]=(int) (opacity*p[0]+transparency*back[0]); ++ q[1]=(int) (opacity*p[1]+transparency*back[1]); ++ q[2]=(int) (opacity*p[2]+transparency*back[2]); ++ if (w == 0) ++ s = q; + w = w + 1; + } else if (s) { + /* copy run to photo image */ +@@ -179,6 +222,7 @@ + w = 0; + } + p += block.pixelSize; ++ q += block.pixelSize; + } + if (w > 0) { + /* copy final run, if any */ +@@ -188,10 +232,15 @@ + } + } + +- } else +- +- /* Copy opaque block to photo image, and leave the rest to TK */ +- Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height); ++ } else { ++ /* Copy block to photo image, and leave the rest to TK */ ++ Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height); ++ ++ if (strcmp(im->mode, "RGBA") == 0) ++ /* Tk workaround: we need apply ToggleComplexAlphaIfNeeded */ ++ /* (fixed in Tk 8.5a3) */ ++ Tk_PhotoSetSize(photo, block.width, block.height); ++ } + + return TCL_OK; + } +diff -ru Imaging-1.1.6/_imagingtk.c Imaging-1.1.6J/_imagingtk.c +--- Imaging-1.1.6/_imagingtk.c 2006-12-03 04:51:25.000000000 -0700 ++++ Imaging-1.1.6J/_imagingtk.c 2007-11-14 17:42:54.000000000 -0700 +@@ -17,6 +17,9 @@ + #include "Python.h" + #include "Imaging.h" + ++#define CONST84 const ++#define CONST84_RETURN const ++ + #include "tk.h" + + /* must link with Tk/tkImaging.c */ |