static HRESULT WINAPI BitmapImpl_SetPalette(IWICBitmap *iface, IWICPalette *pIPalette) { BitmapImpl *This = impl_from_IWICBitmap(iface); HRESULT hr; 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_CopyPalette(IWICBitmap *iface, IWICPalette *pIPalette) { BitmapImpl *This = impl_from_IWICBitmap(iface); TRACE("(%p,%p)\n", iface, pIPalette); if (!This->palette_set) return WINCODEC_ERR_PALETTEUNAVAILABLE; return IWICPalette_InitializeFromPalette(pIPalette, This->palette); }
HRESULT WINAPI IWICPalette_InitializeFromPalette_Proxy_W(IWICPalette *iface, IWICPalette *pIPalette) { return IWICPalette_InitializeFromPalette(iface, pIPalette); }
static void test_custom_palette(void) { IWICImagingFactory *factory; IWICPalette *palette, *palette2; HRESULT hr; WICBitmapPaletteType type=0xffffffff; UINT count=1; const WICColor initcolors[4]={0xff000000,0xff0000ff,0xffffff00,0xffffffff}; WICColor colors[4]; BOOL boolresult; hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory); ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr); if (FAILED(hr)) return; hr = IWICImagingFactory_CreatePalette(factory, &palette); ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { hr = IWICPalette_GetType(palette, &type); ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr); ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type); hr = IWICPalette_GetColorCount(palette, &count); ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr); ok(count == 0, "expected 0, got %u\n", count); hr = IWICPalette_GetColors(palette, 0, colors, &count); ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr); ok(count == 0, "expected 0, got %u\n", count); hr = IWICPalette_GetColors(palette, 4, colors, &count); ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr); ok(count == 0, "expected 0, got %u\n", count); memcpy(colors, initcolors, sizeof(initcolors)); hr = IWICPalette_InitializeCustom(palette, colors, 4); ok(SUCCEEDED(hr), "InitializeCustom failed, hr=%x\n", hr); hr = IWICPalette_GetType(palette, &type); ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr); ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type); hr = IWICPalette_GetColorCount(palette, &count); ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr); ok(count == 4, "expected 4, got %u\n", count); memset(colors, 0, sizeof(colors)); count = 0; hr = IWICPalette_GetColors(palette, 4, colors, &count); ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr); ok(count == 4, "expected 4, got %u\n", count); ok(!memcmp(colors, initcolors, sizeof(colors)), "got unexpected palette data\n"); memset(colors, 0, sizeof(colors)); count = 0; hr = IWICPalette_GetColors(palette, 2, colors, &count); ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr); ok(count == 2, "expected 2, got %u\n", count); ok(!memcmp(colors, initcolors, sizeof(WICColor)*2), "got unexpected palette data\n"); count = 0; hr = IWICPalette_GetColors(palette, 6, colors, &count); ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr); ok(count == 4, "expected 4, got %u\n", count); hr = IWICPalette_HasAlpha(palette, &boolresult); ok(SUCCEEDED(hr), "HasAlpha failed, hr=%x\n", hr); ok(!boolresult, "expected FALSE, got TRUE\n"); hr = IWICPalette_IsBlackWhite(palette, &boolresult); ok(SUCCEEDED(hr), "IsBlackWhite failed, hr=%x\n", hr); ok(!boolresult, "expected FALSE, got TRUE\n"); hr = IWICPalette_IsGrayscale(palette, &boolresult); ok(SUCCEEDED(hr), "IsGrayscale failed, hr=%x\n", hr); ok(!boolresult, "expected FALSE, got TRUE\n"); hr = IWICImagingFactory_CreatePalette(factory, &palette2); ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr); hr = IWICPalette_InitializeFromPalette(palette2, palette); ok(SUCCEEDED(hr), "InitializeFromPalette failed, hr=%x\n", hr); type = 0xdeadbeef; hr = IWICPalette_GetType(palette2, &type); ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr); ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type); count = 0xdeadbeef; hr = IWICPalette_GetColorCount(palette2, &count); ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr); ok(count == 4, "expected 4, got %u\n", count); memset(colors, 0, sizeof(colors)); count = 0xdeadbeef; hr = IWICPalette_GetColors(palette2, 4, colors, &count); ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr); ok(count == 4, "expected 4, got %u\n", count); ok(!memcmp(colors, initcolors, sizeof(colors)), "got unexpected palette data\n"); /* try a palette with some alpha in it */ colors[2] = 0x80ffffff; hr = IWICPalette_InitializeCustom(palette, colors, 4); ok(SUCCEEDED(hr), "InitializeCustom failed, hr=%x\n", hr); hr = IWICPalette_HasAlpha(palette, &boolresult); ok(SUCCEEDED(hr), "HasAlpha failed, hr=%x\n", hr); ok(boolresult, "expected TRUE, got FALSE\n"); /* setting to a 0-color palette is acceptable */ hr = IWICPalette_InitializeCustom(palette, NULL, 0); ok(SUCCEEDED(hr), "InitializeCustom failed, hr=%x\n", hr); type = 0xdeadbeef; hr = IWICPalette_GetType(palette, &type); ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr); ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type); count = 0xdeadbeef; hr = IWICPalette_GetColorCount(palette, &count); ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr); ok(count == 0, "expected 0, got %u\n", count); count = 0xdeadbeef; hr = IWICPalette_GetColors(palette, 4, colors, &count); ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr); ok(count == 0, "expected 0, got %u\n", count); hr = IWICPalette_InitializeFromPalette(palette2, palette); ok(SUCCEEDED(hr), "InitializeFromPalette failed, hr=%x\n", hr); type = 0xdeadbeef; hr = IWICPalette_GetType(palette2, &type); ok(SUCCEEDED(hr), "GetType failed, hr=%x\n", hr); ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %x\n", type); count = 0xdeadbeef; hr = IWICPalette_GetColorCount(palette2, &count); ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr); ok(count == 0, "expected 0, got %u\n", count); memset(colors, 0, sizeof(colors)); count = 0xdeadbeef; hr = IWICPalette_GetColors(palette2, 4, colors, &count); ok(SUCCEEDED(hr), "GetColors failed, hr=%x\n", hr); ok(count == 0, "expected 0, got %u\n", count); /* IWICPalette is paranoid about NULL pointers */ hr = IWICPalette_GetType(palette, NULL); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr); hr = IWICPalette_GetColorCount(palette, NULL); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr); hr = IWICPalette_InitializeCustom(palette, NULL, 4); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr); hr = IWICPalette_GetColors(palette, 4, NULL, &count); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr); hr = IWICPalette_GetColors(palette, 4, colors, NULL); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr); hr = IWICPalette_HasAlpha(palette, NULL); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr); hr = IWICPalette_IsBlackWhite(palette, NULL); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr); hr = IWICPalette_IsGrayscale(palette, NULL); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr); hr = IWICPalette_InitializeFromPalette(palette, NULL); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr); IWICPalette_Release(palette2); IWICPalette_Release(palette); } IWICImagingFactory_Release(factory); }