[WINDOWSCODECS_WINETEST] Sync with Wine Staging 3.3. CORE-14434
authorAmine Khaldi <amine.khaldi@reactos.org>
Sun, 4 Mar 2018 23:20:56 +0000 (00:20 +0100)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 4 Mar 2018 23:20:56 +0000 (00:20 +0100)
16 files changed:
modules/rostests/winetests/windowscodecs/CMakeLists.txt
modules/rostests/winetests/windowscodecs/bitmap.c
modules/rostests/winetests/windowscodecs/bmpformat.c
modules/rostests/winetests/windowscodecs/converter.c
modules/rostests/winetests/windowscodecs/gifformat.c
modules/rostests/winetests/windowscodecs/icoformat.c
modules/rostests/winetests/windowscodecs/info.c
modules/rostests/winetests/windowscodecs/jpegformat.c [new file with mode: 0644]
modules/rostests/winetests/windowscodecs/metadata.c
modules/rostests/winetests/windowscodecs/palette.c
modules/rostests/winetests/windowscodecs/pngformat.c
modules/rostests/winetests/windowscodecs/precomp.h
modules/rostests/winetests/windowscodecs/propertybag.c
modules/rostests/winetests/windowscodecs/stream.c
modules/rostests/winetests/windowscodecs/testlist.c
modules/rostests/winetests/windowscodecs/tiffformat.c

index 293a437..0cffe52 100644 (file)
@@ -8,6 +8,7 @@ list(APPEND SOURCE
     gifformat.c
     icoformat.c
     info.c
+    jpegformat.c
     metadata.c
     palette.c
     pngformat.c
index b35c07f..42f452a 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <assert.h>
+#include <math.h>
+
+#define COBJMACROS
+#define CONST_VTABLE
+
+#include "windef.h"
+#include "objbase.h"
+#include "wincodec.h"
+#include "wine/test.h"
 
 static IWICImagingFactory *factory;
 
index afa2bd9..48985b9 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdarg.h>
+#include <math.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "initguid.h"
+#include "objbase.h"
+#include "wincodec.h"
+#include "wincodecsdk.h"
+#include "wine/test.h"
 
 static const char testbmp_24bpp[] = {
     /* BITMAPFILEHEADER */
index 2a44ef5..91deda2 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <math.h>
+
+#define COBJMACROS
+#define CONST_VTABLE
+
+#include "windef.h"
+#include "objbase.h"
+#include "wincodec.h"
+#include "wincodecsdk.h"
+#include "wine/test.h"
 
 static IWICImagingFactory *factory;
 
@@ -107,9 +118,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,
@@ -241,16 +273,58 @@ static BOOL compare_bits(const struct bitmap_data *expect, UINT buffersize, cons
                 break;
             }
     }
+    else if (IsEqualGUID(expect->format, &GUID_WICPixelFormat2bppIndexed) ||
+             IsEqualGUID(expect->format, &GUID_WICPixelFormat4bppIndexed) ||
+             IsEqualGUID(expect->format, &GUID_WICPixelFormat8bppIndexed))
+    {
+        UINT i;
+        const BYTE *a=(const BYTE*)expect->bits, *b=(const BYTE*)converted_bits;
+        equal=TRUE;
+
+        for (i=0; i<buffersize; i++)
+            if (a[i] != b[i])
+            {
+                equal = FALSE;
+                break;
+            }
+    }
     else
         equal = (memcmp(expect->bits, converted_bits, buffersize) == 0);
 
     if (!equal && expect->alt_data)
         equal = compare_bits(expect->alt_data, buffersize, converted_bits);
 
+    if (!equal && winetest_debug > 1)
+    {
+        UINT i, bps;
+        bps = expect->bpp / 8;
+        if (!bps) bps = buffersize;
+        printf("converted_bits (%u bytes):\n    ", buffersize);
+        for (i = 0; i < buffersize; i++)
+        {
+            printf("%u,", converted_bits[i]);
+            if (!((i + 1) % 32)) printf("\n    ");
+            else if (!((i+1) % bps)) printf(" ");
+        }
+        printf("\n");
+    }
+
     return equal;
 }
 
-static void compare_bitmap_data(const struct bitmap_data *expect, IWICBitmapSource *source, const char *name)
+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;
@@ -283,15 +357,24 @@ static void compare_bitmap_data(const struct bitmap_data *expect, IWICBitmapSour
     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);
-    ok(compare_bits(expect, buffersize, converted_bits), "unexpected pixel data (%s)\n", name);
+
+    /* 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);
-    ok(compare_bits(expect, buffersize, converted_bits), "unexpected pixel data (%s)\n", name);
+    /* 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);
 }
@@ -305,66 +388,161 @@ static const struct bitmap_data testdata_BlackWhite = {
 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,
-    4,5,6,7};
+    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, 4, 2, 96.0, 96.0};
+    &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 struct bitmap_data testdata_32bppBGRA80 = {
+    &GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGR, 32, 2, 96.0, 96.0};
+static const struct bitmap_data testdata_32bppRGBA80 = {
+    &GUID_WICPixelFormat32bppRGBA, 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};
+static const struct bitmap_data testdata_32bppRGBA = {
+    &GUID_WICPixelFormat32bppRGBA, 32, bits_32bppBGRA, 32, 2, 96.0, 96.0};
+static const struct bitmap_data testdata_32bppRGB = {
+    &GUID_WICPixelFormat32bppRGB, 32, bits_32bppBGRA, 32, 2, 96.0, 96.0};
+
+static const BYTE bits_32bppPBGRA[] = {
+    80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80,
+    80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80,
+    80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80,
+    80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80, 80,0,0,80, 0,80,0,80, 0,0,80,80, 0,0,0,80,
+    0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80,
+    0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80,
+    0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80,
+    0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80, 0,80,80,80, 80,0,80,80, 80,80,0,80, 80,80,80,80};
+static const struct bitmap_data testdata_32bppPBGRA = {
+    &GUID_WICPixelFormat32bppPBGRA, 32, bits_32bppPBGRA, 32, 2, 96.0, 96.0};
+static const struct bitmap_data testdata_32bppPRGBA = {
+    &GUID_WICPixelFormat32bppPRGBA, 32, bits_32bppPBGRA, 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.886000f,0.413000f,0.701000f,1.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.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, 4, 2, 96.0, 96.0};
+    &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, &testdata_32bppGrayFloat_xp};
+    &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,
-    226,105,179,255};
+    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, 4, 2, 96.0, 96.0};
+    &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, &testdata_8bppGray_xp};
+    &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)
 {
@@ -376,11 +554,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 || hr == WINCODEC_ERR_COMPONENTNOTFOUND) /* 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);
     }
@@ -428,7 +607,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);
     }
@@ -456,6 +635,7 @@ static const WCHAR wszLuminance[] = {'L','u','m','i','n','a','n','c','e',0};
 static const WCHAR wszChrominance[] = {'C','h','r','o','m','i','n','a','n','c','e',0};
 static const WCHAR wszJpegYCrCbSubsampling[] = {'J','p','e','g','Y','C','r','C','b','S','u','b','s','a','m','p','l','i','n','g',0};
 static const WCHAR wszSuppressApp0[] = {'S','u','p','p','r','e','s','s','A','p','p','0',0};
+static const WCHAR wszEnableV5Header32bppBGRA[] = {'E','n','a','b','l','e','V','5','H','e','a','d','e','r','3','2','b','p','p','B','G','R','A',0};
 
 static const struct property_opt_test_data testdata_tiff_props[] = {
     { wszTiffCompressionMethod, VT_UI1,         VT_UI1,  WICTiffCompressionDontCare },
@@ -479,6 +659,11 @@ static const struct property_opt_test_data testdata_jpeg_props[] = {
     { NULL }
 };
 
+static const struct property_opt_test_data testdata_bmp_props[] = {
+    { wszEnableV5Header32bppBGRA, VT_BOOL, VT_BOOL, VARIANT_FALSE, 0.0f, TRUE }, /* Supported since Win7 */
+    { NULL }
+};
+
 static int find_property_index(const WCHAR* name, PROPBAG2* all_props, int all_prop_cnt)
 {
     int i;
@@ -605,6 +790,8 @@ static void test_encoder_properties(const CLSID* clsid_encoder, IPropertyBag2 *o
         test_specific_encoder_properties(options, testdata_png_props, all_props, cProperties2);
     else if (IsEqualCLSID(clsid_encoder, &CLSID_WICJpegEncoder))
         test_specific_encoder_properties(options, testdata_jpeg_props, all_props, cProperties2);
+    else if (IsEqualCLSID(clsid_encoder, &CLSID_WICBmpEncoder))
+        test_specific_encoder_properties(options, testdata_bmp_props, all_props, cProperties2);
 
     for (i=0; i < cProperties2; i++)
     {
@@ -613,14 +800,232 @@ static void test_encoder_properties(const CLSID* clsid_encoder, IPropertyBag2 *o
     }
 }
 
-static void check_bmp_format(IStream *stream, const WICPixelFormatGUID *format)
+static void load_stream(IUnknown *reader, IStream *stream)
 {
-    /* FIXME */
+    HRESULT hr;
+    IWICPersistStream *persist;
+#ifdef WORDS_BIGENDIAN
+    DWORD persist_options = WICPersistOptionBigEndian;
+#else
+    DWORD persist_options = WICPersistOptionLittleEndian;
+#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)
 {
-    /* FIXME */
+    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)
@@ -677,9 +1082,31 @@ static void check_png_format(IStream *stream, const WICPixelFormatGUID *format)
         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) == 4, "wrong width %u\n", be_uint(png.width));
+        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);
@@ -690,7 +1117,7 @@ static void check_png_format(IStream *stream, const WICPixelFormatGUID *format)
     }
     else if (IsEqualGUID(format, &GUID_WICPixelFormat24bppBGR))
     {
-        ok(be_uint(png.width) == 4, "wrong width %u\n", be_uint(png.width));
+        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);
@@ -703,6 +1130,40 @@ static void check_png_format(IStream *stream, const WICPixelFormatGUID *format)
         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;
