From: Connor McAdams <cmcadams@codeweavers.com> Signed-off-by: Connor McAdams <cmcadams@codeweavers.com> --- dlls/d3dx10_43/tests/d3dx10.c | 4 ++-- dlls/d3dx11_43/tests/d3dx11.c | 4 ++-- dlls/d3dx9_36/d3dx_helpers.c | 30 ++++++++++++++++++++++++++++++ dlls/d3dx9_36/d3dx_helpers.h | 2 ++ dlls/d3dx9_36/tests/surface.c | 24 ++++++++++++------------ 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index d72ff411e04..1bd2388c3d7 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -5674,7 +5674,7 @@ static void test_image_filters(void) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); get_resource_readback(resource, 0, &rb); - todo_wine check_test_readback(&rb, a8r8g8b8_4_4_srgb_in_expected, 4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0); + check_test_readback(&rb, a8r8g8b8_4_4_srgb_in_expected, 4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0); release_resource_readback(&rb); ID3D10Resource_Release(resource); @@ -5687,7 +5687,7 @@ static void test_image_filters(void) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); get_resource_readback(resource, 0, &rb); - todo_wine check_test_readback(&rb, a8r8g8b8_4_4_srgb_out_expected, 4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0); + check_test_readback(&rb, a8r8g8b8_4_4_srgb_out_expected, 4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0); release_resource_readback(&rb); ID3D10Resource_Release(resource); diff --git a/dlls/d3dx11_43/tests/d3dx11.c b/dlls/d3dx11_43/tests/d3dx11.c index d94dedfef04..b396c3fb452 100644 --- a/dlls/d3dx11_43/tests/d3dx11.c +++ b/dlls/d3dx11_43/tests/d3dx11.c @@ -4492,7 +4492,7 @@ static void test_image_filters(void) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); get_resource_readback(resource, 0, &rb); - todo_wine check_test_readback(&rb, a8r8g8b8_4_4_srgb_in_expected, 4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0); + check_test_readback(&rb, a8r8g8b8_4_4_srgb_in_expected, 4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0); release_resource_readback(&rb); ID3D11Resource_Release(resource); @@ -4505,7 +4505,7 @@ static void test_image_filters(void) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); get_resource_readback(resource, 0, &rb); - todo_wine check_test_readback(&rb, a8r8g8b8_4_4_srgb_out_expected, 4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0); + check_test_readback(&rb, a8r8g8b8_4_4_srgb_out_expected, 4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0); release_resource_readback(&rb); ID3D11Resource_Release(resource); diff --git a/dlls/d3dx9_36/d3dx_helpers.c b/dlls/d3dx9_36/d3dx_helpers.c index 7a4647c2385..4b3ef05c408 100644 --- a/dlls/d3dx9_36/d3dx_helpers.c +++ b/dlls/d3dx9_36/d3dx_helpers.c @@ -73,6 +73,8 @@ static uint32_t d3dx_conv_flags_from_filter(uint32_t filter) if ((filter & D3DX_FILTER_PMA) && ((filter & D3DX_FILTER_PMA) != D3DX_FILTER_PMA)) conv_flags |= (filter & D3DX_FILTER_PMA_IN) ? CONV_FLAG_PM_ALPHA_IN : CONV_FLAG_PM_ALPHA_OUT; + if ((filter & D3DX_FILTER_SRGB) && ((filter & D3DX_FILTER_SRGB) != D3DX_FILTER_SRGB)) + conv_flags |= (filter & D3DX_FILTER_SRGB_IN) ? CONV_FLAG_GAMMA_2_2_IN : CONV_FLAG_GAMMA_2_2_OUT; return conv_flags; } @@ -2468,6 +2470,20 @@ static void undo_premultiplied_alpha(struct vec4 *vec) vec->z = (vec->w == 0.0f) ? 0.0f : vec->z / vec->w; } +static void apply_gamma_2_2(struct vec4 *vec) +{ + vec->x = powf(vec->x, 1.0f / 2.2f); + vec->y = powf(vec->y, 1.0f / 2.2f); + vec->z = powf(vec->z, 1.0f / 2.2f); +} + +static void undo_gamma_2_2(struct vec4 *vec) +{ + vec->x = powf(vec->x, 2.2f); + vec->y = powf(vec->y, 2.2f); + vec->z = powf(vec->z, 2.2f); +} + static void convert_argb_pixel(const uint8_t *src_ptr, const struct pixel_format_desc *src_fmt, uint8_t *dst_ptr, const struct pixel_format_desc *dst_fmt, const PALETTEENTRY *palette, struct argb_conversion_info *conv_info, const struct d3dx_color_key *color_key, @@ -2509,6 +2525,8 @@ static void convert_argb_pixel(const uint8_t *src_ptr, const struct pixel_format format_to_d3dx_color(src_fmt, src_ptr, palette, &color); if (conv_flags & CONV_FLAG_PM_ALPHA_IN) undo_premultiplied_alpha(&color.value); + if (conv_flags & CONV_FLAG_GAMMA_2_2_IN) + undo_gamma_2_2(&color.value); tmp = color; if (color_key) @@ -2528,6 +2546,8 @@ static void convert_argb_pixel(const uint8_t *src_ptr, const struct pixel_format } color = tmp; + if (conv_flags & CONV_FLAG_GAMMA_2_2_OUT) + apply_gamma_2_2(&color.value); if (conv_flags & CONV_FLAG_PM_ALPHA_OUT) premultiply_alpha(&color.value); format_from_d3dx_color(dst_fmt, &color, dst_ptr); @@ -2727,6 +2747,8 @@ static void box_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src format_to_d3dx_color(src_format, ptr, palette, &tmp); if (conv_flags & CONV_FLAG_PM_ALPHA_IN) undo_premultiplied_alpha(&color.value); + if (conv_flags & CONV_FLAG_GAMMA_2_2_IN) + undo_gamma_2_2(&color.value); if (color_key) check_color_key(&tmp, color_key, ck_format); vec4_add(&color.value, &tmp.value); @@ -2734,6 +2756,8 @@ static void box_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src format_to_d3dx_color(src_format, ptr + src_format->bytes_per_pixel, palette, &tmp); if (conv_flags & CONV_FLAG_PM_ALPHA_IN) undo_premultiplied_alpha(&color.value); + if (conv_flags & CONV_FLAG_GAMMA_2_2_IN) + undo_gamma_2_2(&color.value); if (color_key) check_color_key(&tmp, color_key, ck_format); vec4_add(&color.value, &tmp.value); @@ -2742,6 +2766,8 @@ static void box_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src format_to_d3dx_color(src_format, ptr, palette, &tmp); if (conv_flags & CONV_FLAG_PM_ALPHA_IN) undo_premultiplied_alpha(&color.value); + if (conv_flags & CONV_FLAG_GAMMA_2_2_IN) + undo_gamma_2_2(&color.value); if (color_key) check_color_key(&tmp, color_key, ck_format); vec4_add(&color.value, &tmp.value); @@ -2749,12 +2775,16 @@ static void box_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src format_to_d3dx_color(src_format, ptr + src_format->bytes_per_pixel, palette, &tmp); if (conv_flags & CONV_FLAG_PM_ALPHA_IN) undo_premultiplied_alpha(&color.value); + if (conv_flags & CONV_FLAG_GAMMA_2_2_IN) + undo_gamma_2_2(&color.value); if (color_key) check_color_key(&tmp, color_key, ck_format); vec4_add(&color.value, &tmp.value); } vec4_scale(&color.value, src_size->depth > 1 ? 0.125f : 0.25f); + if (conv_flags & CONV_FLAG_GAMMA_2_2_OUT) + apply_gamma_2_2(&color.value); if (conv_flags & CONV_FLAG_PM_ALPHA_OUT) premultiply_alpha(&color.value); format_from_d3dx_color(dst_format, &color, dst_ptr); diff --git a/dlls/d3dx9_36/d3dx_helpers.h b/dlls/d3dx9_36/d3dx_helpers.h index 5b65f52cfa3..ec93236c891 100644 --- a/dlls/d3dx9_36/d3dx_helpers.h +++ b/dlls/d3dx9_36/d3dx_helpers.h @@ -246,6 +246,8 @@ enum conversion_flag { CONV_FLAG_PM_ALPHA_IN = 0x01, CONV_FLAG_PM_ALPHA_OUT = 0x02, + CONV_FLAG_GAMMA_2_2_IN = 0x04, + CONV_FLAG_GAMMA_2_2_OUT = 0x08, }; enum component_type diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index d3ff833f494..9d742816f03 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -1407,7 +1407,7 @@ static void test_dxt_premultiplied_alpha(IDirect3DDevice9 *device) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); IDirect3DSurface9_LockRect(decomp_surf, &lock_rect, NULL, D3DLOCK_READONLY); - todo_wine check_test_readback(lock_rect.pBits, lock_rect.Pitch, 0, dxt_srgb_in_expected, 4, 4, 1, D3DFMT_A8R8G8B8, 1); + check_test_readback(lock_rect.pBits, lock_rect.Pitch, 0, dxt_srgb_in_expected, 4, 4, 1, D3DFMT_A8R8G8B8, 1); IDirect3DSurface9_UnlockRect(decomp_surf); /* DXT4, SRGB in. */ @@ -1416,7 +1416,7 @@ static void test_dxt_premultiplied_alpha(IDirect3DDevice9 *device) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); IDirect3DSurface9_LockRect(decomp_surf, &lock_rect, NULL, D3DLOCK_READONLY); - todo_wine check_test_readback(lock_rect.pBits, lock_rect.Pitch, 0, dxt_srgb_in_expected, 4, 4, 1, D3DFMT_A8R8G8B8, 1); + check_test_readback(lock_rect.pBits, lock_rect.Pitch, 0, dxt_srgb_in_expected, 4, 4, 1, D3DFMT_A8R8G8B8, 1); IDirect3DSurface9_UnlockRect(decomp_surf); /* @@ -1439,7 +1439,7 @@ static void test_dxt_premultiplied_alpha(IDirect3DDevice9 *device) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); IDirect3DSurface9_LockRect(decomp_surf, &lock_rect, NULL, D3DLOCK_READONLY); - todo_wine check_test_readback(lock_rect.pBits, lock_rect.Pitch, 0, dxt_srgb_out_expected, 4, 4, 1, D3DFMT_A8R8G8B8, 0); + check_test_readback(lock_rect.pBits, lock_rect.Pitch, 0, dxt_srgb_out_expected, 4, 4, 1, D3DFMT_A8R8G8B8, 0); IDirect3DSurface9_UnlockRect(decomp_surf); /* DXT4, SRGB out. */ @@ -1459,7 +1459,7 @@ static void test_dxt_premultiplied_alpha(IDirect3DDevice9 *device) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr); IDirect3DSurface9_LockRect(decomp_surf, &lock_rect, NULL, D3DLOCK_READONLY); - todo_wine check_test_readback(lock_rect.pBits, lock_rect.Pitch, 0, dxt_srgb_out_expected, 4, 4, 1, D3DFMT_A8R8G8B8, 0); + check_test_readback(lock_rect.pBits, lock_rect.Pitch, 0, dxt_srgb_out_expected, 4, 4, 1, D3DFMT_A8R8G8B8, 0); IDirect3DSurface9_UnlockRect(decomp_surf); IDirect3DSurface9_Release(decomp_surf); @@ -2998,10 +2998,10 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) /* SRGB in, no SRGB out. */ 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, 0x00010306); - todo_wine check_pixel_4bpp(&lockrect, 1, 0, 0x40141e2a); - todo_wine check_pixel_4bpp(&lockrect, 0, 1, 0x80495b71); - todo_wine check_pixel_4bpp(&lockrect, 1, 1, 0xc0a3c0ff); + check_pixel_4bpp(&lockrect, 0, 0, 0x00010306); + check_pixel_4bpp(&lockrect, 1, 0, 0x40141e2a); + check_pixel_4bpp(&lockrect, 0, 1, 0x80495b71); + check_pixel_4bpp(&lockrect, 1, 1, 0xc0a3c0ff); hr = IDirect3DSurface9_UnlockRect(surf); ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); @@ -3012,10 +3012,10 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) /* No SRGB in, SRGB out. */ 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, 0x00486377); - todo_wine check_pixel_4bpp(&lockrect, 1, 0, 0x4097a4af); - todo_wine check_pixel_4bpp(&lockrect, 0, 1, 0x80c5ced7); - todo_wine check_pixel_4bpp(&lockrect, 1, 1, 0xc0e8f0ff); + check_pixel_4bpp(&lockrect, 0, 0, 0x00486377); + check_pixel_4bpp(&lockrect, 1, 0, 0x4097a4af); + check_pixel_4bpp(&lockrect, 0, 1, 0x80c5ced7); + check_pixel_4bpp(&lockrect, 1, 1, 0xc0e8f0ff); hr = IDirect3DSurface9_UnlockRect(surf); ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10513