[PATCH] wined3d: Store RGBQUADs in palettes (try 2).

Stefan Dösinger stefan at codeweavers.com
Wed May 7 11:02:14 CDT 2014


This supersedes patch 104460.

Try 2: Remove strange count + 0 construct. Not sure why I wrote that.
Thanks to Nikolay for catching it.

We never need PALETTEENTRYs, only RGBQUADs to pass to SetDIBColorTable.
---
 dlls/wined3d/palette.c         | 38 ++++++++++++++-------
 dlls/wined3d/surface.c         | 77 +++++++++++-------------------------------
 dlls/wined3d/utils.c           | 10 +++---
 dlls/wined3d/wined3d_private.h |  2 +-
 4 files changed, 52 insertions(+), 75 deletions(-)

diff --git a/dlls/wined3d/palette.c b/dlls/wined3d/palette.c
index 5572d10..e103b5b 100644
--- a/dlls/wined3d/palette.c
+++ b/dlls/wined3d/palette.c
@@ -53,6 +53,7 @@ ULONG CDECL wined3d_palette_decref(struct wined3d_palette *palette)
 HRESULT CDECL wined3d_palette_get_entries(const struct wined3d_palette *palette,
         DWORD flags, DWORD start, DWORD count, PALETTEENTRY *entries)
 {
+    unsigned int i;
     TRACE("palette %p, flags %#x, start %u, count %u, entries %p.\n",
             palette, flags, start, count, entries);
 
@@ -64,13 +65,20 @@ HRESULT CDECL wined3d_palette_get_entries(const struct wined3d_palette *palette,
     if (palette->flags & WINED3D_PALETTE_8BIT_ENTRIES)
     {
         BYTE *entry = (BYTE *)entries;
-        unsigned int i;
 
         for (i = start; i < count + start; ++i)
-            *entry++ = palette->palents[i].peRed;
+            *entry++ = palette->colors[i].rgbRed;
     }
     else
-        memcpy(entries, palette->palents + start, count * sizeof(*entries));
+    {
+        for (i = 0; i < count; ++i)
+        {
+            entries[i].peRed = palette->colors[i + start].rgbRed;
+            entries[i].peGreen = palette->colors[i + start].rgbGreen;
+            entries[i].peBlue = palette->colors[i + start].rgbBlue;
+            entries[i].peFlags = palette->colors[i + start].rgbReserved;
+        }
+    }
 
     return WINED3D_OK;
 }
@@ -79,6 +87,7 @@ HRESULT CDECL wined3d_palette_set_entries(struct wined3d_palette *palette,
         DWORD flags, DWORD start, DWORD count, const PALETTEENTRY *entries)
 {
     struct wined3d_resource *resource;
+    unsigned int i;
 
     TRACE("palette %p, flags %#x, start %u, count %u, entries %p.\n",
             palette, flags, start, count, entries);
@@ -87,26 +96,31 @@ HRESULT CDECL wined3d_palette_set_entries(struct wined3d_palette *palette,
     if (palette->flags & WINED3D_PALETTE_8BIT_ENTRIES)
     {
         const BYTE *entry = (const BYTE *)entries;
-        unsigned int i;
 
         for (i = start; i < count + start; ++i)
-            palette->palents[i].peRed = *entry++;
+            palette->colors[i].rgbRed = *entry++;
     }
     else
     {
-        memcpy(palette->palents + start, entries, count * sizeof(*palette->palents));
+        for (i = 0; i < count; ++i)
+        {
+            palette->colors[i + start].rgbRed = entries[i].peRed;
+            palette->colors[i + start].rgbGreen = entries[i].peGreen;
+            palette->colors[i + start].rgbBlue = entries[i].peBlue;
+            palette->colors[i + start].rgbReserved = entries[i].peFlags;
+        }
 
         /* When WINEDDCAPS_ALLOW256 isn't set we need to override entry 0 with black and 255 with white */
         if (!(palette->flags & WINED3D_PALETTE_ALLOW_256))
         {
             TRACE("WINED3D_PALETTE_ALLOW_256 not set, overriding palette entry 0 with black and 255 with white.\n");
-            palette->palents[0].peRed = 0;
-            palette->palents[0].peGreen = 0;
-            palette->palents[0].peBlue = 0;
+            palette->colors[0].rgbRed = 0;
+            palette->colors[0].rgbGreen = 0;
+            palette->colors[0].rgbBlue = 0;
 
-            palette->palents[255].peRed = 255;
-            palette->palents[255].peGreen = 255;
-            palette->palents[255].peBlue = 255;
+            palette->colors[255].rgbRed = 255;
+            palette->colors[255].rgbGreen = 255;
+            palette->colors[255].rgbBlue = 255;
         }
     }
 
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index dc8c595..4b40944 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -789,19 +789,8 @@ static void surface_realize_palette(struct wined3d_surface *surface)
 
     if (surface->flags & SFLAG_DIBSECTION)
     {
-        RGBQUAD col[256];
-        unsigned int i;
-
         TRACE("Updating the DC's palette.\n");
-
-        for (i = 0; i < 256; ++i)
-        {
-            col[i].rgbRed   = palette->palents[i].peRed;
-            col[i].rgbGreen = palette->palents[i].peGreen;
-            col[i].rgbBlue  = palette->palents[i].peBlue;
-            col[i].rgbReserved = 0;
-        }
-        SetDIBColorTable(surface->hDC, 0, 256, col);
+        SetDIBColorTable(surface->hDC, 0, 256, palette->colors);
     }
 
     /* Propagate the changes to the drawable when we have a palette. */
@@ -1122,9 +1111,9 @@ static BOOL surface_convert_color_to_float(const struct wined3d_surface *surface
         case WINED3DFMT_P8_UINT:
             if (surface->palette)
             {
-                float_color->r = surface->palette->palents[color].peRed / 255.0f;
-                float_color->g = surface->palette->palents[color].peGreen / 255.0f;
-                float_color->b = surface->palette->palents[color].peBlue / 255.0f;
+                float_color->r = surface->palette->colors[color].rgbRed / 255.0f;
+                float_color->g = surface->palette->colors[color].rgbGreen / 255.0f;
+                float_color->b = surface->palette->colors[color].rgbBlue / 255.0f;
             }
             else
             {
@@ -1393,19 +1382,8 @@ static void gdi_surface_realize_palette(struct wined3d_surface *surface)
 
     if (surface->flags & SFLAG_DIBSECTION)
     {
-        RGBQUAD col[256];
-        unsigned int i;
-
         TRACE("Updating the DC's palette.\n");
-
-        for (i = 0; i < 256; ++i)
-        {
-            col[i].rgbRed = palette->palents[i].peRed;
-            col[i].rgbGreen = palette->palents[i].peGreen;
-            col[i].rgbBlue = palette->palents[i].peBlue;
-            col[i].rgbReserved = 0;
-        }
-        SetDIBColorTable(surface->hDC, 0, 256, col);
+        SetDIBColorTable(surface->hDC, 0, 256, palette->colors);
     }
 
     /* Update the image because of the palette change. Some games like e.g.
@@ -3177,11 +3155,11 @@ HRESULT CDECL wined3d_surface_getdc(struct wined3d_surface *surface, HDC *dc)
         /* GetDC on palettized formats is unsupported in D3D9, and the method
          * is missing in D3D8, so this should only be used for DX <=7
          * surfaces (with non-device palettes). */
-        const PALETTEENTRY *pal = NULL;
+        const RGBQUAD *colors = NULL;
 
         if (surface->palette)
         {
-            pal = surface->palette->palents;
+            colors = surface->palette->colors;
         }
         else
         {
@@ -3189,23 +3167,11 @@ HRESULT CDECL wined3d_surface_getdc(struct wined3d_surface *surface, HDC *dc)
             struct wined3d_surface *dds_primary = swapchain->front_buffer;
 
             if (dds_primary && dds_primary->palette)
-                pal = dds_primary->palette->palents;
+                colors = dds_primary->palette->colors;
         }
 
-        if (pal)
-        {
-            RGBQUAD col[256];
-            unsigned int i;
-
-            for (i = 0; i < 256; ++i)
-            {
-                col[i].rgbRed = pal[i].peRed;
-                col[i].rgbGreen = pal[i].peGreen;
-                col[i].rgbBlue = pal[i].peBlue;
-                col[i].rgbReserved = 0;
-            }
-            SetDIBColorTable(surface->hDC, 0, 256, col);
-        }
+        if (colors)
+            SetDIBColorTable(surface->hDC, 0, 256, colors);
     }
 
     surface->flags |= SFLAG_DCINUSE;
@@ -3417,20 +3383,17 @@ static void read_from_framebuffer(struct wined3d_surface *surface, DWORD dst_loc
      * the index is stored in the alpha component so no conversion is needed. */
     if (surface->resource.format->id == WINED3DFMT_P8_UINT && !swapchain_is_p8(context->swapchain))
     {
-        const PALETTEENTRY *pal = NULL;
+        const RGBQUAD *colors = NULL;
         DWORD width = pitch / 3;
         int x, y, c;
 
-        if (surface->palette)
-        {
-            pal = surface->palette->palents;
-        }
-        else
+        if (!surface->palette)
         {
             ERR("Palette is missing, cannot perform inverse palette lookup\n");
             HeapFree(GetProcessHeap(), 0, mem);
             return;
         }
+        colors = surface->palette->colors;
 
         for (y = 0; y < surface->resource.height; y++)
         {
@@ -3443,9 +3406,9 @@ static void read_from_framebuffer(struct wined3d_surface *surface, DWORD dst_loc
 
                 for (c = 0; c < 256; c++)
                 {
-                    if (*red == pal[c].peRed
-                            && *green == pal[c].peGreen
-                            && *blue == pal[c].peBlue)
+                    if (*red == colors[c].rgbRed
+                            && *green == colors[c].rgbGreen
+                            && *blue == colors[c].rgbBlue)
                     {
                         *((BYTE *)data.addr + y * width + x) = c;
                         break;
@@ -3590,9 +3553,9 @@ void d3dfmt_p8_init_palette(const struct wined3d_surface *surface, BYTE table[25
         /* Get the surface's palette */
         for (i = 0; i < 256; ++i)
         {
-            table[i][0] = pal->palents[i].peRed;
-            table[i][1] = pal->palents[i].peGreen;
-            table[i][2] = pal->palents[i].peBlue;
+            table[i][0] = pal->colors[i].rgbRed;
+            table[i][1] = pal->colors[i].rgbGreen;
+            table[i][2] = pal->colors[i].rgbBlue;
 
             /* When index_in_alpha is set the palette index is stored in the
              * alpha component. In case of a readback we can then read
@@ -3605,7 +3568,7 @@ void d3dfmt_p8_init_palette(const struct wined3d_surface *surface, BYTE table[25
             else if (colorkey && color_in_range(&surface->container->src_blt_color_key, i))
                 table[i][3] = 0x00;
             else if (pal->flags & WINED3D_PALETTE_ALPHA)
-                table[i][3] = pal->palents[i].peFlags;
+                table[i][3] = pal->colors[i].rgbReserved;
             else
                 table[i][3] = 0xff;
         }
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 78060e2..ad15c05 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -3089,7 +3089,7 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface, c
 
     if (format->id == WINED3DFMT_P8_UINT)
     {
-        PALETTEENTRY *e;
+        const RGBQUAD *e;
         BYTE r, g, b, a;
 
         if (!surface->palette)
@@ -3103,16 +3103,16 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface, c
         b = (BYTE)((color->b * 255.0f) + 0.5f);
         a = (BYTE)((color->a * 255.0f) + 0.5f);
 
-        e = &surface->palette->palents[a];
-        if (e->peRed == r && e->peGreen == g && e->peBlue == b)
+        e = &surface->palette->colors[a];
+        if (e->rgbRed == r && e->rgbGreen == g && e->rgbBlue == b)
             return a;
 
         WARN("Alpha didn't match index, searching full palette.\n");
 
         for (i = 0; i < 256; ++i)
         {
-            e = &surface->palette->palents[i];
-            if (e->peRed == r && e->peGreen == g && e->peBlue == b)
+            e = &surface->palette->colors[i];
+            if (e->rgbRed == r && e->rgbGreen == g && e->rgbBlue == b)
                 return i;
         }
 
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 395568a..943600d 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2958,7 +2958,7 @@ struct wined3d_palette
     struct wined3d_device *device;
 
     unsigned int size;
-    PALETTEENTRY palents[256];
+    RGBQUAD colors[256];
     DWORD flags;
 };
 
-- 
1.8.5.5




More information about the wine-patches mailing list