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

Alexandre Julliard julliard at winehq.org
Thu Jul 28 13:55:44 CDT 2011


Module: wine
Branch: master
Commit: 3460665c50cafb5af8e7a8d4d82d6b4aebbbb328
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3460665c50cafb5af8e7a8d4d82d6b4aebbbb328

Author: Huw Davies <huw at codeweavers.com>
Date:   Thu Jul 28 15:34:14 2011 +0100

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

---

 dlls/gdi32/dib.c         |   16 ++++------------
 dlls/gdi32/dibdrv/dc.c   |   10 ++--------
 dlls/gdi32/gdi_private.h |    6 ++++++
 3 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c
index a590b94..99baf67 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 50ceffe..aa74859 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 b825df9..013eb44 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 */




More information about the wine-cvs mailing list