[5/5] windowscodecs: Implement getters on IWICBitmapLock.

Vincent Povirk madewokherd at gmail.com
Tue Aug 14 16:53:10 CDT 2012


-------------- next part --------------
From 858e841a05d04ad2f1f1d7ac7993e26222399b60 Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Tue, 14 Aug 2012 15:24:58 -0500
Subject: [PATCH 05/12] windowscodecs: Implement getters on IWICBitmapLock.

---
 dlls/windowscodecs/bitmap.c       |   85 ++++++++++++++++++++++++++++++++++---
 dlls/windowscodecs/tests/bitmap.c |   50 +++++++++++-----------
 2 files changed, 103 insertions(+), 32 deletions(-)

diff --git a/dlls/windowscodecs/bitmap.c b/dlls/windowscodecs/bitmap.c
index cb958fa..26f09c3 100644
--- a/dlls/windowscodecs/bitmap.c
+++ b/dlls/windowscodecs/bitmap.c
@@ -39,12 +39,18 @@ typedef struct BitmapImpl {
     IWICPalette *palette;
     int palette_set;
     LONG lock; /* 0 if not locked, -1 if locked for writing, count if locked for reading */
+    BYTE *data;
+    UINT width, height;
+    UINT stride;
+    UINT bpp;
 } BitmapImpl;
 
 typedef struct BitmapLockImpl {
     IWICBitmapLock IWICBitmapLock_iface;
     LONG ref;
     BitmapImpl *parent;
+    UINT width, height;
+    BYTE *data;
 } BitmapLockImpl;
 
 static inline BitmapImpl *impl_from_IWICBitmap(IWICBitmap *iface)
