[WINDOWSCODECS_WINETEST] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / rostests / winetests / windowscodecs / tiffformat.c
index a6d4915..d99c005 100644 (file)
@@ -98,7 +98,49 @@ static const struct tiff_1bpp_data
     { 900, 3 },
     { 0x11, 0x22, 0x33, 0 }
 };
-#include <poppack.h>
+
+static const struct tiff_8bpp_alpha
+{
+    USHORT byte_order;
+    USHORT version;
+    ULONG  dir_offset;
+    USHORT number_of_entries;
+    struct IFD_entry entry[15];
+    ULONG next_IFD;
+    struct IFD_rational res;
+    BYTE pixel_data[8];
+} tiff_8bpp_alpha =
+{
+#ifdef WORDS_BIGENDIAN
+    'M' | 'M' << 8,
+#else
+    'I' | 'I' << 8,
+#endif
+    42,
+    FIELD_OFFSET(struct tiff_8bpp_alpha, number_of_entries),
+    15,
+    {
+        { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */
+        { 0x100, IFD_LONG, 1, 2 }, /* IMAGEWIDTH */
+        { 0x101, IFD_LONG, 1, 2 }, /* IMAGELENGTH */
+        { 0x102, IFD_SHORT, 2, MAKELONG(8, 8) }, /* 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_8bpp_alpha, pixel_data) }, /* STRIPOFFSETS */
+        { 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) },
+        { 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 */
+    },
+    0,
+    { 96, 1 },
+    { 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88 }
+};
+#include "poppack.h"
 
 static IWICImagingFactory *factory;
 
@@ -134,6 +176,7 @@ static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size
 
     hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
     ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
+    if (FAILED(hr)) return NULL;
 
     hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guid);
     ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
@@ -154,6 +197,7 @@ static void test_tiff_palette(void)
 
     decoder = create_decoder(&tiff_1bpp_data, sizeof(tiff_1bpp_data));
     ok(decoder != 0, "Failed to load TIFF image data\n");
+    if (!decoder) return;
 
     hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
     ok(hr == S_OK, "GetFrame error %#x\n", hr);
@@ -195,6 +239,7 @@ static void test_QueryCapability(void)
 
     hr = IWICImagingFactory_CreateDecoder(factory, &GUID_ContainerFormatTiff, NULL, &decoder);
     ok(hr == S_OK, "CreateDecoder error %#x\n", hr);
+    if (FAILED(hr)) return;
 
     frame_count = 0xdeadbeef;
     hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
@@ -241,6 +286,9 @@ static void test_QueryCapability(void)
 todo_wine
     ok(hr == WINCODEC_ERR_COMPONENTNOTFOUND, "expected WINCODEC_ERR_COMPONENTNOTFOUND, got %#x\n", hr);
 
+    if (SUCCEEDED(hr))
+        IWICBitmapDecoder_Release(decoder);
+
     pos.QuadPart = 0;
     hr = IStream_Seek(stream, pos, SEEK_SET, NULL);
     ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
@@ -267,6 +315,67 @@ todo_wine
     IStream_Release(stream);
 }
 
+static void test_tiff_8bpp_alpha(void)
+{
+    HRESULT hr;
+    IWICBitmapDecoder *decoder;
+    IWICBitmapFrameDecode *frame;
+    UINT frame_count, width, height, i;
+    double dpi_x, dpi_y;
+    IWICPalette *palette;
+    GUID format;
+    WICRect rc;
+    BYTE data[16];
+    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 = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
+    ok(hr == S_OK, "GetFrameCount error %#x\n", hr);
+    ok(frame_count == 1, "expected 1, got %u\n", frame_count);
+
+    hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
+    ok(hr == S_OK, "GetFrame error %#x\n", hr);
+
+    hr = IWICBitmapFrameDecode_GetSize(frame, &width, &height);
+    ok(hr == S_OK, "GetSize error %#x\n", hr);
+    ok(width == 2, "expected 2, got %u\n", width);
+    ok(height == 2, "expected 2, got %u\n", height);
+
+    hr = IWICBitmapFrameDecode_GetResolution(frame, &dpi_x, &dpi_y);
+    ok(hr == S_OK, "GetResolution error %#x\n", hr);
+    ok(dpi_x == 96.0, "expected 96.0, got %f\n", dpi_x);
+    ok(dpi_y == 96.0, "expected 96.0, got %f\n", dpi_y);
+
+    hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
+    ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
+    ok(IsEqualGUID(&format, &GUID_WICPixelFormat32bppPBGRA),
+       "got wrong format %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 == WINCODEC_ERR_PALETTEUNAVAILABLE,
+       "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr);
+    IWICPalette_Release(palette);
+
+    rc.X = 0;
+    rc.Y = 0;
+    rc.Width = 2;
+    rc.Height = 2;
+    hr = IWICBitmapFrameDecode_CopyPixels(frame, &rc, 8, sizeof(data), data);
+    ok(hr == S_OK, "CopyPixels error %#x\n", hr);
+
+    for (i = 0; i < sizeof(data); i++)
+        ok(data[i] == expected_data[i], "%u: expected %02x, got %02x\n", i, expected_data[i], data[i]);
+
+    IWICBitmapFrameDecode_Release(frame);
+    IWICBitmapDecoder_Release(decoder);
+}
+
 START_TEST(tiffformat)
 {
     HRESULT hr;
@@ -280,6 +389,7 @@ START_TEST(tiffformat)
 
     test_tiff_palette();
     test_QueryCapability();
+    test_tiff_8bpp_alpha();
 
     IWICImagingFactory_Release(factory);
     CoUninitialize();