@@ -718,6 +1179,8 @@ static void check_bitmap_format(IStream *stream, const CLSID *encoder, const WIC
         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));
 
@@ -793,8 +1256,26 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
     int i;
 
     hr = CoCreateInstance(clsid_encoder, NULL, CLSCTX_INPROC_SERVER,
-        &IID_IWICBitmapEncoder, (void**)&encoder);
+        &IID_IWICBitmapEncoder, (void **)&encoder);
     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
+
+    hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
+    ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
+
+    hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
+    ok(SUCCEEDED(hr), "Initialize failed, hr=%x\n", hr);
+
+    /* Encoder options are optional. */
+    hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frameencode, NULL);
+    ok(SUCCEEDED(hr), "Failed to create encode frame, hr %#x.\n", hr);
+
+    IStream_Release(stream);
+    IWICBitmapEncoder_Release(encoder);
+    IWICBitmapFrameEncode_Release(frameencode);
+
+    hr = CoCreateInstance(clsid_encoder, NULL, CLSCTX_INPROC_SERVER,
+        &IID_IWICBitmapEncoder, (void**)&encoder);
+    ok(SUCCEEDED(hr), "CoCreateInstance(%s) failed, hr=%x\n", wine_dbgstr_guid(clsid_encoder), hr);
     if (SUCCEEDED(hr))
     {
         hglobal = GlobalAlloc(GMEM_MOVEABLE, 0);
@@ -819,7 +1300,10 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
             if (palette)
             {
                 hr = IWICBitmapEncoder_SetPalette(encoder, palette);
-                ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "wrong error %#x\n", hr);
+                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;
             }
 
@@ -868,8 +1352,10 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
                     memcpy(&pixelformat, srcs[i]->format, sizeof(GUID));
                     hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &pixelformat);
                     ok(SUCCEEDED(hr), "SetPixelFormat failed, hr=%x\n", hr);
-                    ok(IsEqualGUID(&pixelformat, dsts[i]->format), "SetPixelFormat changed the format to %s (%s)\n",
-                       wine_dbgstr_guid(&pixelformat), name);
+                    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);
@@ -904,6 +1390,8 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
                             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);
                     }
@@ -935,7 +1423,8 @@ 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);
 
-                check_bitmap_format(stream, clsid_encoder, dsts[0]->format);
+                if (IsEqualGUID(&pixelformat, dsts[0]->format))
+                    check_bitmap_format(stream, clsid_encoder, dsts[0]->format);
             }
 
             if (SUCCEEDED(hr))
@@ -953,13 +1442,19 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
                 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
 
                 hr = IWICBitmapDecoder_CopyPalette(decoder, frame_palette);
-                ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "wrong error %#x\n", hr);
+                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);
-                ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "wrong error %#x\n", hr);
+                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;
@@ -970,7 +1465,10 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
 
                     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)
@@ -995,7 +1493,12 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
                             ok(ret == count, "expected %u, got %u\n", count, ret);
                             if (IsEqualGUID(clsid_decoder, &CLSID_WICPngDecoder))
                             {
-                                ok(count == 256 || count == 2 /* newer libpng versions */, "expected 256, got %u (%s)\n", count, name);
+                                /* 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);
@@ -1003,15 +1506,19 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
                                 {
                                     ok(colors[2] == 0x33333333, "got %08x (%s)\n", colors[2], name);
                                     ok(colors[3] == 0x44444444, "got %08x (%s)\n", colors[3], name);
-                                    ok(colors[4] == 0x55555555, "got %08x (%s)\n", colors[4], name);
-                                    ok(colors[5] == 0, "got %08x (%s)\n", colors[5], 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_WICTiffDecoder) ||
+                                     IsEqualGUID(clsid_decoder, &CLSID_WICGifDecoder))
                             {
-                                if (IsEqualGUID(dsts[i]->format, &GUID_WICPixelFormatBlackWhite) ||
-                                    IsEqualGUID(dsts[i]->format, &GUID_WICPixelFormat8bppIndexed))
+                                if (IsEqualGUID(&pixelformat, &GUID_WICPixelFormatBlackWhite) ||
+                                    IsEqualGUID(&pixelformat, &GUID_WICPixelFormat8bppIndexed))
                                 {
                                     ok(count == 256, "expected 256, got %u (%s)\n", count, name);
 
@@ -1022,6 +1529,26 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
                                     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);
@@ -1101,7 +1628,7 @@ 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", NULL);
@@ -1112,7 +1639,7 @@ static void test_encoder_rects(void)
     rc.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", NULL);
 
@@ -1134,6 +1661,163 @@ 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;
@@ -1144,9 +1828,27 @@ START_TEST(converter)
                           &IID_IWICImagingFactory, (void **)&factory);
     ok(hr == S_OK, "failed to create factory: %#x\n", hr);
 
+    test_converter_8bppIndexed();
+
+    test_conversion(&testdata_24bppRGB, &testdata_1bppIndexed, "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);
+    test_conversion(&testdata_32bppBGRA80, &testdata_32bppPBGRA, "BGRA -> PBGRA", FALSE);
+
+    test_conversion(&testdata_32bppRGBA, &testdata_32bppRGB, "RGBA -> RGB", FALSE);
+    test_conversion(&testdata_32bppRGB, &testdata_32bppRGBA, "RGB -> RGBA", FALSE);
+    test_conversion(&testdata_32bppRGBA, &testdata_32bppRGBA, "RGBA -> RGBA", FALSE);
+    test_conversion(&testdata_32bppRGBA80, &testdata_32bppPRGBA, "RGBA -> PRGBA", FALSE);
 
     test_conversion(&testdata_24bppBGR, &testdata_24bppBGR, "24bppBGR -> 24bppBGR", FALSE);
     test_conversion(&testdata_24bppBGR, &testdata_24bppRGB, "24bppBGR -> 24bppRGB", FALSE);
@@ -1169,36 +1871,50 @@ START_TEST(converter)
     test_invalid_conversion();
     test_default_converter();
 
+    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");
-if (!strcmp(winetest_platform, "windows")) /* FIXME: enable once implemented in Wine */
-{
     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");
 
index 3af0a80..53b4e47 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdarg.h>
+#include <stdio.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "wincodec.h"
+#include "wine/test.h"
 
 HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT, IWICImagingFactory**);
 
index c614898..c53739d 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdarg.h>
+#include <math.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "objbase.h"
+#include "wincodec.h"
+#include "wine/test.h"
 
 static unsigned char testico_bad_icondirentry_size[] = {
     /* ICONDIR */
index 83b729a..4a9c9c6 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include <math.h>
 
-#include <initguid.h>
+#define COBJMACROS
+
+#include "windef.h"
+#include "objbase.h"
+#include "wincodec.h"
+#include "wincodecsdk.h"
+#include "wine/test.h"
+
+#include "initguid.h"
 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
 
 static HRESULT get_component_info(const GUID *clsid, IWICComponentInfo **result)
@@ -57,126 +67,218 @@ static BOOL is_pixelformat(GUID *format)
 
 static void test_decoder_info(void)
 {
+    struct decoder_info_test
+    {
+        const CLSID *clsid;
+        const char *mimetype;
+        const char *extensions;
+        unsigned int todo;
+    } decoder_info_tests[] =
+    {
+        {
+            &CLSID_WICBmpDecoder,
+            "image/bmp",
+            ".bmp,.dib,.rle"
+        },
+        {
+            &CLSID_WICGifDecoder,
+            "image/gif",
+            ".gif"
+        },
+        {
+            &CLSID_WICIcoDecoder,
+            "image/ico,image/x-icon",
+            ".ico,.icon",
+            1
+        },
+        {
+            &CLSID_WICJpegDecoder,
+            "image/jpeg,image/jpe,image/jpg",
+            ".jpeg,.jpe,.jpg,.jfif,.exif",
+            1
+        },
+        {
+            &CLSID_WICPngDecoder,
+            "image/png",
+            ".png"
+        },
+        {
+            &CLSID_WICTiffDecoder,
+            "image/tiff,image/tif",
+            ".tiff,.tif",
+            1
+        },
+    };
+    IWICBitmapDecoderInfo *decoder_info, *decoder_info2;
     IWICComponentInfo *info;
-    IWICBitmapDecoderInfo *decoder_info;
     HRESULT hr;
     ULONG len;
     WCHAR value[256];
-    const WCHAR expected_mimetype[] = {'i','m','a','g','e','/','b','m','p',0};
-    const WCHAR expected_extensions[] = {'.','b','m','p',',','.','d','i','b',',','.','r','l','e',0};
     CLSID clsid;
-    GUID pixelformats[20];
+    GUID pixelformats[32];
     UINT num_formats, count;
-    int i;
-
-    hr = get_component_info(&CLSID_WICBmpDecoder, &info);
-    ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
-
-    hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void**)&decoder_info);
-    ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
-
-    hr = IWICBitmapDecoderInfo_GetCLSID(decoder_info, NULL);
-    ok(hr == E_INVALIDARG, "GetCLSID failed, hr=%x\n", hr);
-
-    hr = IWICBitmapDecoderInfo_GetCLSID(decoder_info, &clsid);
-    ok(hr == S_OK, "GetCLSID failed, hr=%x\n", hr);
-    ok(IsEqualGUID(&CLSID_WICBmpDecoder, &clsid), "GetCLSID returned wrong result\n");
-
-    hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 0, NULL, NULL);
-    ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
-
-    hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 1, NULL, &len);
-    ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
-    ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
-
-    hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, len, value, NULL);
-    ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
-
-    hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 0, NULL, &len);
-    ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
-    ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
-
-    value[0] = 0;
-    hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, len, value, &len);
-    ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
-    ok(lstrcmpW(value, expected_mimetype) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value));
-    ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
+    int i, j;
 