@@ -144,25 +150,46 @@ static ULONG WINAPI BitmapLockImpl_Release(IWICBitmapLock *iface)
 static HRESULT WINAPI BitmapLockImpl_GetSize(IWICBitmapLock *iface,
     UINT *puiWidth, UINT *puiHeight)
 {
-    FIXME("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
+    BitmapLockImpl *This = impl_from_IWICBitmapLock(iface);
+    TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
 
-    return E_NOTIMPL;
+    if (!puiWidth || !puiHeight)
+        return E_INVALIDARG;
+
+    *puiWidth = This->width;
+    *puiHeight = This->height;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI BitmapLockImpl_GetStride(IWICBitmapLock *iface,
     UINT *pcbStride)
 {
-    FIXME("(%p,%p)\n", iface, pcbStride);
+    BitmapLockImpl *This = impl_from_IWICBitmapLock(iface);
+    TRACE("(%p,%p)\n", iface, pcbStride);
 
-    return E_NOTIMPL;
+    if (!pcbStride)
+        return E_INVALIDARG;
+
+    *pcbStride = This->parent->stride;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI BitmapLockImpl_GetDataPointer(IWICBitmapLock *iface,
     UINT *pcbBufferSize, BYTE **ppbData)
 {
-    FIXME("(%p,%p,%p)\n", iface, pcbBufferSize, ppbData);
+    BitmapLockImpl *This = impl_from_IWICBitmapLock(iface);
+    TRACE("(%p,%p,%p)\n", iface, pcbBufferSize, ppbData);
 
-    return E_NOTIMPL;
+    if (!pcbBufferSize || !ppbData)
+        return E_INVALIDARG;
+
+    *pcbBufferSize = This->parent->stride * (This->height - 1) +
+        ((This->parent->bpp * This->width) + 7)/8;
+    *ppbData = This->data;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI BitmapLockImpl_GetPixelFormat(IWICBitmapLock *iface,
@@ -227,6 +254,7 @@ static ULONG WINAPI BitmapImpl_Release(IWICBitmap *iface)
     if (ref == 0)
     {
         if (This->palette) IWICPalette_Release(This->palette);
+        HeapFree(GetProcessHeap(), 0, This->data);
         HeapFree(GetProcessHeap(), 0, This);
     }
 
@@ -282,12 +310,31 @@ static HRESULT WINAPI BitmapImpl_Lock(IWICBitmap *iface, const WICRect *prcLock,
 {
     BitmapImpl *This = impl_from_IWICBitmap(iface);
     BitmapLockImpl *result;
+    WICRect rc;
 
     TRACE("(%p,%p,%x,%p)\n", iface, prcLock, flags, ppILock);
 
     if (!(flags & (WICBitmapLockRead|WICBitmapLockWrite)) || !ppILock)
         return E_INVALIDARG;
 
+    if (!prcLock)
+    {
+        rc.X = rc.Y = 0;
+        rc.Width = This->width;
+        rc.Height = This->height;
+        prcLock = &rc;
+    }
+    else if (prcLock->X >= This->width || prcLock->Y >= This->height ||
+             prcLock->X + prcLock->Width > This->width ||
+             prcLock->Y + prcLock->Height > This->height ||
+             prcLock->Width <= 0 || prcLock->Height <= 0)
+        return E_INVALIDARG;
+    else if (((prcLock->X * This->bpp) % 8) != 0)
+    {
+        FIXME("Cannot lock at an X coordinate not at a full byte\n");
+        return E_FAIL;
+    }
+
     result = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapLockImpl));
     if (!result)
         return E_OUTOFMEMORY;
@@ -301,6 +348,10 @@ static HRESULT WINAPI BitmapImpl_Lock(IWICBitmap *iface, const WICRect *prcLock,
     result->IWICBitmapLock_iface.lpVtbl = &BitmapLockImpl_Vtbl;
     result->ref = 1;
     result->parent = This;
+    result->width = prcLock->Width;
+    result->height = prcLock->Height;
+    result->data = This->data + This->stride * prcLock->Y +
+        (This->bpp * prcLock->X)/8;
 
     IWICBitmap_AddRef(&This->IWICBitmap_iface);
     *ppILock = &result->IWICBitmapLock_iface;
@@ -363,16 +414,36 @@ HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight,
     REFWICPixelFormatGUID pixelFormat, WICBitmapCreateCacheOption option,
     IWICBitmap **ppIBitmap)
 {
+    HRESULT hr;
     BitmapImpl *This;
+    UINT bpp, stride, datasize;
+    BYTE *data;
+
+    hr = get_pixelformat_bpp(pixelFormat, &bpp);
+    if (FAILED(hr)) return hr;
+
+    stride = (((bpp*uiWidth)+31)/32)*4;
+    datasize = stride * uiHeight;
 
     This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapImpl));
-    if (!This) return E_OUTOFMEMORY;
+    data = HeapAlloc(GetProcessHeap(), 0, datasize);
+    if (!This || !data)
+    {
+        HeapFree(GetProcessHeap(), 0, This);
+        HeapFree(GetProcessHeap(), 0, data);
+        return E_OUTOFMEMORY;
+    }
 
     This->IWICBitmap_iface.lpVtbl = &BitmapImpl_Vtbl;
     This->ref = 1;
     This->palette = NULL;
     This->palette_set = 0;
     This->lock = 0;
+    This->data = data;
+    This->width = uiWidth;
+    This->height = uiHeight;
+    This->stride = stride;
+    This->bpp = bpp;
 
     *ppIBitmap = &This->IWICBitmap_iface;
 
diff --git a/dlls/windowscodecs/tests/bitmap.c b/dlls/windowscodecs/tests/bitmap.c
index 2f874f1..32726f1 100644
--- a/dlls/windowscodecs/tests/bitmap.c
+++ b/dlls/windowscodecs/tests/bitmap.c
@@ -95,25 +95,25 @@ void test_createbitmap(void)
     rc.Width = 4;
     rc.Height = 3;
     hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock);
-    todo_wine ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
+    ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
     if (SUCCEEDED(hr)) IWICBitmapLock_Release(lock);
 
     rc.Width = 3;
     rc.Height = 4;
     hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock);
-    todo_wine ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
+    ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
     if (SUCCEEDED(hr)) IWICBitmapLock_Release(lock);
 
     rc.Height = 3;
     rc.X = 4;
     hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock);
-    todo_wine ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
+    ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
     if (SUCCEEDED(hr)) IWICBitmapLock_Release(lock);
 
     rc.X = 0;
     rc.Y = 4;
     hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock);
-    todo_wine ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
+    ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
     if (SUCCEEDED(hr)) IWICBitmapLock_Release(lock);
 
     /* NULL lock rect */
@@ -124,9 +124,9 @@ void test_createbitmap(void)
     {
         /* entire bitmap is locked */
         hr = IWICBitmapLock_GetSize(lock, &width, &height);
-        todo_wine ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
-        todo_wine ok(width == 3, "got %d, expected 3\n", width);
-        todo_wine ok(height == 3, "got %d, expected 3\n", height);
+        ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
+        ok(width == 3, "got %d, expected 3\n", width);
+        ok(height == 3, "got %d, expected 3\n", height);
 
         IWICBitmapLock_Release(lock);
     }
