Tk Source Code

Artifact [6e6cecb8]
Login

Artifact 6e6cecb8e62c06ff14182fd29acd5c966cbc3097e1e81f9bc51f7deecbdf839b:

Attachment "tk-winrgbfix-2.diff" to ticket [21525158] added by scotty 2018-12-30 12:32:15.
Index: generic/tkCanvas.c
==================================================================
--- generic/tkCanvas.c
+++ generic/tkCanvas.c
@@ -2767,25 +2767,14 @@
             /*
              * We have a pixel with the correct byte order, so pull out the
              * colours and place them in the photo block. Perhaps we could
              * just not bother with the alpha byte because we are using
              * TK_PHOTO_COMPOSITE_SET later?
-             * ***Windows: We have to swap the red and blue values. The
-             * XImage storage is B - G - R - A which becomes a 32bit ARGB
-             * quad. However the visual mask is a 32bit ABGR quad. And
-             * Tk_PhotoPutBlock() wants R-G-B-A which is a 32bit ABGR quad.
-             * If the visual mask was correct there would be no need to
-             * swap anything here.
              */
 
-#if defined(NO_WINRGBFIX) && defined(_WIN32)
-#define   R_OFFSET 2
-#define   B_OFFSET 0
-#else
 #define   R_OFFSET 0
 #define   B_OFFSET 2
-#endif
             blockPtr.pixelPtr[blockPtr.pitch * y + blockPtr.pixelSize * x + R_OFFSET] =
                     (unsigned char)((pixel & visualPtr->red_mask) >> rshift);
             blockPtr.pixelPtr[blockPtr.pitch * y + blockPtr.pixelSize * x +1] =
                     (unsigned char)((pixel & visualPtr->green_mask) >> gshift);
             blockPtr.pixelPtr[blockPtr.pitch * y + blockPtr.pixelSize * x + B_OFFSET] =

Index: win/tkWinDraw.c
==================================================================
--- win/tkWinDraw.c
+++ win/tkWinDraw.c
@@ -557,49 +557,40 @@
 
 	if (usePalette) {
 	    infoPtr = ckalloc(sizeof(BITMAPINFOHEADER)
 		    + sizeof(RGBQUAD)*ncolors);
 	} else {
-	    infoPtr = ckalloc(sizeof(BITMAPINFOHEADER));
+	    infoPtr = ckalloc(sizeof(BITMAPINFOHEADER) + sizeof(DWORD)*4);
 	}
 
 	infoPtr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 	infoPtr->bmiHeader.biWidth = image->width;
 	infoPtr->bmiHeader.biHeight = -image->height; /* Top-down order */
 	infoPtr->bmiHeader.biPlanes = 1;
 	infoPtr->bmiHeader.biBitCount = image->bits_per_pixel;
-#ifdef NO_WINRGBFIX
-	infoPtr->bmiHeader.biCompression = BI_RGB;
-#endif
 	infoPtr->bmiHeader.biSizeImage = 0;
 	infoPtr->bmiHeader.biXPelsPerMeter = 0;
 	infoPtr->bmiHeader.biYPelsPerMeter = 0;
 	infoPtr->bmiHeader.biClrImportant = 0;
 
 	if (usePalette) {
-#ifndef NO_WINRGBFIX
 	    infoPtr->bmiHeader.biCompression = BI_RGB;
-#endif
 	    infoPtr->bmiHeader.biClrUsed = ncolors;
 	    for (i = 0; i < ncolors; i++) {
 		infoPtr->bmiColors[i].rgbBlue = GetBValue(colors[i]);
 		infoPtr->bmiColors[i].rgbGreen = GetGValue(colors[i]);
 		infoPtr->bmiColors[i].rgbRed = GetRValue(colors[i]);
 		infoPtr->bmiColors[i].rgbReserved = 0;
 	    }
 	} else {
-#ifdef NO_WINRGBFIX
-	    infoPtr->bmiHeader.biClrUsed = 0;
-#else
 	    infoPtr->bmiHeader.biCompression = BI_BITFIELDS;
 	    /* Modelled on XGetVisualInfo() in xutil.c.
 	     * We want to get the rgb masks for the default visual for the given display. */
 	    visual = DefaultVisual(display,0);
 	    *((DWORD *)((unsigned char *)infoPtr + sizeof(BITMAPINFOHEADER))) = visual->blue_mask;
 	    *((DWORD *)((unsigned char *)infoPtr + sizeof(BITMAPINFOHEADER))+1) = visual->green_mask;
 	    *((DWORD *)((unsigned char *)infoPtr + sizeof(BITMAPINFOHEADER))+2) = visual->red_mask;
-#endif
 	}
 	bitmap = CreateDIBitmap(dc, &infoPtr->bmiHeader, CBM_INIT,
 		image->data, infoPtr, DIB_RGB_COLORS);
 	ckfree(infoPtr);
     }

Index: win/tkWinX.c
==================================================================
--- win/tkWinX.c
+++ win/tkWinX.c
@@ -455,43 +455,25 @@
 	screen->root_visual->class = StaticColor;
 	screen->root_visual->map_entries = 256;
     } else if (screen->root_depth == 12) {
 	screen->root_visual->class = TrueColor;
 	screen->root_visual->map_entries = 32;
-#ifdef NO_WINRGBFIX
-	screen->root_visual->red_mask = 0xf0;
-	screen->root_visual->green_mask = 0xf000;
-	screen->root_visual->blue_mask = 0xf00000;
-#else
 	screen->root_visual->red_mask = 0xf00000;
 	screen->root_visual->green_mask = 0xf000;
 	screen->root_visual->blue_mask = 0xf0;
-#endif
     } else if (screen->root_depth == 16) {
 	screen->root_visual->class = TrueColor;
 	screen->root_visual->map_entries = 64;
-#ifdef NO_WINRGBFIX
-	screen->root_visual->red_mask = 0xf8;
-	screen->root_visual->green_mask = 0xfc00;
-	screen->root_visual->blue_mask = 0xf80000;
-#else
 	screen->root_visual->red_mask = 0xf80000;
 	screen->root_visual->green_mask = 0xfc00;
 	screen->root_visual->blue_mask = 0xf8;
-#endif
     } else if (screen->root_depth >= 24) {
 	screen->root_visual->class = TrueColor;
 	screen->root_visual->map_entries = 256;
-#ifdef NO_WINRGBFIX
-	screen->root_visual->red_mask = 0xff;
-	screen->root_visual->green_mask = 0xff00;
-	screen->root_visual->blue_mask = 0xff0000;
-#else
 	screen->root_visual->red_mask = 0xff0000;
 	screen->root_visual->green_mask = 0xff00;
 	screen->root_visual->blue_mask = 0xff;
-#endif
     }
     screen->root_visual->bits_per_rgb = screen->root_depth;
     ReleaseDC(NULL, dc);
 
     if (screen->cmap) {