-    hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 1, value, &len);
-    ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetMimeType failed, hr=%x\n", hr);
-    ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
-
-    hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 256, value, &len);
-    ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
-    ok(lstrcmpW(value, expected_mimetype) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value));
-    ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len);
-
-    num_formats = 0xdeadbeef;
-    hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, NULL, &num_formats);
-    ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
-    ok(num_formats < 20 && num_formats > 1, "got %d formats\n", num_formats);
-
-    hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, NULL, NULL);
-    ok(hr == E_INVALIDARG, "GetPixelFormats failed, hr=%x\n", hr);
-
-    count = 0xdeadbeef;
-    hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, pixelformats, &count);
-    ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
-    ok(count == 0, "got %d formats\n", count);
-
-    count = 0xdeadbeef;
-    hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 1, pixelformats, &count);
-    ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
-    ok(count == 1, "got %d formats\n", count);
-    ok(is_pixelformat(&pixelformats[0]), "got invalid pixel format\n");
-
-    count = 0xdeadbeef;
-    hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, num_formats, pixelformats, &count);
-    ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
-    ok(count == num_formats, "got %d formats, expected %d\n", count, num_formats);
-    for (i=0; i<num_formats; i++)
-        ok(is_pixelformat(&pixelformats[i]), "got invalid pixel format\n");
-
-    hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, num_formats, pixelformats, NULL);
-    ok(hr == E_INVALIDARG, "GetPixelFormats failed, hr=%x\n", hr);
-
-    count = 0xdeadbeef;
-    hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 20, pixelformats, &count);
-    ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
-    ok(count == num_formats, "got %d formats, expected %d\n", count, num_formats);
-
-    hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 0, NULL, NULL);
-    ok(hr == E_INVALIDARG, "GetFileExtensions failed, hr=%x\n", hr);
-
-    hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 1, NULL, &len);
-    ok(hr == E_INVALIDARG, "GetFileExtensions failed, hr=%x\n", hr);
-    ok(len == lstrlenW(expected_extensions)+1, "GetFileExtensions returned wrong len %i\n", len);
-
-    hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, len, value, NULL);
-    ok(hr == E_INVALIDARG, "GetFileExtensions failed, hr=%x\n", hr);
-
-    hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 0, NULL, &len);
-    ok(hr == S_OK, "GetFileExtensions failed, hr=%x\n", hr);
-    ok(len == lstrlenW(expected_extensions)+1, "GetFileExtensions returned wrong len %i\n", len);
-
-    value[0] = 0;
-    hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, len, value, &len);
-    ok(hr == S_OK, "GetFileExtensions failed, hr=%x\n", hr);
-    ok(lstrcmpW(value, expected_extensions) == 0, "GetFileExtensions returned wrong value %s\n", wine_dbgstr_w(value));
-    ok(len == lstrlenW(expected_extensions)+1, "GetFileExtensions returned wrong len %i\n", len);
-
-    hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 1, value, &len);
-    ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetFileExtensions failed, hr=%x\n", hr);
-    ok(len == lstrlenW(expected_extensions)+1, "GetFileExtensions returned wrong len %i\n", len);
-
-    hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 256, value, &len);
-    ok(hr == S_OK, "GetFileExtensions failed, hr=%x\n", hr);
-    ok(lstrcmpW(value, expected_extensions) == 0, "GetFileExtensions returned wrong value %s\n", wine_dbgstr_w(value));
-    ok(len == lstrlenW(expected_extensions)+1, "GetFileExtensions returned wrong len %i\n", len);
-
-    IWICBitmapDecoderInfo_Release(decoder_info);
-
-    IWICComponentInfo_Release(info);
+    for (i = 0; i < sizeof(decoder_info_tests)/sizeof(decoder_info_tests[0]); i++)
+    {
+        struct decoder_info_test *test = &decoder_info_tests[i];
+        IWICBitmapDecoder *decoder, *decoder2;
+        WCHAR extensionsW[64];
+        WCHAR mimetypeW[64];
+
+        hr = CoCreateInstance(test->clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IWICBitmapDecoder, (void **)&decoder);
+        ok(SUCCEEDED(hr), "Failed to create decoder, hr %#x.\n", hr);
+
+        decoder_info = NULL;
+        hr = IWICBitmapDecoder_GetDecoderInfo(decoder, &decoder_info);
+        ok(hr == S_OK || broken(IsEqualCLSID(&CLSID_WICBmpDecoder, test->clsid) && FAILED(hr)) /* Fails on Windows */,
+            "%u: failed to get decoder info, hr %#x.\n", i, hr);
+
+        if (hr == S_OK)
+        {
+            decoder_info2 = NULL;
+            hr = IWICBitmapDecoder_GetDecoderInfo(decoder, &decoder_info2);
+            ok(hr == S_OK, "Failed to get decoder info, hr %#x.\n", hr);
+        todo_wine
+            ok(decoder_info == decoder_info2, "Unexpected decoder info instance.\n");
+
+            hr = IWICBitmapDecoderInfo_QueryInterface(decoder_info, &IID_IWICBitmapDecoder, (void **)&decoder2);
+            ok(hr == E_NOINTERFACE, "Unexpected hr %#x.\n", hr);
+
+            IWICBitmapDecoderInfo_Release(decoder_info);
+            IWICBitmapDecoderInfo_Release(decoder_info2);
+        }
+        IWICBitmapDecoder_Release(decoder);
+
+        MultiByteToWideChar(CP_ACP, 0, test->mimetype, -1, mimetypeW, sizeof(mimetypeW)/sizeof(mimetypeW[0]));
+        MultiByteToWideChar(CP_ACP, 0, test->extensions, -1, extensionsW, sizeof(extensionsW)/sizeof(extensionsW[0]));
+
+        hr = get_component_info(test->clsid, &info);
+        ok(hr == S_OK, "CreateComponentInfo failed, hr=%x\n", hr);
+
+        hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void **)&decoder_info);
+        ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
+
+        hr = IWICBitmapDecoderInfo_GetCLSID(decoder_info, NULL);
+        ok(hr == E_INVALIDARG, "GetCLSID failed, hr=%x\n", hr);
+
+        hr = IWICBitmapDecoderInfo_GetCLSID(decoder_info, &clsid);
+        ok(hr == S_OK, "GetCLSID failed, hr=%x\n", hr);
+        ok(IsEqualGUID(test->clsid, &clsid), "GetCLSID returned wrong result\n");
+
+        hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 0, NULL, NULL);
+        ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
+
+        len = 0;
+        hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 1, NULL, &len);
+        ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
+    todo_wine_if(test->todo)
+        ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
+
+        hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, len, value, NULL);
+        ok(hr == E_INVALIDARG, "GetMimeType failed, hr=%x\n", hr);
+
+        len = 0;
+        hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 0, NULL, &len);
+        ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
+    todo_wine_if(test->todo)
+        ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
+
+        value[0] = 0;
+        hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, len, value, &len);
+        ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
+    todo_wine_if(test->todo) {
+        ok(lstrcmpW(value, mimetypeW) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value));
+        ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
+    }
+        hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 1, value, &len);
+        ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetMimeType failed, hr=%x\n", hr);
+    todo_wine_if(test->todo)
+        ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
+
+        hr = IWICBitmapDecoderInfo_GetMimeTypes(decoder_info, 256, value, &len);
+        ok(hr == S_OK, "GetMimeType failed, hr=%x\n", hr);
+    todo_wine_if(test->todo) {
+        ok(lstrcmpW(value, mimetypeW) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value));
+        ok(len == lstrlenW(mimetypeW) + 1, "GetMimeType returned wrong len %i\n", len);
+    }
+        num_formats = 0xdeadbeef;
+        hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, NULL, &num_formats);
+        ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
+        ok((num_formats <= 21 && num_formats >= 1) ||
+            broken(IsEqualCLSID(test->clsid, &CLSID_WICIcoDecoder) && num_formats == 0) /* WinXP */,
+            "%u: got %d formats\n", i, num_formats);
+
+        hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, NULL, NULL);
+        ok(hr == E_INVALIDARG, "GetPixelFormats failed, hr=%x\n", hr);
+
+        count = 0xdeadbeef;
+        hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, pixelformats, &count);
+        ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
+        ok(count == 0, "got %d formats\n", count);
+
+        count = 0xdeadbeef;
+        hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 1, pixelformats, &count);
+        ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
+        ok((count == 1) || broken(IsEqualCLSID(test->clsid, &CLSID_WICIcoDecoder) && count == 0) /* WinXP */,
+            "%u: got %d formats\n", i, num_formats);
+        ok(is_pixelformat(&pixelformats[0]), "got invalid pixel format\n");
+
+        count = 0xdeadbeef;
+        hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, num_formats, pixelformats, &count);
+        ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
+        ok(count == num_formats, "got %d formats, expected %d\n", count, num_formats);
+        for (j = 0; j < num_formats; j++)
+            ok(is_pixelformat(&pixelformats[j]), "got invalid pixel format\n");
+
+        hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, num_formats, pixelformats, NULL);
+        ok(hr == E_INVALIDARG, "GetPixelFormats failed, hr=%x\n", hr);
+
+        count = 0xdeadbeef;
+        hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, sizeof(pixelformats)/sizeof(pixelformats[0]),
+            pixelformats, &count);
+        ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr);
+        ok(count == num_formats, "got %d formats, expected %d\n", count, num_formats);
+
+        hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 0, NULL, NULL);
+        ok(hr == E_INVALIDARG, "GetFileExtensions failed, hr=%x\n", hr);
+
+        hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 1, NULL, &len);
+        ok(hr == E_INVALIDARG, "GetFileExtensions failed, hr=%x\n", hr);
+    todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
+        ok(len == lstrlenW(extensionsW) + 1, "%u: GetFileExtensions returned wrong len %i\n", i, len);
+
+        hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, len, value, NULL);
+        ok(hr == E_INVALIDARG, "GetFileExtensions failed, hr=%x\n", hr);
+
+        hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 0, NULL, &len);
+        ok(hr == S_OK, "GetFileExtensions failed, hr=%x\n", hr);
+    todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
+        ok(len == lstrlenW(extensionsW) + 1, "GetFileExtensions returned wrong len %i\n", len);
+
+        value[0] = 0;
+        hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, len, value, &len);
+        ok(hr == S_OK, "GetFileExtensions failed, hr=%x\n", hr);
+    todo_wine_if(test->todo)
+        ok(lstrcmpW(value, extensionsW) == 0, "GetFileExtensions returned wrong value %s\n", wine_dbgstr_w(value));
+    todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
+        ok(len == lstrlenW(extensionsW) + 1, "GetFileExtensions returned wrong len %i\n", len);
+
+        hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 1, value, &len);
+        ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetFileExtensions failed, hr=%x\n", hr);
+    todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
+        ok(len == lstrlenW(extensionsW) + 1, "GetFileExtensions returned wrong len %i\n", len);
+
+        hr = IWICBitmapDecoderInfo_GetFileExtensions(decoder_info, 256, value, &len);
+        ok(hr == S_OK, "GetFileExtensions failed, hr=%x\n", hr);
+    todo_wine_if(test->todo)
+        ok(lstrcmpW(value, extensionsW) == 0, "GetFileExtensions returned wrong value %s\n", wine_dbgstr_w(value));
+    todo_wine_if(test->todo && !IsEqualCLSID(test->clsid, &CLSID_WICTiffDecoder))
+        ok(len == lstrlenW(extensionsW) + 1, "GetFileExtensions returned wrong len %i\n", len);
+
+        IWICBitmapDecoderInfo_Release(decoder_info);
+        IWICComponentInfo_Release(info);
+    }
 }
 
 static void test_pixelformat_info(void)
