This is my last set of patches changing DDS pixel format handling.
-- v2: d3dx9: Add support for more DDS pixel formats. d3dx9: Rework conversion to/from D3DFORMAT from/to DDS pixel format. d3dx9: Validate the size of DDS files containing packed pixel formats. d3dx9/tests: Add file size validation tests for DDS files containing packed pixel formats.
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/surface.c | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 3a85a7d949f..5600ceb5808 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -265,6 +265,39 @@ static void check_dds_pixel_format_(unsigned int line, ok_(__FILE__, line)(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n", info.Format, expected_format); } + + /* Test again with unused fields set. */ + if (flags & DDS_PF_FOURCC) + rmask = gmask = bmask = amask = bpp = ~0ul; + else if ((flags & (DDS_PF_INDEXED | DDS_PF_ALPHA)) == (DDS_PF_INDEXED | DDS_PF_ALPHA)) + rmask = gmask = bmask = fourcc = ~0ul; + else if (flags & DDS_PF_INDEXED) + rmask = gmask = bmask = amask = fourcc = ~0ul; + else if ((flags & (DDS_PF_RGB | DDS_PF_ALPHA)) == (DDS_PF_RGB | DDS_PF_ALPHA)) + fourcc = ~0ul; + else if (flags & DDS_PF_RGB) + fourcc = amask = ~0ul; + else if ((flags & (DDS_PF_LUMINANCE | DDS_PF_ALPHA)) == (DDS_PF_LUMINANCE | DDS_PF_ALPHA)) + gmask = bmask = fourcc = ~0ul; + else if (flags & DDS_PF_LUMINANCE) + gmask = bmask = amask = fourcc = ~0ul; + else if (flags & DDS_PF_ALPHA_ONLY) + rmask = gmask = bmask = fourcc = ~0ul; + else if (flags & DDS_PF_BUMPDUDV) + fourcc = ~0ul; + else if (flags & DDS_PF_BUMPLUMINANCE) + fourcc = amask = ~0ul; + + dds.header.pixel_format.fourcc = fourcc; + dds.header.pixel_format.bpp = bpp; + dds.header.pixel_format.rmask = rmask; + dds.header.pixel_format.gmask = gmask; + dds.header.pixel_format.bmask = bmask; + dds.header.pixel_format.amask = amask; + hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info); + ok_(__FILE__, line)(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + ok_(__FILE__, line)(info.Format == expected_format, "Unexpected format %#x.\n", info.Format); }
static void test_dds_header_handling(void) @@ -720,6 +753,18 @@ static void test_D3DXGetImageInfo(void) todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8); todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0, D3DFMT_UYVY); todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0, D3DFMT_YUY2); + /* + * D3DFMTs that aren't fourCC values, but are supported in the fourCC + * field. + */ + todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_A16B16G16R16, 0, 0, 0, 0, 0, D3DFMT_A16B16G16R16); + todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_Q16W16V16U16, 0, 0, 0, 0, 0, D3DFMT_Q16W16V16U16); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_R16F, 0, 0, 0, 0, 0, D3DFMT_R16F); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_G16R16F, 0, 0, 0, 0, 0, D3DFMT_G16R16F); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_A16B16G16R16F, 0, 0, 0, 0, 0, D3DFMT_A16B16G16R16F); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_R32F, 0, 0, 0, 0, 0, D3DFMT_R32F); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_G32R32F, 0, 0, 0, 0, 0, D3DFMT_G32R32F); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_A32B32G32R32F, 0, 0, 0, 0, 0, D3DFMT_A32B32G32R32F); check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5); check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5); check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4); @@ -741,7 +786,10 @@ static void test_D3DXGetImageInfo(void) check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4); check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8); check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16); + todo_wine check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0xff, 0xff00, 0x00ff0000, 0xff000000, D3DFMT_Q8W8V8U8); + todo_wine check_dds_pixel_format(DDS_PF_BUMPDUDV | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2W10V10U10); check_dds_pixel_format(DDS_PF_BUMPLUMINANCE, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8L8V8U8); + todo_wine check_dds_pixel_format(DDS_PF_BUMPLUMINANCE, 0, 16, 0x001f, 0x03e0, 0xfc00, 0, D3DFMT_L6V5U5); check_dds_pixel_format(DDS_PF_INDEXED, 0, 8, 0, 0, 0, 0, D3DFMT_P8); check_dds_pixel_format(DDS_PF_INDEXED | DDS_PF_ALPHA, 0, 16, 0, 0, 0, 0xff00, D3DFMT_A8P8);
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/surface.c | 36 ++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 5600ceb5808..93ec87010a0 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -325,6 +325,7 @@ static void test_dds_header_handling(void) { HRESULT hr; UINT miplevels; + BOOL todo; } expected; } tests[] = { @@ -350,6 +351,7 @@ static void test_dds_header_handling(void) /* linear size is ignored */ { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 4, 4, 0, 0, 7 /* pixel data size */, { D3DXERR_INVALIDDATA, 1 } }, + /* 10. */ { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 0 /* linear size */, 0, 8, { D3D_OK, 1 } }, { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 1 /* linear size */, 0, @@ -364,14 +366,14 @@ static void test_dds_header_handling(void) 8, { D3D_OK, 1 } }, /* integer overflows */ { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0, 0, - 64, { D3D_OK, 1 } }, + 64, { D3D_OK, 1, .todo = TRUE } }, { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0, 0, 64, { D3DXERR_INVALIDDATA, 0 } }, { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0, 4, { D3D_OK, 1 } }, { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0, 3 /* pixel data size */, { D3DXERR_INVALIDDATA, 0 } }, - /* file size is validated */ + /* 20. File size is validated. */ { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49151, { D3DXERR_INVALIDDATA, 0 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49152, { D3D_OK, 1 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 64, 0, 4, 65279, { D3DXERR_INVALIDDATA, 0 } }, @@ -382,6 +384,7 @@ static void test_dds_header_handling(void) { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196608, { D3D_OK, 1 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196609, { D3D_OK, 1 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 1, 196607, { D3DXERR_INVALIDDATA, 0 } }, + /* 30. */ { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 1, 196608, { D3D_OK, 1 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 196607, { D3DXERR_INVALIDDATA, 0 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 196608, { D3D_OK, 1 } }, @@ -392,6 +395,7 @@ static void test_dds_header_handling(void) { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 10, 262146, { D3D_OK, 10 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 262175, { D3DXERR_INVALIDDATA, 0 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 262176, { D3D_OK, 20 } }, + /* 40. */ { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA, 0 } }, { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32768, { D3D_OK, 1 } }, { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA, 0 } }, @@ -402,6 +406,7 @@ static void test_dds_header_handling(void) { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 43792, { D3D_OK, 20 } }, { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA, 0 } }, { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65536, { D3D_OK, 1 } }, + /* 50. */ { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA, 0 } }, { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 65536, { D3D_OK, 1 } }, { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 87407, { D3DXERR_INVALIDDATA, 0 } }, @@ -413,8 +418,24 @@ static void test_dds_header_handling(void) /* DDS_MIPMAPCOUNT is ignored */ { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 262146, { D3D_OK, 1 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 2, 262146, { D3D_OK, 2 } }, + /* 60. */ { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 9, 262146, { D3D_OK, 9 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 10, 262146, { D3D_OK, 10 } }, + /* Packed formats. */ + { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, + { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, + { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, + { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, + /* Uneven height/width is supported, but pixel size must align. */ + { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } }, + { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } }, + { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, + { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, + /* 70. */ + { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } }, + { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } }, + { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, + { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, }; static const struct { @@ -484,6 +505,7 @@ static void test_dds_header_handling(void) DWORD file_size = sizeof(dds->magic) + sizeof(dds->header) + tests[i].pixel_data_size; assert(file_size <= sizeof(*dds));
+ winetest_push_context("Test %u", i); dds->magic = MAKEFOURCC('D','D','S',' '); fill_dds_header(&dds->header); dds->header.flags |= tests[i].flags; @@ -494,14 +516,14 @@ static void test_dds_header_handling(void) dds->header.pixel_format = tests[i].pixel_format;
hr = D3DXGetImageInfoFromFileInMemory(dds, file_size, &info); - todo_wine_if(i == 16) - ok(hr == tests[i].expected.hr, "%d: D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", - i, hr, tests[i].expected.hr); + todo_wine_if(tests[i].expected.todo) ok(hr == tests[i].expected.hr, "Unexpected hr %#lx, expected %#lx.\n", + hr, tests[i].expected.hr); if (SUCCEEDED(hr)) { - ok(info.MipLevels == tests[i].expected.miplevels, "%d: Got MipLevels %u, expected %u\n", - i, info.MipLevels, tests[i].expected.miplevels); + ok(info.MipLevels == tests[i].expected.miplevels, "Unexpected MipLevels %u, expected %u.\n", + info.MipLevels, tests[i].expected.miplevels); } + winetest_pop_context(); }
for (i = 0; i < ARRAY_SIZE(info_tests); i++)
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 10 ++++++++-- dlls/d3dx9_36/tests/surface.c | 24 ++++++++++++------------ dlls/d3dx9_36/util.c | 4 ++++ 3 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index 303489374f8..d01682cc51e 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -104,6 +104,7 @@ enum component_type enum format_flag { FMT_FLAG_DXT = 0x01, + FMT_FLAG_PACKED = 0x02, };
struct pixel_format_desc { @@ -197,6 +198,11 @@ static inline BOOL is_compressed_format(const struct pixel_format_desc *format) return !!(format->flags & FMT_FLAG_DXT); }
+static inline BOOL is_packed_format(const struct pixel_format_desc *format) +{ + return !!(format->flags & FMT_FLAG_PACKED); +} + static inline BOOL format_types_match(const struct pixel_format_desc *src, const struct pixel_format_desc *dst) { if ((src->a_type && dst->a_type) && (src->a_type != dst->a_type)) @@ -213,12 +219,12 @@ static inline BOOL format_types_match(const struct pixel_format_desc *src, const
static inline BOOL is_conversion_from_supported(const struct pixel_format_desc *format) { - return !is_unknown_format(format); + return !is_packed_format(format) && !is_unknown_format(format); }
static inline BOOL is_conversion_to_supported(const struct pixel_format_desc *format) { - return !is_index_format(format) && !is_unknown_format(format); + return !is_index_format(format) && !is_packed_format(format) && !is_unknown_format(format); }
HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length); diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 93ec87010a0..98bd33cbbc4 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -422,20 +422,20 @@ static void test_dds_header_handling(void) { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 9, 262146, { D3D_OK, 9 } }, { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 10, 262146, { D3D_OK, 10 } }, /* Packed formats. */ - { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, - { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, - { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, - { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, + { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1 } }, + { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1 } }, + { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1 } }, + { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1 } }, /* Uneven height/width is supported, but pixel size must align. */ { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } }, { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } }, - { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, - { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, /* 70. */ + { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1 } }, + { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1 } }, { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } }, { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } }, - { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, - { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1, .todo = TRUE } }, + { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1 } }, + { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1 } }, }; static const struct { @@ -771,10 +771,10 @@ static void test_D3DXGetImageInfo(void) check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT3, 0, 0, 0, 0, 0, D3DFMT_DXT3); check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0, D3DFMT_DXT4); check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT5, 0, 0, 0, 0, 0, D3DFMT_DXT5); - todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8); - todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8); - todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0, D3DFMT_UYVY); - todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0, D3DFMT_YUY2); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0, D3DFMT_UYVY); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0, D3DFMT_YUY2); /* * D3DFMTs that aren't fourCC values, but are supported in the fourCC * field. diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index 09bd4cd3e59..31b6bdaeb8a 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -71,6 +71,10 @@ static const struct pixel_format_desc formats[] = {D3DFMT_V16U16, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_SNORM, 0 }, {D3DFMT_X8L8V8U8, { 8, 8, 8, 0}, {16, 0, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 }, {D3DFMT_A2W10V10U10, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 }, + {D3DFMT_R8G8_B8G8, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, + {D3DFMT_G8R8_G8B8, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, + {D3DFMT_UYVY, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, + {D3DFMT_YUY2, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 2, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_PACKED}, /* marks last element */ {D3DFMT_UNKNOWN, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, CTYPE_EMPTY, CTYPE_EMPTY, 0 }, };
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 270 ++++++++++++++++------------------------ 1 file changed, 109 insertions(+), 161 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 59e18ed952c..0882eb9997c 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -147,62 +147,6 @@ struct dds_header DWORD reserved2; };
-static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc) -{ - unsigned int i; - static const DWORD known_fourcc[] = { - D3DFMT_UYVY, - D3DFMT_YUY2, - D3DFMT_R8G8_B8G8, - D3DFMT_G8R8_G8B8, - D3DFMT_DXT1, - D3DFMT_DXT2, - D3DFMT_DXT3, - D3DFMT_DXT4, - D3DFMT_DXT5, - D3DFMT_R16F, - D3DFMT_G16R16F, - D3DFMT_A16B16G16R16F, - D3DFMT_R32F, - D3DFMT_G32R32F, - D3DFMT_A32B32G32R32F, - }; - - for (i = 0; i < ARRAY_SIZE(known_fourcc); i++) - { - if (known_fourcc[i] == fourcc) - return fourcc; - } - - WARN("Unknown FourCC %#lx.\n", fourcc); - return D3DFMT_UNKNOWN; -} - -static const struct { - DWORD bpp; - DWORD rmask; - DWORD gmask; - DWORD bmask; - DWORD amask; - D3DFORMAT format; -} rgb_pixel_formats[] = { - { 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2 }, - { 16, 0xf800, 0x07e0, 0x001f, 0x0000, D3DFMT_R5G6B5 }, - { 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5 }, - { 16, 0x7c00, 0x03e0, 0x001f, 0x0000, D3DFMT_X1R5G5B5 }, - { 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4 }, - { 16, 0x0f00, 0x00f0, 0x000f, 0x0000, D3DFMT_X4R4G4B4 }, - { 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2 }, - { 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000, D3DFMT_R8G8B8 }, - { 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8 }, - { 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000, D3DFMT_X8R8G8B8 }, - { 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10 }, - { 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10 }, - { 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000, D3DFMT_G16R16 }, - { 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8 }, - { 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000, D3DFMT_X8B8G8R8 }, -}; - HRESULT lock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, D3DLOCKED_RECT *lock, IDirect3DSurface9 **temp_surface, BOOL write) { @@ -297,115 +241,127 @@ HRESULT unlock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, return hr; }
-static D3DFORMAT dds_rgb_to_d3dformat(const struct dds_pixel_format *pixel_format) +static const struct { - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(rgb_pixel_formats); i++) - { - if (rgb_pixel_formats[i].bpp == pixel_format->bpp - && rgb_pixel_formats[i].rmask == pixel_format->rmask - && rgb_pixel_formats[i].gmask == pixel_format->gmask - && rgb_pixel_formats[i].bmask == pixel_format->bmask) - { - if ((pixel_format->flags & DDS_PF_ALPHA) && rgb_pixel_formats[i].amask == pixel_format->amask) - return rgb_pixel_formats[i].format; - if (rgb_pixel_formats[i].amask == 0) - return rgb_pixel_formats[i].format; - } - } + struct dds_pixel_format dds_pixel_format; + D3DFORMAT d3d_format; +} dds_pixel_formats[] = { + /* DDS_PF_FOURCC. */ + { { 32, DDS_PF_FOURCC, MAKEFOURCC('U','Y','V','Y') }, D3DFMT_UYVY }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('Y','U','Y','2') }, D3DFMT_YUY2 }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('R','G','B','G') }, D3DFMT_R8G8_B8G8 }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('G','R','G','B') }, D3DFMT_G8R8_G8B8 }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','1') }, D3DFMT_DXT1 }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','2') }, D3DFMT_DXT2 }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','3') }, D3DFMT_DXT3 }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4') }, D3DFMT_DXT4 }, + { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5') }, D3DFMT_DXT5 }, + /* These aren't actually fourcc values, they're just D3DFMT values. */ + { { 32, DDS_PF_FOURCC, 0x6f }, D3DFMT_R16F, }, + { { 32, DDS_PF_FOURCC, 0x70 }, D3DFMT_G16R16F }, + { { 32, DDS_PF_FOURCC, 0x71 }, D3DFMT_A16B16G16R16F }, + { { 32, DDS_PF_FOURCC, 0x72 }, D3DFMT_R32F }, + { { 32, DDS_PF_FOURCC, 0x73 }, D3DFMT_G32R32F }, + { { 32, DDS_PF_FOURCC, 0x74 }, D3DFMT_A32B32G32R32F }, + /* DDS_PF_RGB. */ + { { 32, DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0x00 }, D3DFMT_R3G3B2 }, + { { 32, DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0x0000 }, D3DFMT_R5G6B5 }, + { { 32, DDS_PF_RGB, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x0000 }, D3DFMT_X1R5G5B5 }, + { { 32, DDS_PF_RGB, 0, 16, 0x0f00, 0x00f0, 0x000f, 0x0000 }, D3DFMT_X4R4G4B4 }, + { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, D3DFMT_R8G8B8 }, + { { 32, DDS_PF_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }, D3DFMT_X8R8G8B8 }, + { { 32, DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }, D3DFMT_G16R16 }, + { { 32, DDS_PF_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }, D3DFMT_X8B8G8R8 }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00 }, D3DFMT_A8R3G3B2 }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000 }, D3DFMT_A1R5G5B5 }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000 }, D3DFMT_A4R4G4B4 }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, D3DFMT_A8R8G8B8 }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }, D3DFMT_A8B8G8R8 }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }, D3DFMT_A2B10G10R10 }, + { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000 }, D3DFMT_A2R10G10B10 }, + /* DDS_PF_INDEXED. */ + { { 32, DDS_PF_INDEXED, 0, 8 }, D3DFMT_P8 }, + { { 32, DDS_PF_INDEXED | DDS_PF_ALPHA, 0, 16, 0, 0, 0, 0xff00, }, D3DFMT_A8P8 }, + /* DDS_PF_LUMINANCE. */ + { { 32, DDS_PF_LUMINANCE, 0, 8, 0x00ff }, D3DFMT_L8 }, + { { 32, DDS_PF_LUMINANCE, 0, 16, 0xffff }, D3DFMT_L16 }, + { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x000f, 0, 0, 0x00f0 }, D3DFMT_A4L4 }, + { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00 }, D3DFMT_A8L8 }, + /* DDS_PF_ALPHA_ONLY. */ + { { 32, DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff }, D3DFMT_A8 }, + /* DDS_PF_BUMPDUDV. */ + { { 32, DDS_PF_BUMPDUDV, 0, 16, 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000 }, D3DFMT_V8U8 }, + { { 32, DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }, D3DFMT_V16U16 }, + /* DDS_PF_BUMPLUMINANCE. */ + { { 32, DDS_PF_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }, D3DFMT_X8L8V8U8 }, +};
- WARN("Unknown RGB pixel format (r %#lx, g %#lx, b %#lx, a %#lx).\n", - pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask); - return D3DFMT_UNKNOWN; +static BOOL dds_pixel_format_compare(const struct dds_pixel_format *pf_a, const struct dds_pixel_format *pf_b, + BOOL check_rmask, BOOL check_gmask, BOOL check_bmask, BOOL check_amask) +{ + return pf_a->bpp == pf_b->bpp && !((check_rmask && pf_a->rmask != pf_b->rmask) + || (check_gmask && pf_a->gmask != pf_b->gmask) || (check_bmask && pf_a->bmask != pf_b->bmask) + || (check_amask && pf_a->amask != pf_b->amask)); }
-static D3DFORMAT dds_luminance_to_d3dformat(const struct dds_pixel_format *pixel_format) +static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pixel_format) { - if (pixel_format->bpp == 8) - { - if (pixel_format->rmask == 0xff) - return D3DFMT_L8; - if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x0f && pixel_format->amask == 0xf0) - return D3DFMT_A4L4; - } - if (pixel_format->bpp == 16) - { - if (pixel_format->rmask == 0xffff) - return D3DFMT_L16; - if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x00ff && pixel_format->amask == 0xff00) - return D3DFMT_A8L8; - } + uint32_t i;
- WARN("Unknown luminance pixel format (bpp %lu, l %#lx, a %#lx).\n", - pixel_format->bpp, pixel_format->rmask, pixel_format->amask); - return D3DFMT_UNKNOWN; -} + TRACE("pixel_format: size %lu, flags %#lx, fourcc %#lx, bpp %lu.\n", pixel_format->size, + pixel_format->flags, pixel_format->fourcc, pixel_format->bpp); + TRACE("rmask %#lx, gmask %#lx, bmask %#lx, amask %#lx.\n", pixel_format->rmask, pixel_format->gmask, + pixel_format->bmask, pixel_format->amask);
-static D3DFORMAT dds_alpha_to_d3dformat(const struct dds_pixel_format *pixel_format) -{ - if (pixel_format->bpp == 8 && pixel_format->amask == 0xff) - return D3DFMT_A8; + for (i = 0; i < ARRAY_SIZE(dds_pixel_formats); ++i) + { + const struct dds_pixel_format *dds_pf = &dds_pixel_formats[i].dds_pixel_format;
- WARN("Unknown alpha pixel format (bpp %lu, a %#lx).\n", pixel_format->bpp, pixel_format->rmask); - return D3DFMT_UNKNOWN; -} + if (pixel_format->flags != dds_pf->flags) + continue;
-static D3DFORMAT dds_indexed_to_d3dformat(const struct dds_pixel_format *pixel_format) -{ - if (pixel_format->bpp == 8) - return D3DFMT_P8; - if (pixel_format->bpp == 16 && pixel_format->amask == 0xff00) - return D3DFMT_A8P8; + switch (pixel_format->flags & ~DDS_PF_ALPHA) + { + case DDS_PF_ALPHA_ONLY: + if (dds_pixel_format_compare(pixel_format, dds_pf, FALSE, FALSE, FALSE, TRUE)) + return dds_pixel_formats[i].d3d_format; + break;
- WARN("Unknown indexed pixel format (bpp %lu).\n", pixel_format->bpp); - return D3DFMT_UNKNOWN; -} + case DDS_PF_FOURCC: + if (pixel_format->fourcc == dds_pf->fourcc) + return dds_pixel_formats[i].d3d_format; + break;
-static D3DFORMAT dds_bump_to_d3dformat(const struct dds_pixel_format *pixel_format) -{ - if (pixel_format->bpp == 16 && pixel_format->rmask == 0x00ff && pixel_format->gmask == 0xff00) - return D3DFMT_V8U8; - if (pixel_format->bpp == 32 && pixel_format->rmask == 0x0000ffff && pixel_format->gmask == 0xffff0000) - return D3DFMT_V16U16; + case DDS_PF_INDEXED: + if (dds_pixel_format_compare(pixel_format, dds_pf, FALSE, FALSE, FALSE, pixel_format->flags & DDS_PF_ALPHA)) + return dds_pixel_formats[i].d3d_format; + break;
- WARN("Unknown bump pixel format (bpp %lu, r %#lx, g %#lx, b %#lx, a %#lx).\n", pixel_format->bpp, - pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask); - return D3DFMT_UNKNOWN; -} + case DDS_PF_RGB: + if (dds_pixel_format_compare(pixel_format, dds_pf, TRUE, TRUE, TRUE, pixel_format->flags & DDS_PF_ALPHA)) + return dds_pixel_formats[i].d3d_format; + break;
-static D3DFORMAT dds_bump_luminance_to_d3dformat(const struct dds_pixel_format *pixel_format) -{ - if (pixel_format->bpp == 32 && pixel_format->rmask == 0x000000ff && pixel_format->gmask == 0x0000ff00 - && pixel_format->bmask == 0x00ff0000) - return D3DFMT_X8L8V8U8; + case DDS_PF_LUMINANCE: + if (dds_pixel_format_compare(pixel_format, dds_pf, TRUE, FALSE, FALSE, pixel_format->flags & DDS_PF_ALPHA)) + return dds_pixel_formats[i].d3d_format; + break;
- WARN("Unknown bump pixel format (bpp %lu, r %#lx, g %#lx, b %#lx, a %#lx).\n", pixel_format->bpp, - pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask); - return D3DFMT_UNKNOWN; -} + case DDS_PF_BUMPLUMINANCE: + if (dds_pixel_format_compare(pixel_format, dds_pf, TRUE, TRUE, TRUE, FALSE)) + return dds_pixel_formats[i].d3d_format; + break;
-static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pixel_format) -{ - TRACE("pixel_format: size %lu, flags %#lx, fourcc %#lx, bpp %lu.\n", pixel_format->size, - pixel_format->flags, pixel_format->fourcc, pixel_format->bpp); - TRACE("rmask %#lx, gmask %#lx, bmask %#lx, amask %#lx.\n", pixel_format->rmask, pixel_format->gmask, - pixel_format->bmask, pixel_format->amask); + case DDS_PF_BUMPDUDV: + if (dds_pixel_format_compare(pixel_format, dds_pf, TRUE, TRUE, TRUE, TRUE)) + return dds_pixel_formats[i].d3d_format; + break;
- if (pixel_format->flags & DDS_PF_FOURCC) - return dds_fourcc_to_d3dformat(pixel_format->fourcc); - if (pixel_format->flags & DDS_PF_INDEXED) - return dds_indexed_to_d3dformat(pixel_format); - if (pixel_format->flags & DDS_PF_RGB) - return dds_rgb_to_d3dformat(pixel_format); - if (pixel_format->flags & DDS_PF_LUMINANCE) - return dds_luminance_to_d3dformat(pixel_format); - if (pixel_format->flags & DDS_PF_ALPHA_ONLY) - return dds_alpha_to_d3dformat(pixel_format); - if (pixel_format->flags & DDS_PF_BUMPDUDV) - return dds_bump_to_d3dformat(pixel_format); - if (pixel_format->flags & DDS_PF_BUMPLUMINANCE) - return dds_bump_luminance_to_d3dformat(pixel_format); + default: + assert(0); /* Should not happen. */ + break; + } + }
WARN("Unknown pixel format (flags %#lx, fourcc %#lx, bpp %lu, r %#lx, g %#lx, b %#lx, a %#lx).\n", pixel_format->flags, pixel_format->fourcc, pixel_format->bpp, @@ -415,23 +371,15 @@ static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pi
static HRESULT d3dformat_to_dds_pixel_format(struct dds_pixel_format *pixel_format, D3DFORMAT d3dformat) { - unsigned int i; + uint32_t i;
memset(pixel_format, 0, sizeof(*pixel_format)); - pixel_format->size = sizeof(*pixel_format); - - for (i = 0; i < ARRAY_SIZE(rgb_pixel_formats); i++) + for (i = 0; i < ARRAY_SIZE(dds_pixel_formats); ++i) { - if (rgb_pixel_formats[i].format == d3dformat) + if (dds_pixel_formats[i].d3d_format == d3dformat) { - pixel_format->flags |= DDS_PF_RGB; - pixel_format->bpp = rgb_pixel_formats[i].bpp; - pixel_format->rmask = rgb_pixel_formats[i].rmask; - pixel_format->gmask = rgb_pixel_formats[i].gmask; - pixel_format->bmask = rgb_pixel_formats[i].bmask; - pixel_format->amask = rgb_pixel_formats[i].amask; - if (pixel_format->amask) pixel_format->flags |= DDS_PF_ALPHA; + *pixel_format = dds_pixel_formats[i].dds_pixel_format; return D3D_OK; } }
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 6 ++++++ dlls/d3dx9_36/tests/surface.c | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 0882eb9997c..21ff8732550 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -257,6 +257,8 @@ static const struct { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','4') }, D3DFMT_DXT4 }, { { 32, DDS_PF_FOURCC, MAKEFOURCC('D','X','T','5') }, D3DFMT_DXT5 }, /* These aren't actually fourcc values, they're just D3DFMT values. */ + { { 32, DDS_PF_FOURCC, 0x24 }, D3DFMT_A16B16G16R16 }, + { { 32, DDS_PF_FOURCC, 0x6e }, D3DFMT_Q16W16V16U16 }, { { 32, DDS_PF_FOURCC, 0x6f }, D3DFMT_R16F, }, { { 32, DDS_PF_FOURCC, 0x70 }, D3DFMT_G16R16F }, { { 32, DDS_PF_FOURCC, 0x71 }, D3DFMT_A16B16G16R16F }, @@ -287,11 +289,15 @@ static const struct { { 32, DDS_PF_LUMINANCE, 0, 16, 0xffff }, D3DFMT_L16 }, { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x000f, 0, 0, 0x00f0 }, D3DFMT_A4L4 }, { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00 }, D3DFMT_A8L8 }, + /* Exceptional case, A8L8 can also have 8bpp. */ + { { 32, DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x00ff, 0, 0, 0xff00 }, D3DFMT_A8L8 }, /* DDS_PF_ALPHA_ONLY. */ { { 32, DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff }, D3DFMT_A8 }, /* DDS_PF_BUMPDUDV. */ { { 32, DDS_PF_BUMPDUDV, 0, 16, 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000 }, D3DFMT_V8U8 }, { { 32, DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }, D3DFMT_V16U16 }, + { { 32, DDS_PF_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }, D3DFMT_Q8W8V8U8 }, + { { 32, DDS_PF_BUMPDUDV | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 }, D3DFMT_A2W10V10U10 }, /* DDS_PF_BUMPLUMINANCE. */ { { 32, DDS_PF_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }, D3DFMT_X8L8V8U8 }, }; diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 98bd33cbbc4..f6432800494 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -779,8 +779,8 @@ static void test_D3DXGetImageInfo(void) * D3DFMTs that aren't fourCC values, but are supported in the fourCC * field. */ - todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_A16B16G16R16, 0, 0, 0, 0, 0, D3DFMT_A16B16G16R16); - todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_Q16W16V16U16, 0, 0, 0, 0, 0, D3DFMT_Q16W16V16U16); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_A16B16G16R16, 0, 0, 0, 0, 0, D3DFMT_A16B16G16R16); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_Q16W16V16U16, 0, 0, 0, 0, 0, D3DFMT_Q16W16V16U16); check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_R16F, 0, 0, 0, 0, 0, D3DFMT_R16F); check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_G16R16F, 0, 0, 0, 0, 0, D3DFMT_G16R16F); check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_A16B16G16R16F, 0, 0, 0, 0, 0, D3DFMT_A16B16G16R16F); @@ -805,11 +805,13 @@ static void test_D3DXGetImageInfo(void) check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8); check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16); check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8); + /* 8bpp works too for D3DFMT_A8L8. */ + check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8); check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4); check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8); check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16); - todo_wine check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0xff, 0xff00, 0x00ff0000, 0xff000000, D3DFMT_Q8W8V8U8); - todo_wine check_dds_pixel_format(DDS_PF_BUMPDUDV | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2W10V10U10); + check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0xff, 0xff00, 0x00ff0000, 0xff000000, D3DFMT_Q8W8V8U8); + check_dds_pixel_format(DDS_PF_BUMPDUDV | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2W10V10U10); check_dds_pixel_format(DDS_PF_BUMPLUMINANCE, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8L8V8U8); todo_wine check_dds_pixel_format(DDS_PF_BUMPLUMINANCE, 0, 16, 0x001f, 0x03e0, 0xfc00, 0, D3DFMT_L6V5U5); check_dds_pixel_format(DDS_PF_INDEXED, 0, 8, 0, 0, 0, 0, D3DFMT_P8);
On Mon Oct 14 08:35:27 2024 +0000, Matteo Bruni wrote:
Maybe consider adding a "counter" comment every 10 entries or so (to be able to find a specific test a bit more quickly, in particular in case of a test failure)?
I had issues finding which particular test number failed in the past and was keeping comments locally, but wasn't sure if that was something that made sense to upstream. Added them in just now. :)