[PATCH 1/6] quartz/vmr9: Fix copying from the d3d9 surface if the pitch doesn't match the width.

Zebediah Figura z.figura12 at gmail.com
Tue Feb 11 21:08:28 CST 2020


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
Thanks to Henri Verbeet.

 dlls/quartz/vmr9.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/dlls/quartz/vmr9.c b/dlls/quartz/vmr9.c
index 928e98f6056..58a7e2b1218 100644
--- a/dlls/quartz/vmr9.c
+++ b/dlls/quartz/vmr9.c
@@ -627,7 +627,10 @@ static HRESULT WINAPI VMR9_GetStaticImage(BaseControlVideo *iface, LONG *size, L
     IDirect3DSurface9 *rt = NULL, *surface = NULL;
     D3DLOCKED_RECT locked_rect;
     IDirect3DDevice9 *device;
+    unsigned int row_size;
     BITMAPINFOHEADER bih;
+    LONG i, size_left;
+    char *dst;
     HRESULT hr;
 
     TRACE("filter %p, size %d, image %p.\n", filter, *size, image);
@@ -661,7 +664,20 @@ static HRESULT WINAPI VMR9_GetStaticImage(BaseControlVideo *iface, LONG *size, L
     if (FAILED(hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, D3DLOCK_READONLY)))
         goto out;
 
-    memcpy(image, &bih, min(*size, sizeof(BITMAPINFOHEADER)));
+    size_left = *size;
+    memcpy(image, &bih, min(size_left, sizeof(BITMAPINFOHEADER)));
+    size_left -= sizeof(BITMAPINFOHEADER);
+
+    dst = (char *)image + sizeof(BITMAPINFOHEADER);
+    row_size = bih.biWidth * bih.biBitCount / 8;
+
+    for (i = 0; i < bih.biHeight && size_left > 0; ++i)
+    {
+        memcpy(dst, (char *)locked_rect.pBits + (i * locked_rect.Pitch), min(row_size, size_left));
+        dst += row_size;
+        size_left -= row_size;
+    }
+
     if (*size > sizeof(BITMAPINFOHEADER))
         memcpy((char *)image + sizeof(BITMAPINFOHEADER), locked_rect.pBits,
                 min(*size - sizeof(BITMAPINFOHEADER), bih.biSizeImage));
-- 
2.25.0




More information about the wine-devel mailing list