From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/d3dx9_test_images.h | 100 ++++++++++++++++++++++++ dlls/d3dx9_36/tests/surface.c | 69 ++++++++++++++++ dlls/d3dx9_36/tests/texture.c | 82 +++++++++++++++++++ dlls/d3dx9_36/tests/volume.c | 54 +++++++++++++ 4 files changed, 305 insertions(+)
diff --git a/dlls/d3dx9_36/tests/d3dx9_test_images.h b/dlls/d3dx9_36/tests/d3dx9_test_images.h index 0c4a72da57d..68d4152d542 100644 --- a/dlls/d3dx9_36/tests/d3dx9_test_images.h +++ b/dlls/d3dx9_36/tests/d3dx9_test_images.h @@ -133,6 +133,106 @@ static const uint8_t png_grayscale[] = 0x42,0x60,0x82 };
+static const uint8_t png_2_2_24bpp_bgr[] = +{ + 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, + 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x08,0x02,0x00,0x00,0x00,0xfd,0xd4,0x9a, + 0x73,0x00,0x00,0x00,0x16,0x49,0x44,0x41,0x54,0x08,0x99,0x63,0x54,0x10,0x60,0x30, + 0x30,0x30,0x60,0x49,0x48,0x48,0x30,0x30,0x30,0x00,0x00,0x0e,0x68,0x02,0x76,0xd0, + 0x18,0x48,0x79,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82, +}; + +static const uint8_t png_2_2_48bpp_rgb[] = +{ + 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, + 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x10,0x02,0x00,0x00,0x00,0xad,0x44,0x46, + 0x30,0x00,0x00,0x00,0x1d,0x49,0x44,0x41,0x54,0x08,0x99,0x63,0x64,0x60,0x10,0x10, + 0x50,0x50,0x30,0x30,0x30,0x30,0x30,0x30,0x60,0x49,0x48,0x48,0x48,0x48,0x48,0x80, + 0x70,0x00,0x34,0x38,0x04,0xe6,0xd6,0xb5,0xab,0x37,0x00,0x00,0x00,0x00,0x49,0x45, + 0x4e,0x44,0xae,0x42,0x60,0x82, +}; + +static const uint8_t png_2_2_64bpp_rgba[] = +{ + 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, + 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x10,0x06,0x00,0x00,0x00,0x22,0x26,0xd1, + 0x67,0x00,0x00,0x00,0x26,0x49,0x44,0x41,0x54,0x08,0x99,0x63,0x64,0x60,0x10,0x10, + 0x50,0x50,0x30,0x30,0x70,0x80,0x02,0x86,0x86,0x86,0x09,0x13,0x16,0x2c,0xd8,0xb0, + 0xe1,0xc0,0x81,0x0b,0x17,0x1e,0x3c,0xf8,0xf0,0x01,0x00,0x97,0x64,0x0e,0x42,0xcc, + 0x1c,0xbb,0xb8,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82, +}; + +static const uint8_t jpg_rgb_2_2[] = +{ + 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x00,0x00,0x01, + 0x00,0x01,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x08,0x06,0x06,0x07,0x06,0x05,0x08, + 0x07,0x07,0x07,0x09,0x09,0x08,0x0a,0x0c,0x14,0x0d,0x0c,0x0b,0x0b,0x0c,0x19,0x12, + 0x13,0x0f,0x14,0x1d,0x1a,0x1f,0x1e,0x1d,0x1a,0x1c,0x1c,0x20,0x24,0x2e,0x27,0x20, + 0x22,0x2c,0x23,0x1c,0x1c,0x28,0x37,0x29,0x2c,0x30,0x31,0x34,0x34,0x34,0x1f,0x27, + 0x39,0x3d,0x38,0x32,0x3c,0x2e,0x33,0x34,0x32,0xff,0xdb,0x00,0x43,0x01,0x08,0x09, + 0x09,0x0c,0x0b,0x0c,0x18,0x0d,0x0d,0x18,0x32,0x21,0x1c,0x21,0x32,0x32,0x32,0x32, + 0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32, + 0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32, + 0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0x32,0xff,0xc0, + 0x00,0x11,0x08,0x00,0x02,0x00,0x02,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11, + 0x01,0xff,0xc4,0x00,0x1f,0x00,0x00,0x01,0x05,0x01,0x01,0x01,0x01,0x01,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, + 0x0a,0x0b,0xff,0xc4,0x00,0xb5,0x10,0x00,0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05, + 0x05,0x04,0x04,0x00,0x00,0x01,0x7d,0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21, + 0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,0x23, + 0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17, + 0x18,0x19,0x1a,0x25,0x26,0x27,0x28,0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a, + 0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a, + 0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a, + 0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99, + 0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7, + 0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5, + 0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf1, + 0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xff,0xc4,0x00,0x1f,0x01,0x00,0x03, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01, + 0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,0xc4,0x00,0xb5,0x11,0x00, + 0x02,0x01,0x02,0x04,0x04,0x03,0x04,0x07,0x05,0x04,0x04,0x00,0x01,0x02,0x77,0x00, + 0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,0x13, + 0x22,0x32,0x81,0x08,0x14,0x42,0x91,0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,0x15, + 0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,0x27, + 0x28,0x29,0x2a,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49, + 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69, + 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,0x88, + 0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6, + 0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4, + 0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe2, + 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9, + 0xfa,0xff,0xda,0x00,0x0c,0x03,0x01,0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb7, + 0x69,0xa4,0xe9,0xbf,0x62,0x83,0xfe,0x25,0xf6,0x9f,0xea,0xd7,0xfe,0x58,0xaf,0xa7, + 0xd2,0x8a,0x28,0xae,0xb3,0x98,0xff,0xd9, +}; + +static const uint8_t jpg_grayscale_2_2[] = +{ + 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x00,0x00,0x01, + 0x00,0x01,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x08,0x06,0x06,0x07,0x06,0x05,0x08, + 0x07,0x07,0x07,0x09,0x09,0x08,0x0a,0x0c,0x14,0x0d,0x0c,0x0b,0x0b,0x0c,0x19,0x12, + 0x13,0x0f,0x14,0x1d,0x1a,0x1f,0x1e,0x1d,0x1a,0x1c,0x1c,0x20,0x24,0x2e,0x27,0x20, + 0x22,0x2c,0x23,0x1c,0x1c,0x28,0x37,0x29,0x2c,0x30,0x31,0x34,0x34,0x34,0x1f,0x27, + 0x39,0x3d,0x38,0x32,0x3c,0x2e,0x33,0x34,0x32,0xff,0xc0,0x00,0x0b,0x08,0x00,0x02, + 0x00,0x02,0x01,0x01,0x11,0x00,0xff,0xc4,0x00,0x1f,0x00,0x00,0x01,0x05,0x01,0x01, + 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04, + 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,0xc4,0x00,0xb5,0x10,0x00,0x02,0x01,0x03, + 0x03,0x02,0x04,0x03,0x05,0x05,0x04,0x04,0x00,0x00,0x01,0x7d,0x01,0x02,0x03,0x00, + 0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,0x71,0x14,0x32, + 0x81,0x91,0xa1,0x08,0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72, + 0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,0x29,0x2a,0x34,0x35, + 0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55, + 0x56,0x57,0x58,0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75, + 0x76,0x77,0x78,0x79,0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x92,0x93,0x94, + 0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2, + 0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9, + 0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6, + 0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xff,0xda, + 0x00,0x08,0x01,0x01,0x00,0x00,0x3f,0x00,0xea,0x2c,0x34,0x1d,0x1f,0xfb,0x3a,0xdb, + 0xfe,0x25,0x36,0x3f,0xea,0x93,0xfe,0x5d,0xd3,0xd0,0x7b,0x57,0xff,0xd9, +}; + /* 2x2 A8R8G8B8 pixel data */ static const uint8_t pixdata[] = { diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index c4cd89b2ccc..9fa86044250 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -927,6 +927,30 @@ static void test_D3DXGetImageInfo(void) ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); ok(info.Format == D3DFMT_A8R8G8B8, "Got unexpected format %u.\n", info.Format);
+ /* Test JPG support. */ + hr = D3DXGetImageInfoFromFileInMemory(jpg_rgb_2_2, sizeof(jpg_rgb_2_2), &info); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, TRUE); + + hr = D3DXGetImageInfoFromFileInMemory(jpg_grayscale_2_2, sizeof(jpg_grayscale_2_2), &info); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_L8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, FALSE); + + /* Test PNG support. */ + hr = D3DXGetImageInfoFromFileInMemory(png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), &info); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + check_image_info(&info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + + hr = D3DXGetImageInfoFromFileInMemory(png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), &info); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + check_image_info(&info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + + hr = D3DXGetImageInfoFromFileInMemory(png_2_2_24bpp_bgr, sizeof(png_2_2_24bpp_bgr), &info); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); + /* Grayscale PNG */ hr = D3DXGetImageInfoFromFileInMemory(png_grayscale, sizeof(png_grayscale), &info); ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK); @@ -1082,6 +1106,13 @@ static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_RECT *lo ok_(__FILE__, line)(color == expected_color, "Got color 0x%08lx, expected 0x%08lx\n", color, expected_color); }
+#define check_pixel_8bpp(lockrect, x, y, color) _check_pixel_8bpp(__LINE__, lockrect, x, y, color) +static inline void _check_pixel_8bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, uint64_t expected_color) +{ + uint64_t color = ((uint64_t *)lockrect->pBits)[x + y * (lockrect->Pitch / 8)]; + ok_(__FILE__, line)(color == expected_color, "Got color %#I64x, expected %#I64x.\n", color, expected_color); +} + #define check_pixel_float4(lockrect, x, y, fx, fy, fz, fw, ulps, todo) \ _check_pixel_float4(__LINE__, lockrect, x, y, fx, fy, fz, fw, ulps, todo) static inline void _check_pixel_float4(uint32_t line, const D3DLOCKED_RECT *lockrect, uint32_t x, uint32_t y, @@ -3372,6 +3403,44 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) check_release((IUnknown*)tex, 0); }
+ hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A16B16G16R16, D3DPOOL_SCRATCH, &surf, NULL); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + + hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), NULL, + D3DX_FILTER_NONE, 0, NULL); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + + check_pixel_8bpp(&lockrect, 0, 0, 0xffff202010100000); + check_pixel_8bpp(&lockrect, 1, 0, 0xffff505040403030); + check_pixel_8bpp(&lockrect, 0, 1, 0xffff808070706060); + check_pixel_8bpp(&lockrect, 1, 1, 0xffffb0b0a0a09090); + + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); + } + + hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), NULL, + D3DX_FILTER_NONE, 0, NULL); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + + check_pixel_8bpp(&lockrect, 0, 0, 0x3030202010100000); + check_pixel_8bpp(&lockrect, 1, 0, 0x7070606050504040); + check_pixel_8bpp(&lockrect, 0, 1, 0xb0b0a0a090908080); + check_pixel_8bpp(&lockrect, 1, 1, 0xf0f0e0e0d0d0c0c0); + + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); + } + check_release((IUnknown *)surf, 0); + test_format_conversion(device); test_dxt_premultiplied_alpha(device); test_load_surface_from_tga(device); diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index bc9e5daaf1d..6c5cd682f8e 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -2481,6 +2481,46 @@ static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device) { skip("D3DFMT_DXT3 textures are not supported, skipping tests.\n"); } + + /* Create texture from JPG. */ + hr = D3DXCreateTextureFromFileInMemoryEx(device, jpg_rgb_2_2, sizeof(jpg_rgb_2_2), D3DX_DEFAULT, + D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, + D3DX_DEFAULT, D3DX_DEFAULT, 0, &img_info, NULL, &texture); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, TRUE); + check_texture_level_desc(texture, 0, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, 2, FALSE); + check_texture_level_desc(texture, 1, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 1, 1, FALSE); + + IDirect3DTexture9_Release(texture); + + /* Create texture from PNG. */ + hr = D3DXCreateTextureFromFileInMemoryEx(device, png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), D3DX_DEFAULT, + D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, + D3DX_DEFAULT, D3DX_DEFAULT, 0, &img_info, NULL, &texture); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); + check_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, 2, FALSE); + check_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 1, 1, FALSE); + IDirect3DTexture9_Release(texture); + } + + hr = D3DXCreateTextureFromFileInMemoryEx(device, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), D3DX_DEFAULT, + D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, + D3DX_DEFAULT, D3DX_DEFAULT, 0, &img_info, NULL, &texture); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); + check_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, 2, FALSE); + check_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 1, 1, FALSE); + IDirect3DTexture9_Release(texture); + } }
static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device) @@ -3013,6 +3053,48 @@ static void test_D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *dev release_volume_readback(&volume_rb); } IDirect3DVolumeTexture9_Release(texture); + + /* Create texture from JPG. */ + hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, jpg_rgb_2_2, sizeof(jpg_rgb_2_2), + D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, + D3DX_DEFAULT, D3DX_FILTER_POINT, 0, &img_info, NULL, &texture); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, TRUE); + check_volume_texture_level_desc(texture, 0, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 2, 2, 1, FALSE); + check_volume_texture_level_desc(texture, 1, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 1, 1, 1, FALSE); + + IDirect3DVolumeTexture9_Release(texture); + + /* Create texture from PNG. */ + hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), + D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, + D3DX_DEFAULT, D3DX_FILTER_POINT, 0, &img_info, NULL, &texture); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); + check_volume_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 2, 2, 1, FALSE); + check_volume_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 1, 1, 1, FALSE); + + IDirect3DVolumeTexture9_Release(texture); + } + + hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), + D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, + D3DX_DEFAULT, D3DX_FILTER_POINT, 0, &img_info, NULL, &texture); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); + check_volume_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 2, 2, 1, FALSE); + check_volume_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 1, 1, 1, FALSE); + + IDirect3DVolumeTexture9_Release(texture); + } }
/* fills positive x face with red color */ diff --git a/dlls/d3dx9_36/tests/volume.c b/dlls/d3dx9_36/tests/volume.c index 68eca7c531b..881968397b9 100644 --- a/dlls/d3dx9_36/tests/volume.c +++ b/dlls/d3dx9_36/tests/volume.c @@ -30,6 +30,13 @@ static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_BOX *box ok_(__FILE__, line)(color == expected_color, "Got color 0x%08lx, expected 0x%08lx\n", color, expected_color); }
+#define check_pixel_8bpp(box, x, y, z, color) _check_pixel_8bpp(__LINE__, box, x, y, z, color) +static inline void _check_pixel_8bpp(unsigned int line, const D3DLOCKED_BOX *box, int x, int y, int z, uint64_t expected_color) +{ + uint64_t color = ((uint64_t *)box->pBits)[x + (y * box->RowPitch + z * box->SlicePitch) / 8]; + ok_(__FILE__, line)(color == expected_color, "Got color %#I64x, expected %#I64x.\n", color, expected_color); +} + static inline void set_box(D3DBOX *box, UINT left, UINT top, UINT right, UINT bottom, UINT front, UINT back) { box->Left = left; @@ -214,6 +221,7 @@ static void test_D3DXLoadVolumeFromFileInMemory(IDirect3DDevice9 *device) D3DVOLUME_DESC desc; D3DXIMAGE_INFO img_info; IDirect3DVolume9 *volume; + D3DLOCKED_BOX locked_box; struct volume_readback volume_rb; IDirect3DVolumeTexture9 *volume_texture; static const uint32_t bmp_32bpp_4_4_argb_expected[] = @@ -336,6 +344,52 @@ static void test_D3DXLoadVolumeFromFileInMemory(IDirect3DDevice9 *device)
IDirect3DVolume9_Release(volume); IDirect3DVolumeTexture9_Release(volume_texture); + + /* PNG tests. */ + hr = IDirect3DDevice9_CreateVolumeTexture(device, 2, 2, 2, 1, D3DUSAGE_DYNAMIC, D3DFMT_A16B16G16R16, D3DPOOL_DEFAULT, + &volume_texture, NULL); + if (FAILED(hr)) + { + skip("Failed to create volume texture\n"); + return; + } + + IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, 0, &volume); + + hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), NULL, + D3DX_FILTER_POINT, 0, NULL); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + + IDirect3DVolume9_LockBox(volume, &locked_box, NULL, D3DLOCK_READONLY); + + for (i = 0; i < 2; ++i) + { + todo_wine check_pixel_8bpp(&locked_box, 0, 0, i, 0xffff202010100000); + todo_wine check_pixel_8bpp(&locked_box, 1, 0, i, 0xffff505040403030); + todo_wine check_pixel_8bpp(&locked_box, 0, 1, i, 0xffff808070706060); + todo_wine check_pixel_8bpp(&locked_box, 1, 1, i, 0xffffb0b0a0a09090); + } + + IDirect3DVolume9_UnlockBox(volume); + + hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), NULL, + D3DX_FILTER_POINT, 0, NULL); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + + IDirect3DVolume9_LockBox(volume, &locked_box, NULL, D3DLOCK_READONLY); + + for (i = 0; i < 2; ++i) + { + todo_wine check_pixel_8bpp(&locked_box, 0, 0, i, 0x3030202010100000); + todo_wine check_pixel_8bpp(&locked_box, 1, 0, i, 0x7070606050504040); + todo_wine check_pixel_8bpp(&locked_box, 0, 1, i, 0xb0b0a0a090908080); + todo_wine check_pixel_8bpp(&locked_box, 1, 1, i, 0xf0f0e0e0d0d0c0c0); + } + + IDirect3DVolume9_UnlockBox(volume); + + IDirect3DVolume9_Release(volume); + IDirect3DVolumeTexture9_Release(volume_texture); }
START_TEST(volume)
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 | 4 ++-- dlls/d3dx9_36/tests/texture.c | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 7f37fb0337f..3b02f0708f7 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1365,7 +1365,11 @@ void d3dximage_info_from_d3dx_image(D3DXIMAGE_INFO *info, struct d3dx_image *ima info->Height = image->size.height; info->Depth = image->size.depth; info->MipLevels = image->mip_levels; - info->Format = d3dformat_from_d3dx_pixel_format_id(image->format); + if ((info->ImageFileFormat == D3DXIFF_PNG || info->ImageFileFormat == D3DXIFF_JPG) + && image->format == D3DX_PIXEL_FORMAT_B8G8R8_UNORM) + info->Format = D3DFMT_X8R8G8B8; + else + info->Format = d3dformat_from_d3dx_pixel_format_id(image->format); info->ResourceType = image->resource_type; }
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 9fa86044250..9cbe629275d 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -930,7 +930,7 @@ static void test_D3DXGetImageInfo(void) /* Test JPG support. */ hr = D3DXGetImageInfoFromFileInMemory(jpg_rgb_2_2, sizeof(jpg_rgb_2_2), &info); ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - check_image_info(&info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, TRUE); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, FALSE);
hr = D3DXGetImageInfoFromFileInMemory(jpg_grayscale_2_2, sizeof(jpg_grayscale_2_2), &info); ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); @@ -949,7 +949,7 @@ static void test_D3DXGetImageInfo(void)
hr = D3DXGetImageInfoFromFileInMemory(png_2_2_24bpp_bgr, sizeof(png_2_2_24bpp_bgr), &info); ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - check_image_info(&info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE);
/* Grayscale PNG */ hr = D3DXGetImageInfoFromFileInMemory(png_grayscale, sizeof(png_grayscale), &info); diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index 6c5cd682f8e..0d880e6938f 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -2489,7 +2489,7 @@ static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
check_texture_mip_levels(texture, 2, FALSE); - check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, TRUE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, FALSE); check_texture_level_desc(texture, 0, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, 2, FALSE); check_texture_level_desc(texture, 1, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 1, 1, FALSE);
@@ -3061,7 +3061,7 @@ static void test_D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *dev ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
check_texture_mip_levels(texture, 2, FALSE); - check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, TRUE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_TEXTURE, D3DXIFF_JPG, FALSE); check_volume_texture_level_desc(texture, 0, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 2, 2, 1, FALSE); check_volume_texture_level_desc(texture, 1, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 1, 1, 1, FALSE);
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 3 ++- dlls/d3dx9_36/tests/surface.c | 27 ++++++++++++--------------- dlls/d3dx9_36/tests/texture.c | 32 ++++++++++++++------------------ dlls/d3dx9_36/tests/volume.c | 10 +++++----- 4 files changed, 33 insertions(+), 39 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 3b02f0708f7..49089f21d6a 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -46,7 +46,8 @@ static const struct { &GUID_WICPixelFormat16bppBGR565, D3DX_PIXEL_FORMAT_B5G6R5_UNORM }, { &GUID_WICPixelFormat24bppBGR, D3DX_PIXEL_FORMAT_B8G8R8_UNORM }, { &GUID_WICPixelFormat32bppBGR, D3DX_PIXEL_FORMAT_B8G8R8X8_UNORM }, - { &GUID_WICPixelFormat32bppBGRA, D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM } + { &GUID_WICPixelFormat32bppBGRA, D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM }, + { &GUID_WICPixelFormat64bppRGBA, D3DX_PIXEL_FORMAT_R16G16B16A16_UNORM }, };
static enum d3dx_pixel_format_id d3dx_pixel_format_id_from_wic_pixel_format(const GUID *guid) diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 9cbe629275d..9e115cb5b0a 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -943,9 +943,8 @@ static void test_D3DXGetImageInfo(void) check_image_info(&info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE);
hr = D3DXGetImageInfoFromFileInMemory(png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), &info); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - check_image_info(&info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE);
hr = D3DXGetImageInfoFromFileInMemory(png_2_2_24bpp_bgr, sizeof(png_2_2_24bpp_bgr), &info); ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); @@ -3425,20 +3424,18 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), NULL, D3DX_FILTER_NONE, 0, NULL); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); - ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
- check_pixel_8bpp(&lockrect, 0, 0, 0x3030202010100000); - check_pixel_8bpp(&lockrect, 1, 0, 0x7070606050504040); - check_pixel_8bpp(&lockrect, 0, 1, 0xb0b0a0a090908080); - check_pixel_8bpp(&lockrect, 1, 1, 0xf0f0e0e0d0d0c0c0); + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
- hr = IDirect3DSurface9_UnlockRect(surf); - ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); - } + check_pixel_8bpp(&lockrect, 0, 0, 0x3030202010100000); + check_pixel_8bpp(&lockrect, 1, 0, 0x7070606050504040); + check_pixel_8bpp(&lockrect, 0, 1, 0xb0b0a0a090908080); + check_pixel_8bpp(&lockrect, 1, 1, 0xf0f0e0e0d0d0c0c0); + + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); check_release((IUnknown *)surf, 0);
test_format_conversion(device); diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index 0d880e6938f..e7ca1320d0b 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -2512,15 +2512,13 @@ static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device) hr = D3DXCreateTextureFromFileInMemoryEx(device, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, &img_info, NULL, &texture); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - check_texture_mip_levels(texture, 2, FALSE); - check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); - check_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, 2, FALSE); - check_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 1, 1, FALSE); - IDirect3DTexture9_Release(texture); - } + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + check_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, 2, FALSE); + check_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 1, 1, FALSE); + IDirect3DTexture9_Release(texture); }
static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device) @@ -3085,16 +3083,14 @@ static void test_D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *dev hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_FILTER_POINT, 0, &img_info, NULL, &texture); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - check_texture_mip_levels(texture, 2, FALSE); - check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); - check_volume_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 2, 2, 1, FALSE); - check_volume_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 1, 1, 1, FALSE); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
- IDirect3DVolumeTexture9_Release(texture); - } + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + check_volume_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 2, 2, 1, FALSE); + check_volume_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 1, 1, 1, FALSE); + + IDirect3DVolumeTexture9_Release(texture); }
/* fills positive x face with red color */ diff --git a/dlls/d3dx9_36/tests/volume.c b/dlls/d3dx9_36/tests/volume.c index 881968397b9..cf32604ae0c 100644 --- a/dlls/d3dx9_36/tests/volume.c +++ b/dlls/d3dx9_36/tests/volume.c @@ -374,16 +374,16 @@ static void test_D3DXLoadVolumeFromFileInMemory(IDirect3DDevice9 *device)
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), NULL, D3DX_FILTER_POINT, 0, NULL); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
IDirect3DVolume9_LockBox(volume, &locked_box, NULL, D3DLOCK_READONLY);
for (i = 0; i < 2; ++i) { - todo_wine check_pixel_8bpp(&locked_box, 0, 0, i, 0x3030202010100000); - todo_wine check_pixel_8bpp(&locked_box, 1, 0, i, 0x7070606050504040); - todo_wine check_pixel_8bpp(&locked_box, 0, 1, i, 0xb0b0a0a090908080); - todo_wine check_pixel_8bpp(&locked_box, 1, 1, i, 0xf0f0e0e0d0d0c0c0); + check_pixel_8bpp(&locked_box, 0, 0, i, 0x3030202010100000); + check_pixel_8bpp(&locked_box, 1, 0, i, 0x7070606050504040); + check_pixel_8bpp(&locked_box, 0, 1, i, 0xb0b0a0a090908080); + check_pixel_8bpp(&locked_box, 1, 1, i, 0xf0f0e0e0d0d0c0c0); }
IDirect3DVolume9_UnlockBox(volume);
From: Connor McAdams cmcadams@codeweavers.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48796 Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 8 ++++++++ dlls/d3dx9_36/surface.c | 23 ++++++++++++++++++----- dlls/d3dx9_36/tests/surface.c | 5 ++--- dlls/d3dx9_36/tests/texture.c | 31 +++++++++++++------------------ dlls/d3dx9_36/util.c | 4 +++- 5 files changed, 44 insertions(+), 27 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index 6c1db3f2e31..6a9b3e12b7b 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -107,6 +107,7 @@ enum d3dx_pixel_format_id D3DX_PIXEL_FORMAT_B4G4R4X4_UNORM, D3DX_PIXEL_FORMAT_B10G10R10A2_UNORM, D3DX_PIXEL_FORMAT_R10G10B10A2_UNORM, + D3DX_PIXEL_FORMAT_R16G16B16_UNORM, D3DX_PIXEL_FORMAT_R16G16B16A16_UNORM, D3DX_PIXEL_FORMAT_R16G16_UNORM, D3DX_PIXEL_FORMAT_A8_UNORM, @@ -155,6 +156,8 @@ enum format_flag { FMT_FLAG_DXT = 0x01, FMT_FLAG_PACKED = 0x02, + /* Internal only format, has no exact D3DFORMAT equivalent. */ + FMT_FLAG_INTERNAL = 0x04, };
struct pixel_format_desc { @@ -267,6 +270,11 @@ static inline BOOL format_types_match(const struct pixel_format_desc *src, const return (src->rgb_type == dst->rgb_type || src->a_type == dst->a_type); }
+static inline BOOL is_internal_format(const struct pixel_format_desc *format) +{ + return !!(format->flags & FMT_FLAG_INTERNAL); +} + static inline BOOL is_conversion_from_supported(const struct pixel_format_desc *format) { return !is_packed_format(format) && !is_unknown_format(format); diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 49089f21d6a..bc190960536 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -47,6 +47,7 @@ static const struct { &GUID_WICPixelFormat24bppBGR, D3DX_PIXEL_FORMAT_B8G8R8_UNORM }, { &GUID_WICPixelFormat32bppBGR, D3DX_PIXEL_FORMAT_B8G8R8X8_UNORM }, { &GUID_WICPixelFormat32bppBGRA, D3DX_PIXEL_FORMAT_B8G8R8A8_UNORM }, + { &GUID_WICPixelFormat48bppRGB, D3DX_PIXEL_FORMAT_R16G16B16_UNORM }, { &GUID_WICPixelFormat64bppRGBA, D3DX_PIXEL_FORMAT_R16G16B16A16_UNORM }, };
@@ -1366,11 +1367,23 @@ void d3dximage_info_from_d3dx_image(D3DXIMAGE_INFO *info, struct d3dx_image *ima info->Height = image->size.height; info->Depth = image->size.depth; info->MipLevels = image->mip_levels; - if ((info->ImageFileFormat == D3DXIFF_PNG || info->ImageFileFormat == D3DXIFF_JPG) - && image->format == D3DX_PIXEL_FORMAT_B8G8R8_UNORM) - info->Format = D3DFMT_X8R8G8B8; - else - info->Format = d3dformat_from_d3dx_pixel_format_id(image->format); + switch (image->format) + { + case D3DX_PIXEL_FORMAT_R16G16B16_UNORM: + info->Format = D3DFMT_A16B16G16R16; + break; + + case D3DX_PIXEL_FORMAT_B8G8R8_UNORM: + if (info->ImageFileFormat == D3DXIFF_PNG || info->ImageFileFormat == D3DXIFF_JPG) + info->Format = D3DFMT_X8R8G8B8; + else + info->Format = d3dformat_from_d3dx_pixel_format_id(image->format); + break; + + default: + info->Format = d3dformat_from_d3dx_pixel_format_id(image->format); + break; + } info->ResourceType = image->resource_type; }
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 9e115cb5b0a..a8b5ccfbbdd 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -938,9 +938,8 @@ static void test_D3DXGetImageInfo(void)
/* Test PNG support. */ hr = D3DXGetImageInfoFromFileInMemory(png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), &info); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - check_image_info(&info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE);
hr = D3DXGetImageInfoFromFileInMemory(png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), &info); ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index e7ca1320d0b..ce7f6d7056f 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -2499,15 +2499,12 @@ static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device) hr = D3DXCreateTextureFromFileInMemoryEx(device, png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, &img_info, NULL, &texture); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - check_texture_mip_levels(texture, 2, FALSE); - check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); - check_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, 2, FALSE); - check_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 1, 1, FALSE); - IDirect3DTexture9_Release(texture); - } + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + check_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, 2, FALSE); + check_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 1, 1, FALSE); + IDirect3DTexture9_Release(texture);
hr = D3DXCreateTextureFromFileInMemoryEx(device, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, @@ -3069,16 +3066,14 @@ static void test_D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *dev hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_FILTER_POINT, 0, &img_info, NULL, &texture); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - check_texture_mip_levels(texture, 2, FALSE); - check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, TRUE); - check_volume_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 2, 2, 1, FALSE); - check_volume_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 1, 1, 1, FALSE); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
- IDirect3DVolumeTexture9_Release(texture); - } + check_texture_mip_levels(texture, 2, FALSE); + check_image_info(&img_info, 2, 2, 1, 1, D3DFMT_A16B16G16R16, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + check_volume_texture_level_desc(texture, 0, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 2, 2, 1, FALSE); + check_volume_texture_level_desc(texture, 1, D3DFMT_A16B16G16R16, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 1, 1, 1, FALSE); + + IDirect3DVolumeTexture9_Release(texture);
hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index f2ea089ce82..e6a11cdc1e4 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -45,6 +45,7 @@ static const struct pixel_format_desc formats[] = {D3DX_PIXEL_FORMAT_B4G4R4X4_UNORM, { 0, 4, 4, 4}, { 0, 8, 4, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_UNORM, 0 }, {D3DX_PIXEL_FORMAT_B10G10R10A2_UNORM, { 2, 10, 10, 10}, {30, 20, 10, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, {D3DX_PIXEL_FORMAT_R10G10B10A2_UNORM, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_UNORM, 0 }, + {D3DX_PIXEL_FORMAT_R16G16B16_UNORM, { 0, 16, 16, 16}, { 0, 0, 16, 32}, 6, 1, 1, 6, CTYPE_EMPTY, CTYPE_UNORM, FMT_FLAG_INTERNAL}, {D3DX_PIXEL_FORMAT_R16G16B16A16_UNORM, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_UNORM, CTYPE_UNORM, 0 }, {D3DX_PIXEL_FORMAT_R16G16_UNORM, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_UNORM, 0 }, {D3DX_PIXEL_FORMAT_A8_UNORM, { 8, 0, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_UNORM, CTYPE_EMPTY, 0 }, @@ -128,7 +129,8 @@ D3DFORMAT d3dformat_from_d3dx_pixel_format_id(enum d3dx_pixel_format_id format) case D3DX_PIXEL_FORMAT_UYVY: return D3DFMT_UYVY; case D3DX_PIXEL_FORMAT_YUY2: return D3DFMT_YUY2; default: - FIXME("Unknown d3dx_pixel_format_id %u.\n", format); + if (!is_internal_format(get_d3dx_pixel_format_info(format))) + FIXME("Unknown d3dx_pixel_format_id %u.\n", format); return D3DFMT_UNKNOWN; } }
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 146 ++++++++++++++++++---------------- dlls/d3dx9_36/tests/surface.c | 22 +++-- 2 files changed, 88 insertions(+), 80 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index bc190960536..23af0f6f816 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1529,6 +1529,73 @@ HRESULT WINAPI D3DXGetImageInfoFromResourceW(HMODULE module, const WCHAR *resour return D3DXGetImageInfoFromFileInMemory(buffer, size, info); }
+static HRESULT d3dx_load_surface_from_memory(IDirect3DSurface9 *dst_surface, + const PALETTEENTRY *dst_palette, const RECT *dst_rect, const void *src_memory, + enum d3dx_pixel_format_id src_format, uint32_t src_pitch, const PALETTEENTRY *src_palette, const RECT *src_rect, + DWORD filter, D3DCOLOR color_key) +{ + const struct pixel_format_desc *src_desc, *dst_desc; + struct d3dx_pixels src_pixels, dst_pixels; + RECT dst_rect_tmp, dst_rect_aligned; + IDirect3DSurface9 *surface; + D3DLOCKED_RECT lock_rect; + D3DSURFACE_DESC desc; + HRESULT hr; + + IDirect3DSurface9_GetDesc(dst_surface, &desc); + if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) + { + TRACE("Multisampled destination surface, doing nothing.\n"); + return D3D_OK; + } + + dst_desc = get_format_info(desc.Format); + if (!dst_rect) + { + SetRect(&dst_rect_tmp, 0, 0, desc.Width, desc.Height); + dst_rect = &dst_rect_tmp; + } + else + { + if (dst_rect->left > dst_rect->right || dst_rect->right > desc.Width + || dst_rect->top > dst_rect->bottom || dst_rect->bottom > desc.Height + || dst_rect->left < 0 || dst_rect->top < 0) + { + WARN("Invalid dst_rect specified.\n"); + return D3DERR_INVALIDCALL; + } + if (dst_rect->left == dst_rect->right || dst_rect->top == dst_rect->bottom) + { + WARN("Empty dst_rect specified.\n"); + return D3D_OK; + } + } + + src_desc = get_d3dx_pixel_format_info(src_format); + hr = d3dx_pixels_init(src_memory, src_pitch, 0, src_palette, src_desc->format, + src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, 0, 1, &src_pixels); + if (FAILED(hr)) + return hr; + + get_aligned_rect(dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, desc.Width, desc.Height, + dst_desc, &dst_rect_aligned); + if (FAILED(hr = lock_surface(dst_surface, &dst_rect_aligned, &lock_rect, &surface, TRUE))) + return hr; + + set_d3dx_pixels(&dst_pixels, lock_rect.pBits, lock_rect.Pitch, 0, dst_palette, + (dst_rect_aligned.right - dst_rect_aligned.left), (dst_rect_aligned.bottom - dst_rect_aligned.top), 1, + dst_rect); + OffsetRect(&dst_pixels.unaligned_rect, -dst_rect_aligned.left, -dst_rect_aligned.top); + + if (FAILED(hr = d3dx_load_pixels_from_pixels(&dst_pixels, dst_desc, &src_pixels, src_desc, filter, color_key))) + { + unlock_surface(dst_surface, &dst_rect_aligned, surface, FALSE); + return hr; + } + + return unlock_surface(dst_surface, &dst_rect_aligned, surface, TRUE); +} + /************************************************************ * D3DXLoadSurfaceFromFileInMemory * @@ -1587,9 +1654,8 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(IDirect3DSurface9 *pDestSurface, if (FAILED(hr)) goto exit;
- hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect, pixels.data, - d3dformat_from_d3dx_pixel_format_id(image.format), pixels.row_pitch, pixels.palette, &src_rect, dwFilter, - Colorkey); + hr = d3dx_load_surface_from_memory(pDestSurface, pDestPalette, pDestRect, pixels.data, image.format, pixels.row_pitch, + pixels.palette, &src_rect, dwFilter, Colorkey); if (SUCCEEDED(hr) && pSrcInfo) *pSrcInfo = img_info;
@@ -2560,12 +2626,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, D3DFORMAT src_format, UINT src_pitch, const PALETTEENTRY *src_palette, const RECT *src_rect, DWORD filter, D3DCOLOR color_key) { - const struct pixel_format_desc *srcformatdesc, *destformatdesc; - struct d3dx_pixels src_pixels, dst_pixels; - RECT dst_rect_temp, dst_rect_aligned; - IDirect3DSurface9 *surface; - D3DSURFACE_DESC surfdesc; - D3DLOCKED_RECT lockrect; + const struct pixel_format_desc *src_desc; HRESULT hr;
TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_memory %p, src_format %#x, " @@ -2578,6 +2639,10 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, WARN("Invalid argument specified.\n"); return D3DERR_INVALIDCALL; } + + if (FAILED(hr = d3dx9_handle_load_filter(&filter))) + return hr; + if (src_format == D3DFMT_UNKNOWN || src_rect->left >= src_rect->right || src_rect->top >= src_rect->bottom) @@ -2586,70 +2651,15 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, return E_FAIL; }
- srcformatdesc = get_format_info(src_format); - if (is_unknown_format(srcformatdesc)) + src_desc = get_format_info(src_format); + if (is_unknown_format(src_desc)) { FIXME("Unsupported format %#x.\n", src_format); return E_NOTIMPL; }
- IDirect3DSurface9_GetDesc(dst_surface, &surfdesc); - if (surfdesc.MultiSampleType != D3DMULTISAMPLE_NONE) - { - TRACE("Multisampled destination surface, doing nothing.\n"); - return D3D_OK; - } - - destformatdesc = get_format_info(surfdesc.Format); - if (!dst_rect) - { - dst_rect = &dst_rect_temp; - dst_rect_temp.left = 0; - dst_rect_temp.top = 0; - dst_rect_temp.right = surfdesc.Width; - dst_rect_temp.bottom = surfdesc.Height; - } - else - { - if (dst_rect->left > dst_rect->right || dst_rect->right > surfdesc.Width - || dst_rect->top > dst_rect->bottom || dst_rect->bottom > surfdesc.Height - || dst_rect->left < 0 || dst_rect->top < 0) - { - WARN("Invalid dst_rect specified.\n"); - return D3DERR_INVALIDCALL; - } - if (dst_rect->left == dst_rect->right || dst_rect->top == dst_rect->bottom) - { - WARN("Empty dst_rect specified.\n"); - return D3D_OK; - } - } - - if (FAILED(hr = d3dx9_handle_load_filter(&filter))) - return hr; - - hr = d3dx_pixels_init(src_memory, src_pitch, 0, src_palette, srcformatdesc->format, - src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, 0, 1, &src_pixels); - if (FAILED(hr)) - return hr; - - get_aligned_rect(dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, surfdesc.Width, surfdesc.Height, - destformatdesc, &dst_rect_aligned); - if (FAILED(hr = lock_surface(dst_surface, &dst_rect_aligned, &lockrect, &surface, TRUE))) - return hr; - - set_d3dx_pixels(&dst_pixels, lockrect.pBits, lockrect.Pitch, 0, dst_palette, - (dst_rect_aligned.right - dst_rect_aligned.left), (dst_rect_aligned.bottom - dst_rect_aligned.top), 1, - dst_rect); - OffsetRect(&dst_pixels.unaligned_rect, -dst_rect_aligned.left, -dst_rect_aligned.top); - - if (FAILED(hr = d3dx_load_pixels_from_pixels(&dst_pixels, destformatdesc, &src_pixels, srcformatdesc, filter, color_key))) - { - unlock_surface(dst_surface, &dst_rect_aligned, surface, FALSE); - return hr; - } - - return unlock_surface(dst_surface, &dst_rect_aligned, surface, TRUE); + return d3dx_load_surface_from_memory(dst_surface, dst_palette, dst_rect, src_memory, src_desc->format, src_pitch, + src_palette, src_rect, filter, color_key); }
/************************************************************ diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index a8b5ccfbbdd..98408d026ed 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -3406,20 +3406,18 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), NULL, D3DX_FILTER_NONE, 0, NULL); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); - ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
- check_pixel_8bpp(&lockrect, 0, 0, 0xffff202010100000); - check_pixel_8bpp(&lockrect, 1, 0, 0xffff505040403030); - check_pixel_8bpp(&lockrect, 0, 1, 0xffff808070706060); - check_pixel_8bpp(&lockrect, 1, 1, 0xffffb0b0a0a09090); + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
- hr = IDirect3DSurface9_UnlockRect(surf); - ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); - } + check_pixel_8bpp(&lockrect, 0, 0, 0xffff202010100000); + check_pixel_8bpp(&lockrect, 1, 0, 0xffff505040403030); + check_pixel_8bpp(&lockrect, 0, 1, 0xffff808070706060); + check_pixel_8bpp(&lockrect, 1, 1, 0xffffb0b0a0a09090); + + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_64bpp_rgba, sizeof(png_2_2_64bpp_rgba), NULL, D3DX_FILTER_NONE, 0, NULL);
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/volume.c | 10 +++--- dlls/d3dx9_36/volume.c | 69 +++++++++++++++++++++++------------- 2 files changed, 49 insertions(+), 30 deletions(-)
diff --git a/dlls/d3dx9_36/tests/volume.c b/dlls/d3dx9_36/tests/volume.c index cf32604ae0c..d7529eb486c 100644 --- a/dlls/d3dx9_36/tests/volume.c +++ b/dlls/d3dx9_36/tests/volume.c @@ -358,16 +358,16 @@ static void test_D3DXLoadVolumeFromFileInMemory(IDirect3DDevice9 *device)
hr = D3DXLoadVolumeFromFileInMemory(volume, NULL, NULL, png_2_2_48bpp_rgb, sizeof(png_2_2_48bpp_rgb), NULL, D3DX_FILTER_POINT, 0, NULL); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
IDirect3DVolume9_LockBox(volume, &locked_box, NULL, D3DLOCK_READONLY);
for (i = 0; i < 2; ++i) { - todo_wine check_pixel_8bpp(&locked_box, 0, 0, i, 0xffff202010100000); - todo_wine check_pixel_8bpp(&locked_box, 1, 0, i, 0xffff505040403030); - todo_wine check_pixel_8bpp(&locked_box, 0, 1, i, 0xffff808070706060); - todo_wine check_pixel_8bpp(&locked_box, 1, 1, i, 0xffffb0b0a0a09090); + check_pixel_8bpp(&locked_box, 0, 0, i, 0xffff202010100000); + check_pixel_8bpp(&locked_box, 1, 0, i, 0xffff505040403030); + check_pixel_8bpp(&locked_box, 0, 1, i, 0xffff808070706060); + check_pixel_8bpp(&locked_box, 1, 1, i, 0xffffb0b0a0a09090); }
IDirect3DVolume9_UnlockBox(volume); diff --git a/dlls/d3dx9_36/volume.c b/dlls/d3dx9_36/volume.c index 87c39e470f6..e3444a063c7 100644 --- a/dlls/d3dx9_36/volume.c +++ b/dlls/d3dx9_36/volume.c @@ -82,9 +82,9 @@ static void set_d3dbox(D3DBOX *box, uint32_t left, uint32_t top, uint32_t right, box->Back = back; }
-HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, +static HRESULT d3dx_load_volume_from_memory(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_memory, - D3DFORMAT src_format, UINT src_row_pitch, UINT src_slice_pitch, + enum d3dx_pixel_format_id src_format, uint32_t src_row_pitch, uint32_t src_slice_pitch, const PALETTEENTRY *src_palette, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key) { const struct pixel_format_desc *src_format_desc, *dst_format_desc; @@ -95,26 +95,6 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, D3DVOLUME_DESC desc; HRESULT hr;
- TRACE("dst_volume %p, dst_palette %p, dst_box %p, src_memory %p, src_format %#x, " - "src_row_pitch %u, src_slice_pitch %u, src_palette %p, src_box %p, filter %#lx, color_key 0x%08lx.\n", - dst_volume, dst_palette, dst_box, src_memory, src_format, src_row_pitch, src_slice_pitch, - src_palette, src_box, filter, color_key); - - if (!dst_volume || !src_memory || !src_box) return D3DERR_INVALIDCALL; - - if (src_format == D3DFMT_UNKNOWN - || src_box->Left >= src_box->Right - || src_box->Top >= src_box->Bottom - || src_box->Front >= src_box->Back) - return E_FAIL; - - if (FAILED(hr = d3dx9_handle_load_filter(&filter))) - return hr; - - src_format_desc = get_format_info(src_format); - if (is_unknown_format(src_format_desc)) - return E_NOTIMPL; - IDirect3DVolume9_GetDesc(dst_volume, &desc); dst_format_desc = get_format_info(desc.Format); if (is_unknown_format(dst_format_desc)) @@ -135,6 +115,7 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, return D3DERR_INVALIDCALL; }
+ src_format_desc = get_d3dx_pixel_format_info(src_format); hr = d3dx_pixels_init(src_memory, src_row_pitch, src_slice_pitch, src_palette, src_format_desc->format, src_box->Left, src_box->Top, src_box->Right, src_box->Bottom, src_box->Front, src_box->Back, &src_pixels); @@ -162,6 +143,39 @@ HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, return hr; }
+HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, + const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_memory, + D3DFORMAT src_format, UINT src_row_pitch, UINT src_slice_pitch, + const PALETTEENTRY *src_palette, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key) +{ + const struct pixel_format_desc *src_format_desc; + HRESULT hr; + + TRACE("dst_volume %p, dst_palette %p, dst_box %p, src_memory %p, src_format %#x, " + "src_row_pitch %u, src_slice_pitch %u, src_palette %p, src_box %p, filter %#lx, color_key 0x%08lx.\n", + dst_volume, dst_palette, dst_box, src_memory, src_format, src_row_pitch, src_slice_pitch, + src_palette, src_box, filter, color_key); + + if (!dst_volume || !src_memory || !src_box) + return D3DERR_INVALIDCALL; + + if (src_format == D3DFMT_UNKNOWN + || src_box->Left >= src_box->Right + || src_box->Top >= src_box->Bottom + || src_box->Front >= src_box->Back) + return E_FAIL; + + if (FAILED(hr = d3dx9_handle_load_filter(&filter))) + return hr; + + src_format_desc = get_format_info(src_format); + if (is_unknown_format(src_format_desc)) + return E_NOTIMPL; + + return d3dx_load_volume_from_memory(dst_volume, dst_palette, dst_box, src_memory, src_format_desc->format, + src_row_pitch, src_slice_pitch, src_palette, src_box, filter, color_key); +} + HRESULT WINAPI D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_data, UINT src_data_size, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key, D3DXIMAGE_INFO *src_info) @@ -197,6 +211,12 @@ HRESULT WINAPI D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9 *dst_volume, cons hr = D3DERR_INVALIDCALL; goto exit; } + if (src_box->Left >= src_box->Right || src_box->Top >= src_box->Bottom + || src_box->Front >= src_box->Back) + { + hr = E_FAIL; + goto exit; + }
box = *src_box; } @@ -209,9 +229,8 @@ HRESULT WINAPI D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9 *dst_volume, cons if (FAILED(hr)) goto exit;
- hr = D3DXLoadVolumeFromMemory(dst_volume, dst_palette, dst_box, pixels.data, - d3dformat_from_d3dx_pixel_format_id(image.format), pixels.row_pitch, pixels.slice_pitch, pixels.palette, - &box, filter, color_key); + hr = d3dx_load_volume_from_memory(dst_volume, dst_palette, dst_box, pixels.data, image.format, + pixels.row_pitch, pixels.slice_pitch, pixels.palette, &box, filter, color_key); if (SUCCEEDED(hr) && src_info) *src_info = image_info;
This merge request was approved by Matteo Bruni.