@@ -140,15 +140,15 @@ void test_createbitmap(void)
     if (SUCCEEDED(hr))
     {
         hr = IWICBitmapLock_GetStride(lock, &lock_buffer_stride);
-        todo_wine ok(hr == S_OK, "IWICBitmapLock_GetStride failed hr=%x\n", hr);
+        ok(hr == S_OK, "IWICBitmapLock_GetStride failed hr=%x\n", hr);
         /* stride is divisible by 4 */
-        todo_wine ok(lock_buffer_stride == 12, "got %i, expected 12\n", lock_buffer_stride);
+        ok(lock_buffer_stride == 12, "got %i, expected 12\n", lock_buffer_stride);
 
         hr = IWICBitmapLock_GetDataPointer(lock, &lock_buffer_size, &lock_buffer);
-        todo_wine ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
+        ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
         /* buffer size does not include padding from the last row */
-        todo_wine ok(lock_buffer_size == 33, "got %i, expected 33\n", lock_buffer_size);
-        todo_wine ok(lock_buffer != NULL, "got NULL data pointer\n");
+        ok(lock_buffer_size == 33, "got %i, expected 33\n", lock_buffer_size);
+        ok(lock_buffer != NULL, "got NULL data pointer\n");
         base_lock_buffer = lock_buffer;
 
         hr = IWICBitmapLock_GetPixelFormat(lock, &pixelformat);
@@ -156,9 +156,9 @@ void test_createbitmap(void)
         todo_wine ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
 
         hr = IWICBitmapLock_GetSize(lock, &width, &height);
-        todo_wine ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
-        todo_wine ok(width == 3, "got %d, expected 3\n", width);
-        todo_wine ok(height == 3, "got %d, expected 3\n", height);
+        ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
+        ok(width == 3, "got %d, expected 3\n", width);
+        ok(height == 3, "got %d, expected 3\n", height);
 
         /* We can have multiple simultaneous read locks */
         hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock2);
@@ -167,8 +167,8 @@ void test_createbitmap(void)
         if (SUCCEEDED(hr))
         {
             hr = IWICBitmapLock_GetDataPointer(lock2, &lock_buffer_size, &lock_buffer);
-            todo_wine ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
-            todo_wine ok(lock_buffer_size == 33, "got %i, expected 33\n", lock_buffer_size);
+            ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
+            ok(lock_buffer_size == 33, "got %i, expected 33\n", lock_buffer_size);
             ok(lock_buffer == base_lock_buffer, "got %p, expected %p\n", lock_buffer, base_lock_buffer);
 
             IWICBitmapLock_Release(lock2);
@@ -219,22 +219,22 @@ void test_createbitmap(void)
         }
 
         hr = IWICBitmapLock_GetStride(lock, &lock_buffer_stride);
-        todo_wine ok(hr == S_OK, "IWICBitmapLock_GetStride failed hr=%x\n", hr);
-        todo_wine ok(lock_buffer_stride == 12, "got %i, expected 12\n", lock_buffer_stride);
+        ok(hr == S_OK, "IWICBitmapLock_GetStride failed hr=%x\n", hr);
+        ok(lock_buffer_stride == 12, "got %i, expected 12\n", lock_buffer_stride);
 
         hr = IWICBitmapLock_GetDataPointer(lock, &lock_buffer_size, &lock_buffer);
-        todo_wine ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
-        todo_wine ok(lock_buffer_size == 15, "got %i, expected 15\n", lock_buffer_size);
-        todo_wine ok(lock_buffer == base_lock_buffer+6, "got %p, expected %p+6\n", lock_buffer, base_lock_buffer);
+        ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
+        ok(lock_buffer_size == 15, "got %i, expected 15\n", lock_buffer_size);
+        ok(lock_buffer == base_lock_buffer+6, "got %p, expected %p+6\n", lock_buffer, base_lock_buffer);
 
         hr = IWICBitmapLock_GetPixelFormat(lock, &pixelformat);
         todo_wine ok(hr == S_OK, "IWICBitmapLock_GetPixelFormat failed hr=%x\n", hr);
         todo_wine ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
 
         hr = IWICBitmapLock_GetSize(lock, &width, &height);
-        todo_wine ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
-        todo_wine ok(width == 1, "got %d, expected 1\n", width);
-        todo_wine ok(height == 2, "got %d, expected 2\n", height);
+        ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
+        ok(width == 1, "got %d, expected 1\n", width);
+        ok(height == 2, "got %d, expected 2\n", height);
 
         IWICBitmapLock_Release(lock);
     }
-- 
1.7.9.5


More information about the wine-patches mailing list