wined3d: Store RGBQUADs in palettes.

This commit is contained in:
Stefan Dösinger 2014-05-07 18:02:14 +02:00 committed by Alexandre Julliard
parent 19f45af19c
commit 1558391a11
4 changed files with 52 additions and 75 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -2958,7 +2958,7 @@ struct wined3d_palette
struct wined3d_device *device;
unsigned int size;
PALETTEENTRY palents[256];
RGBQUAD colors[256];
DWORD flags;
};