From: Amine Khaldi Date: Thu, 17 Nov 2016 23:23:38 +0000 (+0000) Subject: [WINDOWSCODECS_WINETEST] Sync with Wine Staging 1.9.23. CORE-12409 X-Git-Tag: ReactOS-0.4.4-FOSDEM2017~231 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=b81dc9c21f3bf253ac5683bc43c3f92578415254 [WINDOWSCODECS_WINETEST] Sync with Wine Staging 1.9.23. CORE-12409 svn path=/trunk/; revision=73304 --- diff --git a/rostests/winetests/windowscodecs/converter.c b/rostests/winetests/windowscodecs/converter.c index 2a435351a5a..56c4384e9ac 100644 --- a/rostests/winetests/windowscodecs/converter.c +++ b/rostests/winetests/windowscodecs/converter.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Vincent Povirk + * Copyright 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 @@ -17,6 +18,7 @@ */ #include +#include #include #define WIN32_NO_STATUS @@ -28,10 +30,13 @@ #include #include +#include #include -#include +#include #include +static IWICImagingFactory *factory; + typedef struct bitmap_data { const WICPixelFormatGUID *format; UINT bpp; @@ -40,6 +45,7 @@ typedef struct bitmap_data { UINT height; double xres; double yres; + const struct bitmap_data *alt_data; } bitmap_data; typedef struct BitmapTestSrc { @@ -114,9 +120,30 @@ static HRESULT WINAPI BitmapTestSrc_GetResolution(IWICBitmapSource *iface, } static HRESULT WINAPI BitmapTestSrc_CopyPalette(IWICBitmapSource *iface, - IWICPalette *pIPalette) + IWICPalette *palette) { - return E_NOTIMPL; + BitmapTestSrc *This = impl_from_IWICBitmapSource(iface); + + if (IsEqualGUID(This->data->format, &GUID_WICPixelFormat1bppIndexed) || + IsEqualGUID(This->data->format, &GUID_WICPixelFormat2bppIndexed) || + IsEqualGUID(This->data->format, &GUID_WICPixelFormat4bppIndexed) || + IsEqualGUID(This->data->format, &GUID_WICPixelFormat8bppIndexed)) + { + WICColor colors[8]; + + colors[0] = 0xff0000ff; + colors[1] = 0xff00ff00; + colors[2] = 0xffff0000; + colors[3] = 0xff000000; + colors[4] = 0xffffff00; + colors[5] = 0xffff00ff; + colors[6] = 0xff00ffff; + colors[7] = 0xffffffff; + return IWICPalette_InitializeCustom(palette, colors, 8); + } + + /* unique error marker */ + return 0xdeadbeef; } static HRESULT WINAPI BitmapTestSrc_CopyPixels(IWICBitmapSource *iface, @@ -206,184 +233,281 @@ static void DeleteTestBitmap(BitmapTestSrc *This) HeapFree(GetProcessHeap(), 0, This); } -/* XP and 2003 use linear color conversion, later versions use sRGB gamma */ -static const float bits_32bppGrayFloat_xp[] = { - 0.114000f,0.587000f,0.299000f,0.000000f, - 0.886000f,0.413000f,0.701000f,1.000000f}; -static const BYTE bits_8bppGray_xp[] = { - 29,150,76,0, - 226,105,179,255}; - -static void compare_bitmap_data(const struct bitmap_data *expect, IWICBitmapSource *source, const char *name) +static BOOL compare_bits(const struct bitmap_data *expect, UINT buffersize, const BYTE *converted_bits) { - BYTE *converted_bits; - UINT width, height; - double xres, yres; - WICRect prc; - UINT stride, buffersize; - GUID dst_pixelformat; - HRESULT hr; - - hr = IWICBitmapSource_GetSize(source, &width, &height); - ok(SUCCEEDED(hr), "GetSize(%s) failed, hr=%x\n", name, hr); - ok(width == expect->width, "expecting %u, got %u (%s)\n", expect->width, width, name); - ok(height == expect->height, "expecting %u, got %u (%s)\n", expect->height, height, name); - - hr = IWICBitmapSource_GetResolution(source, &xres, &yres); - ok(SUCCEEDED(hr), "GetResolution(%s) failed, hr=%x\n", name, hr); - ok(fabs(xres - expect->xres) < 0.02, "expecting %0.2f, got %0.2f (%s)\n", expect->xres, xres, name); - ok(fabs(yres - expect->yres) < 0.02, "expecting %0.2f, got %0.2f (%s)\n", expect->yres, yres, name); - - hr = IWICBitmapSource_GetPixelFormat(source, &dst_pixelformat); - ok(SUCCEEDED(hr), "GetPixelFormat(%s) failed, hr=%x\n", name, hr); - ok(IsEqualGUID(&dst_pixelformat, expect->format), "got unexpected pixel format (%s)\n", name); - - prc.X = 0; - prc.Y = 0; - prc.Width = expect->width; - prc.Height = expect->height; - - stride = (expect->bpp * expect->width + 7) / 8; - buffersize = stride * expect->height; + BOOL equal; - converted_bits = HeapAlloc(GetProcessHeap(), 0, buffersize); - hr = IWICBitmapSource_CopyPixels(source, &prc, stride, buffersize, converted_bits); - ok(SUCCEEDED(hr), "CopyPixels(%s) failed, hr=%x\n", name, hr); if (IsEqualGUID(expect->format, &GUID_WICPixelFormat32bppBGR)) { /* ignore the padding byte when comparing data */ UINT i; - BOOL equal=TRUE; const DWORD *a=(const DWORD*)expect->bits, *b=(const DWORD*)converted_bits; + equal=TRUE; for (i=0; i<(buffersize/4); i++) if ((a[i]&0xffffff) != (b[i]&0xffffff)) { equal = FALSE; break; } - ok(equal, "unexpected pixel data (%s)\n", name); } else if (IsEqualGUID(expect->format, &GUID_WICPixelFormat32bppGrayFloat)) { - BOOL equal=TRUE; UINT i; const float *a=(const float*)expect->bits, *b=(const float*)converted_bits; + equal=TRUE; for (i=0; i<(buffersize/4); i++) - if (!near_equal(a[i], b[i]) && !near_equal(bits_32bppGrayFloat_xp[i], b[i])) + if (!near_equal(a[i], b[i])) { equal = FALSE; break; } - - ok(equal, "unexpected pixel data (%s)\n", name); } - else if (IsEqualGUID(expect->format, &GUID_WICPixelFormat8bppGray)) + else if (IsEqualGUID(expect->format, &GUID_WICPixelFormatBlackWhite) || + IsEqualGUID(expect->format, &GUID_WICPixelFormat1bppIndexed)) { UINT i; - BOOL equal=TRUE; const BYTE *a=(const BYTE*)expect->bits, *b=(const BYTE*)converted_bits; + equal=TRUE; for (i=0; ibits, converted_bits, buffersize) == 0, "unexpected pixel data (%s)\n", name); - - /* Test with NULL rectangle - should copy the whole bitmap */ - hr = IWICBitmapSource_CopyPixels(source, NULL, stride, buffersize, converted_bits); - ok(SUCCEEDED(hr), "CopyPixels(%s,rc=NULL) failed, hr=%x\n", name, hr); - if (IsEqualGUID(expect->format, &GUID_WICPixelFormat32bppBGR)) + else if (IsEqualGUID(expect->format, &GUID_WICPixelFormat2bppIndexed) || + IsEqualGUID(expect->format, &GUID_WICPixelFormat4bppIndexed) || + IsEqualGUID(expect->format, &GUID_WICPixelFormat8bppIndexed)) { - /* ignore the padding byte when comparing data */ UINT i; - BOOL equal=TRUE; - const DWORD *a=(const DWORD*)expect->bits, *b=(const DWORD*)converted_bits; - for (i=0; i<(buffersize/4); i++) - if ((a[i]&0xffffff) != (b[i]&0xffffff)) - { - equal = FALSE; - break; - } - ok(equal, "unexpected pixel data with rc=NULL (%s)\n", name); - } - else if (IsEqualGUID(expect->format, &GUID_WICPixelFormat32bppGrayFloat)) - { - BOOL equal=TRUE; - UINT i; - const float *a=(const float*)expect->bits, *b=(const float*)converted_bits; - for (i=0; i<(buffersize/4); i++) - if (!near_equal(a[i], b[i]) && !near_equal(bits_32bppGrayFloat_xp[i], b[i])) - { - equal = FALSE; - break; - } - - ok(equal, "unexpected pixel data (%s)\n", name); - } - else if (IsEqualGUID(expect->format, &GUID_WICPixelFormat8bppGray)) - { - UINT i; - BOOL equal=TRUE; const BYTE *a=(const BYTE*)expect->bits, *b=(const BYTE*)converted_bits; + equal=TRUE; + for (i=0; ibits, converted_bits, buffersize) == 0, "unexpected pixel data with rc=NULL (%s)\n", name); + equal = (memcmp(expect->bits, converted_bits, buffersize) == 0); + + if (!equal && expect->alt_data) + equal = compare_bits(expect->alt_data, buffersize, converted_bits); + + return equal; +} + +static BOOL is_indexed_format(const GUID *format) +{ + if (IsEqualGUID(format, &GUID_WICPixelFormat1bppIndexed) || + IsEqualGUID(format, &GUID_WICPixelFormat2bppIndexed) || + IsEqualGUID(format, &GUID_WICPixelFormat4bppIndexed) || + IsEqualGUID(format, &GUID_WICPixelFormat8bppIndexed)) + return TRUE; + + return FALSE; +} + +static void compare_bitmap_data(const struct bitmap_data *src, const struct bitmap_data *expect, + IWICBitmapSource *source, const char *name) +{ + BYTE *converted_bits; + UINT width, height; + double xres, yres; + WICRect prc; + UINT stride, buffersize; + GUID dst_pixelformat; + HRESULT hr; + + hr = IWICBitmapSource_GetSize(source, &width, &height); + ok(SUCCEEDED(hr), "GetSize(%s) failed, hr=%x\n", name, hr); + ok(width == expect->width, "expecting %u, got %u (%s)\n", expect->width, width, name); + ok(height == expect->height, "expecting %u, got %u (%s)\n", expect->height, height, name); + + hr = IWICBitmapSource_GetResolution(source, &xres, &yres); + ok(SUCCEEDED(hr), "GetResolution(%s) failed, hr=%x\n", name, hr); + ok(fabs(xres - expect->xres) < 0.02, "expecting %0.2f, got %0.2f (%s)\n", expect->xres, xres, name); + ok(fabs(yres - expect->yres) < 0.02, "expecting %0.2f, got %0.2f (%s)\n", expect->yres, yres, name); + + hr = IWICBitmapSource_GetPixelFormat(source, &dst_pixelformat); + ok(SUCCEEDED(hr), "GetPixelFormat(%s) failed, hr=%x\n", name, hr); + ok(IsEqualGUID(&dst_pixelformat, expect->format), "got unexpected pixel format %s (%s)\n", wine_dbgstr_guid(&dst_pixelformat), name); + + prc.X = 0; + prc.Y = 0; + prc.Width = expect->width; + prc.Height = expect->height; + + stride = (expect->bpp * expect->width + 7) / 8; + buffersize = stride * expect->height; + + converted_bits = HeapAlloc(GetProcessHeap(), 0, buffersize); + memset(converted_bits, 0xaa, buffersize); + hr = IWICBitmapSource_CopyPixels(source, &prc, stride, buffersize, converted_bits); + ok(SUCCEEDED(hr), "CopyPixels(%s) failed, hr=%x\n", name, hr); + + /* The result of conversion of color to indexed formats depends on + * optimized palette generation implementation. We either need to + * assign our own palette, or just skip the comparison. + */ + if (!(!is_indexed_format(src->format) && is_indexed_format(expect->format))) + ok(compare_bits(expect, buffersize, converted_bits), "unexpected pixel data (%s)\n", name); + + /* Test with NULL rectangle - should copy the whole bitmap */ + memset(converted_bits, 0xaa, buffersize); + hr = IWICBitmapSource_CopyPixels(source, NULL, stride, buffersize, converted_bits); + ok(SUCCEEDED(hr), "CopyPixels(%s,rc=NULL) failed, hr=%x\n", name, hr); + /* see comment above */ + if (!(!is_indexed_format(src->format) && is_indexed_format(expect->format))) + ok(compare_bits(expect, buffersize, converted_bits), "unexpected pixel data (%s)\n", name); HeapFree(GetProcessHeap(), 0, converted_bits); } +/* some encoders (like BMP) require data to be 4-bytes aligned */ +static const BYTE bits_1bpp[] = { + 0x55,0x55,0x55,0x55, /*01010101*/ + 0xaa,0xaa,0xaa,0xaa}; /*10101010*/ +static const struct bitmap_data testdata_BlackWhite = { + &GUID_WICPixelFormatBlackWhite, 1, bits_1bpp, 32, 2, 96.0, 96.0}; +static const struct bitmap_data testdata_1bppIndexed = { + &GUID_WICPixelFormat1bppIndexed, 1, bits_1bpp, 32, 2, 96.0, 96.0}; + +/* some encoders (like BMP) require data to be 4-bytes aligned */ +static const BYTE bits_2bpp[] = { + 0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb, + 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24}; +static const struct bitmap_data testdata_2bppIndexed = { + &GUID_WICPixelFormat2bppIndexed, 2, bits_2bpp, 32, 2, 96.0, 96.0}; + +/* some encoders (like BMP) require data to be 4-bytes aligned */ +static const BYTE bits_4bpp[] = { + 0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23, + 0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67}; + +static const struct bitmap_data testdata_4bppIndexed = { + &GUID_WICPixelFormat4bppIndexed, 4, bits_4bpp, 32, 2, 96.0, 96.0}; + +static const BYTE bits_8bpp_BW[] = { + 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, + 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}; +static const struct bitmap_data testdata_8bppIndexed_BW = { + &GUID_WICPixelFormat8bppIndexed, 8, bits_8bpp_BW, 32, 2, 96.0, 96.0}; + +static const BYTE bits_8bpp_4colors[] = { + 0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0,0,1,2,0, + 3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3,3,2,1,3}; +static const struct bitmap_data testdata_8bppIndexed_4colors = { + &GUID_WICPixelFormat8bppIndexed, 8, bits_8bpp_4colors, 32, 2, 96.0, 96.0}; + +static const BYTE bits_8bpp[] = { + 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3, + 4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7}; +static const struct bitmap_data testdata_8bppIndexed = { + &GUID_WICPixelFormat8bppIndexed, 8, bits_8bpp, 32, 2, 96.0, 96.0}; + static const BYTE bits_24bppBGR[] = { - 255,0,0, 0,255,0, 0,0,255, 0,0,0, - 0,255,255, 255,0,255, 255,255,0, 255,255,255}; + 255,0,0, 0,255,0, 0,0,255, 0,0,0, 255,0,0, 0,255,0, 0,0,255, 0,0,0, + 255,0,0, 0,255,0, 0,0,255, 0,0,0, 255,0,0, 0,255,0, 0,0,255, 0,0,0, + 255,0,0, 0,255,0, 0,0,255, 0,0,0, 255,0,0, 0,255,0, 0,0,255, 0,0,0, + 255,0,0, 0,255,0, 0,0,255, 0,0,0, 255,0,0, 0,255,0, 0,0,255, 0,0,0, + 0,255,255, 255,0,255, 255,255,0, 255,255,255, 0,255,255, 255,0,255, 255,255,0, 255,255,255, + 0,255,255, 255,0,255, 255,255,0, 255,255,255, 0,255,255, 255,0,255, 255,255,0, 255,255,255, + 0,255,255, 255,0,255, 255,255,0, 255,255,255, 0,255,255, 255,0,255, 255,255,0, 255,255,255, + 0,255,255, 255,0,255, 255,255,0, 255,255,255, 0,255,255, 255,0,255, 255,255,0, 255,255,255}; static const struct bitmap_data testdata_24bppBGR = { - &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR, 4, 2, 96.0, 96.0}; + &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR, 32, 2, 96.0, 96.0}; static const BYTE bits_24bppRGB[] = { - 0,0,255, 0,255,0, 255,0,0, 0,0,0, - 255,255,0, 255,0,255, 0,255,255, 255,255,255}; + 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, + 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, + 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, + 0,0,255, 0,255,0, 255,0,0, 0,0,0, 0,0,255, 0,255,0, 255,0,0, 0,0,0, + 255,255,0, 255,0,255, 0,255,255, 255,255,255, 255,255,0, 255,0,255, 0,255,255, 255,255,255, + 255,255,0, 255,0,255, 0,255,255, 255,255,255, 255,255,0, 255,0,255, 0,255,255, 255,255,255, + 255,255,0, 255,0,255, 0,255,255, 255,255,255, 255,255,0, 255,0,255, 0,255,255, 255,255,255, + 255,255,0, 255,0,255, 0,255,255, 255,255,255, 255,255,0, 255,0,255, 0,255,255, 255,255,255 }; static const struct bitmap_data testdata_24bppRGB = { - &GUID_WICPixelFormat24bppRGB, 24, bits_24bppRGB, 4, 2, 96.0, 96.0}; + &GUID_WICPixelFormat24bppRGB, 24, bits_24bppRGB, 32, 2, 96.0, 96.0}; static const BYTE bits_32bppBGR[] = { - 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, - 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80}; + 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, + 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, + 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, + 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, 255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80, + 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, + 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, + 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, + 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80, 0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80}; static const struct bitmap_data testdata_32bppBGR = { - &GUID_WICPixelFormat32bppBGR, 32, bits_32bppBGR, 4, 2, 96.0, 96.0}; + &GUID_WICPixelFormat32bppBGR, 32, bits_32bppBGR, 32, 2, 96.0, 96.0}; static const BYTE bits_32bppBGRA[] = { - 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, - 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255}; + 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, + 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, + 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, + 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, 255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255, + 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, + 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, + 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, + 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255, 0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255}; static const struct bitmap_data testdata_32bppBGRA = { - &GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGRA, 4, 2, 96.0, 96.0}; + &GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGRA, 32, 2, 96.0, 96.0}; + +/* XP and 2003 use linear color conversion, later versions use sRGB gamma */ +static const float bits_32bppGrayFloat_xp[] = { + 0.114000f,0.587000f,0.299000f,0.000000f,0.114000f,0.587000f,0.299000f,0.000000f, + 0.114000f,0.587000f,0.299000f,0.000000f,0.114000f,0.587000f,0.299000f,0.000000f, + 0.114000f,0.587000f,0.299000f,0.000000f,0.114000f,0.587000f,0.299000f,0.000000f, + 0.114000f,0.587000f,0.299000f,0.000000f,0.114000f,0.587000f,0.299000f,0.000000f, + 0.886000f,0.413000f,0.701000f,1.000000f,0.886000f,0.413000f,0.701000f,1.000000f, + 0.886000f,0.413000f,0.701000f,1.000000f,0.886000f,0.413000f,0.701000f,1.000000f, + 0.886000f,0.413000f,0.701000f,1.000000f,0.886000f,0.413000f,0.701000f,1.000000f, + 0.886000f,0.413000f,0.701000f,1.000000f,0.886000f,0.413000f,0.701000f,1.000000f}; +static const struct bitmap_data testdata_32bppGrayFloat_xp = { + &GUID_WICPixelFormat32bppGrayFloat, 32, (const BYTE *)bits_32bppGrayFloat_xp, 32, 2, 96.0, 96.0}; static const float bits_32bppGrayFloat[] = { - 0.072200f,0.715200f,0.212600f,0.000000f, - 0.927800f,0.284800f,0.787400f,1.000000f}; + 0.072200f,0.715200f,0.212600f,0.000000f,0.072200f,0.715200f,0.212600f,0.000000f, + 0.072200f,0.715200f,0.212600f,0.000000f,0.072200f,0.715200f,0.212600f,0.000000f, + 0.072200f,0.715200f,0.212600f,0.000000f,0.072200f,0.715200f,0.212600f,0.000000f, + 0.072200f,0.715200f,0.212600f,0.000000f,0.072200f,0.715200f,0.212600f,0.000000f, + 0.927800f,0.284800f,0.787400f,1.000000f,0.927800f,0.284800f,0.787400f,1.000000f, + 0.927800f,0.284800f,0.787400f,1.000000f,0.927800f,0.284800f,0.787400f,1.000000f, + 0.927800f,0.284800f,0.787400f,1.000000f,0.927800f,0.284800f,0.787400f,1.000000f, + 0.927800f,0.284800f,0.787400f,1.000000f,0.927800f,0.284800f,0.787400f,1.000000f}; static const struct bitmap_data testdata_32bppGrayFloat = { - &GUID_WICPixelFormat32bppGrayFloat, 32, (const BYTE *)bits_32bppGrayFloat, 4, 2, 96.0, 96.0}; + &GUID_WICPixelFormat32bppGrayFloat, 32, (const BYTE *)bits_32bppGrayFloat, 32, 2, 96.0, 96.0, &testdata_32bppGrayFloat_xp}; + +static const BYTE bits_8bppGray_xp[] = { + 29,150,76,0,29,150,76,0,29,150,76,0,29,150,76,0, + 29,150,76,0,29,150,76,0,29,150,76,0,29,150,76,0, + 226,105,179,255,226,105,179,255,226,105,179,255,226,105,179,255, + 226,105,179,255,226,105,179,255,226,105,179,255,226,105,179,255}; +static const struct bitmap_data testdata_8bppGray_xp = { + &GUID_WICPixelFormat8bppGray, 8, bits_8bppGray_xp, 32, 2, 96.0, 96.0}; static const BYTE bits_8bppGray[] = { - 76,220,127,0, - 247,145,230,255}; + 76,220,127,0,76,220,127,0,76,220,127,0,76,220,127,0, + 76,220,127,0,76,220,127,0,76,220,127,0,76,220,127,0, + 247,145,230,255,247,145,230,255,247,145,230,255,247,145,230,255, + 247,145,230,255,247,145,230,255,247,145,230,255,247,145,230,255}; static const struct bitmap_data testdata_8bppGray = { - &GUID_WICPixelFormat8bppGray, 8, bits_8bppGray, 4, 2, 96.0, 96.0}; + &GUID_WICPixelFormat8bppGray, 8, bits_8bppGray, 32, 2, 96.0, 96.0, &testdata_8bppGray_xp}; static const BYTE bits_24bppBGR_gray[] = { - 76,76,76, 220,220,220, 127,127,127, 0,0,0, - 247,247,247, 145,145,145, 230,230,230, 255,255,255}; + 76,76,76, 220,220,220, 127,127,127, 0,0,0, 76,76,76, 220,220,220, 127,127,127, 0,0,0, + 76,76,76, 220,220,220, 127,127,127, 0,0,0, 76,76,76, 220,220,220, 127,127,127, 0,0,0, + 76,76,76, 220,220,220, 127,127,127, 0,0,0, 76,76,76, 220,220,220, 127,127,127, 0,0,0, + 76,76,76, 220,220,220, 127,127,127, 0,0,0, 76,76,76, 220,220,220, 127,127,127, 0,0,0, + 247,247,247, 145,145,145, 230,230,230, 255,255,255, 247,247,247, 145,145,145, 230,230,230, 255,255,255, + 247,247,247, 145,145,145, 230,230,230, 255,255,255, 247,247,247, 145,145,145, 230,230,230, 255,255,255, + 247,247,247, 145,145,145, 230,230,230, 255,255,255, 247,247,247, 145,145,145, 230,230,230, 255,255,255, + 247,247,247, 145,145,145, 230,230,230, 255,255,255, 247,247,247, 145,145,145, 230,230,230, 255,255,255}; static const struct bitmap_data testdata_24bppBGR_gray = { - &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR_gray, 4, 2, 96.0, 96.0}; + &GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR_gray, 32, 2, 96.0, 96.0}; static void test_conversion(const struct bitmap_data *src, const struct bitmap_data *dst, const char *name, BOOL todo) { @@ -395,11 +519,12 @@ static void test_conversion(const struct bitmap_data *src, const struct bitmap_d hr = WICConvertBitmapSource(dst->format, &src_obj->IWICBitmapSource_iface, &dst_bitmap); todo_wine_if (todo) - ok(SUCCEEDED(hr), "WICConvertBitmapSource(%s) failed, hr=%x\n", name, hr); + ok(hr == S_OK || + broken(hr == E_INVALIDARG) /* XP */, "WICConvertBitmapSource(%s) failed, hr=%x\n", name, hr); - if (SUCCEEDED(hr)) + if (hr == S_OK) { - compare_bitmap_data(dst, dst_bitmap, name); + compare_bitmap_data(src, dst, dst_bitmap, name); IWICBitmapSource_Release(dst_bitmap); } @@ -447,7 +572,7 @@ static void test_default_converter(void) ok(SUCCEEDED(hr), "Initialize returned %x\n", hr); if (SUCCEEDED(hr)) - compare_bitmap_data(&testdata_32bppBGR, (IWICBitmapSource*)converter, "default converter"); + compare_bitmap_data(&testdata_32bppBGRA, &testdata_32bppBGR, (IWICBitmapSource*)converter, "default converter"); IWICFormatConverter_Release(converter); } @@ -597,6 +722,394 @@ static void test_encoder_properties(const CLSID* clsid_encoder, IPropertyBag2 *o } } +static void load_stream(IUnknown *reader, IStream *stream) +{ + HRESULT hr; + IWICPersistStream *persist; +#ifdef WORDS_BIGENDIAN + DWORD persist_options = WICPersistOptionsBigEndian; +#else + DWORD persist_options = WICPersistOptionsLittleEndian; +#endif + + hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist); + ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr); + + hr = IWICPersistStream_LoadEx(persist, stream, NULL, persist_options); + ok(hr == S_OK, "LoadEx failed, hr=%x\n", hr); + + IWICPersistStream_Release(persist); +} + +static void check_tiff_format(IStream *stream, const WICPixelFormatGUID *format) +{ + HRESULT hr; + IWICMetadataReader *reader; + PROPVARIANT id, value; + struct + { + USHORT byte_order; + USHORT version; + ULONG dir_offset; + } tiff; + LARGE_INTEGER pos; + UINT count, i; + int width, height, bps, photo, samples, colormap; + struct + { + int id, *value; + } tag[] = + { + { 0x100, &width }, { 0x101, &height }, { 0x102, &bps }, + { 0x106, &photo }, { 0x115, &samples }, { 0x140, &colormap } + }; + + memset(&tiff, 0, sizeof(tiff)); + hr = IStream_Read(stream, &tiff, sizeof(tiff), NULL); + ok(hr == S_OK, "IStream_Read error %#x\n", hr); + ok(tiff.byte_order == MAKEWORD('I','I') || tiff.byte_order == MAKEWORD('M','M'), + "wrong TIFF byte order mark %02x\n", tiff.byte_order); + ok(tiff.version == 42, "wrong TIFF version %u\n", tiff.version); + + pos.QuadPart = tiff.dir_offset; + hr = IStream_Seek(stream, pos, SEEK_SET, NULL); + ok(hr == S_OK, "IStream_Seek error %#x\n", hr); + + hr = CoCreateInstance(&CLSID_WICIfdMetadataReader, NULL, CLSCTX_INPROC_SERVER, + &IID_IWICMetadataReader, (void **)&reader); + ok(hr == S_OK, "CoCreateInstance error %#x\n", hr); + + load_stream((IUnknown *)reader, stream); + + hr = IWICMetadataReader_GetCount(reader, &count); + ok(hr == S_OK, "GetCount error %#x\n", hr); + ok(count != 0, "wrong count %u\n", count); + + for (i = 0; i < sizeof(tag)/sizeof(tag[0]); i++) + { + PropVariantInit(&id); + PropVariantInit(&value); + + id.vt = VT_UI2; + U(id).uiVal = tag[i].id; + hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value); + ok(hr == S_OK || (tag[i].id == 0x140 && hr == WINCODEC_ERR_PROPERTYNOTFOUND), + "GetValue(%04x) error %#x\n", tag[i].id, hr); + if (hr == S_OK) + { + ok(value.vt == VT_UI2 || value.vt == VT_UI4 || value.vt == (VT_UI2 | VT_VECTOR), "wrong vt: %d\n", value.vt); + tag[i].value[0] = U(value).uiVal; + } + else + tag[i].value[0] = -1; + } + + IWICMetadataReader_Release(reader); + + if (IsEqualGUID(format, &GUID_WICPixelFormatBlackWhite)) + { + ok(width == 32, "wrong width %u\n", width); + ok(height == 2, "wrong height %u\n", height); + + ok(bps == 1, "wrong bps %d\n", bps); + ok(photo == 1, "wrong photometric %d\n", photo); + ok(samples == 1, "wrong samples %d\n", samples); + ok(colormap == -1, "wrong colormap %d\n", colormap); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat1bppIndexed)) + { + ok(width == 32, "wrong width %u\n", width); + ok(height == 2, "wrong height %u\n", height); + + ok(bps == 1, "wrong bps %d\n", bps); + ok(photo == 3, "wrong photometric %d\n", photo); + ok(samples == 1, "wrong samples %d\n", samples); + ok(colormap == 6, "wrong colormap %d\n", colormap); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat2bppIndexed)) + { + ok(width == 32, "wrong width %u\n", width); + ok(height == 2, "wrong height %u\n", height); + + ok(bps == 2, "wrong bps %d\n", bps); + ok(photo == 3, "wrong photometric %d\n", photo); + ok(samples == 1, "wrong samples %d\n", samples); + ok(colormap == 12, "wrong colormap %d\n", colormap); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat4bppIndexed)) + { + ok(width == 32, "wrong width %u\n", width); + ok(height == 2, "wrong height %u\n", height); + + ok(bps == 4, "wrong bps %d\n", bps); + ok(photo == 3, "wrong photometric %d\n", photo); + ok(samples == 1, "wrong samples %d\n", samples); + ok(colormap == 48, "wrong colormap %d\n", colormap); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat8bppIndexed)) + { + ok(width == 32, "wrong width %u\n", width); + ok(height == 2, "wrong height %u\n", height); + + ok(bps == 8, "wrong bps %d\n", bps); + ok(photo == 3, "wrong photometric %d\n", photo); + ok(samples == 1, "wrong samples %d\n", samples); + ok(colormap == 768, "wrong colormap %d\n", colormap); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat24bppBGR)) + { + ok(width == 32, "wrong width %u\n", width); + ok(height == 2, "wrong height %u\n", height); + + ok(bps == 3, "wrong bps %d\n", bps); + ok(photo == 2, "wrong photometric %d\n", photo); + ok(samples == 3, "wrong samples %d\n", samples); + ok(colormap == -1, "wrong colormap %d\n", colormap); + } + else + ok(0, "unknown TIFF pixel format %s\n", wine_dbgstr_guid(format)); +} + +static void check_bmp_format(IStream *stream, const WICPixelFormatGUID *format) +{ + HRESULT hr; + BITMAPFILEHEADER bfh; + BITMAPV5HEADER bih; + + hr = IStream_Read(stream, &bfh, sizeof(bfh), NULL); + ok(hr == S_OK, "IStream_Read error %#x\n", hr); + + ok(bfh.bfType == 0x4d42, "wrong BMP signature %02x\n", bfh.bfType); + ok(bfh.bfReserved1 == 0, "wrong bfReserved1 %02x\n", bfh.bfReserved1); + ok(bfh.bfReserved2 == 0, "wrong bfReserved2 %02x\n", bfh.bfReserved2); + + hr = IStream_Read(stream, &bih, sizeof(bih), NULL); + ok(hr == S_OK, "IStream_Read error %#x\n", hr); + + if (IsEqualGUID(format, &GUID_WICPixelFormat1bppIndexed)) + { + ok(bfh.bfOffBits == 0x0436, "wrong bfOffBits %08x\n", bfh.bfOffBits); + + ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); + ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); + + ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); + ok(bih.bV5BitCount == 1, "wrong BitCount %d\n", bih.bV5BitCount); + ok(bih.bV5ClrUsed == 256, "wrong ClrUsed %d\n", bih.bV5ClrUsed); + ok(bih.bV5ClrImportant == 256, "wrong ClrImportant %d\n", bih.bV5ClrImportant); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat2bppIndexed)) + { + ok(bfh.bfOffBits == 0x0436, "wrong bfOffBits %08x\n", bfh.bfOffBits); + + ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); + ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); + + ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); + ok(bih.bV5BitCount == 2, "wrong BitCount %d\n", bih.bV5BitCount); + ok(bih.bV5ClrUsed == 256, "wrong ClrUsed %d\n", bih.bV5ClrUsed); + ok(bih.bV5ClrImportant == 256, "wrong ClrImportant %d\n", bih.bV5ClrImportant); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat4bppIndexed)) + { + ok(bfh.bfOffBits == 0x0436, "wrong bfOffBits %08x\n", bfh.bfOffBits); + + ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); + ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); + + ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); + ok(bih.bV5BitCount == 4, "wrong BitCount %d\n", bih.bV5BitCount); + ok(bih.bV5ClrUsed == 256, "wrong ClrUsed %d\n", bih.bV5ClrUsed); + ok(bih.bV5ClrImportant == 256, "wrong ClrImportant %d\n", bih.bV5ClrImportant); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat8bppIndexed)) + { + ok(bfh.bfOffBits == 0x0436, "wrong bfOffBits %08x\n", bfh.bfOffBits); + + ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); + ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); + + ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); + ok(bih.bV5BitCount == 8, "wrong BitCount %d\n", bih.bV5BitCount); + ok(bih.bV5ClrUsed == 256, "wrong ClrUsed %d\n", bih.bV5ClrUsed); + ok(bih.bV5ClrImportant == 256, "wrong ClrImportant %d\n", bih.bV5ClrImportant); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat32bppBGR)) + { + ok(bfh.bfOffBits == 0x0036, "wrong bfOffBits %08x\n", bfh.bfOffBits); + + ok(bih.bV5Width == 32, "wrong width %u\n", bih.bV5Width); + ok(bih.bV5Height == 2, "wrong height %u\n", bih.bV5Height); + + ok(bih.bV5Planes == 1, "wrong Planes %d\n", bih.bV5Planes); + ok(bih.bV5BitCount == 32, "wrong BitCount %d\n", bih.bV5BitCount); + ok(bih.bV5ClrUsed == 0, "wrong ClrUsed %d\n", bih.bV5ClrUsed); + ok(bih.bV5ClrImportant == 0, "wrong ClrImportant %d\n", bih.bV5ClrImportant); + } + else + ok(0, "unknown BMP pixel format %s\n", wine_dbgstr_guid(format)); +} + +static unsigned be_uint(unsigned val) +{ + union + { + unsigned val; + char c[4]; + } u; + + u.val = val; + return (u.c[0] << 24) | (u.c[1] << 16) | (u.c[2] << 8) | u.c[3]; +} + +static void check_png_format(IStream *stream, const WICPixelFormatGUID *format) +{ + static const char png_sig[8] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a}; + static const char png_IHDR[8] = {0,0,0,0x0d,'I','H','D','R'}; + HRESULT hr; + struct + { + char png_sig[8]; + char ihdr_sig[8]; + unsigned width, height; + char bit_depth, color_type, compression, filter, interlace; + } png; + + memset(&png, 0, sizeof(png)); + hr = IStream_Read(stream, &png, sizeof(png), NULL); + ok(hr == S_OK, "IStream_Read error %#x\n", hr); + + ok(!memcmp(png.png_sig, png_sig, sizeof(png_sig)), "expected PNG signature\n"); + ok(!memcmp(png.ihdr_sig, png_IHDR, sizeof(png_IHDR)), "expected PNG IHDR\n"); + + if (IsEqualGUID(format, &GUID_WICPixelFormatBlackWhite)) + { + ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); + ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); + + ok(png.bit_depth == 1, "wrong bit_depth %d\n", png.bit_depth); + ok(png.color_type == 0, "wrong color_type %d\n", png.color_type); + ok(png.compression == 0, "wrong compression %d\n", png.compression); + ok(png.filter == 0, "wrong filter %d\n", png.filter); + ok(png.interlace == 0, "wrong interlace %d\n", png.interlace); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat1bppIndexed)) + { + ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); + ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); + + ok(png.bit_depth == 1, "wrong bit_depth %d\n", png.bit_depth); + ok(png.color_type == 3, "wrong color_type %d\n", png.color_type); + ok(png.compression == 0, "wrong compression %d\n", png.compression); + ok(png.filter == 0, "wrong filter %d\n", png.filter); + ok(png.interlace == 0, "wrong interlace %d\n", png.interlace); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat2bppIndexed)) + { + ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); + ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); + + ok(png.bit_depth == 2, "wrong bit_depth %d\n", png.bit_depth); + ok(png.color_type == 3, "wrong color_type %d\n", png.color_type); + ok(png.compression == 0, "wrong compression %d\n", png.compression); + ok(png.filter == 0, "wrong filter %d\n", png.filter); + ok(png.interlace == 0, "wrong interlace %d\n", png.interlace); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat4bppIndexed)) + { + ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); + ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); + + ok(png.bit_depth == 4, "wrong bit_depth %d\n", png.bit_depth); + ok(png.color_type == 3, "wrong color_type %d\n", png.color_type); + ok(png.compression == 0, "wrong compression %d\n", png.compression); + ok(png.filter == 0, "wrong filter %d\n", png.filter); + ok(png.interlace == 0, "wrong interlace %d\n", png.interlace); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat8bppIndexed)) + { + ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); + ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); + + ok(png.bit_depth == 8, "wrong bit_depth %d\n", png.bit_depth); + ok(png.color_type == 3, "wrong color_type %d\n", png.color_type); + ok(png.compression == 0, "wrong compression %d\n", png.compression); + ok(png.filter == 0, "wrong filter %d\n", png.filter); + ok(png.interlace == 0, "wrong interlace %d\n", png.interlace); + } + else if (IsEqualGUID(format, &GUID_WICPixelFormat24bppBGR)) + { + ok(be_uint(png.width) == 32, "wrong width %u\n", be_uint(png.width)); + ok(be_uint(png.height) == 2, "wrong height %u\n", be_uint(png.height)); + + ok(png.bit_depth == 8, "wrong bit_depth %d\n", png.bit_depth); + ok(png.color_type == 2, "wrong color_type %d\n", png.color_type); + ok(png.compression == 0, "wrong compression %d\n", png.compression); + ok(png.filter == 0, "wrong filter %d\n", png.filter); + ok(png.interlace == 0 || png.interlace == 1, "wrong interlace %d\n", png.interlace); + } + else + ok(0, "unknown PNG pixel format %s\n", wine_dbgstr_guid(format)); +} + +static void check_gif_format(IStream *stream, const WICPixelFormatGUID *format) +{ +#include "pshpack1.h" + struct logical_screen_descriptor + { + char signature[6]; + USHORT width; + USHORT height; + BYTE packed; + /* global_color_table_flag : 1; + * color_resolution : 3; + * sort_flag : 1; + * global_color_table_size : 3; + */ + BYTE background_color_index; + BYTE pixel_aspect_ratio; + } lsd; +#include "poppack.h" + UINT color_resolution; + HRESULT hr; + + memset(&lsd, 0, sizeof(lsd)); + hr = IStream_Read(stream, &lsd, sizeof(lsd), NULL); + ok(hr == S_OK, "IStream_Read error %#x\n", hr); + + ok(!memcmp(lsd.signature, "GIF89a", 6), "wrong GIF signature %.6s\n", lsd.signature); + + ok(lsd.width == 32, "wrong width %u\n", lsd.width); + ok(lsd.height == 2, "wrong height %u\n", lsd.height); + color_resolution = 1 << (((lsd.packed >> 4) & 0x07) + 1); + ok(color_resolution == 256, "wrong color resolution %u\n", color_resolution); + ok(lsd.pixel_aspect_ratio == 0, "wrong pixel_aspect_ratio %u\n", lsd.pixel_aspect_ratio); +} + +static void check_bitmap_format(IStream *stream, const CLSID *encoder, const WICPixelFormatGUID *format) +{ + HRESULT hr; + LARGE_INTEGER pos; + + pos.QuadPart = 0; + hr = IStream_Seek(stream, pos, SEEK_SET, (ULARGE_INTEGER *)&pos); + ok(hr == S_OK, "IStream_Seek error %#x\n", hr); + + if (IsEqualGUID(encoder, &CLSID_WICPngEncoder)) + check_png_format(stream, format); + else if (IsEqualGUID(encoder, &CLSID_WICBmpEncoder)) + check_bmp_format(stream, format); + else if (IsEqualGUID(encoder, &CLSID_WICTiffEncoder)) + check_tiff_format(stream, format); + else if (IsEqualGUID(encoder, &CLSID_WICGifEncoder)) + check_gif_format(stream, format); + else + ok(0, "unknown encoder %s\n", wine_dbgstr_guid(encoder)); + + hr = IStream_Seek(stream, pos, SEEK_SET, NULL); + ok(hr == S_OK, "IStream_Seek error %#x\n", hr); +} + struct setting { const WCHAR *name; PROPBAG2_TYPE type; @@ -606,7 +1119,7 @@ struct setting { static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* clsid_encoder, const struct bitmap_data **dsts, const CLSID *clsid_decoder, WICRect *rc, - const struct setting *settings, const char *name) + const struct setting *settings, const char *name, IWICPalette *palette) { HRESULT hr; IWICBitmapEncoder *encoder; @@ -622,7 +1135,7 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls hr = CoCreateInstance(clsid_encoder, NULL, CLSCTX_INPROC_SERVER, &IID_IWICBitmapEncoder, (void**)&encoder); - ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr); + ok(SUCCEEDED(hr), "CoCreateInstance(%s) failed, hr=%x\n", wine_dbgstr_guid(clsid_encoder), hr); if (SUCCEEDED(hr)) { hglobal = GlobalAlloc(GMEM_MOVEABLE, 0); @@ -635,9 +1148,25 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls if (hglobal && SUCCEEDED(hr)) { + if (palette) + { + hr = IWICBitmapEncoder_SetPalette(encoder, palette); + ok(hr == WINCODEC_ERR_NOTINITIALIZED, "wrong error %#x (%s)\n", hr, name); + } + hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache); ok(SUCCEEDED(hr), "Initialize failed, hr=%x\n", hr); + if (palette) + { + hr = IWICBitmapEncoder_SetPalette(encoder, palette); + if (IsEqualGUID(clsid_encoder, &CLSID_WICGifEncoder)) + ok(hr == S_OK, "SetPalette failed, hr=%#x\n", hr); + else + ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "wrong error %#x\n", hr); + hr = S_OK; + } + i=0; while (SUCCEEDED(hr) && srcs[i]) { @@ -671,28 +1200,64 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls } } + if (palette) + { + hr = IWICBitmapFrameEncode_SetPalette(frameencode, palette); + ok(hr == WINCODEC_ERR_NOTINITIALIZED, "wrong error %#x\n", hr); + } + hr = IWICBitmapFrameEncode_Initialize(frameencode, options); ok(SUCCEEDED(hr), "Initialize failed, hr=%x\n", hr); memcpy(&pixelformat, srcs[i]->format, sizeof(GUID)); hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &pixelformat); ok(SUCCEEDED(hr), "SetPixelFormat failed, hr=%x\n", hr); - ok(IsEqualGUID(&pixelformat, srcs[i]->format), "SetPixelFormat changed the format\n"); + ok(IsEqualGUID(&pixelformat, dsts[i]->format) || + broken(IsEqualGUID(clsid_encoder, &CLSID_WICBmpEncoder) && srcs[i]->bpp == 2 && IsEqualGUID(&pixelformat, &GUID_WICPixelFormat4bppIndexed)) || + broken(IsEqualGUID(clsid_encoder, &CLSID_WICTiffEncoder) && srcs[i]->bpp == 2 && IsEqualGUID(&pixelformat, &GUID_WICPixelFormat4bppIndexed)), + "SetPixelFormat changed the format to %s (%s)\n", wine_dbgstr_guid(&pixelformat), name); hr = IWICBitmapFrameEncode_SetSize(frameencode, srcs[i]->width, srcs[i]->height); ok(SUCCEEDED(hr), "SetSize failed, hr=%x\n", hr); + if (palette) + { + WICColor colors[256]; + + hr = IWICBitmapFrameEncode_SetPalette(frameencode, palette); + ok(SUCCEEDED(hr), "SetPalette failed, hr=%x (%s)\n", hr, name); + + /* trash the assigned palette */ + memset(colors, 0, sizeof(colors)); + hr = IWICPalette_InitializeCustom(palette, colors, 256); + ok(hr == S_OK, "InitializeCustom error %#x\n", hr); + } + hr = IWICBitmapFrameEncode_WriteSource(frameencode, &src_obj->IWICBitmapSource_iface, rc); if (rc && (rc->Width <= 0 || rc->Height <= 0)) { /* WriteSource fails but WriteSource_Proxy succeeds. */ - ok(hr == E_INVALIDARG, "WriteSource failed, hr=%x (%s)\n", hr, name); + ok(hr == E_INVALIDARG, "WriteSource should fail, hr=%x (%s)\n", hr, name); hr = IWICBitmapFrameEncode_WriteSource_Proxy(frameencode, &src_obj->IWICBitmapSource_iface, rc); + ok(SUCCEEDED(hr), "WriteSource_Proxy failed, %dx%d, hr=%x (%s)\n", rc->Width, rc->Height, hr, name); + } + else + { + if (rc) + ok(SUCCEEDED(hr), "WriteSource(%dx%d) failed, hr=%x (%s)\n", rc->Width, rc->Height, hr, name); + else + ok(hr == S_OK || + broken(hr == E_INVALIDARG && IsEqualGUID(clsid_encoder, &CLSID_WICBmpEncoder) && srcs[i]->bpp == 2) /* XP */ || + broken(hr == E_INVALIDARG && IsEqualGUID(clsid_encoder, &CLSID_WICTiffEncoder) && srcs[i]->bpp == 2) /* XP */ || + broken(hr == E_INVALIDARG && IsEqualGUID(clsid_encoder, &CLSID_WICBmpEncoder) && IsEqualGUID(srcs[i]->format, &GUID_WICPixelFormatBlackWhite)) /* XP */, + "WriteSource(NULL) failed, hr=%x (%s)\n", hr, name); } - ok(SUCCEEDED(hr), "WriteSource failed, hr=%x (%s)\n", hr, name); - hr = IWICBitmapFrameEncode_Commit(frameencode); - ok(SUCCEEDED(hr), "Commit failed, hr=%x\n", hr); + if (SUCCEEDED(hr)) + { + hr = IWICBitmapFrameEncode_Commit(frameencode); + ok(SUCCEEDED(hr), "Commit failed, hr=%x (%s)\n", hr, name); + } IWICBitmapFrameEncode_Release(frameencode); IPropertyBag2_Release(options); @@ -707,6 +1272,9 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls { hr = IWICBitmapEncoder_Commit(encoder); ok(SUCCEEDED(hr), "Commit failed, hr=%x\n", hr); + + if (IsEqualGUID(&pixelformat, dsts[0]->format)) + check_bitmap_format(stream, clsid_encoder, dsts[0]->format); } if (SUCCEEDED(hr)) @@ -718,18 +1286,135 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls if (SUCCEEDED(hr)) { + IWICPalette *frame_palette; + + hr = IWICImagingFactory_CreatePalette(factory, &frame_palette); + ok(hr == S_OK, "CreatePalette error %#x\n", hr); + + hr = IWICBitmapDecoder_CopyPalette(decoder, frame_palette); + if (IsEqualGUID(clsid_decoder, &CLSID_WICGifDecoder)) + ok(hr == WINCODEC_ERR_WRONGSTATE, "wrong error %#x\n", hr); + else + ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "wrong error %#x\n", hr); + hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnDemand); ok(SUCCEEDED(hr), "Initialize failed, hr=%x\n", hr); + hr = IWICBitmapDecoder_CopyPalette(decoder, frame_palette); + if (IsEqualGUID(clsid_decoder, &CLSID_WICGifDecoder)) + ok(hr == S_OK || broken(hr == WINCODEC_ERR_FRAMEMISSING) /* XP */, "CopyPalette failed, hr=%#x\n", hr); + else + ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "wrong error %#x\n", hr); + + hr = S_OK; i=0; while (SUCCEEDED(hr) && dsts[i]) { hr = IWICBitmapDecoder_GetFrame(decoder, i, &framedecode); - ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr); + ok(SUCCEEDED(hr), "GetFrame failed, hr=%x (%s)\n", hr, name); if (SUCCEEDED(hr)) { - compare_bitmap_data(dsts[i], (IWICBitmapSource*)framedecode, name); + hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &pixelformat); + ok(hr == S_OK, "GetPixelFormat) failed, hr=%x (%s)\n", hr, name); + if (IsEqualGUID(&pixelformat, dsts[i]->format)) + compare_bitmap_data(srcs[i], dsts[i], (IWICBitmapSource*)framedecode, name); + + hr = IWICBitmapFrameDecode_CopyPalette(framedecode, frame_palette); + if (winetest_debug > 1) + trace("%s, bpp %d, %s, hr %#x\n", name, dsts[i]->bpp, wine_dbgstr_guid(dsts[i]->format), hr); + if (dsts[i]->bpp > 8 || IsEqualGUID(dsts[i]->format, &GUID_WICPixelFormatBlackWhite)) + ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "wrong error %#x\n", hr); + else + { + UINT count, ret; + WICColor colors[256]; + + ok(hr == S_OK, "CopyPalette error %#x (%s)\n", hr, name); + + count = 0; + hr = IWICPalette_GetColorCount(frame_palette, &count); + ok(hr == S_OK, "GetColorCount error %#x\n", hr); + + memset(colors, 0, sizeof(colors)); + ret = 0; + hr = IWICPalette_GetColors(frame_palette, count, colors, &ret); + ok(hr == S_OK, "GetColors error %#x\n", hr); + ok(ret == count, "expected %u, got %u\n", count, ret); + if (IsEqualGUID(clsid_decoder, &CLSID_WICPngDecoder)) + { + /* Newer libpng versions don't accept larger palettes than the declared + * bit depth, so we need to generate the palette of the correct length. + */ + ok(count == 256 || (dsts[i]->bpp == 1 && count == 2) || + (dsts[i]->bpp == 2 && count == 4) || (dsts[i]->bpp == 4 && count == 16), + "expected 256, got %u (%s)\n", count, name); + + ok(colors[0] == 0x11111111, "got %08x (%s)\n", colors[0], name); + ok(colors[1] == 0x22222222, "got %08x (%s)\n", colors[1], name); + if (count > 2) + { + ok(colors[2] == 0x33333333, "got %08x (%s)\n", colors[2], name); + ok(colors[3] == 0x44444444, "got %08x (%s)\n", colors[3], name); + if (count > 4) + { + ok(colors[4] == 0x55555555, "got %08x (%s)\n", colors[4], name); + ok(colors[5] == 0, "got %08x (%s)\n", colors[5], name); + } + } + } + else if (IsEqualGUID(clsid_decoder, &CLSID_WICBmpDecoder) || + IsEqualGUID(clsid_decoder, &CLSID_WICTiffDecoder) || + IsEqualGUID(clsid_decoder, &CLSID_WICGifDecoder)) + { + if (IsEqualGUID(&pixelformat, &GUID_WICPixelFormatBlackWhite) || + IsEqualGUID(&pixelformat, &GUID_WICPixelFormat8bppIndexed)) + { + ok(count == 256, "expected 256, got %u (%s)\n", count, name); + + ok(colors[0] == 0xff111111, "got %08x (%s)\n", colors[0], name); + ok(colors[1] == 0xff222222, "got %08x (%s)\n", colors[1], name); + ok(colors[2] == 0xff333333, "got %08x (%s)\n", colors[2], name); + ok(colors[3] == 0xff444444, "got %08x (%s)\n", colors[3], name); + ok(colors[4] == 0xff555555, "got %08x (%s)\n", colors[4], name); + ok(colors[5] == 0xff000000, "got %08x (%s)\n", colors[5], name); + } + else if (IsEqualGUID(&pixelformat, &GUID_WICPixelFormat2bppIndexed)) + { + ok(count == 4, "expected 4, got %u (%s)\n", count, name); + + ok(colors[0] == 0xff111111, "got %08x (%s)\n", colors[0], name); + ok(colors[1] == 0xff222222, "got %08x (%s)\n", colors[1], name); + ok(colors[2] == 0xff333333, "got %08x (%s)\n", colors[2], name); + ok(colors[3] == 0xff444444, "got %08x (%s)\n", colors[3], name); + } + else if (IsEqualGUID(&pixelformat, &GUID_WICPixelFormat4bppIndexed)) + { + ok(count == 16, "expected 16, got %u (%s)\n", count, name); + + ok(colors[0] == 0xff111111, "got %08x (%s)\n", colors[0], name); + ok(colors[1] == 0xff222222, "got %08x (%s)\n", colors[1], name); + ok(colors[2] == 0xff333333, "got %08x (%s)\n", colors[2], name); + ok(colors[3] == 0xff444444, "got %08x (%s)\n", colors[3], name); + ok(colors[4] == 0xff555555, "got %08x (%s)\n", colors[4], name); + ok(colors[5] == 0xff000000, "got %08x (%s)\n", colors[5], name); + } + else + { + ok(count == 2, "expected 2, got %u (%s)\n", count, name); + + ok(colors[0] == 0xff111111, "got %08x (%s)\n", colors[0], name); + ok(colors[1] == 0xff222222, "got %08x (%s)\n", colors[1], name); + } + } + else + { + ok(count == 2, "expected 2, got %u (%s)\n", count, name); + + ok(colors[0] == 0xff111111, "got %08x\n", colors[0]); + ok(colors[1] == 0xff222222, "got %08x\n", colors[1]); + } + } IWICBitmapFrameDecode_Release(framedecode); } @@ -737,6 +1422,7 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls i++; } + IWICPalette_Release(frame_palette); IWICBitmapDecoder_Release(decoder); } @@ -752,13 +1438,31 @@ static void test_encoder(const struct bitmap_data *src, const CLSID* clsid_encod { const struct bitmap_data *srcs[2]; const struct bitmap_data *dsts[2]; + WICColor colors[256]; + IWICPalette *palette; + HRESULT hr; + + hr = IWICImagingFactory_CreatePalette(factory, &palette); + ok(hr == S_OK, "CreatePalette error %#x\n", hr); + + memset(colors, 0, sizeof(colors)); + colors[0] = 0x11111111; + colors[1] = 0x22222222; + colors[2] = 0x33333333; + colors[3] = 0x44444444; + colors[4] = 0x55555555; + /* TIFF decoder fails to decode a 8bpp frame if palette has less than 256 colors */ + hr = IWICPalette_InitializeCustom(palette, colors, 256); + ok(hr == S_OK, "InitializeCustom error %#x\n", hr); srcs[0] = src; srcs[1] = NULL; dsts[0] = dst; dsts[1] = NULL; - test_multi_encoder(srcs, clsid_encoder, dsts, clsid_decoder, NULL, NULL, name); + test_multi_encoder(srcs, clsid_encoder, dsts, clsid_decoder, NULL, NULL, name, palette); + + IWICPalette_Release(palette); } static void test_encoder_rects(void) @@ -774,23 +1478,23 @@ static void test_encoder_rects(void) rc.X = 0; rc.Y = 0; - rc.Width = 4; + rc.Width = 32; rc.Height = 2; - test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects full"); + test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects full", NULL); rc.Width = 0; - test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects width=0"); + test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects width=0", NULL); rc.Width = -1; - test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects width=-1"); + test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects width=-1", NULL); - rc.Width = 4; + rc.Width = 32; rc.Height = 0; - test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects height=0"); + test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects height=0", NULL); rc.Height = -1; - test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects height=-1"); + test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, NULL, "test_encoder_rects height=-1", NULL); } static const struct bitmap_data *multiple_frames[3] = { @@ -807,10 +1511,185 @@ static const struct setting png_interlace_settings[] = { {NULL} }; +static void test_converter_8bppIndexed(void) +{ + HRESULT hr; + BitmapTestSrc *src_obj; + IWICFormatConverter *converter; + IWICPalette *palette; + UINT count, i; + BYTE buf[32 * 2 * 3]; /* enough to hold 32x2 24bppBGR data */ + + CreateTestBitmap(&testdata_24bppBGR, &src_obj); + + hr = IWICImagingFactory_CreatePalette(factory, &palette); + ok(hr == S_OK, "CreatePalette error %#x\n", hr); + count = 0xdeadbeef; + hr = IWICPalette_GetColorCount(palette, &count); + ok(hr == S_OK, "GetColorCount error %#x\n", hr); + ok(count == 0, "expected 0, got %u\n", count); + + /* NULL palette + Custom type*/ + hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); + ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); + hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, + &GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone, + NULL, 0.0, WICBitmapPaletteTypeCustom); + ok(hr == S_OK, "Initialize error %#x\n", hr); + hr = IWICFormatConverter_CopyPalette(converter, palette); + ok(hr == 0xdeadbeef, "unexpected error %#x\n", hr); + hr = IWICFormatConverter_CopyPixels(converter, NULL, 32 * 3, sizeof(buf), buf); + ok(hr == S_OK, "CopyPixels error %#x\n", hr); + IWICFormatConverter_Release(converter); + + /* NULL palette + Custom type*/ + hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); + ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); + hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, + &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, + NULL, 0.0, WICBitmapPaletteTypeCustom); + ok(hr == E_INVALIDARG, "unexpected error %#x\n", hr); + hr = IWICFormatConverter_CopyPalette(converter, palette); + ok(hr == WINCODEC_ERR_WRONGSTATE, "unexpected error %#x\n", hr); + hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); + ok(hr == WINCODEC_ERR_WRONGSTATE, "unexpected error %#x\n", hr); + IWICFormatConverter_Release(converter); + + /* empty palette + Custom type*/ + hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); + ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); + hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, + &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, + palette, 0.0, WICBitmapPaletteTypeCustom); + ok(hr == S_OK, "Initialize error %#x\n", hr); + hr = IWICFormatConverter_CopyPalette(converter, palette); + ok(hr == S_OK, "CopyPalette error %#x\n", hr); + count = 0xdeadbeef; + hr = IWICPalette_GetColorCount(palette, &count); + ok(hr == S_OK, "GetColorCount error %#x\n", hr); + ok(count == 0, "expected 0, got %u\n", count); + memset(buf, 0xaa, sizeof(buf)); + hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); + ok(hr == S_OK, "CopyPixels error %#x\n", hr); + count = 0; + for (i = 0; i < 32 * 2; i++) + if (buf[i] != 0) count++; + ok(count == 0, "expected 0\n"); + IWICFormatConverter_Release(converter); + + /* NULL palette + Predefined type*/ + hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); + ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); + hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, + &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, + NULL, 0.0, WICBitmapPaletteTypeFixedGray16); + ok(hr == S_OK, "Initialize error %#x\n", hr); + hr = IWICFormatConverter_CopyPalette(converter, palette); + ok(hr == S_OK, "CopyPalette error %#x\n", hr); + count = 0xdeadbeef; + hr = IWICPalette_GetColorCount(palette, &count); + ok(hr == S_OK, "GetColorCount error %#x\n", hr); + ok(count == 16, "expected 16, got %u\n", count); + hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); + ok(hr == S_OK, "CopyPixels error %#x\n", hr); + count = 0; + for (i = 0; i < 32 * 2; i++) + if (buf[i] != 0) count++; + ok(count != 0, "expected != 0\n"); + IWICFormatConverter_Release(converter); + + /* not empty palette + Predefined type*/ + hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); + ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); + hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, + &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, + palette, 0.0, WICBitmapPaletteTypeFixedHalftone64); + ok(hr == S_OK, "Initialize error %#x\n", hr); + hr = IWICFormatConverter_CopyPalette(converter, palette); + ok(hr == S_OK, "CopyPalette error %#x\n", hr); + count = 0xdeadbeef; + hr = IWICPalette_GetColorCount(palette, &count); + ok(hr == S_OK, "GetColorCount error %#x\n", hr); + ok(count == 16, "expected 16, got %u\n", count); + hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); + ok(hr == S_OK, "CopyPixels error %#x\n", hr); + count = 0; + for (i = 0; i < 32 * 2; i++) + if (buf[i] != 0) count++; + ok(count != 0, "expected != 0\n"); + IWICFormatConverter_Release(converter); + + /* not empty palette + MedianCut type*/ + hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); + ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); + hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, + &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, + palette, 0.0, WICBitmapPaletteTypeMedianCut); + ok(hr == S_OK, "Initialize error %#x\n", hr); + hr = IWICFormatConverter_CopyPalette(converter, palette); + ok(hr == S_OK, "CopyPalette error %#x\n", hr); + count = 0xdeadbeef; + hr = IWICPalette_GetColorCount(palette, &count); + ok(hr == S_OK, "GetColorCount error %#x\n", hr); + ok(count == 16, "expected 16, got %u\n", count); + hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); + ok(hr == S_OK, "CopyPixels error %#x\n", hr); + count = 0; + for (i = 0; i < 32 * 2; i++) + if (buf[i] != 0) count++; + ok(count != 0, "expected != 0\n"); + IWICFormatConverter_Release(converter); + + /* NULL palette + MedianCut type*/ + hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); + ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); + hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, + &GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, + NULL, 0.0, WICBitmapPaletteTypeMedianCut); + ok(hr == S_OK || broken(hr == E_INVALIDARG) /* XP */, "Initialize error %#x\n", hr); + if (hr == S_OK) + { + hr = IWICFormatConverter_CopyPalette(converter, palette); + ok(hr == S_OK, "CopyPalette error %#x\n", hr); + count = 0xdeadbeef; + hr = IWICPalette_GetColorCount(palette, &count); + ok(hr == S_OK, "GetColorCount error %#x\n", hr); + ok(count == 8, "expected 8, got %u\n", count); + hr = IWICFormatConverter_CopyPixels(converter, NULL, 32, sizeof(buf), buf); + ok(hr == S_OK, "CopyPixels error %#x\n", hr); + count = 0; + for (i = 0; i < 32 * 2; i++) + if (buf[i] != 0) count++; + ok(count != 0, "expected != 0\n"); + } + IWICFormatConverter_Release(converter); + + IWICPalette_Release(palette); + DeleteTestBitmap(src_obj); +} + START_TEST(converter) { + HRESULT hr; + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, + &IID_IWICImagingFactory, (void **)&factory); + ok(hr == S_OK, "failed to create factory: %#x\n", hr); + + test_converter_8bppIndexed(); + + test_conversion(&testdata_24bppRGB, &testdata_2bppIndexed, "24bppRGB -> 1bppIndexed", TRUE); + test_conversion(&testdata_24bppRGB, &testdata_2bppIndexed, "24bppRGB -> 2bppIndexed", TRUE); + test_conversion(&testdata_24bppRGB, &testdata_4bppIndexed, "24bppRGB -> 4bppIndexed", TRUE); + test_conversion(&testdata_24bppRGB, &testdata_8bppIndexed, "24bppRGB -> 8bppIndexed", FALSE); + + test_conversion(&testdata_BlackWhite, &testdata_8bppIndexed_BW, "BlackWhite -> 8bppIndexed", TRUE); + test_conversion(&testdata_1bppIndexed, &testdata_8bppIndexed_BW, "1bppIndexed -> 8bppIndexed", TRUE); + test_conversion(&testdata_2bppIndexed, &testdata_8bppIndexed_4colors, "2bppIndexed -> 8bppIndexed", TRUE); + test_conversion(&testdata_4bppIndexed, &testdata_8bppIndexed, "4bppIndexed -> 8bppIndexed", TRUE); + test_conversion(&testdata_32bppBGRA, &testdata_32bppBGR, "BGRA -> BGR", FALSE); test_conversion(&testdata_32bppBGR, &testdata_32bppBGRA, "BGR -> BGRA", FALSE); test_conversion(&testdata_32bppBGRA, &testdata_32bppBGRA, "BGRA -> BGRA", FALSE); @@ -823,6 +1702,7 @@ START_TEST(converter) test_conversion(&testdata_32bppBGR, &testdata_24bppRGB, "32bppBGR -> 24bppRGB", FALSE); test_conversion(&testdata_24bppRGB, &testdata_32bppBGR, "24bppRGB -> 32bppBGR", FALSE); + test_conversion(&testdata_32bppBGRA, &testdata_24bppRGB, "32bppBGRA -> 24bppRGB", FALSE); test_conversion(&testdata_24bppRGB, &testdata_32bppGrayFloat, "24bppRGB -> 32bppGrayFloat", FALSE); test_conversion(&testdata_32bppBGR, &testdata_32bppGrayFloat, "32bppBGR -> 32bppGrayFloat", FALSE); @@ -835,22 +1715,62 @@ START_TEST(converter) test_invalid_conversion(); test_default_converter(); - test_encoder(&testdata_32bppBGR, &CLSID_WICBmpEncoder, - &testdata_32bppBGR, &CLSID_WICBmpDecoder, "BMP encoder 32bppBGR"); - + test_encoder(&testdata_8bppIndexed, &CLSID_WICGifEncoder, + &testdata_8bppIndexed, &CLSID_WICGifDecoder, "GIF encoder 8bppIndexed"); + + test_encoder(&testdata_BlackWhite, &CLSID_WICPngEncoder, + &testdata_BlackWhite, &CLSID_WICPngDecoder, "PNG encoder BlackWhite"); + test_encoder(&testdata_1bppIndexed, &CLSID_WICPngEncoder, + &testdata_1bppIndexed, &CLSID_WICPngDecoder, "PNG encoder 1bppIndexed"); + test_encoder(&testdata_2bppIndexed, &CLSID_WICPngEncoder, + &testdata_2bppIndexed, &CLSID_WICPngDecoder, "PNG encoder 2bppIndexed"); + test_encoder(&testdata_4bppIndexed, &CLSID_WICPngEncoder, + &testdata_4bppIndexed, &CLSID_WICPngDecoder, "PNG encoder 4bppIndexed"); + test_encoder(&testdata_8bppIndexed, &CLSID_WICPngEncoder, + &testdata_8bppIndexed, &CLSID_WICPngDecoder, "PNG encoder 8bppIndexed"); test_encoder(&testdata_24bppBGR, &CLSID_WICPngEncoder, &testdata_24bppBGR, &CLSID_WICPngDecoder, "PNG encoder 24bppBGR"); +if (!strcmp(winetest_platform, "windows")) /* FIXME: enable once implemented in Wine */ +{ + test_encoder(&testdata_32bppBGR, &CLSID_WICPngEncoder, + &testdata_24bppBGR, &CLSID_WICPngDecoder, "PNG encoder 32bppBGR"); +} + test_encoder(&testdata_BlackWhite, &CLSID_WICBmpEncoder, + &testdata_1bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder BlackWhite"); + test_encoder(&testdata_1bppIndexed, &CLSID_WICBmpEncoder, + &testdata_1bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder 1bppIndexed"); + test_encoder(&testdata_2bppIndexed, &CLSID_WICBmpEncoder, + &testdata_2bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder 2bppIndexed"); + test_encoder(&testdata_4bppIndexed, &CLSID_WICBmpEncoder, + &testdata_4bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder 4bppIndexed"); + test_encoder(&testdata_8bppIndexed, &CLSID_WICBmpEncoder, + &testdata_8bppIndexed, &CLSID_WICBmpDecoder, "BMP encoder 8bppIndexed"); + test_encoder(&testdata_32bppBGR, &CLSID_WICBmpEncoder, + &testdata_32bppBGR, &CLSID_WICBmpDecoder, "BMP encoder 32bppBGR"); + + test_encoder(&testdata_BlackWhite, &CLSID_WICTiffEncoder, + &testdata_BlackWhite, &CLSID_WICTiffDecoder, "TIFF encoder BlackWhite"); + test_encoder(&testdata_1bppIndexed, &CLSID_WICTiffEncoder, + &testdata_1bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 1bppIndexed"); + test_encoder(&testdata_2bppIndexed, &CLSID_WICTiffEncoder, + &testdata_2bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 2bppIndexed"); + test_encoder(&testdata_4bppIndexed, &CLSID_WICTiffEncoder, + &testdata_4bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 4bppIndexed"); + test_encoder(&testdata_8bppIndexed, &CLSID_WICTiffEncoder, + &testdata_8bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 8bppIndexed"); test_encoder(&testdata_24bppBGR, &CLSID_WICTiffEncoder, &testdata_24bppBGR, &CLSID_WICTiffDecoder, "TIFF encoder 24bppBGR"); test_multi_encoder(multiple_frames, &CLSID_WICTiffEncoder, - multiple_frames, &CLSID_WICTiffDecoder, NULL, NULL, "TIFF encoder multi-frame"); + multiple_frames, &CLSID_WICTiffDecoder, NULL, NULL, "TIFF encoder multi-frame", NULL); test_encoder_rects(); test_multi_encoder(single_frame, &CLSID_WICPngEncoder, - single_frame, &CLSID_WICPngDecoder, NULL, png_interlace_settings, "PNG encoder interlaced"); + single_frame, &CLSID_WICPngDecoder, NULL, png_interlace_settings, "PNG encoder interlaced", NULL); + + IWICImagingFactory_Release(factory); CoUninitialize(); } diff --git a/rostests/winetests/windowscodecs/palette.c b/rostests/winetests/windowscodecs/palette.c index f9381c2e93b..7302d725821 100644 --- a/rostests/winetests/windowscodecs/palette.c +++ b/rostests/winetests/windowscodecs/palette.c @@ -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 #include +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(); } diff --git a/rostests/winetests/windowscodecs/pngformat.c b/rostests/winetests/windowscodecs/pngformat.c index ebf06a55a69..c7c8f3a22a0 100644 --- a/rostests/winetests/windowscodecs/pngformat.c +++ b/rostests/winetests/windowscodecs/pngformat.c @@ -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 = 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 = 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)); - 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; + + 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); - 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_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);