2009-07-03 00:09:47 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Vincent Povirk for CodeWeavers
|
2012-07-12 09:10:27 +02:00
|
|
|
* Copyright 2012 Dmitry Timoshkov
|
2009-07-03 00:09:47 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "wincodec.h"
|
|
|
|
|
|
|
|
#include "wincodecs_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
|
|
|
|
|
|
|
|
typedef struct {
|
2010-11-29 01:01:05 +01:00
|
|
|
IWICPalette IWICPalette_iface;
|
2009-07-03 00:09:47 +02:00
|
|
|
LONG ref;
|
2009-07-03 00:37:06 +02:00
|
|
|
UINT count;
|
|
|
|
WICColor *colors;
|
|
|
|
WICBitmapPaletteType type;
|
2010-03-19 19:17:29 +01:00
|
|
|
CRITICAL_SECTION lock; /* must be held when count, colors, or type is accessed */
|
2009-07-03 00:09:47 +02:00
|
|
|
} PaletteImpl;
|
|
|
|
|
2010-11-29 01:01:05 +01:00
|
|
|
static inline PaletteImpl *impl_from_IWICPalette(IWICPalette *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, PaletteImpl, IWICPalette_iface);
|
|
|
|
}
|
|
|
|
|
2009-07-03 00:09:47 +02:00
|
|
|
static HRESULT WINAPI PaletteImpl_QueryInterface(IWICPalette *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:09:47 +02:00
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICPalette, iid))
|
|
|
|
{
|
2012-08-17 19:09:09 +02:00
|
|
|
*ppv = &This->IWICPalette_iface;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI PaletteImpl_AddRef(IWICPalette *iface)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:09:47 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI PaletteImpl_Release(IWICPalette *iface)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:09:47 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
2009-07-03 00:37:06 +02:00
|
|
|
{
|
2010-03-19 19:17:29 +01:00
|
|
|
This->lock.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->lock);
|
2009-07-03 00:37:06 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->colors);
|
2009-07-03 00:09:47 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2009-07-03 00:37:06 +02:00
|
|
|
}
|
2009-07-03 00:09:47 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2012-07-12 09:55:53 +02:00
|
|
|
static WICColor *generate_gray16_palette(UINT *count)
|
|
|
|
{
|
|
|
|
WICColor *entries;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
*count = 16;
|
|
|
|
entries = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(WICColor));
|
|
|
|
if (!entries) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= (i<<20) | (i<<16) | (i<<12) | (i<<8) | (i<<4) | i;
|
|
|
|
}
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2012-07-12 09:09:26 +02:00
|
|
|
static WICColor *generate_gray256_palette(UINT *count)
|
|
|
|
{
|
|
|
|
WICColor *entries;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
*count = 256;
|
|
|
|
entries = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(WICColor));
|
|
|
|
if (!entries) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= (i<<16) | (i<<8) | i;
|
|
|
|
}
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
static WICColor *generate_halftone8_palette(UINT *count, BOOL add_transparent)
|
2012-07-12 09:10:27 +02:00
|
|
|
{
|
|
|
|
WICColor *entries;
|
|
|
|
UINT i;
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
*count = add_transparent ? 17 : 16;
|
|
|
|
entries = HeapAlloc(GetProcessHeap(), 0, *count * sizeof(WICColor));
|
2012-07-12 09:10:27 +02:00
|
|
|
if (!entries) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
if (i & 1) entries[i] |= 0xff;
|
|
|
|
if (i & 2) entries[i] |= 0xff00;
|
|
|
|
if (i & 4) entries[i] |= 0xff0000;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 8; i < 16; i++)
|
|
|
|
{
|
|
|
|
static const DWORD halftone[8] = { 0xc0c0c0, 0x808080, 0x800000, 0x008000,
|
|
|
|
0x000080, 0x808000, 0x800080, 0x008080 };
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone[i-8];
|
|
|
|
}
|
2012-07-23 05:47:57 +02:00
|
|
|
|
|
|
|
if (add_transparent)
|
|
|
|
entries[i] = 0;
|
|
|
|
|
2012-07-12 09:10:27 +02:00
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
static WICColor *generate_halftone27_palette(UINT *count, BOOL add_transparent)
|
2012-07-23 05:43:45 +02:00
|
|
|
{
|
|
|
|
WICColor *entries;
|
|
|
|
UINT i;
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
*count = add_transparent ? 29 : 28;
|
|
|
|
entries = HeapAlloc(GetProcessHeap(), 0, *count * sizeof(WICColor));
|
2012-07-23 05:43:45 +02:00
|
|
|
if (!entries) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 27; i++)
|
|
|
|
{
|
|
|
|
static const BYTE halftone_values[4] = { 0x00,0x80,0xff };
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone_values[i%3];
|
|
|
|
entries[i] |= halftone_values[(i/3)%3] << 8;
|
|
|
|
entries[i] |= halftone_values[(i/9)%3] << 16;
|
|
|
|
}
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
entries[i++] = 0xffc0c0c0;
|
|
|
|
if (add_transparent)
|
|
|
|
entries[i] = 0;
|
|
|
|
|
2012-07-23 05:43:45 +02:00
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
static WICColor *generate_halftone64_palette(UINT *count, BOOL add_transparent)
|
2012-07-12 09:11:51 +02:00
|
|
|
{
|
|
|
|
WICColor *entries;
|
|
|
|
UINT i;
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
*count = add_transparent ? 73 : 72;
|
|
|
|
entries = HeapAlloc(GetProcessHeap(), 0, *count * sizeof(WICColor));
|
2012-07-12 09:11:51 +02:00
|
|
|
if (!entries) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
static const BYTE halftone_values[4] = { 0x00,0x55,0xaa,0xff };
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone_values[i%4];
|
|
|
|
entries[i] |= halftone_values[(i/4)%4] << 8;
|
|
|
|
entries[i] |= halftone_values[(i/16)%4] << 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 64; i < 72; i++)
|
|
|
|
{
|
|
|
|
static const DWORD halftone[8] = { 0xc0c0c0, 0x808080, 0x800000, 0x008000,
|
|
|
|
0x000080, 0x808000, 0x800080, 0x008080 };
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone[i-64];
|
|
|
|
}
|
2012-07-23 05:47:57 +02:00
|
|
|
|
|
|
|
if (add_transparent)
|
|
|
|
entries[i] = 0;
|
|
|
|
|
2012-07-12 09:11:51 +02:00
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
static WICColor *generate_halftone125_palette(UINT *count, BOOL add_transparent)
|
2012-07-23 05:44:54 +02:00
|
|
|
{
|
|
|
|
WICColor *entries;
|
|
|
|
UINT i;
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
*count = add_transparent ? 127 : 126;
|
|
|
|
entries = HeapAlloc(GetProcessHeap(), 0, *count * sizeof(WICColor));
|
2012-07-23 05:44:54 +02:00
|
|
|
if (!entries) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 125; i++)
|
|
|
|
{
|
|
|
|
static const BYTE halftone_values[5] = { 0x00,0x40,0x80,0xbf,0xff };
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone_values[i%5];
|
|
|
|
entries[i] |= halftone_values[(i/5)%5] << 8;
|
|
|
|
entries[i] |= halftone_values[(i/25)%5] << 16;
|
|
|
|
}
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
entries[i++] = 0xffc0c0c0;
|
|
|
|
if (add_transparent)
|
|
|
|
entries[i] = 0;
|
|
|
|
|
2012-07-23 05:44:54 +02:00
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
static WICColor *generate_halftone216_palette(UINT *count, BOOL add_transparent)
|
2012-07-23 05:45:53 +02:00
|
|
|
{
|
|
|
|
WICColor *entries;
|
|
|
|
UINT i;
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
*count = add_transparent ? 225 : 224;
|
|
|
|
entries = HeapAlloc(GetProcessHeap(), 0, *count * sizeof(WICColor));
|
2012-07-23 05:45:53 +02:00
|
|
|
if (!entries) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 216; i++)
|
|
|
|
{
|
|
|
|
static const BYTE halftone_values[6] = { 0x00,0x33,0x66,0x99,0xcc,0xff };
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone_values[i%6];
|
|
|
|
entries[i] |= halftone_values[(i/6)%6] << 8;
|
|
|
|
entries[i] |= halftone_values[(i/36)%6] << 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 216; i < 224; i++)
|
|
|
|
{
|
|
|
|
static const DWORD halftone[8] = { 0xc0c0c0, 0x808080, 0x800000, 0x008000,
|
|
|
|
0x000080, 0x808000, 0x800080, 0x008080 };
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone[i-216];
|
|
|
|
}
|
2012-07-23 05:47:57 +02:00
|
|
|
|
|
|
|
if (add_transparent)
|
|
|
|
entries[i] = 0;
|
|
|
|
|
2012-07-23 05:45:53 +02:00
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
static WICColor *generate_halftone252_palette(UINT *count, BOOL add_transparent)
|
2012-07-23 05:46:54 +02:00
|
|
|
{
|
|
|
|
WICColor *entries;
|
|
|
|
UINT i;
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
*count = add_transparent ? 253 : 252;
|
|
|
|
entries = HeapAlloc(GetProcessHeap(), 0, *count * sizeof(WICColor));
|
2012-07-23 05:46:54 +02:00
|
|
|
if (!entries) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 252; i++)
|
|
|
|
{
|
|
|
|
static const BYTE halftone_values_rb[6] = { 0x00,0x33,0x66,0x99,0xcc,0xff };
|
|
|
|
static const BYTE halftone_values_g[7] = { 0x00,0x2b,0x55,0x80,0xaa,0xd5,0xff };
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone_values_rb[i%6];
|
|
|
|
entries[i] |= halftone_values_g[(i/6)%7] << 8;
|
|
|
|
entries[i] |= halftone_values_rb[(i/42)%6] << 16;
|
|
|
|
}
|
2012-07-23 05:47:57 +02:00
|
|
|
|
|
|
|
if (add_transparent)
|
|
|
|
entries[i] = 0;
|
|
|
|
|
2012-07-23 05:46:54 +02:00
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2012-07-23 05:47:57 +02:00
|
|
|
static WICColor *generate_halftone256_palette(UINT *count, BOOL add_transparent)
|
2012-07-12 09:14:11 +02:00
|
|
|
{
|
|
|
|
WICColor *entries;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
*count = 256;
|
|
|
|
entries = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(WICColor));
|
|
|
|
if (!entries) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
static const BYTE halftone_values_b[4] = { 0x00,0x55,0xaa,0xff };
|
|
|
|
static const BYTE halftone_values_gr[8] = { 0x00,0x24,0x49,0x6d,0x92,0xb6,0xdb,0xff };
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone_values_b[i%4];
|
|
|
|
entries[i] |= halftone_values_gr[(i/4)%8] << 8;
|
|
|
|
entries[i] |= halftone_values_gr[(i/32)%8] << 16;
|
|
|
|
}
|
2012-07-23 05:47:57 +02:00
|
|
|
|
|
|
|
if (add_transparent)
|
|
|
|
entries[255] = 0;
|
|
|
|
|
2012-07-12 09:14:11 +02:00
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2009-07-03 00:09:47 +02:00
|
|
|
static HRESULT WINAPI PaletteImpl_InitializePredefined(IWICPalette *iface,
|
2012-07-12 09:06:29 +02:00
|
|
|
WICBitmapPaletteType type, BOOL add_transparent)
|
2009-07-03 00:09:47 +02:00
|
|
|
{
|
2012-07-12 09:06:29 +02:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
|
|
|
WICColor *colors;
|
|
|
|
UINT count;
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%d)\n", iface, type, add_transparent);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case WICBitmapPaletteTypeFixedBW:
|
|
|
|
count = 2;
|
|
|
|
colors = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WICColor));
|
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
colors[0] = 0xff000000;
|
|
|
|
colors[1] = 0xffffffff;
|
|
|
|
break;
|
|
|
|
|
2012-07-12 09:55:45 +02:00
|
|
|
case WICBitmapPaletteTypeFixedGray4:
|
|
|
|
count = 4;
|
|
|
|
colors = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WICColor));
|
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
colors[0] = 0xff000000;
|
|
|
|
colors[1] = 0xff555555;
|
|
|
|
colors[2] = 0xffaaaaaa;
|
|
|
|
colors[3] = 0xffffffff;
|
|
|
|
break;
|
|
|
|
|
2012-07-12 09:55:53 +02:00
|
|
|
case WICBitmapPaletteTypeFixedGray16:
|
|
|
|
colors = generate_gray16_palette(&count);
|
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
|
2012-07-12 09:09:26 +02:00
|
|
|
case WICBitmapPaletteTypeFixedGray256:
|
|
|
|
colors = generate_gray256_palette(&count);
|
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
|
2012-07-12 09:10:27 +02:00
|
|
|
case WICBitmapPaletteTypeFixedHalftone8:
|
2012-07-23 05:47:57 +02:00
|
|
|
colors = generate_halftone8_palette(&count, add_transparent);
|
2012-07-12 09:10:27 +02:00
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
|
2012-07-23 05:43:45 +02:00
|
|
|
case WICBitmapPaletteTypeFixedHalftone27:
|
2012-07-23 05:47:57 +02:00
|
|
|
colors = generate_halftone27_palette(&count, add_transparent);
|
2012-07-23 05:43:45 +02:00
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
|
2012-07-12 09:11:51 +02:00
|
|
|
case WICBitmapPaletteTypeFixedHalftone64:
|
2012-07-23 05:47:57 +02:00
|
|
|
colors = generate_halftone64_palette(&count, add_transparent);
|
2012-07-12 09:11:51 +02:00
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
|
2012-07-23 05:44:54 +02:00
|
|
|
case WICBitmapPaletteTypeFixedHalftone125:
|
2012-07-23 05:47:57 +02:00
|
|
|
colors = generate_halftone125_palette(&count, add_transparent);
|
2012-07-23 05:44:54 +02:00
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
|
2012-07-23 05:45:53 +02:00
|
|
|
case WICBitmapPaletteTypeFixedHalftone216:
|
2012-07-23 05:47:57 +02:00
|
|
|
colors = generate_halftone216_palette(&count, add_transparent);
|
2012-07-23 05:45:53 +02:00
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
|
2012-07-23 05:46:54 +02:00
|
|
|
case WICBitmapPaletteTypeFixedHalftone252:
|
2012-07-23 05:47:57 +02:00
|
|
|
colors = generate_halftone252_palette(&count, add_transparent);
|
2012-07-23 05:46:54 +02:00
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
|
2012-07-12 09:14:11 +02:00
|
|
|
case WICBitmapPaletteTypeFixedHalftone256:
|
2012-07-23 05:47:57 +02:00
|
|
|
colors = generate_halftone256_palette(&count, add_transparent);
|
2012-07-12 09:14:11 +02:00
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
|
2012-07-12 09:06:29 +02:00
|
|
|
default:
|
2012-07-23 05:49:03 +02:00
|
|
|
WARN("invalid palette type %u\n", type);
|
|
|
|
return E_INVALIDARG;
|
2012-07-12 09:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->colors);
|
|
|
|
This->colors = colors;
|
|
|
|
This->count = count;
|
|
|
|
This->type = type;
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PaletteImpl_InitializeCustom(IWICPalette *iface,
|
|
|
|
WICColor *pColors, UINT colorCount)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:37:06 +02:00
|
|
|
WICColor *new_colors;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%u)\n", iface, pColors, colorCount);
|
|
|
|
|
|
|
|
if (colorCount == 0)
|
|
|
|
{
|
|
|
|
new_colors = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!pColors) return E_INVALIDARG;
|
|
|
|
new_colors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * colorCount);
|
|
|
|
if (!new_colors) return E_OUTOFMEMORY;
|
|
|
|
memcpy(new_colors, pColors, sizeof(WICColor) * colorCount);
|
|
|
|
}
|
|
|
|
|
2010-03-19 19:17:29 +01:00
|
|
|
EnterCriticalSection(&This->lock);
|
2009-07-03 00:37:06 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->colors);
|
|
|
|
This->colors = new_colors;
|
|
|
|
This->count = colorCount;
|
|
|
|
This->type = WICBitmapPaletteTypeCustom;
|
2010-03-19 19:17:29 +01:00
|
|
|
LeaveCriticalSection(&This->lock);
|
2009-07-03 00:37:06 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PaletteImpl_InitializeFromBitmap(IWICPalette *iface,
|
|
|
|
IWICBitmapSource *pISurface, UINT colorCount, BOOL fAddTransparentColor)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%u,%i): stub\n", iface, pISurface, colorCount, fAddTransparentColor);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PaletteImpl_InitializeFromPalette(IWICPalette *iface,
|
2012-07-30 06:12:28 +02:00
|
|
|
IWICPalette *source)
|
2009-07-03 00:09:47 +02:00
|
|
|
{
|
2012-07-30 06:12:28 +02:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
|
|
|
UINT count;
|
|
|
|
WICColor *colors = NULL;
|
|
|
|
WICBitmapPaletteType type;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, source);
|
|
|
|
|
|
|
|
if (!source) return E_INVALIDARG;
|
|
|
|
|
|
|
|
hr = IWICPalette_GetType(source, &type);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
hr = IWICPalette_GetColorCount(source, &count);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
colors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * count);
|
|
|
|
if (!colors) return E_OUTOFMEMORY;
|
|
|
|
hr = IWICPalette_GetColors(source, count, colors, &count);
|
2012-07-31 09:17:42 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, colors);
|
|
|
|
return hr;
|
|
|
|
}
|
2012-07-30 06:12:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->colors);
|
|
|
|
This->colors = colors;
|
|
|
|
This->count = count;
|
|
|
|
This->type = type;
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PaletteImpl_GetType(IWICPalette *iface,
|
|
|
|
WICBitmapPaletteType *pePaletteType)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:39:40 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, pePaletteType);
|
|
|
|
|
|
|
|
if (!pePaletteType) return E_INVALIDARG;
|
|
|
|
|
2010-03-19 19:17:29 +01:00
|
|
|
EnterCriticalSection(&This->lock);
|
2009-07-03 00:39:40 +02:00
|
|
|
*pePaletteType = This->type;
|
2010-03-19 19:17:29 +01:00
|
|
|
LeaveCriticalSection(&This->lock);
|
2009-07-03 00:39:40 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PaletteImpl_GetColorCount(IWICPalette *iface, UINT *pcCount)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:39:40 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, pcCount);
|
|
|
|
|
|
|
|
if (!pcCount) return E_INVALIDARG;
|
|
|
|
|
2010-03-19 19:17:29 +01:00
|
|
|
EnterCriticalSection(&This->lock);
|
2009-07-03 00:39:40 +02:00
|
|
|
*pcCount = This->count;
|
2010-03-19 19:17:29 +01:00
|
|
|
LeaveCriticalSection(&This->lock);
|
2009-07-03 00:39:40 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PaletteImpl_GetColors(IWICPalette *iface, UINT colorCount,
|
|
|
|
WICColor *pColors, UINT *pcActualColors)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:37:06 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%i,%p,%p)\n", iface, colorCount, pColors, pcActualColors);
|
|
|
|
|
|
|
|
if (!pColors || !pcActualColors) return E_INVALIDARG;
|
|
|
|
|
2010-03-19 19:17:29 +01:00
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
2009-07-03 00:37:06 +02:00
|
|
|
if (This->count < colorCount) colorCount = This->count;
|
|
|
|
|
|
|
|
memcpy(pColors, This->colors, sizeof(WICColor) * colorCount);
|
|
|
|
|
|
|
|
*pcActualColors = colorCount;
|
|
|
|
|
2010-03-19 19:17:29 +01:00
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
2009-07-03 00:37:06 +02:00
|
|
|
return S_OK;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PaletteImpl_IsBlackWhite(IWICPalette *iface, BOOL *pfIsBlackWhite)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:44:31 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, pfIsBlackWhite);
|
|
|
|
|
|
|
|
if (!pfIsBlackWhite) return E_INVALIDARG;
|
|
|
|
|
2010-03-19 19:17:29 +01:00
|
|
|
EnterCriticalSection(&This->lock);
|
2009-07-03 00:44:31 +02:00
|
|
|
if (This->type == WICBitmapPaletteTypeFixedBW)
|
|
|
|
*pfIsBlackWhite = TRUE;
|
|
|
|
else
|
|
|
|
*pfIsBlackWhite = FALSE;
|
2010-03-19 19:17:29 +01:00
|
|
|
LeaveCriticalSection(&This->lock);
|
2009-07-03 00:44:31 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PaletteImpl_IsGrayscale(IWICPalette *iface, BOOL *pfIsGrayscale)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:44:31 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, pfIsGrayscale);
|
|
|
|
|
|
|
|
if (!pfIsGrayscale) return E_INVALIDARG;
|
|
|
|
|
2010-03-19 19:17:29 +01:00
|
|
|
EnterCriticalSection(&This->lock);
|
2009-07-03 00:44:31 +02:00
|
|
|
switch(This->type)
|
|
|
|
{
|
|
|
|
case WICBitmapPaletteTypeFixedBW:
|
|
|
|
case WICBitmapPaletteTypeFixedGray4:
|
|
|
|
case WICBitmapPaletteTypeFixedGray16:
|
|
|
|
case WICBitmapPaletteTypeFixedGray256:
|
|
|
|
*pfIsGrayscale = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*pfIsGrayscale = FALSE;
|
|
|
|
}
|
2010-03-19 19:17:29 +01:00
|
|
|
LeaveCriticalSection(&This->lock);
|
2009-07-03 00:44:31 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PaletteImpl_HasAlpha(IWICPalette *iface, BOOL *pfHasAlpha)
|
|
|
|
{
|
2010-11-29 01:01:05 +01:00
|
|
|
PaletteImpl *This = impl_from_IWICPalette(iface);
|
2009-07-03 00:47:19 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, pfHasAlpha);
|
|
|
|
|
|
|
|
if (!pfHasAlpha) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*pfHasAlpha = FALSE;
|
|
|
|
|
2010-03-19 19:17:29 +01:00
|
|
|
EnterCriticalSection(&This->lock);
|
2009-07-03 00:47:19 +02:00
|
|
|
for (i=0; i<This->count; i++)
|
|
|
|
if ((This->colors[i]&0xff000000) != 0xff000000)
|
|
|
|
{
|
|
|
|
*pfHasAlpha = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-19 19:17:29 +01:00
|
|
|
LeaveCriticalSection(&This->lock);
|
2009-07-03 00:47:19 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-07-03 00:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICPaletteVtbl PaletteImpl_Vtbl = {
|
|
|
|
PaletteImpl_QueryInterface,
|
|
|
|
PaletteImpl_AddRef,
|
|
|
|
PaletteImpl_Release,
|
|
|
|
PaletteImpl_InitializePredefined,
|
|
|
|
PaletteImpl_InitializeCustom,
|
|
|
|
PaletteImpl_InitializeFromBitmap,
|
|
|
|
PaletteImpl_InitializeFromPalette,
|
|
|
|
PaletteImpl_GetType,
|
|
|
|
PaletteImpl_GetColorCount,
|
|
|
|
PaletteImpl_GetColors,
|
|
|
|
PaletteImpl_IsBlackWhite,
|
|
|
|
PaletteImpl_IsGrayscale,
|
|
|
|
PaletteImpl_HasAlpha
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT PaletteImpl_Create(IWICPalette **palette)
|
|
|
|
{
|
|
|
|
PaletteImpl *This;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(PaletteImpl));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
2010-11-29 01:01:05 +01:00
|
|
|
This->IWICPalette_iface.lpVtbl = &PaletteImpl_Vtbl;
|
2009-07-03 00:09:47 +02:00
|
|
|
This->ref = 1;
|
2009-07-03 00:37:06 +02:00
|
|
|
This->count = 0;
|
|
|
|
This->colors = NULL;
|
|
|
|
This->type = WICBitmapPaletteTypeCustom;
|
2010-03-19 19:17:29 +01:00
|
|
|
InitializeCriticalSection(&This->lock);
|
|
|
|
This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": PaletteImpl.lock");
|
2009-07-03 00:09:47 +02:00
|
|
|
|
2012-07-24 08:13:15 +02:00
|
|
|
*palette = &This->IWICPalette_iface;
|
2009-07-03 00:09:47 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|