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. */ -#ifdef _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 @@ -517,10 +517,11 @@ HDC dc, dcMem; TkWinDCState state; BITMAPINFO *infoPtr; HBITMAP bitmap; char *data; + Visual *visual; display->request++; dc = TkWinGetDrawableDC(display, d, &state); SetROP2(dc, tkpWinRopModes[gc->function]); @@ -554,34 +555,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; - infoPtr->bmiHeader.biCompression = BI_RGB; infoPtr->bmiHeader.biSizeImage = 0; infoPtr->bmiHeader.biXPelsPerMeter = 0; infoPtr->bmiHeader.biYPelsPerMeter = 0; infoPtr->bmiHeader.biClrImportant = 0; if (usePalette) { + infoPtr->bmiHeader.biCompression = BI_RGB; 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 { - infoPtr->bmiHeader.biClrUsed = 0; + 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; } 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,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; - screen->root_visual->red_mask = 0xf0; + screen->root_visual->red_mask = 0xf00000; screen->root_visual->green_mask = 0xf000; - screen->root_visual->blue_mask = 0xf00000; + screen->root_visual->blue_mask = 0xf0; } else if (screen->root_depth == 16) { screen->root_visual->class = TrueColor; screen->root_visual->map_entries = 64; - screen->root_visual->red_mask = 0xf8; + screen->root_visual->red_mask = 0xf80000; screen->root_visual->green_mask = 0xfc00; - screen->root_visual->blue_mask = 0xf80000; + screen->root_visual->blue_mask = 0xf8; } else if (screen->root_depth >= 24) { screen->root_visual->class = TrueColor; screen->root_visual->map_entries = 256; - screen->root_visual->red_mask = 0xff; + screen->root_visual->red_mask = 0xff0000; screen->root_visual->green_mask = 0xff00; - screen->root_visual->blue_mask = 0xff0000; + screen->root_visual->blue_mask = 0xff; } screen->root_visual->bits_per_rgb = screen->root_depth; ReleaseDC(NULL, dc); if (screen->cmap != None) {