[WINDOWSCODECS_WINETEST] Sync with Wine Staging 1.9.23. CORE-12409

svn path=/trunk/; revision=73304
This commit is contained in:
Amine Khaldi 2016-11-17 23:23:38 +00:00
parent c3af8cc0b7
commit b81dc9c21f
3 changed files with 1416 additions and 192 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
* Copyright 2009 Vincent Povirk for CodeWeavers
* Copyright 2012 Dmitry Timoshkov
* Copyright 2012,2016 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -32,9 +32,10 @@
#include <wincodec.h>
#include <wine/test.h>
static IWICImagingFactory *factory;
static void test_custom_palette(void)
{
IWICImagingFactory *factory;
IWICPalette *palette, *palette2;
HRESULT hr;
WICBitmapPaletteType type=0xffffffff;
@ -43,11 +44,6 @@ static void test_custom_palette(void)
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))
@ -212,8 +208,6 @@ static void test_custom_palette(void)
IWICPalette_Release(palette2);
IWICPalette_Release(palette);
}
IWICImagingFactory_Release(factory);
}
static void generate_gray16_palette(DWORD *entries, UINT count)
@ -456,7 +450,6 @@ static void test_predefined_palette(void)
{ WICBitmapPaletteTypeFixedHalftone256, 0, 0, 256, { 0 } },
{ WICBitmapPaletteTypeFixedHalftone256, 0, 0, 256, { 0 }, 1 }
};
IWICImagingFactory *factory;
IWICPalette *palette;
HRESULT hr;
WICBitmapPaletteType type;
@ -464,10 +457,6 @@ static void test_predefined_palette(void)
BOOL bret;
WICColor color[256];
hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
&IID_IWICImagingFactory, (void **)&factory);
ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
hr = IWICImagingFactory_CreatePalette(factory, &palette);
ok(hr == S_OK, "CreatePalette error %#x\n", hr);
hr = IWICPalette_InitializePredefined(palette, WICBitmapPaletteTypeCustom, FALSE);
@ -543,16 +532,136 @@ static void test_predefined_palette(void)
IWICPalette_Release(palette);
}
}
IWICImagingFactory_Release(factory);
static BYTE *init_bitmap(UINT *width, UINT *height, UINT *stride)
{
BYTE *src;
UINT i, j, scale;
*width = 256;
*height = 256;
*stride = (*width * 3 + 3) & ~3;
trace("width %d, height %d, stride %d\n", *width, *height, *stride);
src = HeapAlloc(GetProcessHeap(), 0, *stride * *height);
scale = 256 / *width;
if (!scale) scale = 1;
for (i = 0; i < *height; i++)
{
for (j = 0; j < *width; j++)
{
src[i * *stride + j*3 + 0] = scale * i;
src[i * *stride + j*3 + 1] = scale * (255 - (i+j)/2);
src[i * *stride + j*3 + 2] = scale * j;
}
}
return src;
}
static void test_palette_from_bitmap(void)
{
HRESULT hr;
BYTE *data;
IWICBitmap *bitmap;
IWICPalette *palette;
WICBitmapPaletteType type;
UINT width, height, stride, count, ret;
WICColor color[257];
data = init_bitmap(&width, &height, &stride);
hr = IWICImagingFactory_CreateBitmapFromMemory(factory, width, height, &GUID_WICPixelFormat24bppRGB,
stride, stride * height, data, &bitmap);
ok(hr == S_OK, "CreateBitmapFromMemory error %#x\n", hr);
hr = IWICImagingFactory_CreatePalette(factory, &palette);
ok(hr == S_OK, "CreatePalette error %#x\n", hr);
hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 0, FALSE);
ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 1, FALSE);
ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 257, FALSE);
ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
hr = IWICPalette_InitializeFromBitmap(palette, NULL, 16, FALSE);
ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 2, FALSE);
ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr);
count = 0;
hr = IWICPalette_GetColorCount(palette, &count);
ok(hr == S_OK, "GetColorCount error %#x\n", hr);
ok(count == 2, "expected 2, got %u\n", count);
hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 2, TRUE);
ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr);
count = 0;
hr = IWICPalette_GetColorCount(palette, &count);
ok(hr == S_OK, "GetColorCount error %#x\n", hr);
ok(count == 2, "expected 2, got %u\n", count);
/* without trasparent color */
hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 16, FALSE);
ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr);
type = -1;
hr = IWICPalette_GetType(palette, &type);
ok(hr == S_OK, "GetType error %#x\n", hr);
ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %#x\n", type);
count = 0;
hr = IWICPalette_GetColorCount(palette, &count);
ok(hr == S_OK, "GetColorCount error %#x\n", hr);
ok(count == 16, "expected 16, got %u\n", count);
memset(color, 0, sizeof(color));
hr = IWICPalette_GetColors(palette, count, color, &ret);
ok(hr == S_OK, "GetColors error %#x\n", hr);
ok(ret == count, "expected %u, got %u\n", count, ret);
ok(color[count - 1] != 0, "expected !0, got %08x\n", color[count - 1]);
/* with trasparent color */
hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 16, TRUE);
ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr);
type = -1;
hr = IWICPalette_GetType(palette, &type);
ok(hr == S_OK, "GetType error %#x\n", hr);
ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %#x\n", type);
count = 0;
hr = IWICPalette_GetColorCount(palette, &count);
ok(hr == S_OK, "GetColorCount error %#x\n", hr);
ok(count == 16, "expected 16, got %u\n", count);
memset(color, 0xff, sizeof(color));
hr = IWICPalette_GetColors(palette, count, color, &ret);
ok(hr == S_OK, "GetColors error %#x\n", hr);
ok(ret == count, "expected %u, got %u\n", count, ret);
ok(color[count - 1] == 0, "expected 0, got %08x\n", color[count - 1]);
IWICPalette_Release(palette);
IWICBitmap_Release(bitmap);
HeapFree(GetProcessHeap(), 0, data);
}
START_TEST(palette)
{
HRESULT hr;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
&IID_IWICImagingFactory, (void **)&factory);
ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
test_custom_palette();
test_predefined_palette();
test_palette_from_bitmap();
IWICImagingFactory_Release(factory);
CoUninitialize();
}