diff --git a/modules/rostests/winetests/windowscodecs/jpegformat.c b/modules/rostests/winetests/windowscodecs/jpegformat.c
new file mode 100644 (file)
index 0000000..c1e46c4
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#define COBJMACROS
+
+#include "objbase.h"
+#include "wincodec.h"
+#include "wine/test.h"
+
+static const char jpeg_adobe_cmyk_1x5[] =
+    "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46\x00\x01\x01\x01\x01\x2c"
+    "\x01\x2c\x00\x00\xff\xee\x00\x0e\x41\x64\x6f\x62\x65\x00\x64\x00"
+    "\x00\x00\x00\x02\xff\xfe\x00\x13\x43\x72\x65\x61\x74\x65\x64\x20"
+    "\x77\x69\x74\x68\x20\x47\x49\x4d\x50\xff\xdb\x00\x43\x00\x01\x01"
+    "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
+    "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
+    "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
+    "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xff\xdb"
+    "\x00\x43\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
+    "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
+    "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
+    "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
+    "\x01\x01\x01\xff\xc0\x00\x14\x08\x00\x05\x00\x01\x04\x01\x11\x00"
+    "\x02\x11\x01\x03\x11\x01\x04\x11\x00\xff\xc4\x00\x15\x00\x01\x01"
+    "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x08"
+    "\xff\xc4\x00\x14\x10\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+    "\x00\x00\x00\x00\x00\x00\xff\xc4\x00\x14\x01\x01\x00\x00\x00\x00"
+    "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\xff\xc4\x00\x14"
+    "\x11\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+    "\x00\x00\xff\xda\x00\x0e\x04\x01\x00\x02\x11\x03\x11\x04\x00\x00"
+    "\x3f\x00\x40\x44\x02\x1e\xa4\x1f\xff\xd9";
+
+static void test_decode_adobe_cmyk(void)
+{
+    IWICBitmapDecoder *decoder;
+    IWICBitmapFrameDecode *framedecode;
+    HRESULT hr;
+    HGLOBAL hjpegdata;
+    char *jpegdata;
+    IStream *jpegstream;
+    GUID guidresult;
+    UINT count=0, width=0, height=0;
+    BYTE imagedata[5 * 4] = {1};
+    UINT i;
+
+    const BYTE expected_imagedata[5 * 4] = {
+        0x00, 0xb0, 0xfc, 0x6d,
+        0x00, 0xb0, 0xfc, 0x6d,
+        0x00, 0xb0, 0xfc, 0x6d,
+        0x00, 0xb0, 0xfc, 0x6d,
+        0x00, 0xb0, 0xfc, 0x6d,
+    };
+
+    const BYTE expected_imagedata_24bpp[5 * 4] = {
+        0x0d, 0x4b, 0x94, 0x00,
+        0x0d, 0x4b, 0x94, 0x00,
+        0x0d, 0x4b, 0x94, 0x00,
+        0x0d, 0x4b, 0x94, 0x00,
+        0x0d, 0x4b, 0x94, 0x00,
+    };
+
+    hr = CoCreateInstance(&CLSID_WICJpegDecoder, NULL, CLSCTX_INPROC_SERVER,
+        &IID_IWICBitmapDecoder, (void**)&decoder);
+    ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
+    if (FAILED(hr)) return;
+
+    hjpegdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(jpeg_adobe_cmyk_1x5));
+    ok(hjpegdata != 0, "GlobalAlloc failed\n");
+    if (hjpegdata)
+    {
+        jpegdata = GlobalLock(hjpegdata);
+        memcpy(jpegdata, jpeg_adobe_cmyk_1x5, sizeof(jpeg_adobe_cmyk_1x5));
+        GlobalUnlock(hjpegdata);
+
+        hr = CreateStreamOnHGlobal(hjpegdata, FALSE, &jpegstream);
+        ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
+        if (SUCCEEDED(hr))
+        {
+            hr = IWICBitmapDecoder_Initialize(decoder, jpegstream, WICDecodeMetadataCacheOnLoad);
+            ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
+
+            hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
+            ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
+            ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatJpeg), "unexpected container format\n");
+
+            hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
+            ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
+            ok(count == 1, "unexpected count %u\n", count);
+
+            hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
+            ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
+            if (SUCCEEDED(hr))
+            {
+                hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
+                ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
+                ok(width == 1, "expected width=1, got %u\n", width);
+                ok(height == 5, "expected height=5, got %u\n", height);
+
+                hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
+                ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
+                ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppCMYK) ||
+                    broken(IsEqualGUID(&guidresult, &GUID_WICPixelFormat24bppBGR)), /* xp/2003 */
+                    "unexpected pixel format: %s\n", wine_dbgstr_guid(&guidresult));
+
+                /* We want to be sure our state tracking will not impact output
+                 * data on subsequent calls */
+                for(i=2; i>0; --i)
+                {
+                    hr = IWICBitmapFrameDecode_CopyPixels(framedecode, NULL, 4, sizeof(imagedata), imagedata);
+                    ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
+                    ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)) ||
+                            broken(!memcmp(imagedata, expected_imagedata_24bpp, sizeof(expected_imagedata))), /* xp/2003 */
+                            "unexpected image data\n");
+                }
+                IWICBitmapFrameDecode_Release(framedecode);
+            }
+            IStream_Release(jpegstream);
+        }
+        GlobalFree(hjpegdata);
+    }
+    IWICBitmapDecoder_Release(decoder);
+}
+
+
+START_TEST(jpegformat)
+{
+    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+
+    test_decode_adobe_cmyk();
+
+    CoUninitialize();
+}
index 9de1c4d..1d4203d 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include <math.h>
+#include <assert.h>
 
-#include <winnls.h>
-#include <propvarutil.h>
+#define COBJMACROS
 
-#include <initguid.h>
+#include "windef.h"
+#include "objbase.h"
+#include "wincodec.h"
+#include "wincodecsdk.h"
+#include "propvarutil.h"
+#include "wine/test.h"
+
+#include "initguid.h"
 DEFINE_GUID(IID_MdbrUnknown, 0x00240e6f,0x3f23,0x4432,0xb0,0xcc,0x48,0xd5,0xbb,0xff,0x6c,0x36);
 
 #define expect_blob(propvar, data, length) do { \
index 9031556..33fd119 100644 (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
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdarg.h>
+#include <assert.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "objbase.h"
+#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;
@@ -30,11 +39,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))
@@ -199,8 +203,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)
@@ -443,7 +445,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;
@@ -451,10 +452,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);
@@ -530,16 +527,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();
 }
index 22f7793..3a0ea28 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdarg.h>
+#include <stdio.h>
 
-#include <shlwapi.h>
+#define COBJMACROS
+
+#include "windef.h"
+#include "wincodec.h"
+#include "wine/test.h"
+#include "shlwapi.h"
 
 /* 1x1 pixel PNG image */
 static const char png_no_color_profile[] = {
@@ -720,7 +726,6 @@ static void test_color_formats(void)
 
         hr = create_decoder(buf, sizeof(buf), &decoder);
         if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE))
-todo_wine
             ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
         else
 todo_wine_if(td[i].todo_load)
@@ -749,7 +754,6 @@ next_1:
 
         hr = create_decoder(buf, sizeof(buf), &decoder);
         if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE))
-todo_wine
             ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
         else
 todo_wine_if(td[i].todo_load)
@@ -778,7 +782,6 @@ next_2:
 
         hr = create_decoder(buf, sizeof(buf), &decoder);
         if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE))
-todo_wine
             ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
         else
 todo_wine_if(td[i].todo_load)
@@ -806,7 +809,6 @@ next_3:
 
         hr = create_decoder(buf, sizeof(buf), &decoder);
         if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE))
-todo_wine
             ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
         else
 todo_wine_if(td[i].todo_load)
index 59d037a..b5ae868 100644 (file)
@@ -1,3 +1,4 @@
+
 #ifndef _WINDOWSCODECS_WINETEST_PRECOMP_H_
 #define _WINDOWSCODECS_WINETEST_PRECOMP_H_
 
