From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 5 +++++ dlls/d3dx9_36/surface.c | 19 +++++++++++++++++++ dlls/d3dx9_36/tests/surface.c | 10 +--------- 3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index dabe714f611..194d9879f7d 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -359,6 +359,11 @@ static inline BOOL is_conversion_to_supported(const struct pixel_format_desc *fo return !is_index_format(format) && !is_packed_format(format) && !is_unknown_format(format); }
+static inline uint8_t format_channel_count(const struct pixel_format_desc *fmt) +{ + return !!fmt->bits[0] + !!fmt->bits[1] + !!fmt->bits[2] + !!fmt->bits[3]; +} + HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length); HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length);
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 4786b29bfe3..f90a4d30456 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -2732,6 +2732,7 @@ HRESULT d3dx_load_pixels_from_pixels(struct d3dx_pixels *dst_pixels, const struct pixel_format_desc *dst_desc, struct d3dx_pixels *src_pixels, const struct pixel_format_desc *src_desc, uint32_t filter_flags, uint32_t color_key) { + const struct pixel_format_desc *ck_format = get_format_info(D3DFMT_A8R8G8B8); struct volume src_size, dst_size, dst_size_aligned; HRESULT hr = S_OK;
@@ -2860,6 +2861,24 @@ HRESULT d3dx_load_pixels_from_pixels(struct d3dx_pixels *dst_pixels, goto exit; }
+ /* + * Convert color key to the source format and then back again if + * necessary. This ensures the color key represents a value that + * is obtainable when converting from the source format to the color + * key format. + */ + if (color_key && !is_index_format(src_desc) && (!format_types_match(src_desc, ck_format) + || format_channel_count(src_desc) < 4)) + { + struct argb_conversion_info ck_conv_info, conv_info; + uint8_t tmp_buf[16]; + + init_argb_conversion_info(ck_format, src_desc, &ck_conv_info); + init_argb_conversion_info(src_desc, ck_format, &conv_info); + convert_argb_pixel((uint8_t *)&color_key, ck_format, tmp_buf, src_desc, NULL, &ck_conv_info, 0, NULL, NULL); + convert_argb_pixel(tmp_buf, src_desc, (uint8_t *)&color_key, ck_format, NULL, &conv_info, 0, NULL, NULL); + } + if ((filter_flags & 0xf) == D3DX_FILTER_NONE) { convert_argb_pixels(src_pixels->data, src_pixels->row_pitch, src_pixels->slice_pitch, &src_size, src_desc, diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 7bc52914184..2a5569f7836 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -2208,13 +2208,11 @@ static void test_color_key(void)
const void *expected_dst_data; D3DCOLOR color_key; - BOOL todo; } tests[] = { /* Color key with alpha channel unset. */ { D3DFMT_R8G8B8, { 0, 0, 4, 4 }, r8g8b8_4_4, r8g8b8_4_4_expected, 0x00008080, - .todo = TRUE }, /* Same color key as before except the alpha channel is set. */ { @@ -2237,11 +2235,9 @@ static void test_color_key(void) */ { D3DFMT_R32F, { 0, 0, 4, 4 }, r32_4_4, r32_4_4_expected, 0xffff3080, - .todo = TRUE }, { D3DFMT_Q8W8V8U8, { 0, 0, 4, 4 }, q8w8v8u8_4_4, q8w8v8u8_4_4_expected, 0xffff0000, - .todo = TRUE }, /* Alpha channel factors into the color key check. */ { @@ -2276,7 +2272,6 @@ static void test_color_key(void) { winetest_push_context("Test %u", i);
- mismatch_count = 0; src_pitch = get_bpp_for_d3dformat(tests[i].src_format) * tests[i].src_rect.right; hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, tests[i].src_data, tests[i].src_format, src_pitch, tmp_palette, &tests[i].src_rect, D3DX_FILTER_NONE, tests[i].color_key); @@ -2288,12 +2283,9 @@ static void test_color_key(void) const uint8_t *dst_expected_row = ((const uint8_t *)tests[i].expected_dst_data) + (sizeof(uint32_t) * 4 * y); const uint8_t *dst_row = ((const uint8_t *)lock_rect.pBits) + (lock_rect.Pitch * y);
- if (memcmp(dst_row, dst_expected_row, sizeof(uint32_t) * 4)) - mismatch_count++; + ok(!memcmp(dst_row, dst_expected_row, sizeof(uint32_t) * 4), "Unexpected line %u.\n", y); } IDirect3DSurface9_UnlockRect(surf); - - todo_wine_if(tests[i].todo) ok(!mismatch_count, "Unexpected number of mismatched lines %u.\n", mismatch_count); winetest_pop_context(); }