diff --git a/objects/dib.c b/objects/dib.c index 955238163ff..a19f841534c 100644 --- a/objects/dib.c +++ b/objects/dib.c @@ -606,7 +606,7 @@ static void DIB_SetImageBits_RLE8( int lines, const BYTE *bits, DWORD width, BYTE length; /* The length pf a run */ BYTE color_index; /* index into colors[] as read from bits */ BYTE escape_code; /* See enum Rle8_EscapeCodes.*/ - WORD color; /* value of colour[color_index] */ + int color; /* value of colour[color_index] */ if (lines == 0) /* Let's hope this doesn't happen. */ return; @@ -1539,8 +1539,11 @@ INT32 WINAPI GetDIBits32( /* Transfer color info */ if (info->bmiHeader.biBitCount<=8) { + int colors = info->bmiHeader.biClrUsed; + if (!colors && (info->bmiHeader.biBitCount <= 8)) + colors = 1 << info->bmiHeader.biBitCount; palEntry = palette->logpalette.palPalEntry; - for (i = 0; i < info->bmiHeader.biClrUsed; i++, palEntry++) + for (i = 0; i < colors; i++, palEntry++) { if (coloruse == DIB_RGB_COLORS) { @@ -2110,3 +2113,68 @@ void DIB_DeleteDIBSection( BITMAPOBJ *bmp ) } } +/*********************************************************************** + * DIB_FixColorsToLoadflags + * + * Change color table entries when LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS + * are in loadflags + */ +void DIB_FixColorsToLoadflags(BITMAPINFO * bmi, UINT32 loadflags, BYTE pix) +{ + int colors; + COLORREF c_W, c_S, c_F, c_L, c_C; + int incr,i; + RGBQUAD *ptr; + + if (bmi->bmiHeader.biBitCount > 8) return; + if (bmi->bmiHeader.biSize == sizeof(BITMAPINFOHEADER)) incr = 4; + else if (bmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) incr = 3; + else { + WARN(bitmap, "Wrong bitmap header size!\n"); + return; + } + colors = bmi->bmiHeader.biClrUsed; + if (!colors && (bmi->bmiHeader.biBitCount <= 8)) + colors = 1 << bmi->bmiHeader.biBitCount; + c_W = GetSysColor32(COLOR_WINDOW); + c_S = GetSysColor32(COLOR_3DSHADOW); + c_F = GetSysColor32(COLOR_3DFACE); + c_L = GetSysColor32(COLOR_3DLIGHT); + if (loadflags & LR_LOADTRANSPARENT) { + switch (bmi->bmiHeader.biBitCount) { + case 1: pix = pix >> 7; break; + case 4: pix = pix >> 4; break; + case 8: break; + default: + WARN(bitmap, "(%d): Unsupported depth\n", bmi->bmiHeader.biBitCount); + return; + } + if (pix >= colors) { + WARN(bitmap, "pixel has color index greater than biClrUsed!\n"); + return; + } + if (loadflags & LR_LOADMAP3DCOLORS) c_W = c_F; + ptr = (RGBQUAD*)((char*)bmi->bmiColors+pix*incr); + ptr->rgbBlue = GetBValue(c_W); + ptr->rgbGreen = GetGValue(c_W); + ptr->rgbRed = GetRValue(c_W); + } + if (loadflags & LR_LOADMAP3DCOLORS) + for (i=0; ibmiColors+i*incr); + c_C = RGB(ptr->rgbRed, ptr->rgbGreen, ptr->rgbBlue); + if (c_C == RGB(128, 128, 128)) { + ptr->rgbRed = GetRValue(c_S); + ptr->rgbGreen = GetGValue(c_S); + ptr->rgbBlue = GetBValue(c_S); + } else if (c_C == RGB(192, 192, 192)) { + ptr->rgbRed = GetRValue(c_F); + ptr->rgbGreen = GetGValue(c_F); + ptr->rgbBlue = GetBValue(c_F); + } else if (c_C == RGB(223, 223, 223)) { + ptr->rgbRed = GetRValue(c_L); + ptr->rgbGreen = GetGValue(c_L); + ptr->rgbBlue = GetBValue(c_L); + } + } +}