From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/d3dx9_test_images.h | 37 +++++++++++++++ dlls/d3dx9_36/tests/surface.c | 62 +++++++++++++++++++++++++ 2 files changed, 99 insertions(+)
diff --git a/dlls/d3dx9_36/tests/d3dx9_test_images.h b/dlls/d3dx9_36/tests/d3dx9_test_images.h index 3ed5373c705..e9ee1623134 100644 --- a/dlls/d3dx9_36/tests/d3dx9_test_images.h +++ b/dlls/d3dx9_36/tests/d3dx9_test_images.h @@ -297,6 +297,43 @@ static const uint8_t png_2_2_64bpp_rgba[] = 0x1c,0xbb,0xb8,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82, };
+static const uint8_t png_2_2_1bpp_indexed[] = +{ + 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, + 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x01,0x03,0x00,0x00,0x00,0x48,0x78,0x9f, + 0x67,0x00,0x00,0x00,0x06,0x50,0x4c,0x54,0x45,0x00,0x00,0x00,0xff,0xff,0xff,0xa5, + 0xd9,0x9f,0xdd,0x00,0x00,0x00,0x01,0x74,0x52,0x4e,0x53,0x00,0x40,0xe6,0xd8,0x66, + 0x00,0x00,0x00,0x0c,0x49,0x44,0x41,0x54,0x08,0x99,0x63,0x68,0x60,0x70,0x00,0x00, + 0x01,0xc4,0x00,0xc1,0xcd,0x7b,0x18,0xa0,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44, + 0xae,0x42,0x60,0x82, +}; + +static const uint8_t png_2_2_2bpp_indexed[] = +{ + 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, + 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x02,0x03,0x00,0x00,0x00,0x0f,0xd8,0xe5, + 0xb7,0x00,0x00,0x00,0x01,0x73,0x52,0x47,0x42,0x00,0xae,0xce,0x1c,0xe9,0x00,0x00, + 0x00,0x04,0x67,0x41,0x4d,0x41,0x00,0x00,0xb1,0x8f,0x0b,0xfc,0x61,0x05,0x00,0x00, + 0x00,0x0c,0x50,0x4c,0x54,0x45,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xff, + 0xff,0xff,0xfb,0x00,0x60,0xf6,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,0x54,0x18,0xd3, + 0x63,0x90,0x66,0xd8,0x0d,0x00,0x01,0x10,0x00,0xd7,0xa8,0x4b,0x7a,0x58,0x00,0x00, + 0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82, +}; + +static const uint8_t png_2_2_4bpp_indexed[] = +{ + 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, + 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x04,0x03,0x00,0x00,0x00,0x80,0x98,0x10, + 0x17,0x00,0x00,0x00,0x30,0x50,0x4c,0x54,0x45,0x00,0x00,0x00,0x11,0x11,0x11,0x22, + 0x22,0x22,0x33,0x33,0x33,0x44,0x44,0x44,0x55,0x55,0x55,0x66,0x66,0x66,0x77,0x77, + 0x77,0x88,0x88,0x88,0x99,0x99,0x99,0xaa,0xaa,0xaa,0xbb,0xbb,0xbb,0xcc,0xcc,0xcc, + 0xdd,0xdd,0xdd,0xee,0xee,0xee,0xff,0xff,0xff,0x7b,0x10,0x18,0x0a,0x00,0x00,0x00, + 0x10,0x74,0x52,0x4e,0x53,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, + 0xf0,0xf0,0xf0,0xf0,0xf0,0xb1,0x0f,0x99,0x6f,0x00,0x00,0x00,0x0c,0x49,0x44,0x41, + 0x54,0x08,0x99,0x63,0x60,0x61,0xe8,0x01,0x00,0x00,0x9c,0x00,0x91,0x1c,0x0a,0x18, + 0x41,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, diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 5e72eb7d0a4..22afe167155 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -2519,6 +2519,7 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) -0.1f, -0.2f, -NAN, -INFINITY, -1.0f, -1.1f, -1.2f, -1.3f }; static const uint16_t pixdata_v8u8[] = { 0x3000, 0x7f40, 0x8180, 0xffc0 }; BYTE buffer[4 * 8 * 4]; + D3DXIMAGE_INFO info; uint32_t i;
hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */ @@ -3757,6 +3758,67 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); check_release((IUnknown *)surf, 0);
+ hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surf, NULL); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + + /* Indexed PNG. */ + SetRect(&rect, 0, 0, 2, 2); + hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_1bpp_indexed, sizeof(png_2_2_1bpp_indexed), &rect, + D3DX_FILTER_NONE, 0, &info); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_P8, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + + if (!strcmp(winetest_platform, "wine")) + { + skip("Skipping 1bpp indexed PNG readback tests.\n"); + } + else + { + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + check_pixel_4bpp(&lockrect, 0, 0, 0xffffffff); + check_pixel_4bpp(&lockrect, 1, 0, 0x00000000); + check_pixel_4bpp(&lockrect, 0, 1, 0x00000000); + check_pixel_4bpp(&lockrect, 1, 1, 0xffffffff); + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); + } + + /* 2bpp. */ + hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_2bpp_indexed, sizeof(png_2_2_2bpp_indexed), &rect, + D3DX_FILTER_NONE, 0, &info); + todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + { + check_image_info(&info, 2, 2, 1, 1, D3DFMT_P8, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + check_pixel_4bpp(&lockrect, 0, 0, 0xffff0000); + check_pixel_4bpp(&lockrect, 1, 0, 0xff00ff00); + check_pixel_4bpp(&lockrect, 0, 1, 0xff0000ff); + check_pixel_4bpp(&lockrect, 1, 1, 0xffffffff); + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); + } + + /* 4bpp. */ + hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_4bpp_indexed, sizeof(png_2_2_4bpp_indexed), &rect, + D3DX_FILTER_NONE, 0, &info); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_P8, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + todo_wine check_pixel_4bpp(&lockrect, 0, 0, 0xf0000000); + todo_wine check_pixel_4bpp(&lockrect, 1, 0, 0xf0444444); + todo_wine check_pixel_4bpp(&lockrect, 0, 1, 0xf0888888); + todo_wine check_pixel_4bpp(&lockrect, 1, 1, 0xf0cccccc); + 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);
From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 2 + dlls/d3dx9_36/surface.c | 102 +++++++++++++++++++++++++++++++++- dlls/d3dx9_36/tests/surface.c | 31 ++++------- dlls/d3dx9_36/util.c | 2 + 4 files changed, 115 insertions(+), 22 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index dabe714f611..dd254e03a98 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -200,6 +200,8 @@ enum d3dx_pixel_format_id D3DX_PIXEL_FORMAT_R32_FLOAT, D3DX_PIXEL_FORMAT_R32G32_FLOAT, D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT, + D3DX_PIXEL_FORMAT_P1_UINT, + D3DX_PIXEL_FORMAT_P4_UINT, D3DX_PIXEL_FORMAT_P8_UINT, D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM, D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM, diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 37f6229d36c..52e305191cb 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -39,8 +39,8 @@ static const struct } wic_pixel_formats[] = { { &GUID_WICPixelFormat8bppIndexed, D3DX_PIXEL_FORMAT_P8_UINT }, - { &GUID_WICPixelFormat1bppIndexed, D3DX_PIXEL_FORMAT_P8_UINT }, - { &GUID_WICPixelFormat4bppIndexed, D3DX_PIXEL_FORMAT_P8_UINT }, + { &GUID_WICPixelFormat1bppIndexed, D3DX_PIXEL_FORMAT_P1_UINT }, + { &GUID_WICPixelFormat4bppIndexed, D3DX_PIXEL_FORMAT_P4_UINT }, { &GUID_WICPixelFormat8bppGray, D3DX_PIXEL_FORMAT_L8_UNORM }, { &GUID_WICPixelFormat16bppBGR555, D3DX_PIXEL_FORMAT_B5G5R5X1_UNORM }, { &GUID_WICPixelFormat16bppBGR565, D3DX_PIXEL_FORMAT_B5G6R5_UNORM }, @@ -1240,7 +1240,7 @@ static HRESULT d3dx_image_wic_frame_decode(struct d3dx_image *image, goto exit;
colors = malloc(nb_colors * sizeof(colors[0])); - palette = malloc(nb_colors * sizeof(palette[0])); + palette = malloc(256 * sizeof(palette[0])); if (!colors || !palette) { hr = E_OUTOFMEMORY; @@ -1259,6 +1259,8 @@ static HRESULT d3dx_image_wic_frame_decode(struct d3dx_image *image, palette[i].peBlue = colors[i] & 0xff; palette[i].peFlags = (colors[i] >> 24) & 0xff; /* peFlags is the alpha component in DX8 and higher */ } + if (nb_colors < 256) + memset(&palette[nb_colors], 0xff, sizeof(*palette) * (256 - nb_colors)); }
image->image_buf = image->pixels = buffer; @@ -1717,6 +1719,11 @@ void d3dximage_info_from_d3dx_image(D3DXIMAGE_INFO *info, struct d3dx_image *ima info->MipLevels = image->mip_levels; switch (image->format) { + case D3DX_PIXEL_FORMAT_P1_UINT: + case D3DX_PIXEL_FORMAT_P4_UINT: + info->Format = D3DFMT_P8; + break; + case D3DX_PIXEL_FORMAT_R16G16B16_UNORM: info->Format = D3DFMT_A16B16G16R16; break; @@ -2765,6 +2772,72 @@ exit: return S_OK; }
+static HRESULT d3dx_pixels_unpack_index(struct d3dx_pixels *pixels, const struct pixel_format_desc *desc, + void **out_memory, uint32_t *out_row_pitch, uint32_t *out_slice_pitch, const struct pixel_format_desc **out_desc) +{ + uint32_t x, y, z, unpacked_slice_pitch, unpacked_row_pitch; + const struct pixel_format_desc *unpacked_desc = NULL; + const struct volume *size = &pixels->size; + uint8_t *unpacked_mem; + uint8_t mask, shift; + + switch (desc->format) + { + case D3DX_PIXEL_FORMAT_P1_UINT: + case D3DX_PIXEL_FORMAT_P4_UINT: + unpacked_desc = get_d3dx_pixel_format_info(D3DX_PIXEL_FORMAT_P8_UINT); + break; + + default: + FIXME("Unexpected format %u.\n", desc->format); + return E_NOTIMPL; + } + + unpacked_row_pitch = size->width * unpacked_desc->bytes_per_pixel; + unpacked_slice_pitch = unpacked_row_pitch * size->height; + if (!(unpacked_mem = malloc(size->depth * unpacked_slice_pitch))) + return E_OUTOFMEMORY; + + shift = 8 / desc->block_width; + mask = (1u << shift) - 1; + + TRACE("Unpacking pixels.\n"); + for (z = 0; z < size->depth; ++z) + { + const uint8_t *slice_data = (const uint8_t *)pixels->data + (pixels->slice_pitch * z); + + for (y = 0; y < size->height; ++y) + { + uint8_t *ptr = &unpacked_mem[(z * unpacked_slice_pitch) + (y * unpacked_row_pitch)]; + const uint8_t *row_data = slice_data + (pixels->row_pitch * y); + + for (x = 0; x < size->width; x += desc->block_width) + { + const uint8_t packed_data = *row_data; + unsigned int i; + + for (i = 0; i < desc->block_width; ++i) + { + const uint8_t cur_shift = ((desc->block_width - 1) - i) * shift; + + if (x + i >= size->width) + break; + ptr[i] = (packed_data >> cur_shift) & mask; + } + ptr += unpacked_desc->bytes_per_pixel * desc->block_width; + row_data++; + } + } + } + + *out_memory = unpacked_mem; + *out_row_pitch = unpacked_row_pitch; + *out_slice_pitch = unpacked_slice_pitch; + *out_desc = unpacked_desc; + + return S_OK; +} + HRESULT d3dx_pixels_init(const void *data, uint32_t row_pitch, uint32_t slice_pitch, const PALETTEENTRY *palette, enum d3dx_pixel_format_id format, uint32_t left, uint32_t top, uint32_t right, uint32_t bottom, uint32_t front, uint32_t back, struct d3dx_pixels *pixels) @@ -2866,6 +2939,29 @@ HRESULT d3dx_load_pixels_from_pixels(struct d3dx_pixels *dst_pixels, return E_NOTIMPL; }
+ if (is_index_format(src_desc) && (src_desc->block_width > 1)) + { + uint32_t unpacked_row_pitch, unpacked_slice_pitch; + const struct pixel_format_desc *unpacked_desc; + void *unpacked_mem = NULL; + + hr = d3dx_pixels_unpack_index(src_pixels, src_desc, &unpacked_mem, &unpacked_row_pitch, + &unpacked_slice_pitch, &unpacked_desc); + if (SUCCEEDED(hr)) + { + struct d3dx_pixels unpacked_pixels; + + d3dx_pixels_init(unpacked_mem, unpacked_row_pitch, unpacked_slice_pitch, src_pixels->palette, + unpacked_desc->format, 0, 0, src_pixels->size.width, src_pixels->size.height, + 0, src_pixels->size.depth, &unpacked_pixels); + + hr = d3dx_load_pixels_from_pixels(dst_pixels, dst_desc, &unpacked_pixels, unpacked_desc, + filter_flags, color_key); + } + free(unpacked_mem); + goto exit; + } + /* * If the source is a compressed image, we need to decompress it first * before doing any modifications. diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 22afe167155..4886951894a 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -3768,21 +3768,14 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); check_image_info(&info, 2, 2, 1, 1, D3DFMT_P8, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE);
- if (!strcmp(winetest_platform, "wine")) - { - skip("Skipping 1bpp indexed PNG readback tests.\n"); - } - else - { - hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); - ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - check_pixel_4bpp(&lockrect, 0, 0, 0xffffffff); - check_pixel_4bpp(&lockrect, 1, 0, 0x00000000); - check_pixel_4bpp(&lockrect, 0, 1, 0x00000000); - check_pixel_4bpp(&lockrect, 1, 1, 0xffffffff); - hr = IDirect3DSurface9_UnlockRect(surf); - ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); - } + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + check_pixel_4bpp(&lockrect, 0, 0, 0xffffffff); + check_pixel_4bpp(&lockrect, 1, 0, 0x00000000); + check_pixel_4bpp(&lockrect, 0, 1, 0x00000000); + check_pixel_4bpp(&lockrect, 1, 1, 0xffffffff); + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
/* 2bpp. */ hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_2bpp_indexed, sizeof(png_2_2_2bpp_indexed), &rect, @@ -3810,10 +3803,10 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - todo_wine check_pixel_4bpp(&lockrect, 0, 0, 0xf0000000); - todo_wine check_pixel_4bpp(&lockrect, 1, 0, 0xf0444444); - todo_wine check_pixel_4bpp(&lockrect, 0, 1, 0xf0888888); - todo_wine check_pixel_4bpp(&lockrect, 1, 1, 0xf0cccccc); + check_pixel_4bpp(&lockrect, 0, 0, 0xf0000000); + check_pixel_4bpp(&lockrect, 1, 0, 0xf0444444); + check_pixel_4bpp(&lockrect, 0, 1, 0xf0888888); + check_pixel_4bpp(&lockrect, 1, 1, 0xf0cccccc); hr = IDirect3DSurface9_UnlockRect(surf); ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index e6a11cdc1e4..89f66066eaa 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -64,6 +64,8 @@ static const struct pixel_format_desc formats[] = {D3DX_PIXEL_FORMAT_R32_FLOAT, { 0, 32, 0, 0}, { 0, 0, 0, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, {D3DX_PIXEL_FORMAT_R32G32_FLOAT, { 0, 32, 32, 0}, { 0, 0, 32, 0}, 8, 1, 1, 8, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, {D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT, {32, 32, 32, 32}, {96, 0, 32, 64}, 16, 1, 1, 16, CTYPE_FLOAT, CTYPE_FLOAT, 0 }, + {D3DX_PIXEL_FORMAT_P1_UINT, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 8, 1, 1, CTYPE_INDEX, CTYPE_INDEX, FMT_FLAG_INTERNAL}, + {D3DX_PIXEL_FORMAT_P4_UINT, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 2, 1, 1, CTYPE_INDEX, CTYPE_INDEX, FMT_FLAG_INTERNAL}, {D3DX_PIXEL_FORMAT_P8_UINT, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_INDEX, CTYPE_INDEX, 0 }, {D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM, { 8, 8, 8, 8}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_INDEX, 0 }, {D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_SNORM, CTYPE_SNORM, 0 },
From: Connor McAdams cmcadams@codeweavers.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58060 Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx9_private.h | 1 + dlls/d3dx9_36/surface.c | 20 ++++++++++++++++---- dlls/d3dx9_36/tests/surface.c | 23 ++++++++++------------- dlls/d3dx9_36/util.c | 1 + 4 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h index dd254e03a98..c8f72562953 100644 --- a/dlls/d3dx9_36/d3dx9_private.h +++ b/dlls/d3dx9_36/d3dx9_private.h @@ -201,6 +201,7 @@ enum d3dx_pixel_format_id D3DX_PIXEL_FORMAT_R32G32_FLOAT, D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT, D3DX_PIXEL_FORMAT_P1_UINT, + D3DX_PIXEL_FORMAT_P2_UINT, D3DX_PIXEL_FORMAT_P4_UINT, D3DX_PIXEL_FORMAT_P8_UINT, D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM, diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 52e305191cb..7ead6ae3e78 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -40,6 +40,7 @@ static const struct { { &GUID_WICPixelFormat8bppIndexed, D3DX_PIXEL_FORMAT_P8_UINT }, { &GUID_WICPixelFormat1bppIndexed, D3DX_PIXEL_FORMAT_P1_UINT }, + { &GUID_WICPixelFormat2bppIndexed, D3DX_PIXEL_FORMAT_P2_UINT }, { &GUID_WICPixelFormat4bppIndexed, D3DX_PIXEL_FORMAT_P4_UINT }, { &GUID_WICPixelFormat8bppGray, D3DX_PIXEL_FORMAT_L8_UNORM }, { &GUID_WICPixelFormat16bppBGR555, D3DX_PIXEL_FORMAT_B5G5R5X1_UNORM }, @@ -1331,11 +1332,20 @@ static HRESULT d3dx_initialize_image_from_wic(const void *src_data, uint32_t src goto exit;
image->format = d3dx_pixel_format_id_from_wic_pixel_format(&pixel_format); - if (image->format == D3DX_PIXEL_FORMAT_COUNT) + switch (image->format) { - WARN("Unsupported pixel format %s.\n", debugstr_guid(&pixel_format)); - hr = D3DXERR_INVALIDDATA; - goto exit; + case D3DX_PIXEL_FORMAT_P2_UINT: + if (image->image_file_format != D3DXIFF_BMP) + break; + /* Fall through. */ + + case D3DX_PIXEL_FORMAT_COUNT: + WARN("Unsupported pixel format %s.\n", debugstr_guid(&pixel_format)); + hr = D3DXERR_INVALIDDATA; + goto exit; + + default: + break; }
if (image_is_argb(bitmap_frame, image)) @@ -1720,6 +1730,7 @@ void d3dximage_info_from_d3dx_image(D3DXIMAGE_INFO *info, struct d3dx_image *ima switch (image->format) { case D3DX_PIXEL_FORMAT_P1_UINT: + case D3DX_PIXEL_FORMAT_P2_UINT: case D3DX_PIXEL_FORMAT_P4_UINT: info->Format = D3DFMT_P8; break; @@ -2784,6 +2795,7 @@ static HRESULT d3dx_pixels_unpack_index(struct d3dx_pixels *pixels, const struct switch (desc->format) { case D3DX_PIXEL_FORMAT_P1_UINT: + case D3DX_PIXEL_FORMAT_P2_UINT: case D3DX_PIXEL_FORMAT_P4_UINT: unpacked_desc = get_d3dx_pixel_format_info(D3DX_PIXEL_FORMAT_P8_UINT); break; diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 4886951894a..b20d30914e6 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -3780,20 +3780,17 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) /* 2bpp. */ hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_2bpp_indexed, sizeof(png_2_2_2bpp_indexed), &rect, D3DX_FILTER_NONE, 0, &info); - todo_wine ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - check_image_info(&info, 2, 2, 1, 1, D3DFMT_P8, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE); + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); + check_image_info(&info, 2, 2, 1, 1, D3DFMT_P8, D3DRTYPE_TEXTURE, D3DXIFF_PNG, FALSE);
- hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); - ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - check_pixel_4bpp(&lockrect, 0, 0, 0xffff0000); - check_pixel_4bpp(&lockrect, 1, 0, 0xff00ff00); - check_pixel_4bpp(&lockrect, 0, 1, 0xff0000ff); - check_pixel_4bpp(&lockrect, 1, 1, 0xffffffff); - hr = IDirect3DSurface9_UnlockRect(surf); - ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); - } + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + check_pixel_4bpp(&lockrect, 0, 0, 0xffff0000); + check_pixel_4bpp(&lockrect, 1, 0, 0xff00ff00); + check_pixel_4bpp(&lockrect, 0, 1, 0xff0000ff); + check_pixel_4bpp(&lockrect, 1, 1, 0xffffffff); + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
/* 4bpp. */ hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, png_2_2_4bpp_indexed, sizeof(png_2_2_4bpp_indexed), &rect, diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index 89f66066eaa..c41a8eb7647 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -65,6 +65,7 @@ static const struct pixel_format_desc formats[] = {D3DX_PIXEL_FORMAT_R32G32_FLOAT, { 0, 32, 32, 0}, { 0, 0, 32, 0}, 8, 1, 1, 8, CTYPE_EMPTY, CTYPE_FLOAT, 0 }, {D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT, {32, 32, 32, 32}, {96, 0, 32, 64}, 16, 1, 1, 16, CTYPE_FLOAT, CTYPE_FLOAT, 0 }, {D3DX_PIXEL_FORMAT_P1_UINT, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 8, 1, 1, CTYPE_INDEX, CTYPE_INDEX, FMT_FLAG_INTERNAL}, + {D3DX_PIXEL_FORMAT_P2_UINT, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 4, 1, 1, CTYPE_INDEX, CTYPE_INDEX, FMT_FLAG_INTERNAL}, {D3DX_PIXEL_FORMAT_P4_UINT, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 2, 1, 1, CTYPE_INDEX, CTYPE_INDEX, FMT_FLAG_INTERNAL}, {D3DX_PIXEL_FORMAT_P8_UINT, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, CTYPE_INDEX, CTYPE_INDEX, 0 }, {D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM, { 8, 8, 8, 8}, { 8, 0, 0, 0}, 2, 1, 1, 2, CTYPE_UNORM, CTYPE_INDEX, 0 },