Vincent Povirk : windowscodecs: Implement BitmapImpl_SetPalette and CopyPalette.

Alexandre Julliard julliard at winehq.org
Wed Aug 15 14:08:34 CDT 2012


Module: wine
Branch: master
Commit: 3e36f1e4b5d1454fd9e5ae058ec95b34e7dd6496
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3e36f1e4b5d1454fd9e5ae058ec95b34e7dd6496

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Tue Aug 14 14:01:11 2012 -0500

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 5014488..1f8d87d 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 748a1f9..a5577a1 100644
--- a/dlls/windowscodecs/tests/bitmap.c
+++ b/dlls/windowscodecs/tests/bitmap.c
@@ -62,23 +62,23 @@ static 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);




More information about the wine-cvs mailing list