From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 36 +++++++++++++++++++++++++++++++++-- dlls/d3dx9_36/tests/surface.c | 9 +-------- 2 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 1d571d89f65..c2b67bba17e 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -2719,8 +2719,40 @@ static BOOL get_format_color_key(const struct pixel_format_desc *fmt, const PALE
if (is_index_format(fmt)) { - FIXME("Color keying for indexed formats is currently unimplemented.\n"); - return FALSE; + const uint8_t cmp_bytes = (fmt->a_type == CTYPE_INDEX) ? 4 : 3; + unsigned int color_key_idx = 256; + PALETTEENTRY tmp_palette; + unsigned int i; + + tmp_palette.peRed = (in_color_key >> 16) & 0xff; + tmp_palette.peGreen = (in_color_key >> 8) & 0xff; + tmp_palette.peBlue = in_color_key & 0xff; + tmp_palette.peFlags = (in_color_key >> 24) & 0xff; + for (i = 0; i < 256; ++i) + { + if (!memcmp(&tmp_palette, &palette[i], cmp_bytes)) + { + color_key_idx = i; + break; + } + } + + /* No match in the palette for this color key. */ + if (color_key_idx == 256) + return FALSE; + + /* A8P8. */ + if (fmt->a_type == CTYPE_UNORM) + { + out_color_key[0] = color_key_idx; + out_color_key[1] = (in_color_key >> 24) & 0xff; + } + else + { + out_color_key[0] = color_key_idx; + } + + return TRUE; }
format_to_d3dx_color(ck_format, (const uint8_t *)&in_color_key, palette, &tmp_color); diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 9cd989680fa..cfd7e54c4fe 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -2144,7 +2144,6 @@ static void test_color_key(IDirect3DDevice9 *device)
const void *expected_dst_data; D3DCOLOR color_key; - BOOL todo; } tests[] = { /* Color key with alpha channel unset. */ @@ -2158,11 +2157,9 @@ static void test_color_key(IDirect3DDevice9 *device) /* Color key on a palette. */ { D3DFMT_P8, test_palette, { 0, 0, 4, 4 }, p8_4_4, p8_4_4_expected, 0xf0c0c000, - .todo = TRUE }, { D3DFMT_A8P8, test_palette, { 0, 0, 4, 4 }, a8p8_4_4, a8p8_4_4_expected, 0x10c0c000, - .todo = TRUE }, { D3DFMT_A32B32G32R32F, NULL, { 0, 0, 4, 4 }, a32r32g32b32_4_4, a32r32g32b32_4_4_expected, 0xffff0000, @@ -2189,7 +2186,6 @@ static void test_color_key(IDirect3DDevice9 *device) for (i = 0; i < ARRAY_SIZE(tests); ++i) { const uint32_t src_pitch = get_bpp_for_d3dformat(tests[i].src_format) * tests[i].src_rect.right; - unsigned int mismatch_count = 0;
winetest_push_context("Test %u", i);
@@ -2208,13 +2204,10 @@ static void test_color_key(IDirect3DDevice9 *device) const uint8_t *dst_expected_pixel = dst_expected_row + (4 * x); const uint8_t *dst_pixel = dst_row + (4 * x);
- if (memcmp(dst_pixel, dst_expected_pixel, 4)) - mismatch_count++; + ok(!memcmp(dst_pixel, dst_expected_pixel, 4), "Pixel mismatch at (%u,%u).\n", x, y); } } IDirect3DSurface9_UnlockRect(surf); - - todo_wine_if(tests[i].todo) ok(!mismatch_count, "Unexpected number of mismatched pixels %u.\n", mismatch_count); winetest_pop_context(); }