gdi32: Simplify colour table generation.

This commit is contained in:
Huw Davies 2011-06-27 13:26:41 +01:00 committed by Alexandre Julliard
parent 90970651d3
commit 163dfd148b
1 changed files with 89 additions and 177 deletions

View File

@ -441,26 +441,6 @@ static const RGBQUAD EGAColorsQuads[16] = {
{ 0xff, 0xff, 0xff, 0x00 } { 0xff, 0xff, 0xff, 0x00 }
}; };
static const RGBTRIPLE EGAColorsTriples[16] = {
/* rgbBlue, rgbGreen, rgbRed */
{ 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x80 },
{ 0x00, 0x80, 0x00 },
{ 0x00, 0x80, 0x80 },
{ 0x80, 0x00, 0x00 },
{ 0x80, 0x00, 0x80 },
{ 0x80, 0x80, 0x00 },
{ 0x80, 0x80, 0x80 },
{ 0xc0, 0xc0, 0xc0 },
{ 0x00, 0x00, 0xff },
{ 0x00, 0xff, 0x00 },
{ 0x00, 0xff, 0xff },
{ 0xff, 0x00, 0x00 } ,
{ 0xff, 0x00, 0xff },
{ 0xff, 0xff, 0x00 },
{ 0xff, 0xff, 0xff }
};
static const RGBQUAD DefLogPaletteQuads[20] = { /* Copy of Default Logical Palette */ static const RGBQUAD DefLogPaletteQuads[20] = { /* Copy of Default Logical Palette */
/* rgbBlue, rgbGreen, rgbRed, rgbReserved */ /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
{ 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 },
@ -485,31 +465,6 @@ static const RGBQUAD DefLogPaletteQuads[20] = { /* Copy of Default Logical Palet
{ 0xff, 0xff, 0xff, 0x00 } { 0xff, 0xff, 0xff, 0x00 }
}; };
static const RGBTRIPLE DefLogPaletteTriples[20] = { /* Copy of Default Logical Palette */
/* rgbBlue, rgbGreen, rgbRed */
{ 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x80 },
{ 0x00, 0x80, 0x00 },
{ 0x00, 0x80, 0x80 },
{ 0x80, 0x00, 0x00 },
{ 0x80, 0x00, 0x80 },
{ 0x80, 0x80, 0x00 },
{ 0xc0, 0xc0, 0xc0 },
{ 0xc0, 0xdc, 0xc0 },
{ 0xf0, 0xca, 0xa6 },
{ 0xf0, 0xfb, 0xff },
{ 0xa4, 0xa0, 0xa0 },
{ 0x80, 0x80, 0x80 },
{ 0x00, 0x00, 0xf0 },
{ 0x00, 0xff, 0x00 },
{ 0x00, 0xff, 0xff },
{ 0xff, 0x00, 0x00 },
{ 0xff, 0x00, 0xff },
{ 0xff, 0xff, 0x00 },
{ 0xff, 0xff, 0xff}
};
/****************************************************************************** /******************************************************************************
* GetDIBits [GDI32.@] * GetDIBits [GDI32.@]
* *
@ -538,8 +493,8 @@ INT WINAPI GetDIBits(
WORD planes, bpp; WORD planes, bpp;
DWORD compr, size; DWORD compr, size;
void* colorPtr; void* colorPtr;
RGBTRIPLE* rgbTriples; RGBQUAD quad_buf[256];
RGBQUAD* rgbQuads; RGBQUAD* rgbQuads = quad_buf;
if (!info) return 0; if (!info) return 0;
@ -563,8 +518,7 @@ INT WINAPI GetDIBits(
} }
colorPtr = (LPBYTE) info + (WORD) info->bmiHeader.biSize; colorPtr = (LPBYTE) info + (WORD) info->bmiHeader.biSize;
rgbTriples = colorPtr; if(!core_header) rgbQuads = colorPtr;
rgbQuads = colorPtr;
/* Transfer color info */ /* Transfer color info */
@ -621,64 +575,47 @@ INT WINAPI GetDIBits(
case 1: case 1:
case 4: case 4:
case 8: case 8:
{
unsigned int colors = 1 << bpp;
if (!core_header) info->bmiHeader.biClrUsed = 0; if (!core_header) info->bmiHeader.biClrUsed = 0;
if (coloruse == DIB_PAL_COLORS)
{
WORD *index = colorPtr;
for (i = 0; i < colors; i++, index++)
*index = i;
break;
}
/* If the bitmap object already has a dib section at the /* If the bitmap object already has a dib section at the
same color depth then get the color map from it */ same color depth then get the color map from it */
if (bmp->dib && bmp->dib->dsBm.bmBitsPixel == bpp) {
if(coloruse == DIB_RGB_COLORS) {
unsigned int colors = min( bmp->nb_colors, 1 << bpp );
if (core_header) if (bmp->dib && bmp->dib->dsBm.bmBitsPixel == bpp)
{ {
/* Convert the color table (RGBQUAD to RGBTRIPLE) */ colors = min( colors, bmp->nb_colors );
RGBTRIPLE* index = rgbTriples;
for (i=0; i < colors; i++, index++) if (!core_header && colors != 1 << bpp) info->bmiHeader.biClrUsed = colors;
{
index->rgbtRed = bmp->color_table[i].rgbRed; memcpy(rgbQuads, bmp->color_table, colors * sizeof(RGBQUAD));
index->rgbtGreen = bmp->color_table[i].rgbGreen;
index->rgbtBlue = bmp->color_table[i].rgbBlue;
} }
}
else /* For color DDBs in native depth (mono DDBs always have a black/white palette):
{
if (colors != 1 << bpp) info->bmiHeader.biClrUsed = colors;
memcpy(colorPtr, bmp->color_table, colors * sizeof(RGBQUAD));
}
}
else {
WORD *index = colorPtr;
for(i = 0; i < 1 << info->bmiHeader.biBitCount; i++, index++)
*index = i;
}
}
else {
if (coloruse == DIB_PAL_COLORS) {
for (i = 0; i < (1 << bpp); i++)
((WORD *)colorPtr)[i] = (WORD)i;
}
else if(bpp > 1 && bpp == bmp->bitmap.bmBitsPixel) {
/* For color DDBs in native depth (mono DDBs always have
a black/white palette):
Generate the color map from the selected palette */ Generate the color map from the selected palette */
else if (bpp > 1 && bpp == bmp->bitmap.bmBitsPixel)
{
PALETTEENTRY palEntry[256]; PALETTEENTRY palEntry[256];
memset( palEntry, 0, sizeof(palEntry) ); memset( palEntry, 0, sizeof(palEntry) );
if (!GetPaletteEntries( dc->hPalette, 0, 1 << bmp->bitmap.bmBitsPixel, palEntry )) if (!GetPaletteEntries( dc->hPalette, 0, colors, palEntry ))
{ {
release_dc_ptr( dc ); release_dc_ptr( dc );
GDI_ReleaseObj( hbitmap ); GDI_ReleaseObj( hbitmap );
return 0; return 0;
} }
for (i = 0; i < (1 << bmp->bitmap.bmBitsPixel); i++) { for (i = 0; i < colors; i++)
if (core_header)
{
rgbTriples[i].rgbtRed = palEntry[i].peRed;
rgbTriples[i].rgbtGreen = palEntry[i].peGreen;
rgbTriples[i].rgbtBlue = palEntry[i].peBlue;
}
else
{ {
rgbQuads[i].rgbRed = palEntry[i].peRed; rgbQuads[i].rgbRed = palEntry[i].peRed;
rgbQuads[i].rgbGreen = palEntry[i].peGreen; rgbQuads[i].rgbGreen = palEntry[i].peGreen;
@ -686,65 +623,28 @@ INT WINAPI GetDIBits(
rgbQuads[i].rgbReserved = 0; rgbQuads[i].rgbReserved = 0;
} }
} }
} else {
switch (bpp) {
case 1:
if (core_header)
{
rgbTriples[0].rgbtRed = rgbTriples[0].rgbtGreen =
rgbTriples[0].rgbtBlue = 0;
rgbTriples[1].rgbtRed = rgbTriples[1].rgbtGreen =
rgbTriples[1].rgbtBlue = 0xff;
}
else else
{ {
rgbQuads[0].rgbRed = rgbQuads[0].rgbGreen = switch (bpp)
rgbQuads[0].rgbBlue = 0; {
case 1:
rgbQuads[0].rgbRed = rgbQuads[0].rgbGreen = rgbQuads[0].rgbBlue = 0;
rgbQuads[0].rgbReserved = 0; rgbQuads[0].rgbReserved = 0;
rgbQuads[1].rgbRed = rgbQuads[1].rgbGreen = rgbQuads[1].rgbRed = rgbQuads[1].rgbGreen = rgbQuads[1].rgbBlue = 0xff;
rgbQuads[1].rgbBlue = 0xff;
rgbQuads[1].rgbReserved = 0; rgbQuads[1].rgbReserved = 0;
}
break; break;
case 4: case 4:
if (core_header) memcpy(rgbQuads, EGAColorsQuads, sizeof(EGAColorsQuads));
memcpy(colorPtr, EGAColorsTriples, sizeof(EGAColorsTriples));
else
memcpy(colorPtr, EGAColorsQuads, sizeof(EGAColorsQuads));
break; break;
case 8: case 8:
{
if (core_header)
{
INT r, g, b;
RGBTRIPLE *color;
memcpy(rgbTriples, DefLogPaletteTriples,
10 * sizeof(RGBTRIPLE));
memcpy(rgbTriples + 246, DefLogPaletteTriples + 10,
10 * sizeof(RGBTRIPLE));
color = rgbTriples + 10;
for(r = 0; r <= 5; r++) /* FIXME */
for(g = 0; g <= 5; g++)
for(b = 0; b <= 5; b++) {
color->rgbtRed = (r * 0xff) / 5;
color->rgbtGreen = (g * 0xff) / 5;
color->rgbtBlue = (b * 0xff) / 5;
color++;
}
}
else
{ {
INT r, g, b; INT r, g, b;
RGBQUAD *color; RGBQUAD *color;
memcpy(rgbQuads, DefLogPaletteQuads, memcpy(rgbQuads, DefLogPaletteQuads, 10 * sizeof(RGBQUAD));
10 * sizeof(RGBQUAD)); memcpy(rgbQuads + 246, DefLogPaletteQuads + 10, 10 * sizeof(RGBQUAD));
memcpy(rgbQuads + 246, DefLogPaletteQuads + 10,
10 * sizeof(RGBQUAD));
color = rgbQuads + 10; color = rgbQuads + 10;
for(r = 0; r <= 5; r++) /* FIXME */ for(r = 0; r <= 5; r++) /* FIXME */
for(g = 0; g <= 5; g++) for(g = 0; g <= 5; g++)
@ -756,11 +656,23 @@ INT WINAPI GetDIBits(
color++; color++;
} }
} }
} }
} }
if(core_header)
{
RGBTRIPLE *triple = (RGBTRIPLE *)colorPtr;
for (i = 0; i < colors; i++)
{
triple[i].rgbtRed = rgbQuads[i].rgbRed;
triple[i].rgbtGreen = rgbQuads[i].rgbGreen;
triple[i].rgbtBlue = rgbQuads[i].rgbBlue;
} }
} }
break; break;
}
case 15: case 15:
if (info->bmiHeader.biCompression == BI_BITFIELDS) if (info->bmiHeader.biCompression == BI_BITFIELDS)