2 * Copyright 2011 Vincent Povirk for CodeWeavers
3 * Copyright 2012 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wincodecsdk.h"
31 #include "wine/test.h"
33 #define expect_blob(propvar, data, length) do { \
34 ok((propvar).vt == VT_BLOB, "unexpected vt: %i\n", (propvar).vt); \
35 if ((propvar).vt == VT_BLOB) { \
36 ok(U(propvar).blob.cbSize == (length), "expected size %u, got %u\n", (ULONG)(length), U(propvar).blob.cbSize); \
37 if (U(propvar).blob.cbSize == (length)) { \
38 ok(!memcmp(U(propvar).blob.pBlobData, (data), (length)), "unexpected data\n"); \
47 #define IFD_RATIONAL 5
49 #define IFD_UNDEFINED 7
52 #define IFD_SRATIONAL 10
72 static const struct ifd_data
74 USHORT number_of_entries;
75 struct IFD_entry entry[40];
77 struct IFD_rational xres;
79 struct IFD_rational srational_val;
84 struct IFD_rational rational[3];
89 { 0xfe, IFD_SHORT, 1, 1 }, /* NEWSUBFILETYPE */
90 { 0x100, IFD_LONG, 1, 222 }, /* IMAGEWIDTH */
91 { 0x101, IFD_LONG, 1, 333 }, /* IMAGELENGTH */
92 { 0x102, IFD_SHORT, 1, 24 }, /* BITSPERSAMPLE */
93 { 0x103, IFD_LONG, 1, 32773 }, /* COMPRESSION: packbits */
94 { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct ifd_data, xres) },
95 { 0xf001, IFD_BYTE, 1, 0x11223344 },
96 { 0xf002, IFD_BYTE, 4, 0x11223344 },
97 { 0xf003, IFD_SBYTE, 1, 0x11223344 },
98 { 0xf004, IFD_SSHORT, 1, 0x11223344 },
99 { 0xf005, IFD_SSHORT, 2, 0x11223344 },
100 { 0xf006, IFD_SLONG, 1, 0x11223344 },
101 { 0xf007, IFD_FLOAT, 1, 0x11223344 },
102 { 0xf008, IFD_DOUBLE, 1, FIELD_OFFSET(struct ifd_data, double_val) },
103 { 0xf009, IFD_SRATIONAL, 1, FIELD_OFFSET(struct ifd_data, srational_val) },
104 { 0xf00a, IFD_BYTE, 13, FIELD_OFFSET(struct ifd_data, string) },
105 { 0xf00b, IFD_SSHORT, 4, FIELD_OFFSET(struct ifd_data, short_val) },
106 { 0xf00c, IFD_SLONG, 2, FIELD_OFFSET(struct ifd_data, long_val) },
107 { 0xf00d, IFD_FLOAT, 2, FIELD_OFFSET(struct ifd_data, float_val) },
108 { 0xf00e, IFD_ASCII, 13, FIELD_OFFSET(struct ifd_data, string) },
109 { 0xf00f, IFD_ASCII, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
110 { 0xf010, IFD_UNDEFINED, 13, FIELD_OFFSET(struct ifd_data, string) },
111 { 0xf011, IFD_UNDEFINED, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
112 { 0xf012, IFD_BYTE, 0, 0x11223344 },
113 { 0xf013, IFD_SHORT, 0, 0x11223344 },
114 { 0xf014, IFD_LONG, 0, 0x11223344 },
115 { 0xf015, IFD_FLOAT, 0, 0x11223344 },
116 { 0xf016, IFD_SRATIONAL, 3, FIELD_OFFSET(struct ifd_data, rational) },
120 1234567890.0987654321,
121 { 0x1a2b3c4d, 0x5a6b7c8d },
123 { 0x0101, 0x0202, 0x0303, 0x0404 },
124 { 0x11223344, 0x55667788 },
125 { (FLOAT)1234.5678, (FLOAT)8765.4321 },
126 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } },
130 static const char metadata_unknown[] = "lalala";
132 static const char metadata_tEXt[] = {
133 0,0,0,14, /* chunk length */
134 't','E','X','t', /* chunk type */
135 'w','i','n','e','t','e','s','t',0, /* keyword */
136 'v','a','l','u','e', /* text */
137 0x3f,0x64,0x19,0xf3 /* chunk CRC */
140 static const char pngimage[285] = {
141 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
142 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
143 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
144 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
145 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
146 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
147 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
151 static const char gifimage[35] = {
152 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
153 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
157 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
158 static const char animatedgif[] = {
159 'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xA1,0x00,0x00,
160 0x6F,0x6F,0x6F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
161 /*0x21,0xFF,0x0B,'N','E','T','S','C','A','P','E','2','.','0',*/
162 0x21,0xFF,0x0B,'A','N','I','M','E','X','T','S','1','.','0',
163 0x03,0x01,0x05,0x00,0x00,
164 0x21,0xFE,0x0C,'H','e','l','l','o',' ','W','o','r','l','d','!',0x00,
165 0x21,0x01,0x0D,'a','n','i','m','a','t','i','o','n','.','g','i','f',0x00,
166 0x21,0xF9,0x04,0x00,0x0A,0x00,0xFF,0x00,0x2C,
167 0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
168 0xDE,0xDE,0xDE,0x00,0x00,0x00,
169 0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x4C,0x01,0x00,
170 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','1',0x00,
171 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','1',0x00,
172 0x21,0xF9,0x04,0x01,0x0A,0x00,0x01,0x00,0x2C,
173 0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
174 0x4D,0x4D,0x4D,0x00,0x00,0x00,
175 0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x44,0x01,0x00,
176 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','2',0x00,
177 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','2',0x00,0x3B
180 static const char *debugstr_guid(REFIID riid)
187 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
188 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
189 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
190 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
195 static IStream *create_stream(const char *data, int data_size)
202 hdata = GlobalAlloc(GMEM_MOVEABLE, data_size);
203 ok(hdata != 0, "GlobalAlloc failed\n");
204 if (!hdata) return NULL;
206 locked_data = GlobalLock(hdata);
207 memcpy(locked_data, data, data_size);
210 hr = CreateStreamOnHGlobal(hdata, TRUE, &stream);
211 ok(hr == S_OK, "CreateStreamOnHGlobal failed, hr=%x\n", hr);
216 static void load_stream(IUnknown *reader, const char *data, int data_size, DWORD persist_options)
219 IWICPersistStream *persist;
222 ULARGE_INTEGER cur_pos;
224 stream = create_stream(data, data_size);
228 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void**)&persist);
229 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
233 hr = IWICPersistStream_LoadEx(persist, stream, NULL, persist_options);
234 ok(hr == S_OK, "LoadEx failed, hr=%x\n", hr);
236 IWICPersistStream_Release(persist);
240 hr = IStream_Seek(stream, pos, SEEK_CUR, &cur_pos);
241 ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
242 /* IFD metadata reader doesn't rewind the stream to the start */
243 ok(cur_pos.QuadPart == 0 || cur_pos.QuadPart <= data_size,
244 "current stream pos is at %x/%x, data size %x\n", cur_pos.u.LowPart, cur_pos.u.HighPart, data_size);
246 IStream_Release(stream);
249 static void test_metadata_unknown(void)
252 IWICMetadataReader *reader;
253 IWICEnumMetadataItem *enumerator;
254 IWICMetadataBlockReader *blockreader;
255 PROPVARIANT schema, id, value;
256 ULONG items_returned;
258 hr = CoCreateInstance(&CLSID_WICUnknownMetadataReader, NULL, CLSCTX_INPROC_SERVER,
259 &IID_IWICMetadataReader, (void**)&reader);
260 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
261 if (FAILED(hr)) return;
263 load_stream((IUnknown*)reader, metadata_unknown, sizeof(metadata_unknown), WICPersistOptionsDefault);
265 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
266 ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr);
270 PropVariantInit(&schema);
271 PropVariantInit(&id);
272 PropVariantInit(&value);
274 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
275 ok(hr == S_OK, "Next failed, hr=%x\n", hr);
276 ok(items_returned == 1, "unexpected item count %i\n", items_returned);
278 if (hr == S_OK && items_returned == 1)
280 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
281 ok(id.vt == VT_EMPTY, "unexpected vt: %i\n", id.vt);
282 expect_blob(value, metadata_unknown, sizeof(metadata_unknown));
284 PropVariantClear(&schema);
285 PropVariantClear(&id);
286 PropVariantClear(&value);
289 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
290 ok(hr == S_FALSE, "Next failed, hr=%x\n", hr);
291 ok(items_returned == 0, "unexpected item count %i\n", items_returned);
293 IWICEnumMetadataItem_Release(enumerator);
296 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader);
297 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
300 IWICMetadataBlockReader_Release(blockreader);
302 IWICMetadataReader_Release(reader);
305 static void test_metadata_tEXt(void)
308 IWICMetadataReader *reader;
309 IWICEnumMetadataItem *enumerator;
310 PROPVARIANT schema, id, value;
311 ULONG items_returned, count;
314 PropVariantInit(&schema);
315 PropVariantInit(&id);
316 PropVariantInit(&value);
318 hr = CoCreateInstance(&CLSID_WICPngTextMetadataReader, NULL, CLSCTX_INPROC_SERVER,
319 &IID_IWICMetadataReader, (void**)&reader);
320 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
321 if (FAILED(hr)) return;
323 hr = IWICMetadataReader_GetCount(reader, NULL);
324 ok(hr == E_INVALIDARG, "GetCount failed, hr=%x\n", hr);
326 hr = IWICMetadataReader_GetCount(reader, &count);
327 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
328 ok(count == 0, "unexpected count %i\n", count);
330 load_stream((IUnknown*)reader, metadata_tEXt, sizeof(metadata_tEXt), WICPersistOptionsDefault);
332 hr = IWICMetadataReader_GetCount(reader, &count);
333 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
334 ok(count == 1, "unexpected count %i\n", count);
336 hr = IWICMetadataReader_GetEnumerator(reader, NULL);
337 ok(hr == E_INVALIDARG, "GetEnumerator failed, hr=%x\n", hr);
339 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
340 ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr);
344 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
345 ok(hr == S_OK, "Next failed, hr=%x\n", hr);
346 ok(items_returned == 1, "unexpected item count %i\n", items_returned);
348 if (hr == S_OK && items_returned == 1)
350 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
351 ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
352 ok(!strcmp(U(id).pszVal, "winetest"), "unexpected id: %s\n", U(id).pszVal);
353 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", value.vt);
354 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal);
356 PropVariantClear(&schema);
357 PropVariantClear(&id);
358 PropVariantClear(&value);
361 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
362 ok(hr == S_FALSE, "Next failed, hr=%x\n", hr);
363 ok(items_returned == 0, "unexpected item count %i\n", items_returned);
365 IWICEnumMetadataItem_Release(enumerator);
368 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
369 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
370 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", debugstr_guid(&format));
372 hr = IWICMetadataReader_GetMetadataFormat(reader, NULL);
373 ok(hr == E_INVALIDARG, "GetMetadataFormat failed, hr=%x\n", hr);
376 U(id).pszVal = CoTaskMemAlloc(strlen("winetest") + 1);
377 strcpy(U(id).pszVal, "winetest");
379 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL);
380 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
382 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, &value);
383 ok(hr == E_INVALIDARG, "GetValue failed, hr=%x\n", hr);
385 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
386 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
387 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
388 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal);
389 PropVariantClear(&value);
391 strcpy(U(id).pszVal, "test");
393 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
394 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "GetValue failed, hr=%x\n", hr);
396 PropVariantClear(&id);
398 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, NULL);
399 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
401 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, NULL, NULL);
402 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
403 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
405 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &id, NULL);
406 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
407 ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
408 ok(!strcmp(U(id).pszVal, "winetest"), "unexpected id: %s\n", U(id).pszVal);
409 PropVariantClear(&id);
411 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, &value);
412 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
413 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", value.vt);
414 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal);
415 PropVariantClear(&value);
417 hr = IWICMetadataReader_GetValueByIndex(reader, 1, NULL, NULL, NULL);
418 ok(hr == E_INVALIDARG, "GetValueByIndex failed, hr=%x\n", hr);
420 IWICMetadataReader_Release(reader);
423 static inline USHORT ushort_bswap(USHORT s)
425 return (s >> 8) | (s << 8);
428 static inline ULONG ulong_bswap(ULONG l)
430 return ((ULONG)ushort_bswap((USHORT)l) << 16) | ushort_bswap((USHORT)(l >> 16));
433 static inline ULONGLONG ulonglong_bswap(ULONGLONG ll)
435 return ((ULONGLONG)ulong_bswap((ULONG)ll) << 32) | ulong_bswap((ULONG)(ll >> 32));
438 static void byte_swap_ifd_data(char *data)
440 USHORT number_of_entries, i;
441 struct IFD_entry *entry;
442 char *data_start = data;
444 number_of_entries = *(USHORT *)data;
445 *(USHORT *)data = ushort_bswap(*(USHORT *)data);
446 data += sizeof(USHORT);
448 for (i = 0; i < number_of_entries; i++)
450 entry = (struct IFD_entry *)data;
458 if (entry->count > 4)
459 entry->value = ulong_bswap(entry->value);
464 if (entry->count > 2)
466 ULONG j, count = entry->count;
467 USHORT *us = (USHORT *)(data_start + entry->value);
468 if (!count) count = 1;
469 for (j = 0; j < count; j++)
470 us[j] = ushort_bswap(us[j]);
472 entry->value = ulong_bswap(entry->value);
476 ULONG j, count = entry->count;
477 USHORT *us = (USHORT *)&entry->value;
478 if (!count) count = 1;
479 for (j = 0; j < count; j++)
480 us[j] = ushort_bswap(us[j]);
487 if (entry->count > 1)
489 ULONG j, count = entry->count;
490 ULONG *ul = (ULONG *)(data_start + entry->value);
491 if (!count) count = 1;
492 for (j = 0; j < count; j++)
493 ul[j] = ulong_bswap(ul[j]);
495 entry->value = ulong_bswap(entry->value);
502 ULONG *ul = (ULONG *)(data_start + entry->value);
503 for (j = 0; j < entry->count * 2; j++)
504 ul[j] = ulong_bswap(ul[j]);
506 entry->value = ulong_bswap(entry->value);
512 ULONGLONG *ull = (ULONGLONG *)(data_start + entry->value);
513 for (j = 0; j < entry->count; j++)
514 ull[j] = ulonglong_bswap(ull[j]);
516 entry->value = ulong_bswap(entry->value);
524 entry->id = ushort_bswap(entry->id);
525 entry->type = ushort_bswap(entry->type);
526 entry->count = ulong_bswap(entry->count);
527 data += sizeof(*entry);
534 int count; /* if VT_VECTOR */
537 const WCHAR id_string[32];
540 static void compare_metadata(IWICMetadataReader *reader, const struct test_data *td, ULONG count)
543 IWICEnumMetadataItem *enumerator;
544 PROPVARIANT schema, id, value;
545 ULONG items_returned, i;
547 hr = IWICMetadataReader_GetEnumerator(reader, NULL);
548 ok(hr == E_INVALIDARG, "GetEnumerator error %#x\n", hr);
550 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
551 ok(hr == S_OK, "GetEnumerator error %#x\n", hr);
553 PropVariantInit(&schema);
554 PropVariantInit(&id);
555 PropVariantInit(&value);
557 for (i = 0; i < count; i++)
559 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
560 ok(hr == S_OK, "Next error %#x\n", hr);
561 ok(items_returned == 1, "unexpected item count %u\n", items_returned);
563 ok(schema.vt == VT_EMPTY, "%u: unexpected vt: %u\n", i, schema.vt);
564 ok(id.vt == VT_UI2 || id.vt == VT_LPWSTR || id.vt == VT_EMPTY, "%u: unexpected vt: %u\n", i, id.vt);
566 ok(U(id).uiVal == td[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, U(id).uiVal);
567 else if (id.vt == VT_LPWSTR)
568 ok(!lstrcmpW(td[i].id_string, U(id).pwszVal),
569 "%u: expected %s, got %s\n", i, wine_dbgstr_w(td[i].id_string), wine_dbgstr_w(U(id).pwszVal));
571 ok(value.vt == td[i].type, "%u: expected vt %#x, got %#x\n", i, td[i].type, value.vt);
572 if (value.vt & VT_VECTOR)
575 switch (value.vt & ~VT_VECTOR)
579 ok(td[i].count == U(value).caub.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caub.cElems);
580 for (j = 0; j < U(value).caub.cElems; j++)
581 ok(td[i].value[j] == U(value).caub.pElems[j], "%u: expected value[%d] %#x/%#x, got %#x\n", i, j, (ULONG)td[i].value[j], (ULONG)(td[i].value[j] >> 32), U(value).caub.pElems[j]);
585 ok(td[i].count == U(value).caui.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caui.cElems);
586 for (j = 0; j < U(value).caui.cElems; j++)
587 ok(td[i].value[j] == U(value).caui.pElems[j], "%u: expected value[%d] %#x/%#x, got %#x\n", i, j, (ULONG)td[i].value[j], (ULONG)(td[i].value[j] >> 32), U(value).caui.pElems[j]);
592 ok(td[i].count == U(value).caul.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caul.cElems);
593 for (j = 0; j < U(value).caul.cElems; j++)
594 ok(td[i].value[j] == U(value).caul.pElems[j], "%u: expected value[%d] %#x/%#x, got %#x\n", i, j, (ULONG)td[i].value[j], (ULONG)(td[i].value[j] >> 32), U(value).caul.pElems[j]);
599 ok(td[i].count == U(value).cauh.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).cauh.cElems);
600 for (j = 0; j < U(value).cauh.cElems; j++)
601 ok(td[i].value[j] == U(value).cauh.pElems[j].QuadPart, "%u: expected value[%d] %08x/%08x, got %08x/%08x\n", i, j, (ULONG)td[i].value[j], (ULONG)(td[i].value[j] >> 32), U(value).cauh.pElems[j].u.LowPart, U(value).cauh.pElems[j].u.HighPart);
604 ok(td[i].count == U(value).calpstr.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caub.cElems);
605 for (j = 0; j < U(value).calpstr.cElems; j++)
606 trace("%u: %s\n", j, U(value).calpstr.pElems[j]);
607 /* fall through to not handled message */
609 ok(0, "%u: array of type %d is not handled\n", i, value.vt & ~VT_VECTOR);
613 else if (value.vt == VT_LPSTR)
615 ok(td[i].count == strlen(U(value).pszVal) ||
616 broken(td[i].count == strlen(U(value).pszVal) + 1), /* before Win7 */
617 "%u: expected count %d, got %d\n", i, td[i].count, lstrlenA(U(value).pszVal));
618 if (td[i].count == strlen(U(value).pszVal))
619 ok(!strcmp(td[i].string, U(value).pszVal),
620 "%u: expected %s, got %s\n", i, td[i].string, U(value).pszVal);
622 else if (value.vt == VT_BLOB)
624 ok(td[i].count == U(value).blob.cbSize, "%u: expected count %d, got %d\n", i, td[i].count, U(value).blob.cbSize);
625 ok(!memcmp(td[i].string, U(value).blob.pBlobData, td[i].count), "%u: expected %s, got %s\n", i, td[i].string, U(value).blob.pBlobData);
628 ok(U(value).uhVal.QuadPart == td[i].value[0], "%u: expected value %#x/%#x got %#x/%#x\n",
629 i, (UINT)td[i].value[0], (UINT)(td[i].value[0] >> 32), U(value).uhVal.u.LowPart, U(value).uhVal.u.HighPart);
631 PropVariantClear(&schema);
632 PropVariantClear(&id);
633 PropVariantClear(&value);
636 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
637 ok(hr == S_FALSE, "Next should fail\n");
638 ok(items_returned == 0, "unexpected item count %u\n", items_returned);
640 IWICEnumMetadataItem_Release(enumerator);
643 static void test_metadata_IFD(void)
645 static const struct test_data td[28] =
647 { VT_UI2, 0xfe, 0, { 1 } },
648 { VT_UI4, 0x100, 0, { 222 } },
649 { VT_UI4, 0x101, 0, { 333 } },
650 { VT_UI2, 0x102, 0, { 24 } },
651 { VT_UI4, 0x103, 0, { 32773 } },
652 { VT_UI8, 0x11a, 0, { ((LONGLONG)3 << 32) | 900 } },
653 { VT_UI1, 0xf001, 0, { 0x44 } },
654 { VT_UI1|VT_VECTOR, 0xf002, 4, { 0x44, 0x33, 0x22, 0x11 } },
655 { VT_I1, 0xf003, 0, { 0x44 } },
656 { VT_I2, 0xf004, 0, { 0x3344 } },
657 { VT_I2|VT_VECTOR, 0xf005, 2, { 0x3344, 0x1122 } },
658 { VT_I4, 0xf006, 0, { 0x11223344 } },
659 { VT_R4, 0xf007, 0, { 0x11223344 } },
660 { VT_R8, 0xf008, 0, { ((LONGLONG)0x41d26580 << 32) | 0xb486522c } },
661 { VT_I8, 0xf009, 0, { ((LONGLONG)0x5a6b7c8d << 32) | 0x1a2b3c4d } },
662 { VT_UI1|VT_VECTOR, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
663 { VT_I2|VT_VECTOR, 0xf00b, 4, { 0x0101, 0x0202, 0x0303, 0x0404 } },
664 { VT_I4|VT_VECTOR, 0xf00c, 2, { 0x11223344, 0x55667788 } },
665 { VT_R4|VT_VECTOR, 0xf00d, 2, { 0x449a522b, 0x4608f5ba } },
666 { VT_LPSTR, 0xf00e, 12, { 0 }, "Hello World!" },
667 { VT_LPSTR, 0xf00f, 4, { 0 }, "abcd" },
668 { VT_BLOB, 0xf010, 13, { 0 }, "Hello World!" },
669 { VT_BLOB, 0xf011, 4, { 0 }, "abcd" },
670 { VT_UI1, 0xf012, 0, { 0x44 } },
671 { VT_UI2, 0xf013, 0, { 0x3344 } },
672 { VT_UI4, 0xf014, 0, { 0x11223344 } },
673 { VT_R4, 0xf015, 0, { 0x11223344 } },
674 { VT_I8|VT_VECTOR, 0xf016, 3,
675 { ((LONGLONG)0x05060708 << 32) | 0x01020304,
676 ((LONGLONG)0x50607080 << 32) | 0x10203040,
677 ((LONGLONG)0x55667788 << 32) | 0x11223344 } },
680 IWICMetadataReader *reader;
681 IWICMetadataBlockReader *blockreader;
682 PROPVARIANT schema, id, value;
685 char *IFD_data_swapped;
686 #ifdef WORDS_BIGENDIAN
687 DWORD persist_options = WICPersistOptionsBigEndian;
689 DWORD persist_options = WICPersistOptionsLittleEndian;
692 hr = CoCreateInstance(&CLSID_WICIfdMetadataReader, NULL, CLSCTX_INPROC_SERVER,
693 &IID_IWICMetadataReader, (void**)&reader);
694 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
696 hr = IWICMetadataReader_GetCount(reader, NULL);
697 ok(hr == E_INVALIDARG, "GetCount error %#x\n", hr);
699 hr = IWICMetadataReader_GetCount(reader, &count);
700 ok(hr == S_OK, "GetCount error %#x\n", hr);
701 ok(count == 0, "unexpected count %u\n", count);
703 load_stream((IUnknown*)reader, (const char *)&IFD_data, sizeof(IFD_data), persist_options);
705 hr = IWICMetadataReader_GetCount(reader, &count);
706 ok(hr == S_OK, "GetCount error %#x\n", hr);
707 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count);
709 compare_metadata(reader, td, count);
711 /* test IFD data with different endianness */
712 if (persist_options == WICPersistOptionsLittleEndian)
713 persist_options = WICPersistOptionsBigEndian;
715 persist_options = WICPersistOptionsLittleEndian;
717 IFD_data_swapped = HeapAlloc(GetProcessHeap(), 0, sizeof(IFD_data));
718 memcpy(IFD_data_swapped, &IFD_data, sizeof(IFD_data));
719 byte_swap_ifd_data(IFD_data_swapped);
720 load_stream((IUnknown *)reader, IFD_data_swapped, sizeof(IFD_data), persist_options);
721 hr = IWICMetadataReader_GetCount(reader, &count);
722 ok(hr == S_OK, "GetCount error %#x\n", hr);
723 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count);
724 compare_metadata(reader, td, count);
725 HeapFree(GetProcessHeap(), 0, IFD_data_swapped);
727 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
728 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
729 ok(IsEqualGUID(&format, &GUID_MetadataFormatIfd), "unexpected format %s\n", debugstr_guid(&format));
731 hr = IWICMetadataReader_GetMetadataFormat(reader, NULL);
732 ok(hr == E_INVALIDARG, "GetMetadataFormat should fail\n");
734 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, NULL);
735 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
737 PropVariantInit(&schema);
738 PropVariantInit(&id);
739 PropVariantInit(&value);
741 hr = IWICMetadataReader_GetValueByIndex(reader, count - 1, NULL, NULL, NULL);
742 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
744 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, NULL, NULL);
745 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
746 ok(schema.vt == VT_EMPTY, "unexpected vt: %u\n", schema.vt);
748 hr = IWICMetadataReader_GetValueByIndex(reader, count - 1, &schema, NULL, NULL);
749 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
750 ok(schema.vt == VT_EMPTY, "unexpected vt: %u\n", schema.vt);
752 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &id, NULL);
753 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
754 ok(id.vt == VT_UI2, "unexpected vt: %u\n", id.vt);
755 ok(U(id).uiVal == 0xfe, "unexpected id: %#x\n", U(id).uiVal);
756 PropVariantClear(&id);
758 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, &value);
759 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
760 ok(value.vt == VT_UI2, "unexpected vt: %u\n", value.vt);
761 ok(U(value).uiVal == 1, "unexpected id: %#x\n", U(value).uiVal);
762 PropVariantClear(&value);
764 hr = IWICMetadataReader_GetValueByIndex(reader, count, &schema, NULL, NULL);
765 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
767 PropVariantInit(&schema);
768 PropVariantInit(&id);
769 PropVariantInit(&value);
771 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
772 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr);
774 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL);
775 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr);
777 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, NULL);
778 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
780 hr = IWICMetadataReader_GetValue(reader, &schema, &id, NULL);
781 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr);
783 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, &value);
784 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
787 U(id).uiVal = 0xf00e;
788 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL);
789 ok(hr == S_OK, "GetValue error %#x\n", hr);
791 /* schema is ignored by Ifd metadata reader */
793 U(schema).ulVal = 0xdeadbeef;
794 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
795 ok(hr == S_OK, "GetValue error %#x\n", hr);
796 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
797 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal);
798 PropVariantClear(&value);
800 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
801 ok(hr == S_OK, "GetValue error %#x\n", hr);
802 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
803 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal);
804 PropVariantClear(&value);
806 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader);
807 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
810 IWICMetadataBlockReader_Release(blockreader);
812 IWICMetadataReader_Release(reader);
815 static void test_metadata_Exif(void)
818 IWICMetadataReader *reader;
819 IWICMetadataBlockReader *blockreader;
822 hr = CoCreateInstance(&CLSID_WICExifMetadataReader, NULL, CLSCTX_INPROC_SERVER,
823 &IID_IWICMetadataReader, (void**)&reader);
824 todo_wine ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
825 if (FAILED(hr)) return;
827 hr = IWICMetadataReader_GetCount(reader, NULL);
828 ok(hr == E_INVALIDARG, "GetCount error %#x\n", hr);
830 hr = IWICMetadataReader_GetCount(reader, &count);
831 ok(hr == S_OK, "GetCount error %#x\n", hr);
832 ok(count == 0, "unexpected count %u\n", count);
834 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader);
835 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
838 IWICMetadataBlockReader_Release(blockreader);
840 IWICMetadataReader_Release(reader);
843 static void test_create_reader(void)
846 IWICComponentFactory *factory;
848 IWICMetadataReader *reader;
852 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
853 &IID_IWICComponentFactory, (void**)&factory);
854 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
856 stream = create_stream(metadata_tEXt, sizeof(metadata_tEXt));
858 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory,
859 &GUID_ContainerFormatPng, NULL, WICPersistOptionsDefault,
862 ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr);
863 if (FAILED(hr)) return;
867 hr = IWICMetadataReader_GetCount(reader, &count);
868 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
869 ok(count == 1, "unexpected count %i\n", count);
871 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
872 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
873 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", debugstr_guid(&format));
875 IWICMetadataReader_Release(reader);
878 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory,
879 &GUID_ContainerFormatWmp, NULL, WICPersistOptionsDefault,
881 ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr);
885 hr = IWICMetadataReader_GetCount(reader, &count);
886 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
887 ok(count == 1, "unexpected count %i\n", count);
889 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
890 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
891 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown), "unexpected format %s\n", debugstr_guid(&format));
893 IWICMetadataReader_Release(reader);
896 IStream_Release(stream);
898 IWICComponentFactory_Release(factory);
901 static void test_metadata_png(void)
903 static const struct test_data td[6] =
905 { VT_UI2, 0, 0, { 2005 }, NULL, { 'Y','e','a','r',0 } },
906 { VT_UI1, 0, 0, { 6 }, NULL, { 'M','o','n','t','h',0 } },
907 { VT_UI1, 0, 0, { 3 }, NULL, { 'D','a','y',0 } },
908 { VT_UI1, 0, 0, { 15 }, NULL, { 'H','o','u','r',0 } },
909 { VT_UI1, 0, 0, { 7 }, NULL, { 'M','i','n','u','t','e',0 } },
910 { VT_UI1, 0, 0, { 45 }, NULL, { 'S','e','c','o','n','d',0 } }
913 IWICBitmapDecoder *decoder;
914 IWICBitmapFrameDecode *frame;
915 IWICMetadataBlockReader *blockreader;
916 IWICMetadataReader *reader;
917 GUID containerformat;
921 hr = CoCreateInstance(&CLSID_WICPngDecoder, NULL, CLSCTX_INPROC_SERVER,
922 &IID_IWICBitmapDecoder, (void**)&decoder);
923 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
925 if (FAILED(hr)) return;
927 stream = create_stream(pngimage, sizeof(pngimage));
929 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
930 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
932 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void**)&blockreader);
933 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
935 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
936 ok(hr == S_OK, "GetFrame failed, hr=%x\n", hr);
938 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void**)&blockreader);
939 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
943 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, NULL);
944 ok(hr == E_INVALIDARG, "GetContainerFormat failed, hr=%x\n", hr);
946 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &containerformat);
947 ok(hr == S_OK, "GetContainerFormat failed, hr=%x\n", hr);
948 ok(IsEqualGUID(&containerformat, &GUID_ContainerFormatPng), "unexpected container format\n");
950 hr = IWICMetadataBlockReader_GetCount(blockreader, NULL);
951 todo_wine ok(hr == E_INVALIDARG, "GetCount failed, hr=%x\n", hr);
953 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
954 todo_wine ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
955 todo_wine ok(count == 1, "unexpected count %d\n", count);
959 /* Crashes on Windows XP */
960 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, NULL);
961 ok(hr == E_INVALIDARG, "GetReaderByIndex failed, hr=%x\n", hr);
964 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
965 todo_wine ok(hr == S_OK, "GetReaderByIndex failed, hr=%x\n", hr);
969 hr = IWICMetadataReader_GetMetadataFormat(reader, &containerformat);
970 ok(IsEqualGUID(&containerformat, &GUID_MetadataFormatChunktIME) ||
971 broken(IsEqualGUID(&containerformat, &GUID_MetadataFormatUnknown)) /* Windows XP */,
972 "unexpected container format\n");
974 hr = IWICMetadataReader_GetCount(reader, &count);
975 ok(hr == S_OK, "GetCount error %#x\n", hr);
976 ok(count == 6 || broken(count == 1) /* XP */, "expected 6, got %u\n", count);
978 compare_metadata(reader, td, count);
980 IWICMetadataReader_Release(reader);
983 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
984 todo_wine ok(hr == WINCODEC_ERR_VALUEOUTOFRANGE, "GetReaderByIndex failed, hr=%x\n", hr);
986 IWICMetadataBlockReader_Release(blockreader);
989 IWICBitmapFrameDecode_Release(frame);
991 IWICBitmapDecoder_Release(decoder);
993 IStream_Release(stream);
996 static void test_metadata_gif(void)
998 static const struct test_data gif_LSD[9] =
1000 { VT_UI1|VT_VECTOR, 0, 6, {'G','I','F','8','7','a'}, NULL, { 'S','i','g','n','a','t','u','r','e',0 } },
1001 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } },
1002 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } },
1003 { VT_BOOL, 0, 0, { 1 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } },
1004 { VT_UI1, 0, 0, { 0 }, NULL, { 'C','o','l','o','r','R','e','s','o','l','u','t','i','o','n',0 } },
1005 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1006 { VT_UI1, 0, 0, { 0 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } },
1007 { VT_UI1, 0, 0, { 0 }, NULL, { 'B','a','c','k','g','r','o','u','n','d','C','o','l','o','r','I','n','d','e','x',0 } },
1008 { VT_UI1, 0, 0, { 0 }, NULL, { 'P','i','x','e','l','A','s','p','e','c','t','R','a','t','i','o',0 } }
1010 static const struct test_data gif_IMD[8] =
1012 { VT_UI2, 0, 0, { 0 }, NULL, { 'L','e','f','t',0 } },
1013 { VT_UI2, 0, 0, { 0 }, NULL, { 'T','o','p',0 } },
1014 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } },
1015 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } },
1016 { VT_BOOL, 0, 0, { 0 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } },
1017 { VT_BOOL, 0, 0, { 0 }, NULL, { 'I','n','t','e','r','l','a','c','e','F','l','a','g',0 } },
1018 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1019 { VT_UI1, 0, 0, { 0 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } }
1021 static const struct test_data animated_gif_LSD[9] =
1023 { VT_UI1|VT_VECTOR, 0, 6, {'G','I','F','8','9','a'}, NULL, { 'S','i','g','n','a','t','u','r','e',0 } },
1024 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } },
1025 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } },
1026 { VT_BOOL, 0, 0, { 1 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } },
1027 { VT_UI1, 0, 0, { 2 }, NULL, { 'C','o','l','o','r','R','e','s','o','l','u','t','i','o','n',0 } },
1028 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1029 { VT_UI1, 0, 0, { 1 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } },
1030 { VT_UI1, 0, 0, { 0 }, NULL, { 'B','a','c','k','g','r','o','u','n','d','C','o','l','o','r','I','n','d','e','x',0 } },
1031 { VT_UI1, 0, 0, { 0 }, NULL, { 'P','i','x','e','l','A','s','p','e','c','t','R','a','t','i','o',0 } }
1033 static const struct test_data animated_gif_IMD[8] =
1035 { VT_UI2, 0, 0, { 0 }, NULL, { 'L','e','f','t',0 } },
1036 { VT_UI2, 0, 0, { 0 }, NULL, { 'T','o','p',0 } },
1037 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } },
1038 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } },
1039 { VT_BOOL, 0, 0, { 1 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } },
1040 { VT_BOOL, 0, 0, { 0 }, NULL, { 'I','n','t','e','r','l','a','c','e','F','l','a','g',0 } },
1041 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1042 { VT_UI1, 0, 0, { 1 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } }
1044 static const struct test_data animated_gif_GCE[5] =
1046 { VT_UI1, 0, 0, { 0 }, NULL, { 'D','i','s','p','o','s','a','l',0 } },
1047 { VT_BOOL, 0, 0, { 0 }, NULL, { 'U','s','e','r','I','n','p','u','t','F','l','a','g',0 } },
1048 { VT_BOOL, 0, 0, { 1 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 } },
1049 { VT_UI2, 0, 0, { 10 }, NULL, { 'D','e','l','a','y',0 } },
1050 { VT_UI1, 0, 0, { 1 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','t','C','o','l','o','r','I','n','d','e','x',0 } }
1052 static const struct test_data animated_gif_APE[2] =
1054 { VT_UI1|VT_VECTOR, 0, 11, { 'A','N','I','M','E','X','T','S','1','.','0' }, NULL, { 'A','p','p','l','i','c','a','t','i','o','n',0 } },
1055 { VT_UI1|VT_VECTOR, 0, 4, { 0x03,0x01,0x05,0x00 }, NULL, { 'D','a','t','a',0 } }
1057 static const struct test_data animated_gif_comment_1[1] =
1059 { VT_LPSTR, 0, 12, { 0 }, "Hello World!", { 'T','e','x','t','E','n','t','r','y',0 } }
1061 static const struct test_data animated_gif_comment_2[1] =
1063 { VT_LPSTR, 0, 8, { 0 }, "image #1", { 'T','e','x','t','E','n','t','r','y',0 } }
1065 static const struct test_data animated_gif_plain_1[1] =
1067 { VT_BLOB, 0, 17, { 0 }, "\x21\x01\x0d\x61nimation.gif" }
1069 static const struct test_data animated_gif_plain_2[1] =
1071 { VT_BLOB, 0, 16, { 0 }, "\x21\x01\x0cplaintext #1" }
1074 IWICBitmapDecoder *decoder;
1075 IWICBitmapFrameDecode *frame;
1076 IWICMetadataBlockReader *blockreader;
1077 IWICMetadataReader *reader;
1083 stream = create_stream(gifimage, sizeof(gifimage));
1085 hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER,
1086 &IID_IWICBitmapDecoder, (void **)&decoder);
1087 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
1088 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
1089 ok(hr == S_OK, "Initialize error %#x\n", hr);
1091 IStream_Release(stream);
1093 /* global metadata block */
1094 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void **)&blockreader);
1095 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr);
1099 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format);
1100 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
1101 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
1102 "wrong container format %s\n", debugstr_guid(&format));
1104 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
1105 ok(hr == S_OK, "GetCount error %#x\n", hr);
1106 ok(count == 1, "expected 1, got %u\n", count);
1108 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
1109 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1113 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1114 ok(IsEqualGUID(&format, &GUID_MetadataFormatLSD), /* Logical Screen Descriptor */
1115 "wrong metadata format %s\n", debugstr_guid(&format));
1117 hr = IWICMetadataReader_GetCount(reader, &count);
1118 ok(hr == S_OK, "GetCount error %#x\n", hr);
1119 ok(count == sizeof(gif_LSD)/sizeof(gif_LSD[0]), "unexpected count %u\n", count);
1121 compare_metadata(reader, gif_LSD, count);
1123 IWICMetadataReader_Release(reader);
1126 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
1127 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1129 IWICMetadataBlockReader_Release(blockreader);
1132 /* frame metadata block */
1133 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
1134 ok(hr == S_OK, "GetFrame error %#x\n", hr);
1136 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void **)&blockreader);
1137 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr);
1141 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, NULL);
1142 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1144 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format);
1145 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
1146 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
1147 "wrong container format %s\n", debugstr_guid(&format));
1149 hr = IWICMetadataBlockReader_GetCount(blockreader, NULL);
1150 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1152 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
1153 ok(hr == S_OK, "GetCount error %#x\n", hr);
1154 ok(count == 1, "expected 1, got %u\n", count);
1156 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
1157 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1161 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1162 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), /* Image Descriptor */
1163 "wrong metadata format %s\n", debugstr_guid(&format));
1165 hr = IWICMetadataReader_GetCount(reader, &count);
1166 ok(hr == S_OK, "GetCount error %#x\n", hr);
1167 ok(count == sizeof(gif_IMD)/sizeof(gif_IMD[0]), "unexpected count %u\n", count);
1169 compare_metadata(reader, gif_IMD, count);
1171 IWICMetadataReader_Release(reader);
1174 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
1175 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1177 IWICMetadataBlockReader_Release(blockreader);
1180 IWICBitmapFrameDecode_Release(frame);
1181 IWICBitmapDecoder_Release(decoder);
1183 /* 1x1 pixel gif, 2 frames */
1184 stream = create_stream(animatedgif, sizeof(animatedgif));
1186 hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER,
1187 &IID_IWICBitmapDecoder, (void **)&decoder);
1188 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
1189 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
1190 ok(hr == S_OK, "Initialize error %#x\n", hr);
1192 IStream_Release(stream);
1194 /* global metadata block */
1195 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void **)&blockreader);
1196 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr);
1200 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format);
1201 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
1202 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
1203 "wrong container format %s\n", debugstr_guid(&format));
1205 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
1206 ok(hr == S_OK, "GetCount error %#x\n", hr);
1207 ok(count == 4, "expected 4, got %u\n", count);
1209 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
1210 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1214 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1215 ok(IsEqualGUID(&format, &GUID_MetadataFormatLSD), /* Logical Screen Descriptor */
1216 "wrong metadata format %s\n", debugstr_guid(&format));
1218 hr = IWICMetadataReader_GetCount(reader, &count);
1219 ok(hr == S_OK, "GetCount error %#x\n", hr);
1220 ok(count == sizeof(animated_gif_LSD)/sizeof(animated_gif_LSD[0]), "unexpected count %u\n", count);
1222 compare_metadata(reader, animated_gif_LSD, count);
1224 IWICMetadataReader_Release(reader);
1227 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
1228 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1232 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1233 ok(IsEqualGUID(&format, &GUID_MetadataFormatAPE), /* Application Extension */
1234 "wrong metadata format %s\n", debugstr_guid(&format));
1236 hr = IWICMetadataReader_GetCount(reader, &count);
1237 ok(hr == S_OK, "GetCount error %#x\n", hr);
1238 ok(count == sizeof(animated_gif_APE)/sizeof(animated_gif_APE[0]), "unexpected count %u\n", count);
1240 compare_metadata(reader, animated_gif_APE, count);
1242 IWICMetadataReader_Release(reader);
1245 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 2, &reader);
1246 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1250 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1251 ok(IsEqualGUID(&format, &GUID_MetadataFormatGifComment), /* Comment Extension */
1252 "wrong metadata format %s\n", debugstr_guid(&format));
1254 hr = IWICMetadataReader_GetCount(reader, &count);
1255 ok(hr == S_OK, "GetCount error %#x\n", hr);
1256 ok(count == sizeof(animated_gif_comment_1)/sizeof(animated_gif_comment_1[0]), "unexpected count %u\n", count);
1258 compare_metadata(reader, animated_gif_comment_1, count);
1260 IWICMetadataReader_Release(reader);
1263 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 3, &reader);
1264 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1268 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1269 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown),
1270 "wrong metadata format %s\n", debugstr_guid(&format));
1272 hr = IWICMetadataReader_GetCount(reader, &count);
1273 ok(hr == S_OK, "GetCount error %#x\n", hr);
1274 ok(count == sizeof(animated_gif_plain_1)/sizeof(animated_gif_plain_1[0]), "unexpected count %u\n", count);
1276 compare_metadata(reader, animated_gif_plain_1, count);
1278 IWICMetadataReader_Release(reader);
1281 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 4, &reader);
1282 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1284 IWICMetadataBlockReader_Release(blockreader);
1287 /* frame metadata block */
1288 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &frame);
1289 ok(hr == S_OK, "GetFrame error %#x\n", hr);
1291 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void **)&blockreader);
1292 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr);
1296 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, NULL);
1297 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1299 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format);
1300 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
1301 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
1302 "wrong container format %s\n", debugstr_guid(&format));
1304 hr = IWICMetadataBlockReader_GetCount(blockreader, NULL);
1305 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1307 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
1308 ok(hr == S_OK, "GetCount error %#x\n", hr);
1309 ok(count == 4, "expected 4, got %u\n", count);
1311 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
1312 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1316 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1317 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), /* Image Descriptor */
1318 "wrong metadata format %s\n", debugstr_guid(&format));
1320 hr = IWICMetadataReader_GetCount(reader, &count);
1321 ok(hr == S_OK, "GetCount error %#x\n", hr);
1322 ok(count == sizeof(animated_gif_IMD)/sizeof(animated_gif_IMD[0]), "unexpected count %u\n", count);
1324 compare_metadata(reader, animated_gif_IMD, count);
1326 IWICMetadataReader_Release(reader);
1329 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
1330 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1334 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1335 ok(IsEqualGUID(&format, &GUID_MetadataFormatGifComment), /* Comment Extension */
1336 "wrong metadata format %s\n", debugstr_guid(&format));
1338 hr = IWICMetadataReader_GetCount(reader, &count);
1339 ok(hr == S_OK, "GetCount error %#x\n", hr);
1340 ok(count == sizeof(animated_gif_comment_2)/sizeof(animated_gif_comment_2[0]), "unexpected count %u\n", count);
1343 compare_metadata(reader, animated_gif_comment_2, count);
1345 IWICMetadataReader_Release(reader);
1348 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 2, &reader);
1349 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1353 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1354 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown),
1355 "wrong metadata format %s\n", debugstr_guid(&format));
1357 hr = IWICMetadataReader_GetCount(reader, &count);
1358 ok(hr == S_OK, "GetCount error %#x\n", hr);
1359 ok(count == sizeof(animated_gif_plain_2)/sizeof(animated_gif_plain_2[0]), "unexpected count %u\n", count);
1361 compare_metadata(reader, animated_gif_plain_2, count);
1363 IWICMetadataReader_Release(reader);
1366 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 3, &reader);
1367 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1371 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1372 ok(IsEqualGUID(&format, &GUID_MetadataFormatGCE), /* Graphic Control Extension */
1373 "wrong metadata format %s\n", debugstr_guid(&format));
1375 hr = IWICMetadataReader_GetCount(reader, &count);
1376 ok(hr == S_OK, "GetCount error %#x\n", hr);
1377 ok(count == sizeof(animated_gif_GCE)/sizeof(animated_gif_GCE[0]), "unexpected count %u\n", count);
1379 compare_metadata(reader, animated_gif_GCE, count);
1381 IWICMetadataReader_Release(reader);
1384 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 4, &reader);
1385 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1387 IWICMetadataBlockReader_Release(blockreader);
1390 IWICBitmapFrameDecode_Release(frame);
1391 IWICBitmapDecoder_Release(decoder);
1394 static void test_metadata_LSD(void)
1396 static const WCHAR LSD_name[] = {'L','o','g','i','c','a','l',' ','S','c','r','e','e','n',' ','D','e','s','c','r','i','p','t','o','r',' ','R','e','a','d','e','r',0};
1397 static const char LSD_data[] = "hello world!\x1\x2\x3\x4\xab\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf";
1398 static const struct test_data td[9] =
1400 { VT_UI1|VT_VECTOR, 0, 6, {'w','o','r','l','d','!'}, NULL, { 'S','i','g','n','a','t','u','r','e',0 } },
1401 { VT_UI2, 0, 0, { 0x201 }, NULL, { 'W','i','d','t','h',0 } },
1402 { VT_UI2, 0, 0, { 0x403 }, NULL, { 'H','e','i','g','h','t',0 } },
1403 { VT_BOOL, 0, 0, { 1 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } },
1404 { VT_UI1, 0, 0, { 2 }, NULL, { 'C','o','l','o','r','R','e','s','o','l','u','t','i','o','n',0 } },
1405 { VT_BOOL, 0, 0, { 1 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1406 { VT_UI1, 0, 0, { 3 }, NULL, { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } },
1407 { VT_UI1, 0, 0, { 6 }, NULL, { 'B','a','c','k','g','r','o','u','n','d','C','o','l','o','r','I','n','d','e','x',0 } },
1408 { VT_UI1, 0, 0, { 7 }, NULL, { 'P','i','x','e','l','A','s','p','e','c','t','R','a','t','i','o',0 } }
1413 IWICPersistStream *persist;
1414 IWICMetadataReader *reader;
1415 IWICMetadataHandlerInfo *info;
1421 hr = CoCreateInstance(&CLSID_WICLSDMetadataReader, NULL, CLSCTX_INPROC_SERVER,
1422 &IID_IWICMetadataReader, (void **)&reader);
1423 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
1424 "CoCreateInstance error %#x\n", hr);
1426 stream = create_stream(LSD_data, sizeof(LSD_data));
1431 hr = IStream_Seek(stream, pos, SEEK_SET, NULL);
1432 ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
1434 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
1435 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1437 hr = IWICPersistStream_Load(persist, stream);
1438 ok(hr == S_OK, "Load error %#x\n", hr);
1440 IWICPersistStream_Release(persist);
1445 hr = IWICMetadataReader_GetCount(reader, &count);
1446 ok(hr == S_OK, "GetCount error %#x\n", hr);
1447 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count);
1449 compare_metadata(reader, td, count);
1451 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1452 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
1453 ok(IsEqualGUID(&format, &GUID_MetadataFormatLSD), "wrong format %s\n", debugstr_guid(&format));
1455 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
1456 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
1458 hr = IWICMetadataHandlerInfo_GetCLSID(info, &id);
1459 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
1460 ok(IsEqualGUID(&id, &CLSID_WICLSDMetadataReader), "wrong CLSID %s\n", debugstr_guid(&id));
1462 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
1463 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
1464 ok(lstrcmpW(name, LSD_name) == 0, "wrong LSD reader name %s\n", wine_dbgstr_w(name));
1466 IWICMetadataHandlerInfo_Release(info);
1467 IWICMetadataReader_Release(reader);
1470 IStream_Release(stream);
1473 static void test_metadata_IMD(void)
1475 static const WCHAR IMD_name[] = {'I','m','a','g','e',' ','D','e','s','c','r','i','p','t','o','r',' ','R','e','a','d','e','r',0};
1476 static const char IMD_data[] = "hello world!\x1\x2\x3\x4\x5\x6\x7\x8\xed\xa\xb\xc\xd\xe\xf";
1477 static const struct test_data td[8] =
1479 { VT_UI2, 0, 0, { 0x201 }, NULL, { 'L','e','f','t',0 } },
1480 { VT_UI2, 0, 0, { 0x403 }, NULL, { 'T','o','p',0 } },
1481 { VT_UI2, 0, 0, { 0x605 }, NULL, { 'W','i','d','t','h',0 } },
1482 { VT_UI2, 0, 0, { 0x807 }, NULL, { 'H','e','i','g','h','t',0 } },
1483 { VT_BOOL, 0, 0, { 1 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 } },
1484 { VT_BOOL, 0, 0, { 1 }, NULL, { 'I','n','t','e','r','l','a','c','e','F','l','a','g',0 } },
1485 { VT_BOOL, 0, 0, { 1 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1486 { VT_UI1, 0, 0, { 5 }, NULL, { 'L','o','c','a','l','C','o','l','o','r','T','a','b','l','e','S','i','z','e',0 } }
1491 IWICPersistStream *persist;
1492 IWICMetadataReader *reader;
1493 IWICMetadataHandlerInfo *info;
1499 hr = CoCreateInstance(&CLSID_WICIMDMetadataReader, NULL, CLSCTX_INPROC_SERVER,
1500 &IID_IWICMetadataReader, (void **)&reader);
1501 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
1502 "CoCreateInstance error %#x\n", hr);
1504 stream = create_stream(IMD_data, sizeof(IMD_data));
1509 hr = IStream_Seek(stream, pos, SEEK_SET, NULL);
1510 ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
1512 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
1513 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1515 hr = IWICPersistStream_Load(persist, stream);
1516 ok(hr == S_OK, "Load error %#x\n", hr);
1518 IWICPersistStream_Release(persist);
1523 hr = IWICMetadataReader_GetCount(reader, &count);
1524 ok(hr == S_OK, "GetCount error %#x\n", hr);
1525 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count);
1527 compare_metadata(reader, td, count);
1529 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1530 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
1531 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), "wrong format %s\n", debugstr_guid(&format));
1533 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
1534 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
1536 hr = IWICMetadataHandlerInfo_GetCLSID(info, &id);
1537 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
1538 ok(IsEqualGUID(&id, &CLSID_WICIMDMetadataReader), "wrong CLSID %s\n", debugstr_guid(&id));
1540 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
1541 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
1542 ok(lstrcmpW(name, IMD_name) == 0, "wrong IMD reader name %s\n", wine_dbgstr_w(name));
1544 IWICMetadataHandlerInfo_Release(info);
1545 IWICMetadataReader_Release(reader);
1548 IStream_Release(stream);
1551 static void test_metadata_GCE(void)
1553 static const WCHAR GCE_name[] = {'G','r','a','p','h','i','c',' ','C','o','n','t','r','o','l',' ','E','x','t','e','n','s','i','o','n',' ','R','e','a','d','e','r',0};
1554 static const char GCE_data[] = "hello world!\xa\x2\x3\x4\x5\x6\x7\x8\xed\xa\xb\xc\xd\xe\xf";
1555 static const struct test_data td[5] =
1557 { VT_UI1, 0, 0, { 2 }, NULL, { 'D','i','s','p','o','s','a','l',0 } },
1558 { VT_BOOL, 0, 0, { 1 }, NULL, { 'U','s','e','r','I','n','p','u','t','F','l','a','g',0 } },
1559 { VT_BOOL, 0, 0, { 0 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 } },
1560 { VT_UI2, 0, 0, { 0x302 }, NULL, { 'D','e','l','a','y',0 } },
1561 { VT_UI1, 0, 0, { 4 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','t','C','o','l','o','r','I','n','d','e','x',0 } }
1566 IWICPersistStream *persist;
1567 IWICMetadataReader *reader;
1568 IWICMetadataHandlerInfo *info;
1574 hr = CoCreateInstance(&CLSID_WICGCEMetadataReader, NULL, CLSCTX_INPROC_SERVER,
1575 &IID_IWICMetadataReader, (void **)&reader);
1576 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
1577 "CoCreateInstance error %#x\n", hr);
1579 stream = create_stream(GCE_data, sizeof(GCE_data));
1584 hr = IStream_Seek(stream, pos, SEEK_SET, NULL);
1585 ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
1587 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
1588 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1590 hr = IWICPersistStream_Load(persist, stream);
1591 ok(hr == S_OK, "Load error %#x\n", hr);
1593 IWICPersistStream_Release(persist);
1598 hr = IWICMetadataReader_GetCount(reader, &count);
1599 ok(hr == S_OK, "GetCount error %#x\n", hr);
1600 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count);
1602 compare_metadata(reader, td, count);
1604 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1605 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
1606 ok(IsEqualGUID(&format, &GUID_MetadataFormatGCE), "wrong format %s\n", debugstr_guid(&format));
1608 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
1609 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
1611 hr = IWICMetadataHandlerInfo_GetCLSID(info, &id);
1612 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
1613 ok(IsEqualGUID(&id, &CLSID_WICGCEMetadataReader), "wrong CLSID %s\n", debugstr_guid(&id));
1615 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
1616 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
1617 ok(lstrcmpW(name, GCE_name) == 0, "wrong GCE reader name %s\n", wine_dbgstr_w(name));
1619 IWICMetadataHandlerInfo_Release(info);
1620 IWICMetadataReader_Release(reader);
1623 IStream_Release(stream);
1626 static void test_metadata_APE(void)
1628 static const WCHAR APE_name[] = {'A','p','p','l','i','c','a','t','i','o','n',' ','E','x','t','e','n','s','i','o','n',' ','R','e','a','d','e','r',0};
1629 static const char APE_data[] = { 0x21,0xff,0x0b,'H','e','l','l','o',' ','W','o','r','l','d',
1630 /*sub-block*/1,0x11,
1631 /*sub-block*/2,0x22,0x33,
1632 /*sub-block*/4,0x44,0x55,0x66,0x77,
1634 static const struct test_data td[2] =
1636 { VT_UI1|VT_VECTOR, 0, 11, { 'H','e','l','l','o',' ','W','o','r','l','d' }, NULL, { 'A','p','p','l','i','c','a','t','i','o','n',0 } },
1637 { VT_UI1|VT_VECTOR, 0, 10, { 1,0x11,2,0x22,0x33,4,0x44,0x55,0x66,0x77 }, NULL, { 'D','a','t','a',0 } }
1639 WCHAR dataW[] = { 'd','a','t','a',0 };
1642 IWICPersistStream *persist;
1643 IWICMetadataReader *reader;
1644 IWICMetadataHandlerInfo *info;
1646 UINT count, dummy, i;
1649 PROPVARIANT id, value;
1651 hr = CoCreateInstance(&CLSID_WICAPEMetadataReader, NULL, CLSCTX_INPROC_SERVER,
1652 &IID_IWICMetadataReader, (void **)&reader);
1653 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
1654 "CoCreateInstance error %#x\n", hr);
1656 stream = create_stream(APE_data, sizeof(APE_data));
1660 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
1661 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1663 hr = IWICPersistStream_Load(persist, stream);
1664 ok(hr == S_OK, "Load error %#x\n", hr);
1666 IWICPersistStream_Release(persist);
1671 hr = IWICMetadataReader_GetCount(reader, &count);
1672 ok(hr == S_OK, "GetCount error %#x\n", hr);
1673 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count);
1675 compare_metadata(reader, td, count);
1677 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1678 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
1679 ok(IsEqualGUID(&format, &GUID_MetadataFormatAPE), "wrong format %s\n", debugstr_guid(&format));
1681 PropVariantInit(&value);
1683 U(id).pwszVal = dataW;
1685 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
1686 ok(hr == S_OK, "GetValue error %#x\n", hr);
1687 ok(value.vt == (VT_UI1|VT_VECTOR), "unexpected vt: %i\n", id.vt);
1688 ok(td[1].count == U(value).caub.cElems, "expected cElems %d, got %d\n", td[1].count, U(value).caub.cElems);
1689 for (i = 0; i < U(value).caub.cElems; i++)
1690 ok(td[1].value[i] == U(value).caub.pElems[i], "%u: expected value %#x/%#x, got %#x\n", i, (ULONG)td[1].value[i], (ULONG)(td[1].value[i] >> 32), U(value).caub.pElems[i]);
1691 PropVariantClear(&value);
1693 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
1694 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
1696 hr = IWICMetadataHandlerInfo_GetCLSID(info, &clsid);
1697 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
1698 ok(IsEqualGUID(&clsid, &CLSID_WICAPEMetadataReader), "wrong CLSID %s\n", debugstr_guid(&clsid));
1700 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
1701 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
1702 ok(lstrcmpW(name, APE_name) == 0, "wrong APE reader name %s\n", wine_dbgstr_w(name));
1704 IWICMetadataHandlerInfo_Release(info);
1705 IWICMetadataReader_Release(reader);
1708 IStream_Release(stream);
1711 static void test_metadata_GIF_comment(void)
1713 static const WCHAR GIF_comment_name[] = {'C','o','m','m','e','n','t',' ','E','x','t','e','n','s','i','o','n',' ','R','e','a','d','e','r',0};
1714 static const char GIF_comment_data[] = { 0x21,0xfe,
1715 /*sub-block*/5,'H','e','l','l','o',
1717 /*sub-block*/6,'W','o','r','l','d','!',
1719 static const struct test_data td[1] =
1721 { VT_LPSTR, 0, 12, { 0 }, "Hello World!", { 'T','e','x','t','E','n','t','r','y',0 } }
1723 WCHAR text_entryW[] = { 'T','E','X','T','E','N','T','R','Y',0 };
1726 IWICPersistStream *persist;
1727 IWICMetadataReader *reader;
1728 IWICMetadataHandlerInfo *info;
1733 PROPVARIANT id, value;
1735 hr = CoCreateInstance(&CLSID_WICGifCommentMetadataReader, NULL, CLSCTX_INPROC_SERVER,
1736 &IID_IWICMetadataReader, (void **)&reader);
1737 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
1738 "CoCreateInstance error %#x\n", hr);
1740 stream = create_stream(GIF_comment_data, sizeof(GIF_comment_data));
1744 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
1745 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1747 hr = IWICPersistStream_Load(persist, stream);
1748 ok(hr == S_OK, "Load error %#x\n", hr);
1750 IWICPersistStream_Release(persist);
1755 hr = IWICMetadataReader_GetCount(reader, &count);
1756 ok(hr == S_OK, "GetCount error %#x\n", hr);
1757 ok(count == sizeof(td)/sizeof(td[0]), "unexpected count %u\n", count);
1759 compare_metadata(reader, td, count);
1761 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1762 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
1763 ok(IsEqualGUID(&format, &GUID_MetadataFormatGifComment), "wrong format %s\n", debugstr_guid(&format));
1765 PropVariantInit(&value);
1767 U(id).pwszVal = text_entryW;
1769 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
1770 ok(hr == S_OK, "GetValue error %#x\n", hr);
1771 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
1772 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal);
1773 PropVariantClear(&value);
1775 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
1776 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
1778 hr = IWICMetadataHandlerInfo_GetCLSID(info, &clsid);
1779 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
1780 ok(IsEqualGUID(&clsid, &CLSID_WICGifCommentMetadataReader), "wrong CLSID %s\n", debugstr_guid(&clsid));
1782 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
1783 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
1784 ok(lstrcmpW(name, GIF_comment_name) == 0, "wrong APE reader name %s\n", wine_dbgstr_w(name));
1786 IWICMetadataHandlerInfo_Release(info);
1787 IWICMetadataReader_Release(reader);
1790 IStream_Release(stream);
1793 START_TEST(metadata)
1795 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1797 test_metadata_unknown();
1798 test_metadata_tEXt();
1799 test_metadata_IFD();
1800 test_metadata_Exif();
1801 test_create_reader();
1802 test_metadata_png();
1803 test_metadata_gif();
1804 test_metadata_LSD();
1805 test_metadata_IMD();
1806 test_metadata_GCE();
1807 test_metadata_APE();
1808 test_metadata_GIF_comment();