diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c index a590b94c82c..99baf673f3d 100644 --- a/dlls/gdi32/dib.c +++ b/dlls/gdi32/dib.c @@ -91,10 +91,7 @@ int bitmap_info_size( const BITMAPINFO * info, WORD coloruse ) } else /* assume BITMAPINFOHEADER */ { - colors = info->bmiHeader.biClrUsed; - if (colors > 256) colors = 256; - if (!colors && (info->bmiHeader.biBitCount <= 8)) - colors = 1 << info->bmiHeader.biBitCount; + colors = get_dib_num_of_colors( info ); if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3; size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) ); 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 ) { PALETTEENTRY palEntry[256]; - int i, colors = (info->bmiHeader.biBitCount > 8) ? 0 : 1 << info->bmiHeader.biBitCount; - - if (info->bmiHeader.biClrUsed) colors = info->bmiHeader.biClrUsed; + int i, colors = get_dib_num_of_colors( info ); 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) { - 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); assert( src->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) ); - if (src->bmiHeader.biClrUsed) colors = src->bmiHeader.biClrUsed; - if (dst->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) { BITMAPCOREINFO *core = (BITMAPCOREINFO *)dst; @@ -1219,8 +1212,7 @@ static void DIB_CopyColorTable( DC *dc, BITMAPOBJ *bmp, WORD coloruse, const BIT } else { - colors = info->bmiHeader.biClrUsed; - if (!colors) colors = 1 << info->bmiHeader.biBitCount; + colors = get_dib_num_of_colors( info ); } if (colors > 256) { diff --git a/dlls/gdi32/dibdrv/dc.c b/dlls/gdi32/dibdrv/dc.c index 50ceffeba0c..aa748590e8f 100644 --- a/dlls/gdi32/dibdrv/dc.c +++ b/dlls/gdi32/dibdrv/dc.c @@ -163,7 +163,7 @@ BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD u DWORD *masks = NULL; RGBQUAD *color_table = NULL, pal_table[256]; 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) { @@ -171,7 +171,6 @@ BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD u ptr += 3 * sizeof(DWORD); } - if(!num_colors && bi->biBitCount <= 8) num_colors = 1 << bi->biBitCount; if(num_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) { - unsigned int colors = 0; + unsigned int colors = get_dib_num_of_colors( info ); void *colorptr = (char *)&info->bmiHeader + info->bmiHeader.biSize; 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 ); } diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h index b825df9225d..013eb44123d 100644 --- a/dlls/gdi32/gdi_private.h +++ b/dlls/gdi32/gdi_private.h @@ -564,6 +564,12 @@ static inline int get_dib_image_size( const BITMAPINFO *info ) * 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; #endif /* __WINE_GDI_PRIVATE_H */