Index: generic/tkCanvas.c
==================================================================
--- generic/tkCanvas.c
+++ generic/tkCanvas.c
@@ -2775,11 +2775,11 @@
              * 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.
              */
 
-#ifdef _WIN32
+#if defined(NO_WINRGBFIX) && defined(_WIN32)
 #define   R_OFFSET 2
 #define   B_OFFSET 0
 #else
 #define   R_OFFSET 0
 #define   B_OFFSET 2

Index: win/tkWinDraw.c
==================================================================
--- win/tkWinDraw.c
+++ win/tkWinDraw.c
@@ -517,10 +517,13 @@
     HDC dc, dcMem;
     TkWinDCState state;
     BITMAPINFO *infoPtr;
     HBITMAP bitmap;
     char *data;
+#ifndef NO_WINRGBFIX
+    Visual *visual;
+#endif
 
     display->request++;
 
     dc = TkWinGetDrawableDC(display, d, &state);
     SetROP2(dc, tkpWinRopModes[gc->function]);
@@ -562,26 +565,41 @@
 	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,25 +455,43 @@
 	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) {

