windowscodecs: Add more tests for PNG metadata.
[wine/multimedia.git] / dlls / windowscodecs / tests / tiffformat.c
blob0874053a046d9dae2191c857f771ccca539f0c22
1 /*
2 * Copyright 2012 Dmitry Timoshkov
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <stdio.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "wincodec.h"
26 #include "wine/test.h"
28 #define IFD_BYTE 1
29 #define IFD_ASCII 2
30 #define IFD_SHORT 3
31 #define IFD_LONG 4
32 #define IFD_RATIONAL 5
33 #define IFD_SBYTE 6
34 #define IFD_UNDEFINED 7
35 #define IFD_SSHORT 8
36 #define IFD_SLONG 9
37 #define IFD_SRATIONAL 10
38 #define IFD_FLOAT 11
39 #define IFD_DOUBLE 12
41 #include "pshpack2.h"
42 struct IFD_entry
44 SHORT id;
45 SHORT type;
46 ULONG count;
47 LONG value;
50 struct IFD_rational
52 LONG numerator;
53 LONG denominator;
56 static const struct tiff_1bpp_data
58 USHORT byte_order;
59 USHORT version;
60 ULONG dir_offset;
61 USHORT number_of_entries;
62 struct IFD_entry entry[13];
63 ULONG next_IFD;
64 struct IFD_rational res;
65 BYTE pixel_data[4];
66 } tiff_1bpp_data =
68 #ifdef WORDS_BIGENDIAN
69 'M' | 'M' << 8,
70 #else
71 'I' | 'I' << 8,
72 #endif
73 42,
74 FIELD_OFFSET(struct tiff_1bpp_data, number_of_entries),
75 13,
77 { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */
78 { 0x100, IFD_LONG, 1, 1 }, /* IMAGEWIDTH */
79 { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */
80 { 0x102, IFD_SHORT, 1, 1 }, /* BITSPERSAMPLE */
81 { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
82 { 0x106, IFD_SHORT, 1, 1 }, /* PHOTOMETRIC */
83 { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_1bpp_data, pixel_data) }, /* STRIPOFFSETS */
84 { 0x115, IFD_SHORT, 1, 1 }, /* SAMPLESPERPIXEL */
85 { 0x116, IFD_LONG, 1, 1 }, /* ROWSPERSTRIP */
86 { 0x117, IFD_LONG, 1, 1 }, /* STRIPBYTECOUNT */
87 { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1bpp_data, res) },
88 { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1bpp_data, res) },
89 { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */
92 { 900, 3 },
93 { 0x11, 0x22, 0x33, 0 }
95 #include "poppack.h"
97 static const char *debugstr_guid(const GUID *guid)
99 static char buf[50];
101 if (!guid) return "(null)";
102 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
103 guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
104 guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
105 guid->Data4[5], guid->Data4[6], guid->Data4[7]);
106 return buf;
109 static IWICBitmapDecoder *create_decoder(IWICImagingFactory *factory,
110 const void *image_data, UINT image_size)
112 HGLOBAL hmem;
113 BYTE *data;
114 HRESULT hr;
115 IWICBitmapDecoder *decoder = NULL;
116 IStream *stream;
117 GUID guid;
119 hmem = GlobalAlloc(0, image_size);
120 data = GlobalLock(hmem);
121 memcpy(data, image_data, image_size);
122 GlobalUnlock(hmem);
124 hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
125 ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
127 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
128 ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
130 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guid);
131 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
132 ok(IsEqualGUID(&guid, &GUID_ContainerFormatTiff), "container format is not TIFF\n");
134 IStream_Release(stream);
136 return decoder;
139 static void test_tiff_palette(void)
141 HRESULT hr;
142 IWICImagingFactory *factory;
143 IWICBitmapDecoder *decoder;
144 IWICBitmapFrameDecode *frame;
145 IWICPalette *palette;
146 GUID format;
148 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
149 &IID_IWICImagingFactory, (void **)&factory);
150 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
151 if (FAILED(hr)) return;
153 decoder = create_decoder(factory, &tiff_1bpp_data, sizeof(tiff_1bpp_data));
154 ok(decoder != 0, "Failed to load TIFF image data\n");
155 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
156 ok(hr == S_OK, "GetFrame error %#x\n", hr);
158 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
159 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
160 ok(IsEqualGUID(&format, &GUID_WICPixelFormatBlackWhite),
161 "got wrong format %s\n", debugstr_guid(&format));
163 hr = IWICImagingFactory_CreatePalette(factory, &palette);
164 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
165 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
166 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE,
167 "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr);
169 IWICPalette_Release(palette);
170 IWICBitmapFrameDecode_Release(frame);
171 IWICBitmapDecoder_Release(decoder);
172 IWICImagingFactory_Release(factory);
175 START_TEST(tiffformat)
177 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
179 test_tiff_palette();
181 CoUninitialize();