Alexandre Julliard : gdi32: Remove the nb_colors fields in the bitmap object, we always allocate a full size color table.

Alexandre Julliard julliard at winehq.org
Fri Dec 9 14:41:36 CST 2011


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Dec  9 20:00:36 2011 +0100

gdi32: Remove the nb_colors fields in the bitmap object, we always allocate a full size color table.

---

 dlls/gdi32/bitmap.c      |    1 -
 dlls/gdi32/brush.c       |    6 +++---
 dlls/gdi32/dib.c         |   15 ++++++---------
 dlls/gdi32/dibdrv/dc.c   |    2 +-
 dlls/gdi32/gdi_private.h |    3 +--
 5 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/dlls/gdi32/bitmap.c b/dlls/gdi32/bitmap.c
index 510d5f5..af9012b 100644
--- a/dlls/gdi32/bitmap.c
+++ b/dlls/gdi32/bitmap.c
@@ -300,7 +300,6 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp )
     bmpobj->funcs = &null_driver;
     bmpobj->dib = NULL;
     bmpobj->color_table = NULL;
-    bmpobj->nb_colors = 0;
 
     if (!(hbitmap = alloc_gdi_handle( &bmpobj->header, OBJ_BITMAP, &bitmap_funcs )))
     {
diff --git a/dlls/gdi32/brush.c b/dlls/gdi32/brush.c
index a360a1d..34d3a57 100644
--- a/dlls/gdi32/brush.c
+++ b/dlls/gdi32/brush.c
@@ -122,10 +122,10 @@ static BOOL copy_bitmap( BRUSHOBJ *brush, HBITMAP bitmap )
                       bitmap_info_size( (BITMAPINFO *)&bmp->dib->dsBmih, DIB_RGB_COLORS ));
     if (!info) goto done;
     info->bmiHeader = bmp->dib->dsBmih;
-    if (bmp->dib->dsBmih.biCompression == BI_BITFIELDS)
+    if (info->bmiHeader.biCompression == BI_BITFIELDS)
         memcpy( &info->bmiHeader + 1, bmp->dib->dsBitfields, sizeof(bmp->dib->dsBitfields) );
-    else if (bmp->nb_colors)
-        memcpy( &info->bmiHeader + 1, bmp->color_table, bmp->nb_colors * sizeof(RGBQUAD) );
+    else if (info->bmiHeader.biClrUsed)
+        memcpy( &info->bmiHeader + 1, bmp->color_table, info->bmiHeader.biClrUsed * sizeof(RGBQUAD) );
     if (!(brush->bits.ptr = HeapAlloc( GetProcessHeap(), 0, get_dib_image_size( info ))))
     {
         HeapFree( GetProcessHeap(), 0, info );
diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c
index 4c75fc2..b2d18cc 100644
--- a/dlls/gdi32/dib.c
+++ b/dlls/gdi32/dib.c
@@ -894,11 +894,10 @@ UINT WINAPI SetDIBColorTable( HDC hdc, UINT startpos, UINT entries, CONST RGBQUA
         /* Check if currently selected bitmap is a DIB */
         if (bitmap->color_table)
         {
-            if (startpos < bitmap->nb_colors)
+            if (startpos < bitmap->dib->dsBmih.biClrUsed)
             {
-                if (startpos + entries > bitmap->nb_colors) entries = bitmap->nb_colors - startpos;
-                memcpy(bitmap->color_table + startpos, colors, entries * sizeof(RGBQUAD));
-                result = entries;
+                result = min( entries, bitmap->dib->dsBmih.biClrUsed - startpos );
+                memcpy(bitmap->color_table + startpos, colors, result * sizeof(RGBQUAD));
             }
         }
         GDI_ReleaseObj( dc->hBitmap );
@@ -925,11 +924,10 @@ UINT WINAPI GetDIBColorTable( HDC hdc, UINT startpos, UINT entries, RGBQUAD *col
         /* Check if currently selected bitmap is a DIB */
         if (bitmap->color_table)
         {
-            if (startpos < bitmap->nb_colors)
+            if (startpos < bitmap->dib->dsBmih.biClrUsed)
             {
-                if (startpos + entries > bitmap->nb_colors) entries = bitmap->nb_colors - startpos;
-                memcpy(colors, bitmap->color_table + startpos, entries * sizeof(RGBQUAD));
-                result = entries;
+                result = min( entries, bitmap->dib->dsBmih.biClrUsed - startpos );
+                memcpy(colors, bitmap->color_table + startpos, result * sizeof(RGBQUAD));
             }
         }
         GDI_ReleaseObj( dc->hBitmap );
@@ -1534,7 +1532,6 @@ HBITMAP WINAPI CreateDIBSection(HDC hdc, CONST BITMAPINFO *bmi, UINT usage,
         bmp->dib = dib;
         bmp->funcs = physdev->funcs;
         bmp->color_table = color_table;
-        bmp->nb_colors = dib->dsBmih.biClrUsed;
         GDI_ReleaseObj( ret );
 
         if (!physdev->funcs->pCreateDIBSection( physdev, ret, info, usage ))
diff --git a/dlls/gdi32/dibdrv/dc.c b/dlls/gdi32/dibdrv/dc.c
index 384cb5e..44a4075 100644
--- a/dlls/gdi32/dibdrv/dc.c
+++ b/dlls/gdi32/dibdrv/dc.c
@@ -206,7 +206,7 @@ BOOL init_dib_info_from_bitmapobj(dib_info *dib, BITMAPOBJ *bmp, enum dib_info_f
                                               flags | private_color_table );
     }
     return init_dib_info( dib, &bmp->dib->dsBmih, bmp->dib->dsBitfields,
-                          bmp->color_table, bmp->nb_colors, bmp->dib->dsBm.bmBits, flags );
+                          bmp->color_table, bmp->dib->dsBmih.biClrUsed, bmp->dib->dsBm.bmBits, flags );
 }
 
 static void clear_dib_info(dib_info *dib)
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index 23c8f38..6d47143 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -179,8 +179,7 @@ typedef struct tagBITMAPOBJ
     const struct gdi_dc_funcs *funcs; /* DC function table */
     /* For device-independent bitmaps: */
     DIBSECTION         *dib;
-    RGBQUAD            *color_table;  /* DIB color table if <= 8bpp */
-    UINT                nb_colors;    /* number of colors in table */
+    RGBQUAD            *color_table;  /* DIB color table if <= 8bpp (always 1 << bpp in size) */
 } BITMAPOBJ;
 
 /* bidi.c */




More information about the wine-cvs mailing list