@@ -16,7 +17,8 @@
 
 #include <wingdi.h>
 #include <winreg.h>
+#include <winnls.h>
 #include <ole2.h>
 #include <wincodecsdk.h>
 
-#endif /* _WINDOWSCODECS_WINETEST_PRECOMP_H_ */
+#endif /* !_WINDOWSCODECS_WINETEST_PRECOMP_H_ */
index b0a3bd3..fd57073 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <stdarg.h>
+#include <math.h>
+
+#define COBJMACROS
+#define CONST_VTABLE
+
+#include "windef.h"
+#include "objbase.h"
+#include "wincodec.h"
+#include "wincodecsdk.h"
+#include "wine/test.h"
 
 static const WCHAR wszTestProperty1[] = {'P','r','o','p','e','r','t','y','1',0};
 static const WCHAR wszTestProperty2[] = {'P','r','o','p','e','r','t','y','2',0};
index 70807aa..5f311b8 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include "wine/test.h"
+
+#define COBJMACROS
+#include "wincodec.h"
 
 static void test_StreamOnMemory(void)
 {
index 588446a..6ea28ad 100644 (file)
@@ -9,6 +9,7 @@ extern void func_converter(void);
 extern void func_gifformat(void);
 extern void func_icoformat(void);
 extern void func_info(void);
+extern void func_jpegformat(void);
 extern void func_metadata(void);
 extern void func_palette(void);
 extern void func_pngformat(void);
@@ -24,6 +25,7 @@ const struct test winetest_testlist[] =
     { "gifformat", func_gifformat },
     { "icoformat", func_icoformat },
     { "info", func_info },
+    { "jpegformat", func_jpegformat },
     { "metadata", func_metadata },
     { "palette", func_palette },
     { "pngformat", func_pngformat },
index e529a44..5671dfb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "precomp.h"
+#include <math.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "wincodec.h"
+#include "wine/test.h"
 
 #define IFD_BYTE 1
 #define IFD_ASCII 2
@@ -77,8 +85,8 @@ static const struct tiff_1bpp_data
         { 0x115, IFD_SHORT, 1, 1 }, /* SAMPLESPERPIXEL */
         { 0x116, IFD_LONG, 1, 1 }, /* ROWSPERSTRIP */
         { 0x117, IFD_LONG, 1, 1 }, /* STRIPBYTECOUNT */
-        { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1bpp_data, res) },
-        { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1bpp_data, res) },
+        { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1bpp_data, res) }, /* XRESOLUTION */
+        { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1bpp_data, res) }, /* YRESOLUTION */
         { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */
     },
     0,
@@ -117,8 +125,8 @@ static const struct tiff_8bpp_alpha
         { 0x115, IFD_SHORT, 1, 2 }, /* SAMPLESPERPIXEL */
         { 0x116, IFD_LONG, 1, 2 }, /* ROWSPERSTRIP */
         { 0x117, IFD_LONG, 1, 8 }, /* STRIPBYTECOUNT */
-        { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_8bpp_alpha, res) },
-        { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_8bpp_alpha, res) },
+        { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_8bpp_alpha, res) }, /* XRESOLUTION */
+        { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_8bpp_alpha, res) }, /* YRESOLUTION */
         { 0x11c, IFD_SHORT, 1, 1 }, /* PLANARCONFIGURATION */
         { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */
         { 0x152, IFD_SHORT, 1, 1 } /* EXTRASAMPLES: 1 - Associated alpha with pre-multiplied color */
@@ -127,6 +135,124 @@ static const struct tiff_8bpp_alpha
     { 96, 1 },
     { 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88 }
 };
+
+static const struct tiff_8bpp_data
+{
+    USHORT byte_order;
+    USHORT version;
+    ULONG  dir_offset;
+    USHORT number_of_entries;
+    struct IFD_entry entry[14];
+    ULONG next_IFD;
+    struct IFD_rational res;
+    short palette_data[3][256];
+    BYTE pixel_data[4];
+} tiff_8bpp_data =
+{
+#ifdef WORDS_BIGENDIAN
+    'M' | 'M' << 8,
+#else
+    'I' | 'I' << 8,
+#endif
+    42,
+    FIELD_OFFSET(struct tiff_8bpp_data, number_of_entries),
+    14,
+    {
+        { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */
+        { 0x100, IFD_LONG, 1, 4 }, /* IMAGEWIDTH */
+        { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */
+        { 0x102, IFD_SHORT, 1, 8 }, /* BITSPERSAMPLE: XP doesn't accept IFD_LONG here */
+        { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
+        { 0x106, IFD_SHORT, 1, 3 }, /* PHOTOMETRIC */
+        { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_8bpp_data, pixel_data) }, /* STRIPOFFSETS */
+        { 0x115, IFD_SHORT, 1, 1 }, /* SAMPLESPERPIXEL */
+        { 0x116, IFD_LONG, 1, 1 }, /* ROWSPERSTRIP */
+        { 0x117, IFD_LONG, 1, 1 }, /* STRIPBYTECOUNT */
+        { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_8bpp_data, res) },
+        { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_8bpp_data, res) },
+        { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */
+        { 0x140, IFD_SHORT, 256*3, FIELD_OFFSET(struct tiff_8bpp_data, palette_data) } /* COLORMAP */
+    },
+    0,
+    { 96, 1 },
+    { { 0 } },
+    { 0,1,2,3 }
+};
+
+static const struct tiff_resolution_test_data
+{
+    struct IFD_rational resx;
+    struct IFD_rational resy;
+    LONG resolution_unit;
+    double expected_dpi_x;
+    double expected_dpi_y;
+    /* if != 0: values for different behavior of some Windows versions */
+    double broken_dpi_x;
+    double broken_dpi_y;
+} tiff_resolution_test_data[] =
+{
+    { { 100, 1 }, {  50, 1 }, 0, 100.0,  50.0,     0,      0  }, /* invalid resolution unit */
+    { {  50, 1 }, { 100, 1 }, 0,  50.0, 100.0,     0,      0  },
+
+    { { 100, 1 }, {  50, 1 }, 1, 100.0,  50.0,     0,      0  }, /* RESUNIT_NONE */
+    { {  50, 1 }, { 100, 1 }, 1,  50.0, 100.0,     0,      0  },
+
+    { {  49, 1 }, {  49, 1 }, 2,  49.0,  49.0,     0,      0  }, /* same resolution for both X and Y */
+    { {  33, 1 }, {  55, 1 }, 2,  33.0,  55.0,     0,      0  }, /* different resolutions for X and Y */
+    { {  50, 2 }, {  66, 3 }, 2,  25.0,  22.0,     0,      0  }, /* denominator != 1 */
+
+    { { 100, 1 }, { 200, 1 }, 3, 254.0, 508.0,     0,      0  }, /* unit = centimeters */
+
+    /* XP and Server 2003 do not discard both resolution values if only one of them is invalid */
+    { {   0, 1 }, {  29, 1 }, 2,  96.0,  96.0,     0,   29.0  }, /* resolution 0 */
+    { {  58, 1 }, {  29, 0 }, 2,  96.0,  96.0,  58.0,      0  }, /* denominator 0 (division by zero) */
+
+    /* XP and Server 2003 return 96 dots per centimeter (= 243.84 dpi) as fallback value */
+    { {   0, 1 }, { 100, 1 }, 3,  96.0,  96.0, 243.84, 254.0  }, /* resolution 0 and unit = centimeters */
+    { {  50, 1 }, {  72, 0 }, 3,  96.0,  96.0, 127.0,  243.84 }  /* denominator 0 and unit = centimeters */
+};
+
+static struct tiff_resolution_image_data
+{
+    USHORT byte_order;
+    USHORT version;
+    ULONG dir_offset;
+    USHORT number_of_entries;
+    struct IFD_entry entry[13];
+    ULONG next_IFD;
+    struct IFD_rational resx;
+    struct IFD_rational resy;
+    BYTE pixel_data[4];
+} tiff_resolution_image_data =
+{
+#ifdef WORDS_BIGENDIAN
+    'M' | 'M' << 8,
+#else
+    'I' | 'I' << 8,
+#endif
+    42,
+    FIELD_OFFSET(struct tiff_resolution_image_data, number_of_entries),
+    13,
+    {
+        { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */
+        { 0x100, IFD_LONG, 1, 1 }, /* IMAGEWIDTH */
+        { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */
+        { 0x102, IFD_SHORT, 1, 1 }, /* BITSPERSAMPLE */
+        { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
+        { 0x106, IFD_SHORT, 1, 1 }, /* PHOTOMETRIC */
+        { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_resolution_image_data, pixel_data) }, /* STRIPOFFSETS */
+        { 0x115, IFD_SHORT, 1, 1 }, /* SAMPLESPERPIXEL */
+        { 0x116, IFD_LONG, 1, 1 }, /* ROWSPERSTRIP */
+        { 0x117, IFD_LONG, 1, 1 }, /* STRIPBYTECOUNT */
+        { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_resolution_image_data, resx) }, /* XRESOLUTION */
+        { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_resolution_image_data, resy) }, /* YRESOLUTION */
+        { 0x128, IFD_SHORT, 1, 1 }, /* RESOLUTIONUNIT -- value will be filled with test data */
+    },
+    0,
+    { 72, 1 }, /* value will be filled with test data */
+    { 72, 1 }, /* value will be filled with test data */
+    { 0x11, 0x22, 0x33, 0 }
+};
 #include "poppack.h"
 
 static IWICImagingFactory *factory;
@@ -152,29 +278,96 @@ static IStream *create_stream(const void *data, int data_size)
     return stream;
 }
 
-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;
     IStream *stream;
-    IWICBitmapDecoder *decoder = NULL;
-    GUID guid;
+    GUID format;
+    LONG refcount;
 
