gdi32: Add an inline helper to return the number of colour entries in a dib.

This commit is contained in:
Huw Davies 2011-07-28 15:34:14 +01:00 committed by Alexandre Julliard
parent fccd4e29c9
commit 3460665c50
3 changed files with 12 additions and 20 deletions

View File

@ -91,10 +91,7 @@ int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
} }
else /* assume BITMAPINFOHEADER */ else /* assume BITMAPINFOHEADER */
{ {
colors = info->bmiHeader.biClrUsed; colors = get_dib_num_of_colors( info );
if (colors > 256) colors = 256;
if (!colors && (info->bmiHeader.biBitCount <= 8))
colors = 1 << info->bmiHeader.biBitCount;
if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3; if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) ); size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) );
return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD)); return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
@ -212,9 +209,7 @@ static BOOL bitmapinfo_from_user_bitmapinfo( BITMAPINFO *dst, const BITMAPINFO *
static int fill_color_table_from_palette( BITMAPINFO *info, DC *dc ) static int fill_color_table_from_palette( BITMAPINFO *info, DC *dc )
{ {
PALETTEENTRY palEntry[256]; PALETTEENTRY palEntry[256];
int i, colors = (info->bmiHeader.biBitCount > 8) ? 0 : 1 << info->bmiHeader.biBitCount; int i, colors = get_dib_num_of_colors( info );
if (info->bmiHeader.biClrUsed) colors = info->bmiHeader.biClrUsed;
if (!colors) return 0; if (!colors) return 0;
@ -809,13 +804,11 @@ static int fill_query_info( BITMAPINFO *info, BITMAPOBJ *bmp )
*/ */
static void copy_color_info(BITMAPINFO *dst, const BITMAPINFO *src, UINT coloruse) static void copy_color_info(BITMAPINFO *dst, const BITMAPINFO *src, UINT coloruse)
{ {
unsigned int colors = src->bmiHeader.biBitCount > 8 ? 0 : 1 << src->bmiHeader.biBitCount; unsigned int colors = get_dib_num_of_colors( src );
RGBQUAD *src_colors = (RGBQUAD *)((char *)src + src->bmiHeader.biSize); RGBQUAD *src_colors = (RGBQUAD *)((char *)src + src->bmiHeader.biSize);
assert( src->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) ); assert( src->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) );
if (src->bmiHeader.biClrUsed) colors = src->bmiHeader.biClrUsed;
if (dst->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) if (dst->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
{ {
BITMAPCOREINFO *core = (BITMAPCOREINFO *)dst; BITMAPCOREINFO *core = (BITMAPCOREINFO *)dst;
@ -1219,8 +1212,7 @@ static void DIB_CopyColorTable( DC *dc, BITMAPOBJ *bmp, WORD coloruse, const BIT
} }
else else
{ {
colors = info->bmiHeader.biClrUsed; colors = get_dib_num_of_colors( info );
if (!colors) colors = 1 << info->bmiHeader.biBitCount;
} }
if (colors > 256) { if (colors > 256) {

View File

@ -163,7 +163,7 @@ BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD u
DWORD *masks = NULL; DWORD *masks = NULL;
RGBQUAD *color_table = NULL, pal_table[256]; RGBQUAD *color_table = NULL, pal_table[256];
BYTE *ptr = (BYTE*)bi + bi->biSize; BYTE *ptr = (BYTE*)bi + bi->biSize;
int num_colors = bi->biClrUsed; int num_colors = get_dib_num_of_colors( (const BITMAPINFO *)bi );
if(bi->biCompression == BI_BITFIELDS) if(bi->biCompression == BI_BITFIELDS)
{ {
@ -171,7 +171,6 @@ BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD u
ptr += 3 * sizeof(DWORD); ptr += 3 * sizeof(DWORD);
} }
if(!num_colors && bi->biBitCount <= 8) num_colors = 1 << bi->biBitCount;
if(num_colors) if(num_colors)
{ {
if(usage == DIB_PAL_COLORS) if(usage == DIB_PAL_COLORS)
@ -202,15 +201,10 @@ BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD u
BOOL init_dib_info_from_bitmapinfo(dib_info *dib, const BITMAPINFO *info, void *bits, enum dib_info_flags flags) BOOL init_dib_info_from_bitmapinfo(dib_info *dib, const BITMAPINFO *info, void *bits, enum dib_info_flags flags)
{ {
unsigned int colors = 0; unsigned int colors = get_dib_num_of_colors( info );
void *colorptr = (char *)&info->bmiHeader + info->bmiHeader.biSize; void *colorptr = (char *)&info->bmiHeader + info->bmiHeader.biSize;
const DWORD *bitfields = (info->bmiHeader.biCompression == BI_BITFIELDS) ? (DWORD *)colorptr : NULL; const DWORD *bitfields = (info->bmiHeader.biCompression == BI_BITFIELDS) ? (DWORD *)colorptr : NULL;
if (info->bmiHeader.biBitCount <= 8)
{
colors = 1 << info->bmiHeader.biBitCount;
if (info->bmiHeader.biClrUsed) colors = info->bmiHeader.biClrUsed;
}
return init_dib_info( dib, &info->bmiHeader, bitfields, colors ? colorptr : NULL, colors, bits, flags ); return init_dib_info( dib, &info->bmiHeader, bitfields, colors ? colorptr : NULL, colors, bits, flags );
} }

View File

@ -564,6 +564,12 @@ static inline int get_dib_image_size( const BITMAPINFO *info )
* abs( info->bmiHeader.biHeight ); * abs( info->bmiHeader.biHeight );
} }
static inline int get_dib_num_of_colors( const BITMAPINFO *info )
{
if (info->bmiHeader.biClrUsed) return min( info->bmiHeader.biClrUsed, 256 );
return info->bmiHeader.biBitCount > 8 ? 0 : 1 << info->bmiHeader.biBitCount;
}
extern void free_heap_bits( struct gdi_image_bits *bits ) DECLSPEC_HIDDEN; extern void free_heap_bits( struct gdi_image_bits *bits ) DECLSPEC_HIDDEN;
#endif /* __WINE_GDI_PRIVATE_H */ #endif /* __WINE_GDI_PRIVATE_H */