[3/5] windowscodecs: Implement BitmapImpl_SetPalette and CopyPalette.

Vincent Povirk madewokherd at gmail.com
Tue Aug 14 16:50:19 CDT 2012


-------------- next part --------------
From 1f50d8ab7a4fa6ae19d0733dc4e16f272126a5cb Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Tue, 14 Aug 2012 14:01:11 -0500
Subject: [PATCH 03/12] windowscodecs: Implement BitmapImpl_SetPalette and
 CopyPalette.

---
 dlls/windowscodecs/bitmap.c       |   39 +++++++++++++++++++++++++++++++++----
 dlls/windowscodecs/tests/bitmap.c |    8 ++++----
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/dlls/windowscodecs/bitmap.c b/dlls/windowscodecs/bitmap.c
index fe32d48..c3ccfc0 100644
--- a/dlls/windowscodecs/bitmap.c
+++ b/dlls/windowscodecs/bitmap.c
@@ -36,6 +36,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
 typedef struct BitmapImpl {
     IWICBitmap IWICBitmap_iface;
     LONG ref;
+    IWICPalette *palette;
+    int palette_set;
 } BitmapImpl;
 
 static inline BitmapImpl *impl_from_IWICBitmap(IWICBitmap *iface)
@@ -86,6 +88,7 @@ static ULONG WINAPI BitmapImpl_Release(IWICBitmap *iface)
 
     if (ref == 0)
     {
+        if (This->palette) IWICPalette_Release(This->palette);
         HeapFree(GetProcessHeap(), 0, This);
     }
 
@@ -119,9 +122,13 @@ static HRESULT WINAPI BitmapImpl_GetResolution(IWICBitmap *iface,
 static HRESULT WINAPI BitmapImpl_CopyPalette(IWICBitmap *iface,
     IWICPalette *pIPalette)
 {
-    FIXME("(%p,%p)\n", iface, pIPalette);
+    BitmapImpl *This = impl_from_IWICBitmap(iface);
+    TRACE("(%p,%p)\n", iface, pIPalette);
 
-    return E_NOTIMPL;
+    if (!This->palette_set)
+        return WINCODEC_ERR_PALETTEUNAVAILABLE;
+
+    return IWICPalette_InitializeFromPalette(pIPalette, This->palette);
 }
 
 static HRESULT WINAPI BitmapImpl_CopyPixels(IWICBitmap *iface,
@@ -142,9 +149,31 @@ static HRESULT WINAPI BitmapImpl_Lock(IWICBitmap *iface, const WICRect *prcLock,
 
 static HRESULT WINAPI BitmapImpl_SetPalette(IWICBitmap *iface, IWICPalette *pIPalette)
 {
-    FIXME("(%p,%p)\n", iface, pIPalette);
+    BitmapImpl *This = impl_from_IWICBitmap(iface);
+    HRESULT hr;
 
-    return E_NOTIMPL;
+    TRACE("(%p,%p)\n", iface, pIPalette);
+
+    if (!This->palette)
+    {
+        IWICPalette *new_palette;
+        hr = PaletteImpl_Create(&new_palette);
+
+        if (FAILED(hr)) return hr;
+
+        if (InterlockedCompareExchangePointer((void**)&This->palette, new_palette, NULL))
+        {
+            /* someone beat us to it */
+            IWICPalette_Release(new_palette);
+        }
+    }
+
+    hr = IWICPalette_InitializeFromPalette(This->palette, pIPalette);
+
+    if (SUCCEEDED(hr))
+        This->palette_set = 1;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI BitmapImpl_SetResolution(IWICBitmap *iface,
@@ -180,6 +209,8 @@ HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight,
 
     This->IWICBitmap_iface.lpVtbl = &BitmapImpl_Vtbl;
     This->ref = 1;
+    This->palette = NULL;
+    This->palette_set = 0;
 
     *ppIBitmap = &This->IWICBitmap_iface;
 
diff --git a/dlls/windowscodecs/tests/bitmap.c b/dlls/windowscodecs/tests/bitmap.c
index 69840be..e5e71d2 100644
--- a/dlls/windowscodecs/tests/bitmap.c
+++ b/dlls/windowscodecs/tests/bitmap.c
@@ -62,23 +62,23 @@ void test_createbitmap(void)
 
     /* Palette is unavailable until explicitly set */
     hr = IWICBitmap_CopyPalette(bitmap, palette);
-    todo_wine ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
+    ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
 
     hr = IWICPalette_InitializePredefined(palette, WICBitmapPaletteTypeFixedGray256, FALSE);
     ok(hr == S_OK, "IWICPalette_InitializePredefined failed hr=%x\n", hr);
 
     hr = IWICBitmap_SetPalette(bitmap, palette);
-    todo_wine ok(hr == S_OK, "IWICBitmap_SetPalette failed hr=%x\n", hr);
+    ok(hr == S_OK, "IWICBitmap_SetPalette failed hr=%x\n", hr);
 
     hr = IWICPalette_InitializePredefined(palette, WICBitmapPaletteTypeFixedGray4, FALSE);
     ok(hr == S_OK, "IWICPalette_InitializePredefined failed hr=%x\n", hr);
 
     hr = IWICBitmap_CopyPalette(bitmap, palette);
-    todo_wine ok(hr == S_OK, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
+    ok(hr == S_OK, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
 
     hr = IWICPalette_GetType(palette, &palettetype);
     ok(hr == S_OK, "IWICPalette_GetType failed hr=%x\n", hr);
-    todo_wine ok(palettetype == WICBitmapPaletteTypeFixedGray256,
+    ok(palettetype == WICBitmapPaletteTypeFixedGray256,
         "expected WICBitmapPaletteTypeFixedGray256, got %x\n", palettetype);
 
     IWICPalette_Release(palette);
-- 
1.7.9.5


More information about the wine-patches mailing list