-    stream = create_stream(image_data, image_size);
+    *decoder = NULL;
 
-    hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
-    ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
-    if (FAILED(hr)) return NULL;
+    hmem = GlobalAlloc(0, image_size);
+    data = GlobalLock(hmem);
+    memcpy(data, image_data, image_size);
+    GlobalUnlock(hmem);
 
-    hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guid);
-    ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
-    ok(IsEqualGUID(&guid, &GUID_ContainerFormatTiff), "container format is not TIFF\n");
+    hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
+    ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
 
-    IStream_Release(stream);
+    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_ContainerFormatTiff),
+           "wrong container format %s\n", wine_dbgstr_guid(&format));
 
-    return decoder;
+        refcount = IStream_Release(stream);
+        ok(refcount > 0, "expected stream refcount > 0\n");
+    }
+
+    return hr;
 }
 
-static void test_tiff_palette(void)
+static HRESULT get_pixelformat_info(const GUID *format, UINT *bpp, UINT *channels, BOOL *trasparency)
+{
+    HRESULT hr;
+    IWICComponentInfo *info;
+    IWICPixelFormatInfo2 *formatinfo;
+
+    hr = IWICImagingFactory_CreateComponentInfo(factory, format, &info);
+    ok(hr == S_OK, "CreateComponentInfo(%s) error %#x\n", wine_dbgstr_guid(format), hr);
+    if (hr == S_OK)
+    {
+        hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo2, (void **)&formatinfo);
+        if (hr == S_OK)
+        {
+            hr = IWICPixelFormatInfo2_SupportsTransparency(formatinfo, trasparency);
+            ok(hr == S_OK, "SupportsTransparency error %#x\n", hr);
+            IWICPixelFormatInfo2_Release(formatinfo);
+        }
+        hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo, (void **)&formatinfo);
+        if (hr == S_OK)
+        {
+            hr = IWICPixelFormatInfo2_GetBitsPerPixel(formatinfo, bpp);
+            ok(hr == S_OK, "GetBitsPerPixel error %#x\n", hr);
+            hr = IWICPixelFormatInfo2_GetChannelCount(formatinfo, channels);
+            ok(hr == S_OK, "GetChannelCount error %#x\n", hr);
+            IWICPixelFormatInfo2_Release(formatinfo);
+        }
+        IWICComponentInfo_Release(info);
+    }
+    return hr;
+}
+
+static void dump_tiff(void *buf)
+{
+    UINT count, i;
+    struct tiff_1bpp_data *tiff;
+    struct IFD_entry *tag;
+
+    tiff = buf;
+    count = *(short *)((char *)tiff + tiff->dir_offset);
+    tag = (struct IFD_entry *)((char *)tiff + tiff->dir_offset + sizeof(short));
+
+    for (i = 0; i < count; i++)
+    {
+        printf("tag %u: id %04x, type %04x, count %u, value %d",
+                i, tag[i].id, tag[i].type, tag[i].count, tag[i].value);
+        if (tag[i].id == 0x102 && tag[i].count > 2)
+        {
+            short *bps = (short *)((char *)tiff + tag[i].value);
+            printf(" (%d,%d,%d,%d)\n", bps[0], bps[1], bps[2], bps[3]);
+        }
+        else
+            printf("\n");
+    }
+}
+
+static void test_tiff_1bpp_palette(void)
 {
     HRESULT hr;
     IWICBitmapDecoder *decoder;
@@ -182,9 +375,9 @@ static void test_tiff_palette(void)
     IWICPalette *palette;
     GUID format;
 
-    decoder = create_decoder(&tiff_1bpp_data, sizeof(tiff_1bpp_data));
-    ok(decoder != 0, "Failed to load TIFF image data\n");
-    if (!decoder) return;
+    hr = create_decoder(&tiff_1bpp_data, sizeof(tiff_1bpp_data), &decoder);
+    ok(hr == S_OK, "Failed to load TIFF 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);
@@ -316,9 +509,9 @@ static void test_tiff_8bpp_alpha(void)
     static const BYTE expected_data[16] = { 0x11,0x11,0x11,0x22,0x33,0x33,0x33,0x44,
                                             0x55,0x55,0x55,0x66,0x77,0x77,0x77,0x88 };
 
-    decoder = create_decoder(&tiff_8bpp_alpha, sizeof(tiff_8bpp_alpha));
-    ok(decoder != 0, "Failed to load TIFF image data\n");
-    if (!decoder) return;
+    hr = create_decoder(&tiff_8bpp_alpha, sizeof(tiff_8bpp_alpha), &decoder);
+    ok(hr == S_OK, "Failed to load TIFF image data %#x\n", hr);
+    if (hr != S_OK) return;
 
     hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
     ok(hr == S_OK, "GetFrameCount error %#x\n", hr);
@@ -363,6 +556,516 @@ static void test_tiff_8bpp_alpha(void)
     IWICBitmapDecoder_Release(decoder);
 }
 
+static void generate_tiff_palette(void *buf, unsigned count)
+{
+    unsigned short *r, *g, *b;
+    unsigned i;
+
+    r = buf;
+    g = r + count;
+    b = g + count;
+
+    r[0] = 0x11 * 257;
+    g[0] = 0x22 * 257;
+    b[0] = 0x33 * 257;
+    r[1] = 0x44 * 257;
+    g[1] = 0x55 * 257;
+    b[1] = 0x66 * 257;
+    r[2] = 0x77 * 257;
+    g[2] = 0x88 * 257;
+    b[2] = 0x99 * 257;
+    r[3] = 0xa1 * 257;
+    g[3] = 0xb5 * 257;
+    b[3] = 0xff * 257;
+
+    for (i = 4; i < count; i++)
+    {
+        r[i] = i * 257;
+        g[i] = (i | 0x40) * 257;
+        b[i] = (i | 0x80) * 257;
+    }
+}
+
+static void test_tiff_8bpp_palette(void)
+{
+    char buf[sizeof(tiff_8bpp_data)];
+    HRESULT hr;
+    IWICBitmapDecoder *decoder;
+    IWICBitmapFrameDecode *frame;
+    IWICPalette *palette;
+    GUID format;
+    UINT count, ret;
+    WICColor color[256];
+
+    memcpy(buf, &tiff_8bpp_data, sizeof(tiff_8bpp_data));
+    generate_tiff_palette(buf + FIELD_OFFSET(struct tiff_8bpp_data, palette_data), 256);
+
+    hr = create_decoder(buf, sizeof(buf), &decoder);
+    ok(hr == S_OK, "Failed to load TIFF 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);
+
+    hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
+    ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
+    ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
+       "expected GUID_WICPixelFormat8bppIndexed, got %s\n", wine_dbgstr_guid(&format));
+
+    hr = IWICImagingFactory_CreatePalette(factory, &palette);
+    ok(hr == S_OK, "CreatePalette error %#x\n", hr);
+    hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
+    ok(hr == S_OK, "CopyPalette error %#x\n", hr);
+
+    hr = IWICPalette_GetColorCount(palette, &count);
+    ok(hr == S_OK, "GetColorCount error %#x\n", hr);
+    ok(count == 256, "expected 256, got %u\n", count);
+
+    hr = IWICPalette_GetColors(palette, 256, color, &ret);
+    ok(hr == S_OK, "GetColors error %#x\n", hr);
+    ok(ret == count, "expected %u, got %u\n", count, ret);
+    ok(color[0] == 0xff112233, "got %#x\n", color[0]);
+    ok(color[1] == 0xff445566, "got %#x\n", color[1]);
+    ok(color[2] == 0xff778899, "got %#x\n", color[2]);
+    ok(color[3] == 0xffa1b5ff, "got %#x\n", color[3]);
+
+    IWICPalette_Release(palette);
+    IWICBitmapFrameDecode_Release(frame);
+    IWICBitmapDecoder_Release(decoder);
+}
+
+static void test_tiff_resolution(void)
+{
+    HRESULT hr;
+    IWICBitmapDecoder *decoder;
+    IWICBitmapFrameDecode *frame;
+    double dpi_x, dpi_y;
+    int i;
+
+    for (i = 0; i < sizeof(tiff_resolution_test_data)/sizeof(tiff_resolution_test_data[0]); i++)
+    {
+        const struct tiff_resolution_test_data *test_data = &tiff_resolution_test_data[i];
+        tiff_resolution_image_data.resx = test_data->resx;
+        tiff_resolution_image_data.resy = test_data->resy;
+        tiff_resolution_image_data.entry[12].value = test_data->resolution_unit;
+
+        hr = create_decoder(&tiff_resolution_image_data, sizeof(tiff_resolution_image_data), &decoder);
+        ok(hr == S_OK, "Failed to load TIFF image data %#x\n", hr);
+        if (hr != S_OK) return;
+
+        hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
+        ok(hr == S_OK, "%d: GetFrame error %#x\n", i, hr);
+
+        hr = IWICBitmapFrameDecode_GetResolution(frame, &dpi_x, &dpi_y);
+        ok(hr == S_OK, "%d: GetResolution error %#x\n", i, hr);
+
+        if (test_data->broken_dpi_x != 0)
+        {
+            ok(fabs(dpi_x - test_data->expected_dpi_x) < 0.01 || broken(fabs(dpi_x - test_data->broken_dpi_x) < 0.01),
+                "%d: x: expected %f or %f, got %f\n", i, test_data->expected_dpi_x, test_data->broken_dpi_x, dpi_x);
+        }
+        else
+        {
+            ok(fabs(dpi_x - test_data->expected_dpi_x) < 0.01,
+                "%d: x: expected %f, got %f\n", i, test_data->expected_dpi_x, dpi_x);
+        }
+
+        if (test_data->broken_dpi_y != 0)
+        {
+            ok(fabs(dpi_y - test_data->expected_dpi_y) < 0.01 || broken(fabs(dpi_y - test_data->broken_dpi_y) < 0.01),
+                "%d: y: expected %f or %f, got %f\n", i, test_data->expected_dpi_y, test_data->broken_dpi_y, dpi_y);
+        }
+        else
+        {
+            ok(fabs(dpi_y - test_data->expected_dpi_y) < 0.01,
+                "%d: y: expected %f, got %f\n", i, test_data->expected_dpi_y, dpi_y);
+        }
+
+        IWICBitmapFrameDecode_Release(frame);
+        IWICBitmapDecoder_Release(decoder);
+    }
+}
+
+#include "pshpack2.h"
+static const struct tiff_1x1_data
+{
+    USHORT byte_order;
+    USHORT version;
+    ULONG  dir_offset;
+    USHORT number_of_entries;
+    struct IFD_entry entry[12];
+    ULONG next_IFD;
+    struct IFD_rational res;
+    short palette_data[3][256];
+    short bps_data[4];
+    BYTE pixel_data[32];
+} tiff_1x1_data =
+{
+#ifdef WORDS_BIGENDIAN
+    'M' | 'M' << 8,
+#else
+    'I' | 'I' << 8,
+#endif
+    42,
+    FIELD_OFFSET(struct tiff_1x1_data, number_of_entries),
+    12,
+    {
+        { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */
+        { 0x100, IFD_LONG, 1, 1 }, /* IMAGEWIDTH */
+        { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */
+        { 0x102, IFD_SHORT, 3, FIELD_OFFSET(struct tiff_1x1_data, bps_data) }, /* BITSPERSAMPLE */
+        { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
+        { 0x106, IFD_SHORT, 1, 2 }, /* PHOTOMETRIC */
+        { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_1x1_data, pixel_data) }, /* STRIPOFFSETS */
+        { 0x115, IFD_SHORT, 1, 3 }, /* SAMPLESPERPIXEL */
+        { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1x1_data, res) },
+        { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1x1_data, res) },
+        { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */
+        { 0x140, IFD_SHORT, 256*3, FIELD_OFFSET(struct tiff_1x1_data, palette_data) } /* COLORMAP */
+    },
+    0,
+    { 96, 1 },
+    { { 0 } },
+    { 8,8,8,0 },
+    { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 }
+};
+#include "poppack.h"
+
+static UINT width_bytes(UINT width, UINT bpp)
+{
+    return (width * bpp + 7) / 8;
+}
+
+static void test_color_formats(void)
+{
+    struct bitmap_data
+    {
+        UINT bpp;
+        UINT width;
+        UINT height;
+        const WICPixelFormatGUID *format;
+        const BYTE *bits;
+    };
+    static const BYTE bits_1bpsBGR[] = { 0,255,0,255,0,255,255,255,0,0,0,255,255,0,0,0,255,255,255,255,255,0,0,0,0,255,0,255,0,255 };
+    static const struct bitmap_data data_1bpsBGR =
+    {
+        24, 10, 2, &GUID_WICPixelFormat24bppBGR, bits_1bpsBGR
+    };
+    static const BYTE bits_4bpsBGR[] = { 204,85,85,136,187,51,0,85,85,85,0,68,0,102,0,136,0,119,0,153,0 };
+    static const struct bitmap_data data_4bpsBGR =
+    {
+        24, 5, 2, &GUID_WICPixelFormat24bppBGR, bits_4bpsBGR
+    };
+    static const BYTE bits_8bpsBGR[] = { 2,0,1,5,4,3,8,7,6 };
+    static const struct bitmap_data data_8bpsBGR =
+    {
+        24, 3, 1, &GUID_WICPixelFormat24bppBGR, bits_8bpsBGR
+    };
+    static const BYTE bits_48bppRGB[] = { 1,0,2,3,4,5,6,7,8,9,0,1 };
+    static const struct bitmap_data data_48bppRGB =
+    {
+        48, 2, 1, &GUID_WICPixelFormat48bppRGB, bits_48bppRGB
+    };
+    static const BYTE bits_1bpsBGRA[] = { 0,255,0,255,0,255,0,255,0,255,255,0,255,0,0,255,255,0,255,255,0,0,255,0,0,255,0,255,0,255,0,255,0,0,0,0,0,255,0,0 };
+    static const struct bitmap_data data_1bpsBGRA =
+    {
+        32, 5, 2, &GUID_WICPixelFormat32bppBGRA, bits_1bpsBGRA
+    };
+    static const BYTE bits_4bpsBGRA[] = { 204,85,85,51,85,136,187,85,0,68,0,85,0,102,0,119,0,136,0,153,0,0,0,17,0,34,0,51 };
+    static const struct bitmap_data data_4bpsBGRA =
+    {
+        32, 5, 2, &GUID_WICPixelFormat32bppBGRA, bits_4bpsBGRA
+    };
+    static const BYTE bits_8bpsBGRA[] = { 2,0,1,3,6,5,4,7,0,9,8,1,4,3,2,5 };
+    static const struct bitmap_data data_8bpsBGRA =
+    {
+        32, 4, 1, &GUID_WICPixelFormat32bppBGRA, bits_8bpsBGRA
+    };
+    static const BYTE bits_64bppRGBA[] = { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 };
+    static const struct bitmap_data data_64bppRGBA =
+    {
+        64, 2, 1, &GUID_WICPixelFormat64bppRGBA, bits_64bppRGBA
+    };
+    static const BYTE bits_BlackWhite[] = { 85,195,184,85 };
+    static const struct bitmap_data data_BlackWhite =
+    {
+        1, 30, 1, &GUID_WICPixelFormatBlackWhite, bits_BlackWhite
+    };
+    static const BYTE bits_BlackWhite_xp[] = { 85,195,184,84 };
+    static const struct bitmap_data data_BlackWhite_xp =
+    {
+        1, 30, 1, &GUID_WICPixelFormatBlackWhite, bits_BlackWhite_xp
+    };
+    static const BYTE bits_4bppGray[] = { 85,195,184,85 };
+    static const struct bitmap_data data_4bppGray =
+    {
+        4, 7, 1, &GUID_WICPixelFormat4bppGray, bits_4bppGray
+    };
+    static const BYTE bits_4bppGray_xp[] = { 85,195,184,80 };
+    static const struct bitmap_data data_4bppGray_xp =
+    {
+        4, 7, 1, &GUID_WICPixelFormat4bppGray, bits_4bppGray_xp
+    };
+    static const BYTE bits_8bppGray[] = { 1,0,2,3,4,5,6,7,8,9 };
+    static const struct bitmap_data data_8bppGray =
+    {
+        8, 10, 1, &GUID_WICPixelFormat8bppGray, bits_8bppGray
+    };
+    static const BYTE bits_16bppGray[] = { 1,0,2,3,4,5 };
+    static const struct bitmap_data data_16bppGray =
+    {
+        16, 3, 1, &GUID_WICPixelFormat16bppGray, bits_16bppGray
+    };
+    static const BYTE bits_32bppGrayFloat[] = { 1,0,2,3,4,5,6,7,8,9,0,1 };
+    static const struct bitmap_data data_32bppGrayFloat =
+    {
+        32, 3, 1, &GUID_WICPixelFormat32bppGrayFloat, bits_32bppGrayFloat
+    };
+#if 0 /* FIXME */
+    static const BYTE bits_96bpp3Channels[] = { 0 };
+    static const struct bitmap_data data_96bpp3Channels =
+    {
+        64, 1, 1, &GUID_WICPixelFormat96bpp3Channels, bits_96bpp3Channels
+    };
+#endif
+    static const BYTE bits_128bppRGBAFloat[] = { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 };
+    static const struct bitmap_data data_128bppRGBAFloat =
+    {
+        128, 1, 1, &GUID_WICPixelFormat128bppRGBAFloat, bits_128bppRGBAFloat
+    };
+    static const BYTE bits_1bppIndexed[] = { 85,195,184,85 };
+    static const struct bitmap_data data_1bppIndexed =
+    {
+        1, 32, 1, &GUID_WICPixelFormat1bppIndexed, bits_1bppIndexed
+    };
+    static const BYTE bits_4bppIndexed[] = { 85,195,184,85 };
+    static const struct bitmap_data data_4bppIndexed =
+    {
+        4, 7, 1, &GUID_WICPixelFormat4bppIndexed, bits_4bppIndexed
+    };
+    static const BYTE bits_4bppIndexed_xp[] = { 85,195,184,80 };
+    static const struct bitmap_data data_4bppIndexed_xp =
+    {
+        4, 7, 1, &GUID_WICPixelFormat4bppIndexed, bits_4bppIndexed_xp
+    };
+    static const BYTE bits_8bppIndexed[] = { 1,0,2,3,4,5,6,7,8,9 };
+    static const struct bitmap_data data_8bppIndexed =
+    {
+        8, 3, 1, &GUID_WICPixelFormat8bppIndexed, bits_8bppIndexed
+    };
+    static const BYTE bits_32bppCMYK[] = { 1,0,2,3,4,5,6,7,8,9,0,1 };
+    static const struct bitmap_data data_32bppCMYK =
+    {
+        32, 3, 1, &GUID_WICPixelFormat32bppCMYK, bits_32bppCMYK
+    };
+    static const BYTE bits_64bppCMYK[] = { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 };
+    static const struct bitmap_data data_64bppCMYK =
+    {
+        64, 2, 1, &GUID_WICPixelFormat64bppCMYK, bits_64bppCMYK
+    };
+    static const struct
+    {
+        int photometric; /* PhotometricInterpretation */
+        int samples; /* SamplesPerPixel */
+        int bps; /* BitsPerSample */
+        const struct bitmap_data *data;
+        const struct bitmap_data *alt_data;
+    } td[] =
+    {
+        /* 2 - RGB */
+        { 2, 3, 1, &data_1bpsBGR },
+        { 2, 3, 4, &data_4bpsBGR },
+        { 2, 3, 8, &data_8bpsBGR },
+        { 2, 3, 16, &data_48bppRGB },
+        { 2, 3, 24, NULL },
+#if 0 /* FIXME */
+        { 2, 3, 32, &data_96bpp3Channels },
+#endif
+        { 2, 4, 1, &data_1bpsBGRA },
+        { 2, 4, 4, &data_4bpsBGRA },
+        { 2, 4, 8, &data_8bpsBGRA },
+        { 2, 4, 16, &data_64bppRGBA },
+        { 2, 4, 24, NULL },
+        { 2, 4, 32, &data_128bppRGBAFloat },
+        /* 1 - BlackIsZero (Bilevel) */
+        { 1, 1, 1, &data_BlackWhite, &data_BlackWhite_xp },
+        { 1, 1, 4, &data_4bppGray, &data_4bppGray_xp },
+        { 1, 1, 8, &data_8bppGray },
+        { 1, 1, 16, &data_16bppGray },
+        { 1, 1, 24, NULL },
+        { 1, 1, 32, &data_32bppGrayFloat },
+        /* 3 - Palette Color */
+        { 3, 1, 1, &data_1bppIndexed },
+        { 3, 1, 4, &data_4bppIndexed, &data_4bppIndexed_xp },
+        { 3, 1, 8, &data_8bppIndexed },
+#if 0 /* FIXME: for some reason libtiff replaces photometric 3 by 1 for bps > 8 */
+        { 3, 1, 16, &data_8bppIndexed },
+        { 3, 1, 24, &data_8bppIndexed },
+        { 3, 1, 32, &data_8bppIndexed },
+#endif
+        /* 5 - Separated */
+        { 5, 4, 1, NULL },
+        { 5, 4, 4, NULL },
+        { 5, 4, 8, &data_32bppCMYK },
+        { 5, 4, 16, &data_64bppCMYK },
+        { 5, 4, 24, NULL },
+        { 5, 4, 32, NULL },
+    };
+    BYTE buf[sizeof(tiff_1x1_data)];
+    BYTE pixels[256];
+    HRESULT hr;
+    IWICBitmapDecoder *decoder;
+    IWICBitmapFrameDecode *frame;
+    GUID format;
+    UINT count, i, bpp, channels, ret;
+    BOOL trasparency;
+    struct IFD_entry *tag, *tag_photo = NULL, *tag_bps = NULL, *tag_samples = NULL, *tag_colormap = NULL;
+    struct IFD_entry *tag_width = NULL, *tag_height = NULL;
+    short *bps;
+
+    memcpy(buf, &tiff_1x1_data, sizeof(tiff_1x1_data));
+    generate_tiff_palette(buf + FIELD_OFFSET(struct tiff_1x1_data, palette_data), 256);
+
+    count = *(short *)(buf + tiff_1x1_data.dir_offset);
+    tag = (struct IFD_entry *)(buf + tiff_1x1_data.dir_offset + sizeof(short));
+
+    /* verify the TIFF structure */
+    for (i = 0; i < count; i++)
+    {
+        if (tag[i].id == 0x100) /* ImageWidth */
+            tag_width = &tag[i];
+        else if (tag[i].id == 0x101) /* ImageLength */
+            tag_height = &tag[i];
+        else if (tag[i].id == 0x102) /* BitsPerSample */
+            tag_bps = &tag[i];
+        else if (tag[i].id == 0x106) /* PhotometricInterpretation */
+            tag_photo = &tag[i];
+        else if (tag[i].id == 0x115) /* SamplesPerPixel */
+            tag_samples = &tag[i];
+        else if (tag[i].id == 0x140) /* ColorMap */
+            tag_colormap = &tag[i];
+    }
+
+    ok(tag_bps && tag_photo && tag_samples && tag_colormap, "tag 0x102,0x106,0x115 or 0x140 is missing\n");
+    if (!tag_bps || !tag_photo || !tag_samples || !tag_colormap) return;
+
+    ok(tag_bps->type == IFD_SHORT, "tag 0x102 should have type IFD_SHORT\n");
+    bps = (short *)(buf + tag_bps->value);
+    ok(bps[0] == 8 && bps[1] == 8 && bps[2] == 8 && bps[3] == 0,
+       "expected bps 8,8,8,0 got %d,%d,%d,%d\n", bps[0], bps[1], bps[2], bps[3]);
+
+    for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
+    {
+        if (td[i].data)
+        {
+            bpp = td[i].samples * td[i].bps;
+            if (winetest_debug > 1)
+                trace("samples %u, bps %u, bpp %u, width %u => width_bytes %u\n", td[i].samples, td[i].bps, bpp,
+                      td[i].data->width, width_bytes(td[i].data->width, bpp));
+            tag_width->value = td[i].data->width;
+            tag_height->value = td[i].data->height;
+        }
+        else
+        {
+            tag_width->value = 1;
+            tag_height->value = 1;
+        }
+
+        tag_colormap->count = (1 << td[i].bps) * 3;
+
+        if (td[i].bps < 8)
+        {
+            buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data)] = 0x55;
+            buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 1] = 0xc3;
+            buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 2] = 0xb8;
+            buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 3] = 0x55;
+        }
+        else
+        {
+            buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data)] = 1;
+            buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 1] = 0;
+            buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 2] = 2;
+            buf[FIELD_OFFSET(struct tiff_1x1_data, pixel_data) + 3] = 3;
+        }
+
+        tag_photo->value = td[i].photometric;
+        tag_bps->count = td[i].samples;
+        tag_samples->value = td[i].samples;
+
+        if (td[i].samples == 1)
+            tag_bps->value = td[i].bps;
+        else if (td[i].samples == 2)
+            tag_bps->value = MAKELONG(td[i].bps, td[i].bps);
+        else if (td[i].samples == 3)
+        {
+            tag_bps->value = (BYTE *)bps - buf;
+            bps[0] = bps[1] = bps[2] = td[i].bps;
+        }
+        else if (td[i].samples == 4)
+        {
+            tag_bps->value = (BYTE *)bps - buf;
+            bps[0] = bps[1] = bps[2] = bps[3] = td[i].bps;
+        }
+        else
+        {
+            ok(0, "%u: unsupported samples count %d\n", i, td[i].samples);
+            continue;
+        }
+
+        hr = create_decoder(buf, sizeof(buf), &decoder);
+        if (!td[i].data)
+        {
+            ok(hr == WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT || hr == WINCODEC_ERR_COMPONENTNOTFOUND /* win8+ */ || WINCODEC_ERR_BADIMAGE /* XP */,
+               "%u: (%d,%d,%d) wrong error %#x\n", i, td[i].photometric, td[i].samples, td[i].bps, hr);
+            if (hr == S_OK)
+            {
+                IWICBitmapDecoder_Release(decoder);
+                dump_tiff(buf);
+            }
+            continue;
+        }
+        else
+            ok(hr == S_OK || broken(hr == WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT || hr == WINCODEC_ERR_BADIMAGE) /* XP */,
+               "%u: failed to load TIFF image data (%d,%d,%d) %#x\n",
+               i, td[i].photometric, td[i].samples, td[i].bps, hr);
+        if (hr != S_OK) continue;
+
+        hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
+        ok(hr == S_OK, "%u: GetFrame error %#x\n", i, hr);
+
+        hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
+        ok(hr == S_OK, "%u: GetPixelFormat error %#x\n", i, hr);
+        ok(IsEqualGUID(&format, td[i].data->format),
+           "%u (%d,%d,%d): expected %s, got %s\n",
+            i, td[i].photometric, td[i].samples, td[i].bps,
+            wine_dbgstr_guid(td[i].data->format), wine_dbgstr_guid(&format));
+
+        trasparency = (td[i].photometric == 2 && td[i].samples == 4); /* for XP */
+        hr = get_pixelformat_info(&format, &bpp, &channels, &trasparency);
+        ok(hr == S_OK, "%u: get_pixelformat_bpp error %#x\n", i, hr);
+        ok(bpp == td[i].data->bpp, "%u: expected %u, got %u\n", i, td[i].data->bpp, bpp);
+        ok(channels == td[i].samples, "%u: expected %u, got %u\n", i, td[i].samples, channels);
+        ok(trasparency == (td[i].photometric == 2 && td[i].samples == 4), "%u: got %u\n", i, trasparency);
+
+        memset(pixels, 0, sizeof(pixels));
+        hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, width_bytes(td[i].data->width, bpp), sizeof(pixels), pixels);
+        ok(hr == S_OK, "%u: CopyPixels error %#x\n", i, hr);
+        ret = memcmp(pixels, td[i].data->bits, width_bytes(td[i].data->width, bpp));
+        if (ret && td[i].alt_data)
+            ret = memcmp(pixels, td[i].alt_data->bits, width_bytes(td[i].data->width, bpp));
+        ok(ret == 0, "%u: (%d,%d,%d) wrong pixel data\n", i, td[i].photometric, td[i].samples, td[i].bps);
+        if (ret)
+        {
+            UINT j, n = width_bytes(td[i].data->width, bpp);
+            for (j = 0; j < n; j++)
+                printf("%u%s", pixels[j], (j + 1) < n ? "," : "\n");
+        }
+
+        IWICBitmapFrameDecode_Release(frame);
+        IWICBitmapDecoder_Release(decoder);
+    }
+}
+
 START_TEST(tiffformat)
 {
     HRESULT hr;
@@ -374,9 +1077,12 @@ START_TEST(tiffformat)
     ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
     if (FAILED(hr)) return;
 
-    test_tiff_palette();
+    test_color_formats();
+    test_tiff_1bpp_palette();
+    test_tiff_8bpp_palette();
     test_QueryCapability();
     test_tiff_8bpp_alpha();
+    test_tiff_resolution();
 
     IWICImagingFactory_Release(factory);
     CoUninitialize();