From f9676836d672903b0ec07ec5d9d98e4f9fe047fa Mon Sep 17 00:00:00 2001 From: Connor McAdams Date: Thu, 25 Apr 2024 12:27:16 -0400 Subject: [PATCH] d3dx9: Fix destination rectangles passed from D3DXLoadSurfaceFromMemory() to d3dx_load_image_from_memory(). d3dx_load_image_from_memory() expects the address of the dst_memory argument to represent the top left corner of the surface. If a surface is locked using a rectangle that doesn't start at the top left corner of the surface, the rectangle we pass to d3dx_load_image_from_memory() needs to be adjusted so that it properly represents the locked area. Signed-off-by: Connor McAdams --- dlls/d3dx9_36/surface.c | 10 +++++++--- dlls/d3dx9_36/tests/surface.c | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index c3d341e216d..ef6cd57c7da 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -2116,8 +2116,8 @@ 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) { + RECT dst_rect_temp, dst_rect_aligned, dst_locked_rect, dst_locked_rect_aligned; const struct pixel_format_desc *srcformatdesc, *destformatdesc; - RECT dst_rect_temp, dst_rect_aligned; IDirect3DSurface9 *surface; D3DSURFACE_DESC surfdesc; D3DLOCKED_RECT lockrect; @@ -2192,8 +2192,12 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, if (FAILED(hr = lock_surface(dst_surface, &dst_rect_aligned, &lockrect, &surface, TRUE))) return hr; - hr = d3dx_load_image_from_memory(lockrect.pBits, lockrect.Pitch, destformatdesc, dst_palette, dst_rect, - &dst_rect_aligned, src_memory, src_pitch, srcformatdesc, src_palette, src_rect, filter, color_key); + dst_locked_rect_aligned = dst_rect_aligned; + dst_locked_rect = *dst_rect; + OffsetRect(&dst_locked_rect_aligned, -dst_rect_aligned.left, -dst_rect_aligned.top); + OffsetRect(&dst_locked_rect, -dst_rect_aligned.left, -dst_rect_aligned.top); + hr = d3dx_load_image_from_memory(lockrect.pBits, lockrect.Pitch, destformatdesc, dst_palette, &dst_locked_rect, + &dst_locked_rect_aligned, src_memory, src_pitch, srcformatdesc, src_palette, src_rect, filter, color_key); if (FAILED(hr)) WARN("d3dx_load_image_from_memory failed with hr %#lx\n", hr); diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 2a4bc5c1652..3c88eec5dcb 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -1697,7 +1697,7 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) * Bottom left of green block, should still be black from prior * operation. */ - check_readback_pixel_4bpp(&surface_rb, 4, 3, 0xff000000, TRUE); + check_readback_pixel_4bpp(&surface_rb, 4, 3, 0xff000000, FALSE); release_surface_readback(&surface_rb);