View file

@ -281,16 +281,17 @@ static const char png_color_profile[] = {
static IWICImagingFactory *factory;
static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size)
static HRESULT create_decoder(const void *image_data, UINT image_size, IWICBitmapDecoder **decoder)
{
HGLOBAL hmem;
BYTE *data;
HRESULT hr;
IWICBitmapDecoder *decoder = NULL;
IStream *stream;
GUID format;
LONG refcount;
*decoder = NULL;
hmem = GlobalAlloc(0, image_size);
data = GlobalLock(hmem);
memcpy(data, image_data, image_size);
@ -299,19 +300,19 @@ static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size
hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
if (FAILED(hr)) return NULL;
hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, decoder);
if (hr == S_OK)
{
hr = IWICBitmapDecoder_GetContainerFormat(*decoder, &format);
ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
ok(IsEqualGUID(&format, &GUID_ContainerFormatPng),
"wrong container format %s\n", wine_dbgstr_guid(&format));
hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
ok(IsEqualGUID(&format, &GUID_ContainerFormatPng),
"wrong container format %s\n", wine_dbgstr_guid(&format));
refcount = IStream_Release(stream);
ok(refcount > 0, "expected stream refcount > 0\n");
}
refcount = IStream_Release(stream);
ok(refcount > 0, "expected stream refcount > 0\n");
return decoder;
return hr;
}
static WCHAR *save_profile( BYTE *buffer, UINT size )
@ -347,9 +348,9 @@ static void test_color_contexts(void)
BYTE *buffer;
BOOL ret;
decoder = create_decoder(png_no_color_profile, sizeof(png_no_color_profile));
ok(decoder != 0, "Failed to load PNG image data\n");
if (!decoder) return;
hr = create_decoder(png_no_color_profile, sizeof(png_no_color_profile), &decoder);
ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
if (hr != S_OK) return;
/* global color context */
hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, NULL);
@ -375,9 +376,9 @@ static void test_color_contexts(void)
IWICBitmapFrameDecode_Release(frame);
IWICBitmapDecoder_Release(decoder);
decoder = create_decoder(png_color_profile, sizeof(png_color_profile));
ok(decoder != 0, "Failed to load PNG image data\n");
if (!decoder) return;
hr = create_decoder(png_color_profile, sizeof(png_color_profile), &decoder);
ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
if (hr != S_OK) return;
/* global color context */
count = 0xdeadbeef;
@ -553,9 +554,9 @@ static void test_png_palette(void)
UINT count, ret;
WICColor color[256];
decoder = create_decoder(png_PLTE_tRNS, sizeof(png_PLTE_tRNS));
ok(decoder != 0, "Failed to load PNG image data\n");
if (!decoder) return;
hr = create_decoder(png_PLTE_tRNS, sizeof(png_PLTE_tRNS), &decoder);
ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
if (hr != S_OK) return;
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
ok(hr == S_OK, "GetFrame error %#x\n", hr);
@ -589,43 +590,208 @@ static void test_png_palette(void)
static const char png_1x1_data[] = {
0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,
0x00,0x00,0x00,0x0d,'I','H','D','R',0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,0xde,
0x00,0x00,0x03,0x00,'P','L','T','E',
0x01,0x01,0x01,0x02,0x02,0x02,0x03,0x03,0x03,0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x06,0x06,0x07,0x07,0x07,0x08,0x08,0x08,
0x09,0x09,0x09,0x0a,0x0a,0x0a,0x0b,0x0b,0x0b,0x0c,0x0c,0x0c,0x0d,0x0d,0x0d,0x0e,0x0e,0x0e,0x0f,0x0f,0x0f,0x10,0x10,0x10,
0x11,0x11,0x11,0x12,0x12,0x12,0x13,0x13,0x13,0x14,0x14,0x14,0x15,0x15,0x15,0x16,0x16,0x16,0x17,0x17,0x17,0x18,0x18,0x18,
0x19,0x19,0x19,0x1a,0x1a,0x1a,0x1b,0x1b,0x1b,0x1c,0x1c,0x1c,0x1d,0x1d,0x1d,0x1e,0x1e,0x1e,0x1f,0x1f,0x1f,0x20,0x20,0x20,
0x21,0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x23,0x24,0x24,0x24,0x25,0x25,0x25,0x26,0x26,0x26,0x27,0x27,0x27,0x28,0x28,0x28,
0x29,0x29,0x29,0x2a,0x2a,0x2a,0x2b,0x2b,0x2b,0x2c,0x2c,0x2c,0x2d,0x2d,0x2d,0x2e,0x2e,0x2e,0x2f,0x2f,0x2f,0x30,0x30,0x30,
0x31,0x31,0x31,0x32,0x32,0x32,0x33,0x33,0x33,0x34,0x34,0x34,0x35,0x35,0x35,0x36,0x36,0x36,0x37,0x37,0x37,0x38,0x38,0x38,
0x39,0x39,0x39,0x3a,0x3a,0x3a,0x3b,0x3b,0x3b,0x3c,0x3c,0x3c,0x3d,0x3d,0x3d,0x3e,0x3e,0x3e,0x3f,0x3f,0x3f,0x40,0x40,0x40,
0x41,0x41,0x41,0x42,0x42,0x42,0x43,0x43,0x43,0x44,0x44,0x44,0x45,0x45,0x45,0x46,0x46,0x46,0x47,0x47,0x47,0x48,0x48,0x48,
0x49,0x49,0x49,0x4a,0x4a,0x4a,0x4b,0x4b,0x4b,0x4c,0x4c,0x4c,0x4d,0x4d,0x4d,0x4e,0x4e,0x4e,0x4f,0x4f,0x4f,0x50,0x50,0x50,
0x51,0x51,0x51,0x52,0x52,0x52,0x53,0x53,0x53,0x54,0x54,0x54,0x55,0x55,0x55,0x56,0x56,0x56,0x57,0x57,0x57,0x58,0x58,0x58,
0x59,0x59,0x59,0x5a,0x5a,0x5a,0x5b,0x5b,0x5b,0x5c,0x5c,0x5c,0x5d,0x5d,0x5d,0x5e,0x5e,0x5e,0x5f,0x5f,0x5f,0x60,0x60,0x60,
0x61,0x61,0x61,0x62,0x62,0x62,0x63,0x63,0x63,0x64,0x64,0x64,0x65,0x65,0x65,0x66,0x66,0x66,0x67,0x67,0x67,0x68,0x68,0x68,
0x69,0x69,0x69,0x6a,0x6a,0x6a,0x6b,0x6b,0x6b,0x6c,0x6c,0x6c,0x6d,0x6d,0x6d,0x6e,0x6e,0x6e,0x6f,0x6f,0x6f,0x70,0x70,0x70,
0x71,0x71,0x71,0x72,0x72,0x72,0x73,0x73,0x73,0x74,0x74,0x74,0x75,0x75,0x75,0x76,0x76,0x76,0x77,0x77,0x77,0x78,0x78,0x78,
0x79,0x79,0x79,0x7a,0x7a,0x7a,0x7b,0x7b,0x7b,0x7c,0x7c,0x7c,0x7d,0x7d,0x7d,0x7e,0x7e,0x7e,0x7f,0x7f,0x7f,0x80,0x80,0x80,
0x01,0x01,0x01,0x02,0x02,0x02,0x03,0x03,0x03,0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x06,0x06,0x07,0x07,0x07,0x08,0x08,0x08,
0x09,0x09,0x09,0x0a,0x0a,0x0a,0x0b,0x0b,0x0b,0x0c,0x0c,0x0c,0x0d,0x0d,0x0d,0x0e,0x0e,0x0e,0x0f,0x0f,0x0f,0x10,0x10,0x10,
0x11,0x11,0x11,0x12,0x12,0x12,0x13,0x13,0x13,0x14,0x14,0x14,0x15,0x15,0x15,0x16,0x16,0x16,0x17,0x17,0x17,0x18,0x18,0x18,
0x19,0x19,0x19,0x1a,0x1a,0x1a,0x1b,0x1b,0x1b,0x1c,0x1c,0x1c,0x1d,0x1d,0x1d,0x1e,0x1e,0x1e,0x1f,0x1f,0x1f,0x20,0x20,0x20,
0x21,0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x23,0x24,0x24,0x24,0x25,0x25,0x25,0x26,0x26,0x26,0x27,0x27,0x27,0x28,0x28,0x28,
0x29,0x29,0x29,0x2a,0x2a,0x2a,0x2b,0x2b,0x2b,0x2c,0x2c,0x2c,0x2d,0x2d,0x2d,0x2e,0x2e,0x2e,0x2f,0x2f,0x2f,0x30,0x30,0x30,
0x31,0x31,0x31,0x32,0x32,0x32,0x33,0x33,0x33,0x34,0x34,0x34,0x35,0x35,0x35,0x36,0x36,0x36,0x37,0x37,0x37,0x38,0x38,0x38,
0x39,0x39,0x39,0x3a,0x3a,0x3a,0x3b,0x3b,0x3b,0x3c,0x3c,0x3c,0x3d,0x3d,0x3d,0x3e,0x3e,0x3e,0x3f,0x3f,0x3f,0x40,0x40,0x40,
0x41,0x41,0x41,0x42,0x42,0x42,0x43,0x43,0x43,0x44,0x44,0x44,0x45,0x45,0x45,0x46,0x46,0x46,0x47,0x47,0x47,0x48,0x48,0x48,
0x49,0x49,0x49,0x4a,0x4a,0x4a,0x4b,0x4b,0x4b,0x4c,0x4c,0x4c,0x4d,0x4d,0x4d,0x4e,0x4e,0x4e,0x4f,0x4f,0x4f,0x50,0x50,0x50,
0x51,0x51,0x51,0x52,0x52,0x52,0x53,0x53,0x53,0x54,0x54,0x54,0x55,0x55,0x55,0x56,0x56,0x56,0x57,0x57,0x57,0x58,0x58,0x58,
0x59,0x59,0x59,0x5a,0x5a,0x5a,0x5b,0x5b,0x5b,0x5c,0x5c,0x5c,0x5d,0x5d,0x5d,0x5e,0x5e,0x5e,0x5f,0x5f,0x5f,0x60,0x60,0x60,
0x61,0x61,0x61,0x62,0x62,0x62,0x63,0x63,0x63,0x64,0x64,0x64,0x65,0x65,0x65,0x66,0x66,0x66,0x67,0x67,0x67,0x68,0x68,0x68,
0x69,0x69,0x69,0x6a,0x6a,0x6a,0x6b,0x6b,0x6b,0x6c,0x6c,0x6c,0x6d,0x6d,0x6d,0x6e,0x6e,0x6e,0x6f,0x6f,0x6f,0x70,0x70,0x70,
0x71,0x71,0x71,0x72,0x72,0x72,0x73,0x73,0x73,0x74,0x74,0x74,0x75,0x75,0x75,0x76,0x76,0x76,0x77,0x77,0x77,0x78,0x78,0x78,
0x79,0x79,0x79,0x7a,0x7a,0x7a,0x7b,0x7b,0x7b,0x7c,0x7c,0x7c,0x7d,0x7d,0x7d,0x7e,0x7e,0x7e,0x7f,0x7f,0x7f,0x80,0x80,0x80,
0x76,0xb6,0x24,0x31,
0x00,0x00,0x00,0x02,'t','R','N','S',0xff,0x00,0xe5,0xb7,0x30,0x4a,
0x00,0x00,0x00,0x0c,'I','D','A','T',0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,0xe7,
0x00,0x00,0x00,0x00,'I','E','N','D',0xae,0x42,0x60,0x82
};
static BOOL is_valid_png_type_depth(int color_type, int bit_depth, BOOL plte)
{
switch (color_type)
{
case 0: /* Grayscale */
return bit_depth == 1 || bit_depth == 2 || bit_depth == 4 || bit_depth == 8 || bit_depth == 16;
case 2: /* True Color */
return bit_depth == 8 || bit_depth == 16;
case 3: /* Indexed Color */
return (bit_depth == 1 || bit_depth == 2 || bit_depth == 4 || bit_depth == 8) && plte;
case 4: /* Grayscale with alpha */
return bit_depth == 8 || bit_depth == 16;
case 6: /* True Color with alpha */
return bit_depth == 8 || bit_depth == 16;
default:
ok(0, "unknown PNG type %d, depth %d\n", color_type, bit_depth);
return FALSE;
}
}
static void test_color_formats(void)
{
static const struct
{
char bit_depth, color_type;
const GUID *format;
const GUID *format_PLTE;
const GUID *format_PLTE_tRNS;
BOOL todo;
BOOL todo_load;
} td[] =
{
/* 2 - PNG_COLOR_TYPE_RGB */
{ 8, 2, &GUID_WICPixelFormat24bppBGR },
{ 1, 2, NULL, NULL, NULL },
{ 2, 2, NULL, NULL, NULL },
{ 4, 2, NULL, NULL, NULL },
{ 8, 2, &GUID_WICPixelFormat24bppBGR, &GUID_WICPixelFormat24bppBGR, &GUID_WICPixelFormat24bppBGR },
/* libpng refuses to load our test image complaining about extra compressed data,
* but libpng is still able to load the image with other combination of type/depth
* making RGB 16 bpp case special for some reason. Therefore todo = TRUE.
*/
{ 16, 2, &GUID_WICPixelFormat48bppRGB, &GUID_WICPixelFormat48bppRGB, &GUID_WICPixelFormat48bppRGB, TRUE, TRUE },
{ 24, 2, NULL, NULL, NULL },
{ 32, 2, NULL, NULL, NULL },
/* 0 - PNG_COLOR_TYPE_GRAY */
{ 1, 0, &GUID_WICPixelFormatBlackWhite },
{ 2, 0, &GUID_WICPixelFormat2bppGray },
{ 4, 0, &GUID_WICPixelFormat4bppGray },
{ 8, 0, &GUID_WICPixelFormat8bppGray },
{ 16, 0, &GUID_WICPixelFormat16bppGray },
{ 1, 0, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormat1bppIndexed, TRUE },
{ 2, 0, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppIndexed, TRUE },
{ 4, 0, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppIndexed, TRUE },
{ 8, 0, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppIndexed, TRUE },
{ 16, 0, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat64bppRGBA, TRUE },
{ 24, 0, NULL, NULL, NULL },
{ 32, 0, NULL, NULL, NULL },
/* 3 - PNG_COLOR_TYPE_PALETTE */
{ 1, 3, &GUID_WICPixelFormat1bppIndexed, &GUID_WICPixelFormat1bppIndexed, &GUID_WICPixelFormat1bppIndexed },
{ 2, 3, &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat2bppIndexed },
{ 4, 3, &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed },
{ 8, 3, &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed },
{ 16, 3, NULL, NULL, NULL },
{ 24, 3, NULL, NULL, NULL },
{ 32, 3, NULL, NULL, NULL },
};
char buf[sizeof(png_1x1_data)];
HRESULT hr;
IWICBitmapDecoder *decoder;
IWICBitmapFrameDecode *frame;
GUID format;
int i;
int i, PLTE_off = 0, tRNS_off = 0;
memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
for (i = 0; i < sizeof(png_1x1_data) - 4; i++)
{
if (!memcmp(buf + i, "tRNS", 4))
tRNS_off = i;
else if (!memcmp(buf + i, "PLTE", 4))
PLTE_off = i;
}
ok(PLTE_off && tRNS_off, "PLTE offset %d, tRNS offset %d\n", PLTE_off, tRNS_off);
if (!PLTE_off || !tRNS_off) return;
/* In order to test the image data with and without PLTE and tRNS chunks
* it's been decided to simply sero out the chunk id for testing puposes,
* and under Windows such images get loaded just fine. But unfortunately
* libpng refuses to load such images complaining about unknown chunk type.
* A workaround for this libpng limitation is to mark the "disabled" chunks
* with tEXt id.
*/
for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
{
/* with the tRNS and PLTE chunks */
memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
buf[24] = td[i].bit_depth;
buf[25] = td[i].color_type;
decoder = create_decoder(buf, sizeof(buf));
ok(decoder != NULL, "Failed to load PNG image data\n");
if (!decoder) continue;
hr = create_decoder(buf, sizeof(buf), &decoder);
if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE))
ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
else
todo_wine_if(td[i].todo_load)
ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr);
if (hr != S_OK) goto next_1;
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
ok(hr == S_OK, "GetFrame error %#x\n", hr);
hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
todo_wine_if(td[i].todo)
ok(IsEqualGUID(&format, td[i].format_PLTE_tRNS),
"PLTE+tRNS: expected %s, got %s (type %d, bpp %d)\n",
wine_dbgstr_guid(td[i].format_PLTE_tRNS), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth);
IWICBitmapFrameDecode_Release(frame);
IWICBitmapDecoder_Release(decoder);
next_1:
/* without the tRNS chunk */
memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
buf[24] = td[i].bit_depth;
buf[25] = td[i].color_type;
memcpy(buf + tRNS_off, "tEXt", 4);
hr = create_decoder(buf, sizeof(buf), &decoder);
if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE))
ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
else
todo_wine_if(td[i].todo_load)
ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr);
if (hr != S_OK) goto next_2;
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
ok(hr == S_OK, "GetFrame error %#x\n", hr);
hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
ok(IsEqualGUID(&format, td[i].format_PLTE),
"PLTE: expected %s, got %s (type %d, bpp %d)\n",
wine_dbgstr_guid(td[i].format_PLTE), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth);
IWICBitmapFrameDecode_Release(frame);
IWICBitmapDecoder_Release(decoder);
next_2:
/* without the tRNS and PLTE chunks */
memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
buf[24] = td[i].bit_depth;
buf[25] = td[i].color_type;
memcpy(buf + PLTE_off, "tEXt", 4);
memcpy(buf + tRNS_off, "tEXt", 4);
hr = create_decoder(buf, sizeof(buf), &decoder);
if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE))
ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
else
todo_wine_if(td[i].todo_load)
ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr);
if (hr != S_OK) goto next_3;
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
ok(hr == S_OK, "GetFrame error %#x\n", hr);
@ -633,7 +799,36 @@ static void test_color_formats(void)
hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
ok(IsEqualGUID(&format, td[i].format),
"expected %s, got %s\n", wine_dbgstr_guid(td[i].format), wine_dbgstr_guid(&format));
"expected %s, got %s (type %d, bpp %d)\n",
wine_dbgstr_guid(td[i].format), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth);
IWICBitmapFrameDecode_Release(frame);
IWICBitmapDecoder_Release(decoder);
next_3:
/* without the PLTE chunk */
memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
buf[24] = td[i].bit_depth;
buf[25] = td[i].color_type;
memcpy(buf + PLTE_off, "tEXt", 4);
hr = create_decoder(buf, sizeof(buf), &decoder);
if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE))
ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
else
todo_wine_if(td[i].todo_load)
ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr);
if (hr != S_OK) continue;
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
ok(hr == S_OK, "GetFrame error %#x\n", hr);
hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
todo_wine_if(td[i].todo)
ok(IsEqualGUID(&format, td[i].format_PLTE_tRNS),
"tRNS: expected %s, got %s (type %d, bpp %d)\n",
wine_dbgstr_guid(td[i].format_PLTE_tRNS), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth);
IWICBitmapFrameDecode_Release(frame);
IWICBitmapDecoder_Release(decoder);