wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / windowscodecs / tests / metadata.c
blobb597e5490c64624069b22f90abd8a929294da4ac
1 /*
2 * Copyright 2011 Vincent Povirk for CodeWeavers
3 * Copyright 2012,2017 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
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <math.h>
23 #include <assert.h>
25 #define COBJMACROS
27 #include "windef.h"
28 #include "objbase.h"
29 #include "wincodec.h"
30 #include "wincodecsdk.h"
31 #include "propvarutil.h"
32 #include "wine/test.h"
34 #include "initguid.h"
35 DEFINE_GUID(IID_MdbrUnknown, 0x00240e6f,0x3f23,0x4432,0xb0,0xcc,0x48,0xd5,0xbb,0xff,0x6c,0x36);
37 #define expect_blob(propvar, data, length) do { \
38 ok((propvar).vt == VT_BLOB, "unexpected vt: %i\n", (propvar).vt); \
39 if ((propvar).vt == VT_BLOB) { \
40 ok(U(propvar).blob.cbSize == (length), "expected size %u, got %u\n", (ULONG)(length), U(propvar).blob.cbSize); \
41 if (U(propvar).blob.cbSize == (length)) { \
42 ok(!memcmp(U(propvar).blob.pBlobData, (data), (length)), "unexpected data\n"); \
43 } \
44 } \
45 } while (0)
47 #define IFD_BYTE 1
48 #define IFD_ASCII 2
49 #define IFD_SHORT 3
50 #define IFD_LONG 4
51 #define IFD_RATIONAL 5
52 #define IFD_SBYTE 6
53 #define IFD_UNDEFINED 7
54 #define IFD_SSHORT 8
55 #define IFD_SLONG 9
56 #define IFD_SRATIONAL 10
57 #define IFD_FLOAT 11
58 #define IFD_DOUBLE 12
59 #define IFD_IFD 13
61 #include "pshpack2.h"
62 struct IFD_entry
64 SHORT id;
65 SHORT type;
66 ULONG count;
67 LONG value;
70 struct IFD_rational
72 LONG numerator;
73 LONG denominator;
76 static const struct ifd_data
78 USHORT number_of_entries;
79 struct IFD_entry entry[40];
80 ULONG next_IFD;
81 struct IFD_rational xres;
82 DOUBLE double_val;
83 struct IFD_rational srational_val;
84 char string[14];
85 SHORT short_val[4];
86 LONG long_val[2];
87 FLOAT float_val[2];
88 struct IFD_rational rational[3];
89 } IFD_data =
91 28,
93 { 0xfe, IFD_SHORT, 1, 1 }, /* NEWSUBFILETYPE */
94 { 0x100, IFD_LONG, 1, 222 }, /* IMAGEWIDTH */
95 { 0x101, IFD_LONG, 1, 333 }, /* IMAGELENGTH */
96 { 0x102, IFD_SHORT, 1, 24 }, /* BITSPERSAMPLE */
97 { 0x103, IFD_LONG, 1, 32773 }, /* COMPRESSION: packbits */
98 { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct ifd_data, xres) },
99 { 0xf001, IFD_BYTE, 1, 0x11223344 },
100 { 0xf002, IFD_BYTE, 4, 0x11223344 },
101 { 0xf003, IFD_SBYTE, 1, 0x11223344 },
102 { 0xf004, IFD_SSHORT, 1, 0x11223344 },
103 { 0xf005, IFD_SSHORT, 2, 0x11223344 },
104 { 0xf006, IFD_SLONG, 1, 0x11223344 },
105 { 0xf007, IFD_FLOAT, 1, 0x11223344 },
106 { 0xf008, IFD_DOUBLE, 1, FIELD_OFFSET(struct ifd_data, double_val) },
107 { 0xf009, IFD_SRATIONAL, 1, FIELD_OFFSET(struct ifd_data, srational_val) },
108 { 0xf00a, IFD_BYTE, 13, FIELD_OFFSET(struct ifd_data, string) },
109 { 0xf00b, IFD_SSHORT, 4, FIELD_OFFSET(struct ifd_data, short_val) },
110 { 0xf00c, IFD_SLONG, 2, FIELD_OFFSET(struct ifd_data, long_val) },
111 { 0xf00d, IFD_FLOAT, 2, FIELD_OFFSET(struct ifd_data, float_val) },
112 { 0xf00e, IFD_ASCII, 13, FIELD_OFFSET(struct ifd_data, string) },
113 { 0xf00f, IFD_ASCII, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
114 { 0xf010, IFD_UNDEFINED, 13, FIELD_OFFSET(struct ifd_data, string) },
115 { 0xf011, IFD_UNDEFINED, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
116 { 0xf012, IFD_BYTE, 0, 0x11223344 },
117 { 0xf013, IFD_SHORT, 0, 0x11223344 },
118 { 0xf014, IFD_LONG, 0, 0x11223344 },
119 { 0xf015, IFD_FLOAT, 0, 0x11223344 },
120 { 0xf016, IFD_SRATIONAL, 3, FIELD_OFFSET(struct ifd_data, rational) },
123 { 900, 3 },
124 1234567890.0987654321,
125 { 0x1a2b3c4d, 0x5a6b7c8d },
126 "Hello World!",
127 { 0x0101, 0x0202, 0x0303, 0x0404 },
128 { 0x11223344, 0x55667788 },
129 { (FLOAT)1234.5678, (FLOAT)8765.4321 },
130 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } },
132 #include "poppack.h"
134 static const char metadata_unknown[] = "lalala";
136 static const char metadata_tEXt[] = {
137 0,0,0,14, /* chunk length */
138 't','E','X','t', /* chunk type */
139 'w','i','n','e','t','e','s','t',0, /* keyword */
140 'v','a','l','u','e', /* text */
141 0x3f,0x64,0x19,0xf3 /* chunk CRC */
144 static const char metadata_gAMA[] = {
145 0,0,0,4, /* chunk length */
146 'g','A','M','A', /* chunk type */
147 0,0,130,53, /* gamma */
148 0xff,0xff,0xff,0xff /* chunk CRC */
151 static const char metadata_cHRM[] = {
152 0,0,0,32, /* chunk length */
153 'c','H','R','M', /* chunk type */
154 0,0,122,38, 0,0,128,132, /* white point */
155 0,0,250,0, 0,0,128,232, /* red */
156 0,0,117,48, 0,0,234,96, /* green */
157 0,0,58,152, 0,0,23,112, /* blue */
158 0xff,0xff,0xff,0xff /* chunk CRC */
161 static const char pngimage[285] = {
162 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
163 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
164 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
165 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
166 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
167 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
168 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
171 /* 1x1 pixel gif */
172 static const char gifimage[35] = {
173 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
174 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
175 0x01,0x00,0x3b
178 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
179 static const char animatedgif[] = {
180 'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xA1,0x00,0x00,
181 0x6F,0x6F,0x6F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
182 /*0x21,0xFF,0x0B,'N','E','T','S','C','A','P','E','2','.','0',*/
183 0x21,0xFF,0x0B,'A','N','I','M','E','X','T','S','1','.','0',
184 0x03,0x01,0x05,0x00,0x00,
185 0x21,0xFE,0x0C,'H','e','l','l','o',' ','W','o','r','l','d','!',0x00,
186 0x21,0x01,0x0D,'a','n','i','m','a','t','i','o','n','.','g','i','f',0x00,
187 0x21,0xF9,0x04,0x00,0x0A,0x00,0xFF,0x00,0x2C,
188 0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
189 0xDE,0xDE,0xDE,0x00,0x00,0x00,
190 0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x4C,0x01,0x00,
191 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','1',0x00,
192 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','1',0x00,
193 0x21,0xF9,0x04,0x01,0x0A,0x00,0x01,0x00,0x2C,
194 0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
195 0x4D,0x4D,0x4D,0x00,0x00,0x00,
196 0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x44,0x01,0x00,
197 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','2',0x00,
198 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','2',0x00,0x3B
201 static IStream *create_stream(const char *data, int data_size)
203 HRESULT hr;
204 IStream *stream;
205 HGLOBAL hdata;
206 void *locked_data;
208 hdata = GlobalAlloc(GMEM_MOVEABLE, data_size);
209 ok(hdata != 0, "GlobalAlloc failed\n");
210 if (!hdata) return NULL;
212 locked_data = GlobalLock(hdata);
213 memcpy(locked_data, data, data_size);
214 GlobalUnlock(hdata);
216 hr = CreateStreamOnHGlobal(hdata, TRUE, &stream);
217 ok(hr == S_OK, "CreateStreamOnHGlobal failed, hr=%x\n", hr);
219 return stream;
222 static void load_stream(IUnknown *reader, const char *data, int data_size, DWORD persist_options)
224 HRESULT hr;
225 IWICPersistStream *persist;
226 IStream *stream;
227 LARGE_INTEGER pos;
228 ULARGE_INTEGER cur_pos;
230 stream = create_stream(data, data_size);
231 if (!stream)
232 return;
234 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void**)&persist);
235 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
237 if (SUCCEEDED(hr))
239 hr = IWICPersistStream_LoadEx(persist, stream, NULL, persist_options);
240 ok(hr == S_OK, "LoadEx failed, hr=%x\n", hr);
242 IWICPersistStream_Release(persist);
245 pos.QuadPart = 0;
246 hr = IStream_Seek(stream, pos, SEEK_CUR, &cur_pos);
247 ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
248 /* IFD metadata reader doesn't rewind the stream to the start */
249 ok(cur_pos.QuadPart == 0 || cur_pos.QuadPart <= data_size,
250 "current stream pos is at %x/%x, data size %x\n", cur_pos.u.LowPart, cur_pos.u.HighPart, data_size);
252 IStream_Release(stream);
255 static void test_metadata_unknown(void)
257 HRESULT hr;
258 IWICMetadataReader *reader;
259 IWICEnumMetadataItem *enumerator;
260 IWICMetadataBlockReader *blockreader;
261 PROPVARIANT schema, id, value;
262 ULONG items_returned;
264 hr = CoCreateInstance(&CLSID_WICUnknownMetadataReader, NULL, CLSCTX_INPROC_SERVER,
265 &IID_IWICMetadataReader, (void**)&reader);
266 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
267 if (FAILED(hr)) return;
269 load_stream((IUnknown*)reader, metadata_unknown, sizeof(metadata_unknown), WICPersistOptionDefault);
271 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
272 ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr);
274 if (SUCCEEDED(hr))
276 PropVariantInit(&schema);
277 PropVariantInit(&id);
278 PropVariantInit(&value);
280 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
281 ok(hr == S_OK, "Next failed, hr=%x\n", hr);
282 ok(items_returned == 1, "unexpected item count %i\n", items_returned);
284 if (hr == S_OK && items_returned == 1)
286 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
287 ok(id.vt == VT_EMPTY, "unexpected vt: %i\n", id.vt);
288 expect_blob(value, metadata_unknown, sizeof(metadata_unknown));
290 PropVariantClear(&schema);
291 PropVariantClear(&id);
292 PropVariantClear(&value);
295 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
296 ok(hr == S_FALSE, "Next failed, hr=%x\n", hr);
297 ok(items_returned == 0, "unexpected item count %i\n", items_returned);
299 IWICEnumMetadataItem_Release(enumerator);
302 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader);
303 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
305 if (SUCCEEDED(hr))
306 IWICMetadataBlockReader_Release(blockreader);
308 IWICMetadataReader_Release(reader);
311 static void test_metadata_tEXt(void)
313 HRESULT hr;
314 IWICMetadataReader *reader;
315 IWICEnumMetadataItem *enumerator;
316 PROPVARIANT schema, id, value;
317 ULONG items_returned, count;
318 GUID format;
320 PropVariantInit(&schema);
321 PropVariantInit(&id);
322 PropVariantInit(&value);
324 hr = CoCreateInstance(&CLSID_WICPngTextMetadataReader, NULL, CLSCTX_INPROC_SERVER,
325 &IID_IWICMetadataReader, (void**)&reader);
326 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
327 if (FAILED(hr)) return;
329 hr = IWICMetadataReader_GetCount(reader, NULL);
330 ok(hr == E_INVALIDARG, "GetCount failed, hr=%x\n", hr);
332 hr = IWICMetadataReader_GetCount(reader, &count);
333 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
334 ok(count == 0, "unexpected count %i\n", count);
336 load_stream((IUnknown*)reader, metadata_tEXt, sizeof(metadata_tEXt), WICPersistOptionDefault);
338 hr = IWICMetadataReader_GetCount(reader, &count);
339 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
340 ok(count == 1, "unexpected count %i\n", count);
342 hr = IWICMetadataReader_GetEnumerator(reader, NULL);
343 ok(hr == E_INVALIDARG, "GetEnumerator failed, hr=%x\n", hr);
345 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
346 ok(hr == S_OK, "GetEnumerator failed, hr=%x\n", hr);
348 if (SUCCEEDED(hr))
350 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
351 ok(hr == S_OK, "Next failed, hr=%x\n", hr);
352 ok(items_returned == 1, "unexpected item count %i\n", items_returned);
354 if (hr == S_OK && items_returned == 1)
356 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
357 ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
358 ok(!strcmp(U(id).pszVal, "winetest"), "unexpected id: %s\n", U(id).pszVal);
359 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", value.vt);
360 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal);
362 PropVariantClear(&schema);
363 PropVariantClear(&id);
364 PropVariantClear(&value);
367 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
368 ok(hr == S_FALSE, "Next failed, hr=%x\n", hr);
369 ok(items_returned == 0, "unexpected item count %i\n", items_returned);
371 IWICEnumMetadataItem_Release(enumerator);
374 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
375 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
376 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", wine_dbgstr_guid(&format));
378 hr = IWICMetadataReader_GetMetadataFormat(reader, NULL);
379 ok(hr == E_INVALIDARG, "GetMetadataFormat failed, hr=%x\n", hr);
381 id.vt = VT_LPSTR;
382 U(id).pszVal = CoTaskMemAlloc(strlen("winetest") + 1);
383 strcpy(U(id).pszVal, "winetest");
385 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL);
386 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
388 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, &value);
389 ok(hr == E_INVALIDARG, "GetValue failed, hr=%x\n", hr);
391 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
392 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
393 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
394 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal);
395 PropVariantClear(&value);
397 strcpy(U(id).pszVal, "test");
399 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
400 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "GetValue failed, hr=%x\n", hr);
402 PropVariantClear(&id);
404 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, NULL);
405 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
407 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, NULL, NULL);
408 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
409 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
411 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &id, NULL);
412 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
413 ok(id.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
414 ok(!strcmp(U(id).pszVal, "winetest"), "unexpected id: %s\n", U(id).pszVal);
415 PropVariantClear(&id);
417 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, &value);
418 ok(hr == S_OK, "GetValueByIndex failed, hr=%x\n", hr);
419 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", value.vt);
420 ok(!strcmp(U(value).pszVal, "value"), "unexpected value: %s\n", U(value).pszVal);
421 PropVariantClear(&value);
423 hr = IWICMetadataReader_GetValueByIndex(reader, 1, NULL, NULL, NULL);
424 ok(hr == E_INVALIDARG, "GetValueByIndex failed, hr=%x\n", hr);
426 IWICMetadataReader_Release(reader);
429 static void test_metadata_gAMA(void)
431 HRESULT hr;
432 IWICMetadataReader *reader;
433 PROPVARIANT schema, id, value;
434 ULONG count;
435 GUID format;
436 static const WCHAR ImageGamma[] = {'I','m','a','g','e','G','a','m','m','a',0};
438 PropVariantInit(&schema);
439 PropVariantInit(&id);
440 PropVariantInit(&value);
442 hr = CoCreateInstance(&CLSID_WICPngGamaMetadataReader, NULL, CLSCTX_INPROC_SERVER,
443 &IID_IWICMetadataReader, (void**)&reader);
444 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG) /*winxp*/, "CoCreateInstance failed, hr=%x\n", hr);
445 if (FAILED(hr)) return;
447 load_stream((IUnknown*)reader, metadata_gAMA, sizeof(metadata_gAMA), WICPersistOptionDefault);
449 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
450 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
451 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunkgAMA), "unexpected format %s\n", wine_dbgstr_guid(&format));
453 hr = IWICMetadataReader_GetCount(reader, &count);
454 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
455 ok(count == 1, "unexpected count %i\n", count);
457 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, &id, &value);
458 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
460 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
461 PropVariantClear(&schema);
463 ok(id.vt == VT_LPWSTR, "unexpected vt: %i\n", id.vt);
464 ok(!lstrcmpW(U(id).pwszVal, ImageGamma), "unexpected value: %s\n", wine_dbgstr_w(U(id).pwszVal));
465 PropVariantClear(&id);
467 ok(value.vt == VT_UI4, "unexpected vt: %i\n", value.vt);
468 ok(U(value).ulVal == 33333, "unexpected value: %u\n", U(value).ulVal);
469 PropVariantClear(&value);
471 IWICMetadataReader_Release(reader);
474 static void test_metadata_cHRM(void)
476 HRESULT hr;
477 IWICMetadataReader *reader;
478 PROPVARIANT schema, id, value;
479 ULONG count;
480 GUID format;
481 int i;
482 static const WCHAR expected_names[8][12] = {
483 {'W','h','i','t','e','P','o','i','n','t','X',0},
484 {'W','h','i','t','e','P','o','i','n','t','Y',0},
485 {'R','e','d','X',0},
486 {'R','e','d','Y',0},
487 {'G','r','e','e','n','X',0},
488 {'G','r','e','e','n','Y',0},
489 {'B','l','u','e','X',0},
490 {'B','l','u','e','Y',0},
492 static const ULONG expected_vals[8] = {
493 31270,32900, 64000,33000, 30000,60000, 15000,6000
496 PropVariantInit(&schema);
497 PropVariantInit(&id);
498 PropVariantInit(&value);
500 hr = CoCreateInstance(&CLSID_WICPngChrmMetadataReader, NULL, CLSCTX_INPROC_SERVER,
501 &IID_IWICMetadataReader, (void**)&reader);
502 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG) /*winxp*/, "CoCreateInstance failed, hr=%x\n", hr);
503 if (FAILED(hr)) return;
505 load_stream((IUnknown*)reader, metadata_cHRM, sizeof(metadata_cHRM), WICPersistOptionDefault);
507 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
508 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
509 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunkcHRM), "unexpected format %s\n", wine_dbgstr_guid(&format));
511 hr = IWICMetadataReader_GetCount(reader, &count);
512 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
513 ok(count == 8, "unexpected count %i\n", count);
515 for (i=0; i<8; i++)
517 hr = IWICMetadataReader_GetValueByIndex(reader, i, &schema, &id, &value);
518 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
520 ok(schema.vt == VT_EMPTY, "unexpected vt: %i\n", schema.vt);
521 PropVariantClear(&schema);
523 ok(id.vt == VT_LPWSTR, "unexpected vt: %i\n", id.vt);
524 ok(!lstrcmpW(U(id).pwszVal, expected_names[i]), "got %s, expected %s\n", wine_dbgstr_w(U(id).pwszVal), wine_dbgstr_w(expected_names[i]));
525 PropVariantClear(&id);
527 ok(value.vt == VT_UI4, "unexpected vt: %i\n", value.vt);
528 ok(U(value).ulVal == expected_vals[i], "got %u, expected %u\n", U(value).ulVal, expected_vals[i]);
529 PropVariantClear(&value);
532 IWICMetadataReader_Release(reader);
535 static inline USHORT ushort_bswap(USHORT s)
537 return (s >> 8) | (s << 8);
540 static inline ULONG ulong_bswap(ULONG l)
542 return ((ULONG)ushort_bswap((USHORT)l) << 16) | ushort_bswap((USHORT)(l >> 16));
545 static inline ULONGLONG ulonglong_bswap(ULONGLONG ll)
547 return ((ULONGLONG)ulong_bswap((ULONG)ll) << 32) | ulong_bswap((ULONG)(ll >> 32));
550 static void byte_swap_ifd_data(char *data)
552 USHORT number_of_entries, i;
553 struct IFD_entry *entry;
554 char *data_start = data;
556 number_of_entries = *(USHORT *)data;
557 *(USHORT *)data = ushort_bswap(*(USHORT *)data);
558 data += sizeof(USHORT);
560 for (i = 0; i < number_of_entries; i++)
562 entry = (struct IFD_entry *)data;
564 switch (entry->type)
566 case IFD_BYTE:
567 case IFD_SBYTE:
568 case IFD_ASCII:
569 case IFD_UNDEFINED:
570 if (entry->count > 4)
571 entry->value = ulong_bswap(entry->value);
572 break;
574 case IFD_SHORT:
575 case IFD_SSHORT:
576 if (entry->count > 2)
578 ULONG j, count = entry->count;
579 USHORT *us = (USHORT *)(data_start + entry->value);
580 if (!count) count = 1;
581 for (j = 0; j < count; j++)
582 us[j] = ushort_bswap(us[j]);
584 entry->value = ulong_bswap(entry->value);
586 else
588 ULONG j, count = entry->count;
589 USHORT *us = (USHORT *)&entry->value;
590 if (!count) count = 1;
591 for (j = 0; j < count; j++)
592 us[j] = ushort_bswap(us[j]);
594 break;
596 case IFD_LONG:
597 case IFD_SLONG:
598 case IFD_FLOAT:
599 if (entry->count > 1)
601 ULONG j, count = entry->count;
602 ULONG *ul = (ULONG *)(data_start + entry->value);
603 if (!count) count = 1;
604 for (j = 0; j < count; j++)
605 ul[j] = ulong_bswap(ul[j]);
607 entry->value = ulong_bswap(entry->value);
608 break;
610 case IFD_RATIONAL:
611 case IFD_SRATIONAL:
613 ULONG j;
614 ULONG *ul = (ULONG *)(data_start + entry->value);
615 for (j = 0; j < entry->count * 2; j++)
616 ul[j] = ulong_bswap(ul[j]);
618 entry->value = ulong_bswap(entry->value);
619 break;
621 case IFD_DOUBLE:
623 ULONG j;
624 ULONGLONG *ull = (ULONGLONG *)(data_start + entry->value);
625 for (j = 0; j < entry->count; j++)
626 ull[j] = ulonglong_bswap(ull[j]);
628 entry->value = ulong_bswap(entry->value);
629 break;
631 default:
632 assert(0);
633 break;
636 entry->id = ushort_bswap(entry->id);
637 entry->type = ushort_bswap(entry->type);
638 entry->count = ulong_bswap(entry->count);
639 data += sizeof(*entry);
643 struct test_data
645 ULONG type, id;
646 int count; /* if VT_VECTOR */
647 LONGLONG value[13];
648 const char *string;
649 const WCHAR id_string[32];
652 static void compare_metadata(IWICMetadataReader *reader, const struct test_data *td, ULONG count)
654 HRESULT hr;
655 IWICEnumMetadataItem *enumerator;
656 PROPVARIANT schema, id, value;
657 ULONG items_returned, i;
659 hr = IWICMetadataReader_GetEnumerator(reader, NULL);
660 ok(hr == E_INVALIDARG, "GetEnumerator error %#x\n", hr);
662 hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
663 ok(hr == S_OK, "GetEnumerator error %#x\n", hr);
665 PropVariantInit(&schema);
666 PropVariantInit(&id);
667 PropVariantInit(&value);
669 for (i = 0; i < count; i++)
671 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
672 ok(hr == S_OK, "Next error %#x\n", hr);
673 ok(items_returned == 1, "unexpected item count %u\n", items_returned);
675 ok(schema.vt == VT_EMPTY, "%u: unexpected vt: %u\n", i, schema.vt);
676 ok(id.vt == VT_UI2 || id.vt == VT_LPWSTR || id.vt == VT_EMPTY, "%u: unexpected vt: %u\n", i, id.vt);
677 if (id.vt == VT_UI2)
678 ok(U(id).uiVal == td[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, U(id).uiVal);
679 else if (id.vt == VT_LPWSTR)
680 ok(!lstrcmpW(td[i].id_string, U(id).pwszVal),
681 "%u: expected %s, got %s\n", i, wine_dbgstr_w(td[i].id_string), wine_dbgstr_w(U(id).pwszVal));
683 ok(value.vt == td[i].type, "%u: expected vt %#x, got %#x\n", i, td[i].type, value.vt);
684 if (value.vt & VT_VECTOR)
686 ULONG j;
687 switch (value.vt & ~VT_VECTOR)
689 case VT_I1:
690 case VT_UI1:
691 ok(td[i].count == U(value).caub.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caub.cElems);
692 for (j = 0; j < U(value).caub.cElems; j++)
693 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]);
694 break;
695 case VT_I2:
696 case VT_UI2:
697 ok(td[i].count == U(value).caui.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caui.cElems);
698 for (j = 0; j < U(value).caui.cElems; j++)
699 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]);
700 break;
701 case VT_I4:
702 case VT_UI4:
703 case VT_R4:
704 ok(td[i].count == U(value).caul.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caul.cElems);
705 for (j = 0; j < U(value).caul.cElems; j++)
706 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]);
707 break;
708 case VT_I8:
709 case VT_UI8:
710 case VT_R8:
711 ok(td[i].count == U(value).cauh.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).cauh.cElems);
712 for (j = 0; j < U(value).cauh.cElems; j++)
713 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);
714 break;
715 case VT_LPSTR:
716 ok(td[i].count == U(value).calpstr.cElems, "%u: expected cElems %d, got %d\n", i, td[i].count, U(value).caub.cElems);
717 for (j = 0; j < U(value).calpstr.cElems; j++)
718 trace("%u: %s\n", j, U(value).calpstr.pElems[j]);
719 /* fall through to not handled message */
720 default:
721 ok(0, "%u: array of type %d is not handled\n", i, value.vt & ~VT_VECTOR);
722 break;
725 else if (value.vt == VT_LPSTR)
727 ok(td[i].count == strlen(U(value).pszVal) ||
728 broken(td[i].count == strlen(U(value).pszVal) + 1), /* before Win7 */
729 "%u: expected count %d, got %d\n", i, td[i].count, lstrlenA(U(value).pszVal));
730 if (td[i].count == strlen(U(value).pszVal))
731 ok(!strcmp(td[i].string, U(value).pszVal),
732 "%u: expected %s, got %s\n", i, td[i].string, U(value).pszVal);
734 else if (value.vt == VT_BLOB)
736 ok(td[i].count == U(value).blob.cbSize, "%u: expected count %d, got %d\n", i, td[i].count, U(value).blob.cbSize);
737 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);
739 else
740 ok(U(value).uhVal.QuadPart == td[i].value[0], "%u: expected value %#x/%#x got %#x/%#x\n",
741 i, (UINT)td[i].value[0], (UINT)(td[i].value[0] >> 32), U(value).uhVal.u.LowPart, U(value).uhVal.u.HighPart);
743 PropVariantClear(&schema);
744 PropVariantClear(&id);
745 PropVariantClear(&value);
748 hr = IWICEnumMetadataItem_Next(enumerator, 1, &schema, &id, &value, &items_returned);
749 ok(hr == S_FALSE, "Next should fail\n");
750 ok(items_returned == 0, "unexpected item count %u\n", items_returned);
752 IWICEnumMetadataItem_Release(enumerator);
755 static void test_metadata_IFD(void)
757 static const struct test_data td[28] =
759 { VT_UI2, 0xfe, 0, { 1 } },
760 { VT_UI4, 0x100, 0, { 222 } },
761 { VT_UI4, 0x101, 0, { 333 } },
762 { VT_UI2, 0x102, 0, { 24 } },
763 { VT_UI4, 0x103, 0, { 32773 } },
764 { VT_UI8, 0x11a, 0, { ((LONGLONG)3 << 32) | 900 } },
765 { VT_UI1, 0xf001, 0, { 0x44 } },
766 { VT_UI1|VT_VECTOR, 0xf002, 4, { 0x44, 0x33, 0x22, 0x11 } },
767 { VT_I1, 0xf003, 0, { 0x44 } },
768 { VT_I2, 0xf004, 0, { 0x3344 } },
769 { VT_I2|VT_VECTOR, 0xf005, 2, { 0x3344, 0x1122 } },
770 { VT_I4, 0xf006, 0, { 0x11223344 } },
771 { VT_R4, 0xf007, 0, { 0x11223344 } },
772 { VT_R8, 0xf008, 0, { ((LONGLONG)0x41d26580 << 32) | 0xb486522c } },
773 { VT_I8, 0xf009, 0, { ((LONGLONG)0x5a6b7c8d << 32) | 0x1a2b3c4d } },
774 { VT_UI1|VT_VECTOR, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
775 { VT_I2|VT_VECTOR, 0xf00b, 4, { 0x0101, 0x0202, 0x0303, 0x0404 } },
776 { VT_I4|VT_VECTOR, 0xf00c, 2, { 0x11223344, 0x55667788 } },
777 { VT_R4|VT_VECTOR, 0xf00d, 2, { 0x449a522b, 0x4608f5ba } },
778 { VT_LPSTR, 0xf00e, 12, { 0 }, "Hello World!" },
779 { VT_LPSTR, 0xf00f, 4, { 0 }, "abcd" },
780 { VT_BLOB, 0xf010, 13, { 0 }, "Hello World!" },
781 { VT_BLOB, 0xf011, 4, { 0 }, "abcd" },
782 { VT_UI1, 0xf012, 0, { 0x44 } },
783 { VT_UI2, 0xf013, 0, { 0x3344 } },
784 { VT_UI4, 0xf014, 0, { 0x11223344 } },
785 { VT_R4, 0xf015, 0, { 0x11223344 } },
786 { VT_I8|VT_VECTOR, 0xf016, 3,
787 { ((LONGLONG)0x05060708 << 32) | 0x01020304,
788 ((LONGLONG)0x50607080 << 32) | 0x10203040,
789 ((LONGLONG)0x55667788 << 32) | 0x11223344 } },
791 HRESULT hr;
792 IWICMetadataReader *reader;
793 IWICMetadataBlockReader *blockreader;
794 PROPVARIANT schema, id, value;
795 ULONG count;
796 GUID format;
797 char *IFD_data_swapped;
798 #ifdef WORDS_BIGENDIAN
799 DWORD persist_options = WICPersistOptionBigEndian;
800 #else
801 DWORD persist_options = WICPersistOptionLittleEndian;
802 #endif
804 hr = CoCreateInstance(&CLSID_WICIfdMetadataReader, NULL, CLSCTX_INPROC_SERVER,
805 &IID_IWICMetadataReader, (void**)&reader);
806 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
808 hr = IWICMetadataReader_GetCount(reader, NULL);
809 ok(hr == E_INVALIDARG, "GetCount error %#x\n", hr);
811 hr = IWICMetadataReader_GetCount(reader, &count);
812 ok(hr == S_OK, "GetCount error %#x\n", hr);
813 ok(count == 0, "unexpected count %u\n", count);
815 load_stream((IUnknown*)reader, (const char *)&IFD_data, sizeof(IFD_data), persist_options);
817 hr = IWICMetadataReader_GetCount(reader, &count);
818 ok(hr == S_OK, "GetCount error %#x\n", hr);
819 ok(count == ARRAY_SIZE(td), "unexpected count %u\n", count);
821 compare_metadata(reader, td, count);
823 /* test IFD data with different endianness */
824 if (persist_options == WICPersistOptionLittleEndian)
825 persist_options = WICPersistOptionBigEndian;
826 else
827 persist_options = WICPersistOptionLittleEndian;
829 IFD_data_swapped = HeapAlloc(GetProcessHeap(), 0, sizeof(IFD_data));
830 memcpy(IFD_data_swapped, &IFD_data, sizeof(IFD_data));
831 byte_swap_ifd_data(IFD_data_swapped);
832 load_stream((IUnknown *)reader, IFD_data_swapped, sizeof(IFD_data), persist_options);
833 hr = IWICMetadataReader_GetCount(reader, &count);
834 ok(hr == S_OK, "GetCount error %#x\n", hr);
835 ok(count == ARRAY_SIZE(td), "unexpected count %u\n", count);
836 compare_metadata(reader, td, count);
837 HeapFree(GetProcessHeap(), 0, IFD_data_swapped);
839 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
840 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
841 ok(IsEqualGUID(&format, &GUID_MetadataFormatIfd), "unexpected format %s\n", wine_dbgstr_guid(&format));
843 hr = IWICMetadataReader_GetMetadataFormat(reader, NULL);
844 ok(hr == E_INVALIDARG, "GetMetadataFormat should fail\n");
846 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, NULL);
847 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
849 PropVariantInit(&schema);
850 PropVariantInit(&id);
851 PropVariantInit(&value);
853 hr = IWICMetadataReader_GetValueByIndex(reader, count - 1, NULL, NULL, NULL);
854 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
856 hr = IWICMetadataReader_GetValueByIndex(reader, 0, &schema, NULL, NULL);
857 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
858 ok(schema.vt == VT_EMPTY, "unexpected vt: %u\n", schema.vt);
860 hr = IWICMetadataReader_GetValueByIndex(reader, count - 1, &schema, NULL, NULL);
861 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
862 ok(schema.vt == VT_EMPTY, "unexpected vt: %u\n", schema.vt);
864 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &id, NULL);
865 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
866 ok(id.vt == VT_UI2, "unexpected vt: %u\n", id.vt);
867 ok(U(id).uiVal == 0xfe, "unexpected id: %#x\n", U(id).uiVal);
868 PropVariantClear(&id);
870 hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, NULL, &value);
871 ok(hr == S_OK, "GetValueByIndex error %#x\n", hr);
872 ok(value.vt == VT_UI2, "unexpected vt: %u\n", value.vt);
873 ok(U(value).uiVal == 1, "unexpected id: %#x\n", U(value).uiVal);
874 PropVariantClear(&value);
876 hr = IWICMetadataReader_GetValueByIndex(reader, count, &schema, NULL, NULL);
877 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
879 PropVariantInit(&schema);
880 PropVariantInit(&id);
881 PropVariantInit(&value);
883 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
884 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr);
886 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL);
887 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr);
889 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, NULL);
890 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
892 hr = IWICMetadataReader_GetValue(reader, &schema, &id, NULL);
893 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "expected WINCODEC_ERR_PROPERTYNOTFOUND, got %#x\n", hr);
895 hr = IWICMetadataReader_GetValue(reader, &schema, NULL, &value);
896 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
898 id.vt = VT_UI2;
899 U(id).uiVal = 0xf00e;
900 hr = IWICMetadataReader_GetValue(reader, NULL, &id, NULL);
901 ok(hr == S_OK, "GetValue error %#x\n", hr);
903 /* schema is ignored by Ifd metadata reader */
904 schema.vt = VT_UI4;
905 U(schema).ulVal = 0xdeadbeef;
906 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
907 ok(hr == S_OK, "GetValue error %#x\n", hr);
908 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
909 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal);
910 PropVariantClear(&value);
912 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
913 ok(hr == S_OK, "GetValue error %#x\n", hr);
914 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
915 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal);
916 PropVariantClear(&value);
918 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader);
919 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
921 if (SUCCEEDED(hr))
922 IWICMetadataBlockReader_Release(blockreader);
924 IWICMetadataReader_Release(reader);
927 static void test_metadata_Exif(void)
929 HRESULT hr;
930 IWICMetadataReader *reader;
931 IWICMetadataBlockReader *blockreader;
932 UINT count=0;
934 hr = CoCreateInstance(&CLSID_WICExifMetadataReader, NULL, CLSCTX_INPROC_SERVER,
935 &IID_IWICMetadataReader, (void**)&reader);
936 todo_wine ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
937 if (FAILED(hr)) return;
939 hr = IWICMetadataReader_GetCount(reader, NULL);
940 ok(hr == E_INVALIDARG, "GetCount error %#x\n", hr);
942 hr = IWICMetadataReader_GetCount(reader, &count);
943 ok(hr == S_OK, "GetCount error %#x\n", hr);
944 ok(count == 0, "unexpected count %u\n", count);
946 hr = IWICMetadataReader_QueryInterface(reader, &IID_IWICMetadataBlockReader, (void**)&blockreader);
947 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
949 if (SUCCEEDED(hr))
950 IWICMetadataBlockReader_Release(blockreader);
952 IWICMetadataReader_Release(reader);
955 static void test_create_reader(void)
957 HRESULT hr;
958 IWICComponentFactory *factory;
959 IStream *stream;
960 IWICMetadataReader *reader;
961 UINT count=0;
962 GUID format;
964 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
965 &IID_IWICComponentFactory, (void**)&factory);
966 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
968 stream = create_stream(metadata_tEXt, sizeof(metadata_tEXt));
970 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory,
971 NULL, NULL, WICPersistOptionDefault,
972 stream, &reader);
973 ok(hr == E_INVALIDARG, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr);
975 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory,
976 &GUID_ContainerFormatPng, NULL, WICPersistOptionDefault,
977 NULL, &reader);
978 ok(hr == E_INVALIDARG, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr);
980 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory,
981 &GUID_ContainerFormatPng, NULL, WICPersistOptionDefault,
982 stream, NULL);
983 ok(hr == E_INVALIDARG, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr);
985 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory,
986 &GUID_ContainerFormatPng, NULL, WICPersistOptionDefault,
987 stream, &reader);
988 ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr);
990 if (SUCCEEDED(hr))
992 hr = IWICMetadataReader_GetCount(reader, &count);
993 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
994 ok(count == 1, "unexpected count %i\n", count);
996 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
997 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
998 ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", wine_dbgstr_guid(&format));
1000 IWICMetadataReader_Release(reader);
1003 hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory,
1004 &GUID_ContainerFormatWmp, NULL, WICPersistOptionDefault,
1005 stream, &reader);
1006 ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr);
1008 if (SUCCEEDED(hr))
1010 hr = IWICMetadataReader_GetCount(reader, &count);
1011 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
1012 ok(count == 1, "unexpected count %i\n", count);
1014 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1015 ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr);
1016 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown), "unexpected format %s\n", wine_dbgstr_guid(&format));
1018 IWICMetadataReader_Release(reader);
1021 IStream_Release(stream);
1023 IWICComponentFactory_Release(factory);
1026 static void test_metadata_png(void)
1028 static const struct test_data td[6] =
1030 { VT_UI2, 0, 0, { 2005 }, NULL, { 'Y','e','a','r',0 } },
1031 { VT_UI1, 0, 0, { 6 }, NULL, { 'M','o','n','t','h',0 } },
1032 { VT_UI1, 0, 0, { 3 }, NULL, { 'D','a','y',0 } },
1033 { VT_UI1, 0, 0, { 15 }, NULL, { 'H','o','u','r',0 } },
1034 { VT_UI1, 0, 0, { 7 }, NULL, { 'M','i','n','u','t','e',0 } },
1035 { VT_UI1, 0, 0, { 45 }, NULL, { 'S','e','c','o','n','d',0 } }
1037 IStream *stream;
1038 IWICBitmapDecoder *decoder;
1039 IWICBitmapFrameDecode *frame;
1040 IWICMetadataBlockReader *blockreader;
1041 IWICMetadataReader *reader;
1042 IWICMetadataQueryReader *queryreader;
1043 IWICComponentFactory *factory;
1044 GUID containerformat;
1045 HRESULT hr;
1046 UINT count=0xdeadbeef;
1048 hr = CoCreateInstance(&CLSID_WICPngDecoder, NULL, CLSCTX_INPROC_SERVER,
1049 &IID_IWICBitmapDecoder, (void**)&decoder);
1050 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
1052 if (FAILED(hr)) return;
1054 stream = create_stream(pngimage, sizeof(pngimage));
1056 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
1057 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
1059 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void**)&blockreader);
1060 ok(hr == E_NOINTERFACE, "QueryInterface failed, hr=%x\n", hr);
1062 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
1063 ok(hr == S_OK, "GetFrame failed, hr=%x\n", hr);
1065 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void**)&blockreader);
1066 ok(hr == S_OK, "QueryInterface failed, hr=%x\n", hr);
1068 if (SUCCEEDED(hr))
1070 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, NULL);
1071 ok(hr == E_INVALIDARG, "GetContainerFormat failed, hr=%x\n", hr);
1073 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &containerformat);
1074 ok(hr == S_OK, "GetContainerFormat failed, hr=%x\n", hr);
1075 ok(IsEqualGUID(&containerformat, &GUID_ContainerFormatPng), "unexpected container format\n");
1077 hr = IWICMetadataBlockReader_GetCount(blockreader, NULL);
1078 ok(hr == E_INVALIDARG, "GetCount failed, hr=%x\n", hr);
1080 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
1081 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
1082 ok(count == 1, "unexpected count %d\n", count);
1084 if (0)
1086 /* Crashes on Windows XP */
1087 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, NULL);
1088 ok(hr == E_INVALIDARG, "GetReaderByIndex failed, hr=%x\n", hr);
1091 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
1092 ok(hr == S_OK, "GetReaderByIndex failed, hr=%x\n", hr);
1094 if (SUCCEEDED(hr))
1096 hr = IWICMetadataReader_GetMetadataFormat(reader, &containerformat);
1097 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1098 todo_wine ok(IsEqualGUID(&containerformat, &GUID_MetadataFormatChunktIME) ||
1099 broken(IsEqualGUID(&containerformat, &GUID_MetadataFormatUnknown)) /* Windows XP */,
1100 "unexpected container format\n");
1102 hr = IWICMetadataReader_GetCount(reader, &count);
1103 ok(hr == S_OK, "GetCount error %#x\n", hr);
1104 todo_wine ok(count == 6 || broken(count == 1) /* XP */, "expected 6, got %u\n", count);
1105 if (count == 6)
1106 compare_metadata(reader, td, count);
1108 IWICMetadataReader_Release(reader);
1111 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
1112 todo_wine ok(hr == WINCODEC_ERR_VALUEOUTOFRANGE, "GetReaderByIndex failed, hr=%x\n", hr);
1114 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1115 &IID_IWICComponentFactory, (void**)&factory);
1116 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
1118 hr = IWICComponentFactory_CreateQueryReaderFromBlockReader(factory, NULL, &queryreader);
1119 ok(hr == E_INVALIDARG, "CreateQueryReaderFromBlockReader should have failed: %08x\n", hr);
1121 hr = IWICComponentFactory_CreateQueryReaderFromBlockReader(factory, blockreader, NULL);
1122 ok(hr == E_INVALIDARG, "CreateQueryReaderFromBlockReader should have failed: %08x\n", hr);
1124 hr = IWICComponentFactory_CreateQueryReaderFromBlockReader(factory, blockreader, &queryreader);
1125 ok(hr == S_OK, "CreateQueryReaderFromBlockReader failed: %08x\n", hr);
1127 IWICMetadataQueryReader_Release(queryreader);
1129 IWICComponentFactory_Release(factory);
1131 IWICMetadataBlockReader_Release(blockreader);
1134 hr = IWICBitmapFrameDecode_GetMetadataQueryReader(frame, &queryreader);
1135 ok(hr == S_OK, "GetMetadataQueryReader failed: %08x\n", hr);
1137 if (SUCCEEDED(hr))
1139 IWICMetadataQueryReader_Release(queryreader);
1142 IWICBitmapFrameDecode_Release(frame);
1144 IWICBitmapDecoder_Release(decoder);
1146 IStream_Release(stream);
1149 static void test_metadata_gif(void)
1151 static const struct test_data gif_LSD[9] =
1153 { VT_UI1|VT_VECTOR, 0, 6, {'G','I','F','8','7','a'}, NULL, { 'S','i','g','n','a','t','u','r','e',0 } },
1154 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } },
1155 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } },
1156 { 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 } },
1157 { VT_UI1, 0, 0, { 0 }, NULL, { 'C','o','l','o','r','R','e','s','o','l','u','t','i','o','n',0 } },
1158 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1159 { 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 } },
1160 { 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 } },
1161 { VT_UI1, 0, 0, { 0 }, NULL, { 'P','i','x','e','l','A','s','p','e','c','t','R','a','t','i','o',0 } }
1163 static const struct test_data gif_IMD[8] =
1165 { VT_UI2, 0, 0, { 0 }, NULL, { 'L','e','f','t',0 } },
1166 { VT_UI2, 0, 0, { 0 }, NULL, { 'T','o','p',0 } },
1167 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } },
1168 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } },
1169 { 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 } },
1170 { VT_BOOL, 0, 0, { 0 }, NULL, { 'I','n','t','e','r','l','a','c','e','F','l','a','g',0 } },
1171 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1172 { 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 } }
1174 static const struct test_data animated_gif_LSD[9] =
1176 { VT_UI1|VT_VECTOR, 0, 6, {'G','I','F','8','9','a'}, NULL, { 'S','i','g','n','a','t','u','r','e',0 } },
1177 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } },
1178 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } },
1179 { 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 } },
1180 { VT_UI1, 0, 0, { 2 }, NULL, { 'C','o','l','o','r','R','e','s','o','l','u','t','i','o','n',0 } },
1181 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1182 { 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 } },
1183 { 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 } },
1184 { VT_UI1, 0, 0, { 0 }, NULL, { 'P','i','x','e','l','A','s','p','e','c','t','R','a','t','i','o',0 } }
1186 static const struct test_data animated_gif_IMD[8] =
1188 { VT_UI2, 0, 0, { 0 }, NULL, { 'L','e','f','t',0 } },
1189 { VT_UI2, 0, 0, { 0 }, NULL, { 'T','o','p',0 } },
1190 { VT_UI2, 0, 0, { 1 }, NULL, { 'W','i','d','t','h',0 } },
1191 { VT_UI2, 0, 0, { 1 }, NULL, { 'H','e','i','g','h','t',0 } },
1192 { 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 } },
1193 { VT_BOOL, 0, 0, { 0 }, NULL, { 'I','n','t','e','r','l','a','c','e','F','l','a','g',0 } },
1194 { VT_BOOL, 0, 0, { 0 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1195 { 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 } }
1197 static const struct test_data animated_gif_GCE[5] =
1199 { VT_UI1, 0, 0, { 0 }, NULL, { 'D','i','s','p','o','s','a','l',0 } },
1200 { VT_BOOL, 0, 0, { 0 }, NULL, { 'U','s','e','r','I','n','p','u','t','F','l','a','g',0 } },
1201 { VT_BOOL, 0, 0, { 1 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 } },
1202 { VT_UI2, 0, 0, { 10 }, NULL, { 'D','e','l','a','y',0 } },
1203 { 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 } }
1205 static const struct test_data animated_gif_APE[2] =
1207 { 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 } },
1208 { VT_UI1|VT_VECTOR, 0, 4, { 0x03,0x01,0x05,0x00 }, NULL, { 'D','a','t','a',0 } }
1210 static const struct test_data animated_gif_comment_1[1] =
1212 { VT_LPSTR, 0, 12, { 0 }, "Hello World!", { 'T','e','x','t','E','n','t','r','y',0 } }
1214 static const struct test_data animated_gif_comment_2[1] =
1216 { VT_LPSTR, 0, 8, { 0 }, "image #1", { 'T','e','x','t','E','n','t','r','y',0 } }
1218 static const struct test_data animated_gif_plain_1[1] =
1220 { VT_BLOB, 0, 17, { 0 }, "\x21\x01\x0d\x61nimation.gif" }
1222 static const struct test_data animated_gif_plain_2[1] =
1224 { VT_BLOB, 0, 16, { 0 }, "\x21\x01\x0cplaintext #1" }
1226 IStream *stream;
1227 IWICBitmapDecoder *decoder;
1228 IWICBitmapFrameDecode *frame;
1229 IWICMetadataBlockReader *blockreader;
1230 IWICMetadataReader *reader;
1231 IWICMetadataQueryReader *queryreader;
1232 GUID format;
1233 HRESULT hr;
1234 UINT count;
1236 /* 1x1 pixel gif */
1237 stream = create_stream(gifimage, sizeof(gifimage));
1239 hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER,
1240 &IID_IWICBitmapDecoder, (void **)&decoder);
1241 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
1242 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
1243 ok(hr == S_OK, "Initialize error %#x\n", hr);
1245 IStream_Release(stream);
1247 /* global metadata block */
1248 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void **)&blockreader);
1249 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr);
1251 if (SUCCEEDED(hr))
1253 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format);
1254 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
1255 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
1256 "wrong container format %s\n", wine_dbgstr_guid(&format));
1258 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
1259 ok(hr == S_OK, "GetCount error %#x\n", hr);
1260 ok(count == 1, "expected 1, got %u\n", count);
1262 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
1263 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1265 if (SUCCEEDED(hr))
1267 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1268 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1269 ok(IsEqualGUID(&format, &GUID_MetadataFormatLSD), /* Logical Screen Descriptor */
1270 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1272 hr = IWICMetadataReader_GetCount(reader, &count);
1273 ok(hr == S_OK, "GetCount error %#x\n", hr);
1274 ok(count == ARRAY_SIZE(gif_LSD), "unexpected count %u\n", count);
1276 compare_metadata(reader, gif_LSD, count);
1278 IWICMetadataReader_Release(reader);
1281 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &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, 0, &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);
1294 if (SUCCEEDED(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", wine_dbgstr_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 == 1, "expected 1, got %u\n", count);
1311 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
1312 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1314 if (SUCCEEDED(hr))
1316 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1317 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1318 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), /* Image Descriptor */
1319 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1321 hr = IWICMetadataReader_GetCount(reader, &count);
1322 ok(hr == S_OK, "GetCount error %#x\n", hr);
1323 ok(count == ARRAY_SIZE(gif_IMD), "unexpected count %u\n", count);
1325 compare_metadata(reader, gif_IMD, count);
1327 IWICMetadataReader_Release(reader);
1330 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
1331 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1333 IWICMetadataBlockReader_Release(blockreader);
1336 IWICBitmapFrameDecode_Release(frame);
1337 IWICBitmapDecoder_Release(decoder);
1339 /* 1x1 pixel gif, 2 frames */
1340 stream = create_stream(animatedgif, sizeof(animatedgif));
1342 hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER,
1343 &IID_IWICBitmapDecoder, (void **)&decoder);
1344 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
1345 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
1346 ok(hr == S_OK, "Initialize error %#x\n", hr);
1348 IStream_Release(stream);
1350 /* global metadata block */
1351 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void **)&blockreader);
1352 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr);
1354 if (SUCCEEDED(hr))
1356 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format);
1357 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
1358 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
1359 "wrong container format %s\n", wine_dbgstr_guid(&format));
1361 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
1362 ok(hr == S_OK, "GetCount error %#x\n", hr);
1363 ok(count == 4, "expected 4, got %u\n", count);
1365 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
1366 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1368 if (SUCCEEDED(hr))
1370 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1371 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1372 ok(IsEqualGUID(&format, &GUID_MetadataFormatLSD), /* Logical Screen Descriptor */
1373 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1375 hr = IWICMetadataReader_GetCount(reader, &count);
1376 ok(hr == S_OK, "GetCount error %#x\n", hr);
1377 ok(count == ARRAY_SIZE(animated_gif_LSD), "unexpected count %u\n", count);
1379 compare_metadata(reader, animated_gif_LSD, count);
1381 IWICMetadataReader_Release(reader);
1384 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
1385 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1387 if (SUCCEEDED(hr))
1389 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1390 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1391 ok(IsEqualGUID(&format, &GUID_MetadataFormatAPE), /* Application Extension */
1392 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1394 hr = IWICMetadataReader_GetCount(reader, &count);
1395 ok(hr == S_OK, "GetCount error %#x\n", hr);
1396 ok(count == ARRAY_SIZE(animated_gif_APE), "unexpected count %u\n", count);
1398 compare_metadata(reader, animated_gif_APE, count);
1400 IWICMetadataReader_Release(reader);
1403 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 2, &reader);
1404 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1406 if (SUCCEEDED(hr))
1408 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1409 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1410 ok(IsEqualGUID(&format, &GUID_MetadataFormatGifComment), /* Comment Extension */
1411 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1413 hr = IWICMetadataReader_GetCount(reader, &count);
1414 ok(hr == S_OK, "GetCount error %#x\n", hr);
1415 ok(count == ARRAY_SIZE(animated_gif_comment_1), "unexpected count %u\n", count);
1417 compare_metadata(reader, animated_gif_comment_1, count);
1419 IWICMetadataReader_Release(reader);
1422 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 3, &reader);
1423 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1425 if (SUCCEEDED(hr))
1427 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1428 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1429 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown),
1430 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1432 hr = IWICMetadataReader_GetCount(reader, &count);
1433 ok(hr == S_OK, "GetCount error %#x\n", hr);
1434 ok(count == ARRAY_SIZE(animated_gif_plain_1), "unexpected count %u\n", count);
1436 compare_metadata(reader, animated_gif_plain_1, count);
1438 IWICMetadataReader_Release(reader);
1441 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 4, &reader);
1442 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1444 IWICMetadataBlockReader_Release(blockreader);
1447 /* frame metadata block */
1448 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &frame);
1449 ok(hr == S_OK, "GetFrame error %#x\n", hr);
1451 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void **)&blockreader);
1452 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* before Win7 */, "QueryInterface error %#x\n", hr);
1454 if (SUCCEEDED(hr))
1456 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, NULL);
1457 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1459 hr = IWICMetadataBlockReader_GetContainerFormat(blockreader, &format);
1460 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
1461 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
1462 "wrong container format %s\n", wine_dbgstr_guid(&format));
1464 hr = IWICMetadataBlockReader_GetCount(blockreader, NULL);
1465 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1467 hr = IWICMetadataBlockReader_GetCount(blockreader, &count);
1468 ok(hr == S_OK, "GetCount error %#x\n", hr);
1469 ok(count == 4, "expected 4, got %u\n", count);
1471 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 0, &reader);
1472 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1474 if (SUCCEEDED(hr))
1476 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1477 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1478 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), /* Image Descriptor */
1479 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1481 hr = IWICMetadataReader_GetCount(reader, &count);
1482 ok(hr == S_OK, "GetCount error %#x\n", hr);
1483 ok(count == ARRAY_SIZE(animated_gif_IMD), "unexpected count %u\n", count);
1485 compare_metadata(reader, animated_gif_IMD, count);
1487 IWICMetadataReader_Release(reader);
1490 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 1, &reader);
1491 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1493 if (SUCCEEDED(hr))
1495 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1496 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1497 ok(IsEqualGUID(&format, &GUID_MetadataFormatGifComment), /* Comment Extension */
1498 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1500 hr = IWICMetadataReader_GetCount(reader, &count);
1501 ok(hr == S_OK, "GetCount error %#x\n", hr);
1502 ok(count == ARRAY_SIZE(animated_gif_comment_2), "unexpected count %u\n", count);
1504 if (count == 1)
1505 compare_metadata(reader, animated_gif_comment_2, count);
1507 IWICMetadataReader_Release(reader);
1510 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 2, &reader);
1511 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1513 if (SUCCEEDED(hr))
1515 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1516 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1517 ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown),
1518 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1520 hr = IWICMetadataReader_GetCount(reader, &count);
1521 ok(hr == S_OK, "GetCount error %#x\n", hr);
1522 ok(count == ARRAY_SIZE(animated_gif_plain_2), "unexpected count %u\n", count);
1524 compare_metadata(reader, animated_gif_plain_2, count);
1526 IWICMetadataReader_Release(reader);
1529 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 3, &reader);
1530 ok(hr == S_OK, "GetReaderByIndex error %#x\n", hr);
1532 if (SUCCEEDED(hr))
1534 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1535 ok(hr == S_OK, "GetMetadataFormat failed, hr=%#x\n", hr);
1536 ok(IsEqualGUID(&format, &GUID_MetadataFormatGCE), /* Graphic Control Extension */
1537 "wrong metadata format %s\n", wine_dbgstr_guid(&format));
1539 hr = IWICMetadataReader_GetCount(reader, &count);
1540 ok(hr == S_OK, "GetCount error %#x\n", hr);
1541 ok(count == ARRAY_SIZE(animated_gif_GCE), "unexpected count %u\n", count);
1543 compare_metadata(reader, animated_gif_GCE, count);
1545 IWICMetadataReader_Release(reader);
1548 hr = IWICMetadataBlockReader_GetReaderByIndex(blockreader, 4, &reader);
1549 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
1551 IWICMetadataBlockReader_Release(blockreader);
1554 hr = IWICBitmapDecoder_GetMetadataQueryReader(decoder, &queryreader);
1555 ok(hr == S_OK || broken(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION) /* before Vista */,
1556 "GetMetadataQueryReader error %#x\n", hr);
1557 if (SUCCEEDED(hr))
1559 static const struct
1561 const char *query;
1562 HRESULT hr;
1563 UINT vt;
1564 } decoder_data[] =
1566 { "/logscrdesc/Signature", S_OK, VT_UI1 | VT_VECTOR },
1567 { "/[0]logscrdesc/Signature", S_OK, VT_UI1 | VT_VECTOR },
1568 { "/logscrdesc/\\Signature", S_OK, VT_UI1 | VT_VECTOR },
1569 { "/Logscrdesc/\\signature", S_OK, VT_UI1 | VT_VECTOR },
1570 { "/logscrdesc/{str=signature}", S_OK, VT_UI1 | VT_VECTOR },
1571 { "/[0]logscrdesc/{str=signature}", S_OK, VT_UI1 | VT_VECTOR },
1572 { "/logscrdesc/{wstr=signature}", S_OK, VT_UI1 | VT_VECTOR },
1573 { "/[0]logscrdesc/{wstr=signature}", S_OK, VT_UI1 | VT_VECTOR },
1574 { "/appext/Application", S_OK, VT_UI1 | VT_VECTOR },
1575 { "/appext/{STR=APPlication}", S_OK, VT_UI1 | VT_VECTOR },
1576 { "/appext/{WSTR=APPlication}", S_OK, VT_UI1 | VT_VECTOR },
1577 { "/LogSCRdesC", S_OK, VT_UNKNOWN },
1578 { "/[0]LogSCRdesC", S_OK, VT_UNKNOWN },
1579 { "/appEXT", S_OK, VT_UNKNOWN },
1580 { "/[0]appEXT", S_OK, VT_UNKNOWN },
1581 { "grctlext", WINCODEC_ERR_PROPERTYNOTSUPPORTED, 0 },
1582 { "/imgdesc", WINCODEC_ERR_PROPERTYNOTFOUND, 0 },
1584 static const WCHAR rootW[] = {'/',0};
1585 WCHAR name[256];
1586 UINT len, i, j;
1587 PROPVARIANT value;
1588 IWICMetadataQueryReader *meta_reader;
1590 hr = IWICMetadataQueryReader_GetContainerFormat(queryreader, &format);
1591 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
1592 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
1593 "wrong container format %s\n", wine_dbgstr_guid(&format));
1595 name[0] = 0;
1596 len = 0xdeadbeef;
1597 hr = IWICMetadataQueryReader_GetLocation(queryreader, 256, name, &len);
1598 ok(hr == S_OK, "GetLocation error %#x\n", hr);
1599 ok(len == 2, "expected 2, got %u\n", len);
1600 ok(!lstrcmpW(name, rootW), "expected '/', got %s\n", wine_dbgstr_w(name));
1602 for (i = 0; i < ARRAY_SIZE(decoder_data); i++)
1604 WCHAR queryW[256];
1606 if (winetest_debug > 1)
1607 trace("query: %s\n", decoder_data[i].query);
1608 MultiByteToWideChar(CP_ACP, 0, decoder_data[i].query, -1, queryW, 256);
1610 hr = IWICMetadataQueryReader_GetMetadataByName(queryreader, queryW, NULL);
1611 ok(hr == decoder_data[i].hr, "GetMetadataByName(%s) returned %#x, expected %#x\n", wine_dbgstr_w(queryW), hr, decoder_data[i].hr);
1613 PropVariantInit(&value);
1614 hr = IWICMetadataQueryReader_GetMetadataByName(queryreader, queryW, &value);
1615 ok(hr == decoder_data[i].hr, "GetMetadataByName(%s) returned %#x, expected %#x\n", wine_dbgstr_w(queryW), hr, decoder_data[i].hr);
1616 ok(value.vt == decoder_data[i].vt, "expected %#x, got %#x\n", decoder_data[i].vt, value.vt);
1617 if (hr == S_OK && value.vt == VT_UNKNOWN)
1619 hr = IUnknown_QueryInterface(value.punkVal, &IID_IWICMetadataQueryReader, (void **)&meta_reader);
1620 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1622 name[0] = 0;
1623 len = 0xdeadbeef;
1624 hr = IWICMetadataQueryReader_GetLocation(meta_reader, 256, name, &len);
1625 ok(hr == S_OK, "GetLocation error %#x\n", hr);
1626 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len);
1627 ok(!lstrcmpW(name, queryW), "expected %s, got %s\n", wine_dbgstr_w(queryW), wine_dbgstr_w(name));
1629 for (j = 0; j < ARRAY_SIZE(decoder_data); j++)
1631 MultiByteToWideChar(CP_ACP, 0, decoder_data[j].query, -1, queryW, 256);
1633 if (CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, queryW, len-1, name, len-1) == CSTR_EQUAL && decoder_data[j].query[len - 1] != 0)
1635 if (winetest_debug > 1)
1636 trace("query: %s\n", wine_dbgstr_w(queryW + len - 1));
1637 PropVariantClear(&value);
1638 hr = IWICMetadataQueryReader_GetMetadataByName(meta_reader, queryW + len - 1, &value);
1639 ok(hr == decoder_data[j].hr, "GetMetadataByName(%s) returned %#x, expected %#x\n", wine_dbgstr_w(queryW + len - 1), hr, decoder_data[j].hr);
1640 ok(value.vt == decoder_data[j].vt, "expected %#x, got %#x\n", decoder_data[j].vt, value.vt);
1644 IWICMetadataQueryReader_Release(meta_reader);
1647 PropVariantClear(&value);
1650 IWICMetadataQueryReader_Release(queryreader);
1653 hr = IWICBitmapFrameDecode_GetMetadataQueryReader(frame, &queryreader);
1654 ok(hr == S_OK || broken(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION) /* before Vista */,
1655 "GetMetadataQueryReader error %#x\n", hr);
1656 if (SUCCEEDED(hr))
1658 static const struct
1660 const char *query;
1661 HRESULT hr;
1662 UINT vt;
1663 } frame_data[] =
1665 { "/grctlext/Delay", S_OK, VT_UI2 },
1666 { "/[0]grctlext/Delay", S_OK, VT_UI2 },
1667 { "/grctlext/{str=delay}", S_OK, VT_UI2 },
1668 { "/[0]grctlext/{str=delay}", S_OK, VT_UI2 },
1669 { "/grctlext/{wstr=delay}", S_OK, VT_UI2 },
1670 { "/[0]grctlext/{wstr=delay}", S_OK, VT_UI2 },
1671 { "/imgdesc/InterlaceFlag", S_OK, VT_BOOL },
1672 { "/imgdesc/{STR=interlaceFLAG}", S_OK, VT_BOOL },
1673 { "/imgdesc/{WSTR=interlaceFLAG}", S_OK, VT_BOOL },
1674 { "/grctlext", S_OK, VT_UNKNOWN },
1675 { "/[0]grctlext", S_OK, VT_UNKNOWN },
1676 { "/imgdesc", S_OK, VT_UNKNOWN },
1677 { "/[0]imgdesc", S_OK, VT_UNKNOWN },
1678 { "/LogSCRdesC", WINCODEC_ERR_PROPERTYNOTFOUND, 0 },
1679 { "/appEXT", WINCODEC_ERR_PROPERTYNOTFOUND, 0 },
1680 { "/grctlext/{\\str=delay}", WINCODEC_ERR_WRONGSTATE, 0 },
1681 { "/grctlext/{str=\\delay}", S_OK, VT_UI2 },
1682 { "grctlext/Delay", WINCODEC_ERR_PROPERTYNOTSUPPORTED, 0 },
1684 static const WCHAR rootW[] = {'/',0};
1685 static const WCHAR guidW[] = {'/','{','g','u','i','d','=','\\',0};
1686 static const WCHAR imgdescW[] = {'i','m','g','d','e','s','c',0};
1687 static const WCHAR ImgDescW[] = {'I','m','g','D','e','s','c',0};
1688 WCHAR name[256], queryW[256];
1689 UINT len, i;
1690 PROPVARIANT value;
1691 IWICMetadataQueryReader *meta_reader;
1693 hr = IWICMetadataQueryReader_GetContainerFormat(queryreader, &format);
1694 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
1695 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
1696 "wrong container format %s\n", wine_dbgstr_guid(&format));
1698 name[0] = 0;
1699 len = 0xdeadbeef;
1700 hr = IWICMetadataQueryReader_GetLocation(queryreader, 256, name, &len);
1701 ok(hr == S_OK, "GetLocation error %#x\n", hr);
1702 ok(len == 2, "expected 2, got %u\n", len);
1703 ok(!lstrcmpW(name, rootW), "expected '/', got %s\n", wine_dbgstr_w(name));
1705 for (i = 0; i < ARRAY_SIZE(frame_data); i++)
1707 if (winetest_debug > 1)
1708 trace("query: %s\n", frame_data[i].query);
1709 MultiByteToWideChar(CP_ACP, 0, frame_data[i].query, -1, queryW, 256);
1710 PropVariantInit(&value);
1711 hr = IWICMetadataQueryReader_GetMetadataByName(queryreader, queryW, &value);
1712 ok(hr == frame_data[i].hr, "GetMetadataByName(%s) returned %#x, expected %#x\n", wine_dbgstr_w(queryW), hr, frame_data[i].hr);
1713 ok(value.vt == frame_data[i].vt, "expected %#x, got %#x\n", frame_data[i].vt, value.vt);
1714 if (hr == S_OK && value.vt == VT_UNKNOWN)
1716 hr = IUnknown_QueryInterface(value.punkVal, &IID_IWICMetadataQueryReader, (void **)&meta_reader);
1717 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1719 name[0] = 0;
1720 len = 0xdeadbeef;
1721 hr = IWICMetadataQueryReader_GetLocation(meta_reader, 256, name, &len);
1722 ok(hr == S_OK, "GetLocation error %#x\n", hr);
1723 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len);
1724 ok(!lstrcmpW(name, queryW), "expected %s, got %s\n", wine_dbgstr_w(queryW), wine_dbgstr_w(name));
1726 IWICMetadataQueryReader_Release(meta_reader);
1729 PropVariantClear(&value);
1732 name[0] = 0;
1733 len = 0xdeadbeef;
1734 hr = WICMapGuidToShortName(&GUID_MetadataFormatIMD, 256, name, &len);
1735 ok(hr == S_OK, "WICMapGuidToShortName error %#x\n", hr);
1736 ok(!lstrcmpW(name, imgdescW), "wrong short name %s\n", wine_dbgstr_w(name));
1738 format = GUID_NULL;
1739 hr = WICMapShortNameToGuid(imgdescW, &format);
1740 ok(hr == S_OK, "WICMapGuidToShortName error %#x\n", hr);
1741 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), "wrong guid %s\n", wine_dbgstr_guid(&format));
1743 format = GUID_NULL;
1744 hr = WICMapShortNameToGuid(ImgDescW, &format);
1745 ok(hr == S_OK, "WICMapGuidToShortName error %#x\n", hr);
1746 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), "wrong guid %s\n", wine_dbgstr_guid(&format));
1748 lstrcpyW(queryW, guidW);
1749 StringFromGUID2(&GUID_MetadataFormatIMD, queryW + lstrlenW(queryW) - 1, 39);
1750 memcpy(queryW, guidW, sizeof(guidW) - 2);
1751 if (winetest_debug > 1)
1752 trace("query: %s\n", wine_dbgstr_w(queryW));
1753 PropVariantInit(&value);
1754 hr = IWICMetadataQueryReader_GetMetadataByName(queryreader, queryW, &value);
1755 ok(hr == S_OK, "GetMetadataByName(%s) error %#x\n", wine_dbgstr_w(queryW), hr);
1756 ok(value.vt == VT_UNKNOWN, "expected VT_UNKNOWN, got %#x\n", value.vt);
1757 PropVariantClear(&value);
1759 IWICMetadataQueryReader_Release(queryreader);
1762 IWICBitmapFrameDecode_Release(frame);
1763 IWICBitmapDecoder_Release(decoder);
1766 static void test_metadata_LSD(void)
1768 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};
1769 static const char LSD_data[] = "hello world!\x1\x2\x3\x4\xab\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf";
1770 static const struct test_data td[9] =
1772 { VT_UI1|VT_VECTOR, 0, 6, {'w','o','r','l','d','!'}, NULL, { 'S','i','g','n','a','t','u','r','e',0 } },
1773 { VT_UI2, 0, 0, { 0x201 }, NULL, { 'W','i','d','t','h',0 } },
1774 { VT_UI2, 0, 0, { 0x403 }, NULL, { 'H','e','i','g','h','t',0 } },
1775 { 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 } },
1776 { VT_UI1, 0, 0, { 2 }, NULL, { 'C','o','l','o','r','R','e','s','o','l','u','t','i','o','n',0 } },
1777 { VT_BOOL, 0, 0, { 1 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1778 { 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 } },
1779 { 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 } },
1780 { VT_UI1, 0, 0, { 7 }, NULL, { 'P','i','x','e','l','A','s','p','e','c','t','R','a','t','i','o',0 } }
1782 LARGE_INTEGER pos;
1783 HRESULT hr;
1784 IStream *stream;
1785 IWICPersistStream *persist;
1786 IWICMetadataReader *reader;
1787 IWICMetadataHandlerInfo *info;
1788 WCHAR name[64];
1789 UINT count, dummy;
1790 GUID format;
1791 CLSID id;
1793 hr = CoCreateInstance(&CLSID_WICLSDMetadataReader, NULL, CLSCTX_INPROC_SERVER,
1794 &IID_IWICMetadataReader, (void **)&reader);
1795 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
1796 "CoCreateInstance error %#x\n", hr);
1798 stream = create_stream(LSD_data, sizeof(LSD_data));
1800 if (SUCCEEDED(hr))
1802 pos.QuadPart = 6;
1803 hr = IStream_Seek(stream, pos, SEEK_SET, NULL);
1804 ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
1806 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
1807 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1809 hr = IWICPersistStream_Load(persist, stream);
1810 ok(hr == S_OK, "Load error %#x\n", hr);
1812 IWICPersistStream_Release(persist);
1815 if (SUCCEEDED(hr))
1817 hr = IWICMetadataReader_GetCount(reader, &count);
1818 ok(hr == S_OK, "GetCount error %#x\n", hr);
1819 ok(count == ARRAY_SIZE(td), "unexpected count %u\n", count);
1821 compare_metadata(reader, td, count);
1823 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1824 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
1825 ok(IsEqualGUID(&format, &GUID_MetadataFormatLSD), "wrong format %s\n", wine_dbgstr_guid(&format));
1827 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
1828 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
1830 hr = IWICMetadataHandlerInfo_GetCLSID(info, &id);
1831 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
1832 ok(IsEqualGUID(&id, &CLSID_WICLSDMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&id));
1834 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
1835 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
1836 ok(lstrcmpW(name, LSD_name) == 0, "wrong LSD reader name %s\n", wine_dbgstr_w(name));
1838 IWICMetadataHandlerInfo_Release(info);
1839 IWICMetadataReader_Release(reader);
1842 IStream_Release(stream);
1845 static void test_metadata_IMD(void)
1847 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};
1848 static const char IMD_data[] = "hello world!\x1\x2\x3\x4\x5\x6\x7\x8\xed\xa\xb\xc\xd\xe\xf";
1849 static const struct test_data td[8] =
1851 { VT_UI2, 0, 0, { 0x201 }, NULL, { 'L','e','f','t',0 } },
1852 { VT_UI2, 0, 0, { 0x403 }, NULL, { 'T','o','p',0 } },
1853 { VT_UI2, 0, 0, { 0x605 }, NULL, { 'W','i','d','t','h',0 } },
1854 { VT_UI2, 0, 0, { 0x807 }, NULL, { 'H','e','i','g','h','t',0 } },
1855 { 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 } },
1856 { VT_BOOL, 0, 0, { 1 }, NULL, { 'I','n','t','e','r','l','a','c','e','F','l','a','g',0 } },
1857 { VT_BOOL, 0, 0, { 1 }, NULL, { 'S','o','r','t','F','l','a','g',0 } },
1858 { 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 } }
1860 LARGE_INTEGER pos;
1861 HRESULT hr;
1862 IStream *stream;
1863 IWICPersistStream *persist;
1864 IWICMetadataReader *reader;
1865 IWICMetadataHandlerInfo *info;
1866 WCHAR name[64];
1867 UINT count, dummy;
1868 GUID format;
1869 CLSID id;
1871 hr = CoCreateInstance(&CLSID_WICIMDMetadataReader, NULL, CLSCTX_INPROC_SERVER,
1872 &IID_IWICMetadataReader, (void **)&reader);
1873 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
1874 "CoCreateInstance error %#x\n", hr);
1876 stream = create_stream(IMD_data, sizeof(IMD_data));
1878 if (SUCCEEDED(hr))
1880 pos.QuadPart = 12;
1881 hr = IStream_Seek(stream, pos, SEEK_SET, NULL);
1882 ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
1884 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
1885 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1887 hr = IWICPersistStream_Load(persist, stream);
1888 ok(hr == S_OK, "Load error %#x\n", hr);
1890 IWICPersistStream_Release(persist);
1893 if (SUCCEEDED(hr))
1895 hr = IWICMetadataReader_GetCount(reader, &count);
1896 ok(hr == S_OK, "GetCount error %#x\n", hr);
1897 ok(count == ARRAY_SIZE(td), "unexpected count %u\n", count);
1899 compare_metadata(reader, td, count);
1901 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1902 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
1903 ok(IsEqualGUID(&format, &GUID_MetadataFormatIMD), "wrong format %s\n", wine_dbgstr_guid(&format));
1905 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
1906 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
1908 hr = IWICMetadataHandlerInfo_GetCLSID(info, &id);
1909 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
1910 ok(IsEqualGUID(&id, &CLSID_WICIMDMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&id));
1912 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
1913 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
1914 ok(lstrcmpW(name, IMD_name) == 0, "wrong IMD reader name %s\n", wine_dbgstr_w(name));
1916 IWICMetadataHandlerInfo_Release(info);
1917 IWICMetadataReader_Release(reader);
1920 IStream_Release(stream);
1923 static void test_metadata_GCE(void)
1925 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};
1926 static const char GCE_data[] = "hello world!\xa\x2\x3\x4\x5\x6\x7\x8\xed\xa\xb\xc\xd\xe\xf";
1927 static const struct test_data td[5] =
1929 { VT_UI1, 0, 0, { 2 }, NULL, { 'D','i','s','p','o','s','a','l',0 } },
1930 { VT_BOOL, 0, 0, { 1 }, NULL, { 'U','s','e','r','I','n','p','u','t','F','l','a','g',0 } },
1931 { VT_BOOL, 0, 0, { 0 }, NULL, { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 } },
1932 { VT_UI2, 0, 0, { 0x302 }, NULL, { 'D','e','l','a','y',0 } },
1933 { 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 } }
1935 LARGE_INTEGER pos;
1936 HRESULT hr;
1937 IStream *stream;
1938 IWICPersistStream *persist;
1939 IWICMetadataReader *reader;
1940 IWICMetadataHandlerInfo *info;
1941 WCHAR name[64];
1942 UINT count, dummy;
1943 GUID format;
1944 CLSID id;
1946 hr = CoCreateInstance(&CLSID_WICGCEMetadataReader, NULL, CLSCTX_INPROC_SERVER,
1947 &IID_IWICMetadataReader, (void **)&reader);
1948 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
1949 "CoCreateInstance error %#x\n", hr);
1951 stream = create_stream(GCE_data, sizeof(GCE_data));
1953 if (SUCCEEDED(hr))
1955 pos.QuadPart = 12;
1956 hr = IStream_Seek(stream, pos, SEEK_SET, NULL);
1957 ok(hr == S_OK, "IStream_Seek error %#x\n", hr);
1959 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
1960 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
1962 hr = IWICPersistStream_Load(persist, stream);
1963 ok(hr == S_OK, "Load error %#x\n", hr);
1965 IWICPersistStream_Release(persist);
1968 if (SUCCEEDED(hr))
1970 hr = IWICMetadataReader_GetCount(reader, &count);
1971 ok(hr == S_OK, "GetCount error %#x\n", hr);
1972 ok(count == ARRAY_SIZE(td), "unexpected count %u\n", count);
1974 compare_metadata(reader, td, count);
1976 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
1977 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
1978 ok(IsEqualGUID(&format, &GUID_MetadataFormatGCE), "wrong format %s\n", wine_dbgstr_guid(&format));
1980 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
1981 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
1983 hr = IWICMetadataHandlerInfo_GetCLSID(info, &id);
1984 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
1985 ok(IsEqualGUID(&id, &CLSID_WICGCEMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&id));
1987 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
1988 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
1989 ok(lstrcmpW(name, GCE_name) == 0, "wrong GCE reader name %s\n", wine_dbgstr_w(name));
1991 IWICMetadataHandlerInfo_Release(info);
1992 IWICMetadataReader_Release(reader);
1995 IStream_Release(stream);
1998 static void test_metadata_APE(void)
2000 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};
2001 static const char APE_data[] = { 0x21,0xff,0x0b,'H','e','l','l','o',' ','W','o','r','l','d',
2002 /*sub-block*/1,0x11,
2003 /*sub-block*/2,0x22,0x33,
2004 /*sub-block*/4,0x44,0x55,0x66,0x77,
2005 /*terminator*/0 };
2006 static const struct test_data td[2] =
2008 { 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 } },
2009 { VT_UI1|VT_VECTOR, 0, 10, { 1,0x11,2,0x22,0x33,4,0x44,0x55,0x66,0x77 }, NULL, { 'D','a','t','a',0 } }
2011 WCHAR dataW[] = { 'd','a','t','a',0 };
2012 HRESULT hr;
2013 IStream *stream;
2014 IWICPersistStream *persist;
2015 IWICMetadataReader *reader;
2016 IWICMetadataHandlerInfo *info;
2017 WCHAR name[64];
2018 UINT count, dummy, i;
2019 GUID format;
2020 CLSID clsid;
2021 PROPVARIANT id, value;
2023 hr = CoCreateInstance(&CLSID_WICAPEMetadataReader, NULL, CLSCTX_INPROC_SERVER,
2024 &IID_IWICMetadataReader, (void **)&reader);
2025 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
2026 "CoCreateInstance error %#x\n", hr);
2028 stream = create_stream(APE_data, sizeof(APE_data));
2030 if (SUCCEEDED(hr))
2032 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
2033 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
2035 hr = IWICPersistStream_Load(persist, stream);
2036 ok(hr == S_OK, "Load error %#x\n", hr);
2038 IWICPersistStream_Release(persist);
2041 if (SUCCEEDED(hr))
2043 hr = IWICMetadataReader_GetCount(reader, &count);
2044 ok(hr == S_OK, "GetCount error %#x\n", hr);
2045 ok(count == ARRAY_SIZE(td), "unexpected count %u\n", count);
2047 compare_metadata(reader, td, count);
2049 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
2050 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
2051 ok(IsEqualGUID(&format, &GUID_MetadataFormatAPE), "wrong format %s\n", wine_dbgstr_guid(&format));
2053 PropVariantInit(&value);
2054 id.vt = VT_LPWSTR;
2055 U(id).pwszVal = dataW;
2057 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
2058 ok(hr == S_OK, "GetValue error %#x\n", hr);
2059 ok(value.vt == (VT_UI1|VT_VECTOR), "unexpected vt: %i\n", id.vt);
2060 ok(td[1].count == U(value).caub.cElems, "expected cElems %d, got %d\n", td[1].count, U(value).caub.cElems);
2061 for (i = 0; i < U(value).caub.cElems; i++)
2062 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]);
2063 PropVariantClear(&value);
2065 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
2066 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
2068 hr = IWICMetadataHandlerInfo_GetCLSID(info, &clsid);
2069 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
2070 ok(IsEqualGUID(&clsid, &CLSID_WICAPEMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&clsid));
2072 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
2073 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
2074 ok(lstrcmpW(name, APE_name) == 0, "wrong APE reader name %s\n", wine_dbgstr_w(name));
2076 IWICMetadataHandlerInfo_Release(info);
2077 IWICMetadataReader_Release(reader);
2080 IStream_Release(stream);
2083 static void test_metadata_GIF_comment(void)
2085 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};
2086 static const char GIF_comment_data[] = { 0x21,0xfe,
2087 /*sub-block*/5,'H','e','l','l','o',
2088 /*sub-block*/1,' ',
2089 /*sub-block*/6,'W','o','r','l','d','!',
2090 /*terminator*/0 };
2091 static const struct test_data td[1] =
2093 { VT_LPSTR, 0, 12, { 0 }, "Hello World!", { 'T','e','x','t','E','n','t','r','y',0 } }
2095 WCHAR text_entryW[] = { 'T','E','X','T','E','N','T','R','Y',0 };
2096 HRESULT hr;
2097 IStream *stream;
2098 IWICPersistStream *persist;
2099 IWICMetadataReader *reader;
2100 IWICMetadataHandlerInfo *info;
2101 WCHAR name[64];
2102 UINT count, dummy;
2103 GUID format;
2104 CLSID clsid;
2105 PROPVARIANT id, value;
2107 hr = CoCreateInstance(&CLSID_WICGifCommentMetadataReader, NULL, CLSCTX_INPROC_SERVER,
2108 &IID_IWICMetadataReader, (void **)&reader);
2109 ok(hr == S_OK || broken(hr == E_NOINTERFACE || hr == REGDB_E_CLASSNOTREG) /* before Win7 */,
2110 "CoCreateInstance error %#x\n", hr);
2112 stream = create_stream(GIF_comment_data, sizeof(GIF_comment_data));
2114 if (SUCCEEDED(hr))
2116 hr = IUnknown_QueryInterface(reader, &IID_IWICPersistStream, (void **)&persist);
2117 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
2119 hr = IWICPersistStream_Load(persist, stream);
2120 ok(hr == S_OK, "Load error %#x\n", hr);
2122 IWICPersistStream_Release(persist);
2125 if (SUCCEEDED(hr))
2127 hr = IWICMetadataReader_GetCount(reader, &count);
2128 ok(hr == S_OK, "GetCount error %#x\n", hr);
2129 ok(count == ARRAY_SIZE(td), "unexpected count %u\n", count);
2131 compare_metadata(reader, td, count);
2133 hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
2134 ok(hr == S_OK, "GetMetadataFormat error %#x\n", hr);
2135 ok(IsEqualGUID(&format, &GUID_MetadataFormatGifComment), "wrong format %s\n", wine_dbgstr_guid(&format));
2137 PropVariantInit(&value);
2138 id.vt = VT_LPWSTR;
2139 U(id).pwszVal = text_entryW;
2141 hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
2142 ok(hr == S_OK, "GetValue error %#x\n", hr);
2143 ok(value.vt == VT_LPSTR, "unexpected vt: %i\n", id.vt);
2144 ok(!strcmp(U(value).pszVal, "Hello World!"), "unexpected value: %s\n", U(value).pszVal);
2145 PropVariantClear(&value);
2147 hr = IWICMetadataReader_GetMetadataHandlerInfo(reader, &info);
2148 ok(hr == S_OK, "GetMetadataHandlerInfo error %#x\n", hr);
2150 hr = IWICMetadataHandlerInfo_GetCLSID(info, &clsid);
2151 ok(hr == S_OK, "GetCLSID error %#x\n", hr);
2152 ok(IsEqualGUID(&clsid, &CLSID_WICGifCommentMetadataReader), "wrong CLSID %s\n", wine_dbgstr_guid(&clsid));
2154 hr = IWICMetadataHandlerInfo_GetFriendlyName(info, 64, name, &dummy);
2155 ok(hr == S_OK, "GetFriendlyName error %#x\n", hr);
2156 ok(lstrcmpW(name, GIF_comment_name) == 0, "wrong APE reader name %s\n", wine_dbgstr_w(name));
2158 IWICMetadataHandlerInfo_Release(info);
2159 IWICMetadataReader_Release(reader);
2162 IStream_Release(stream);
2165 static void test_WICMapGuidToShortName(void)
2167 static const WCHAR unkW[] = { 'u','n','k',0 };
2168 static const WCHAR unknownW[] = { 'u','n','k','n','o','w','n',0 };
2169 HRESULT hr;
2170 UINT len;
2171 WCHAR name[16];
2173 name[0] = 0;
2174 len = 0xdeadbeef;
2175 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 8, name, &len);
2176 ok(hr == S_OK, "got %#x\n", hr);
2177 ok(len == 8, "got %u\n", len);
2178 ok(!lstrcmpW(name, unknownW), "got %s\n", wine_dbgstr_w(name));
2180 name[0] = 0;
2181 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 8, name, NULL);
2182 ok(hr == S_OK, "got %#x\n", hr);
2183 ok(!lstrcmpW(name, unknownW), "got %s\n", wine_dbgstr_w(name));
2185 len = 0xdeadbeef;
2186 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 8, NULL, &len);
2187 ok(hr == S_OK, "got %#x\n", hr);
2188 ok(len == 8, "got %u\n", len);
2190 len = 0xdeadbeef;
2191 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 0, NULL, &len);
2192 ok(hr == S_OK, "got %#x\n", hr);
2193 ok(len == 8, "got %u\n", len);
2195 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 0, NULL, NULL);
2196 ok(hr == S_OK, "got %#x\n", hr);
2198 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 8, NULL, NULL);
2199 ok(hr == S_OK, "got %#x\n", hr);
2201 hr = WICMapGuidToShortName(&GUID_NULL, 0, NULL, NULL);
2202 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "got %#x\n", hr);
2204 name[0] = 0;
2205 len = 0xdeadbeef;
2206 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 4, name, &len);
2207 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "got %#x\n", hr);
2208 ok(len == 0xdeadbeef, "got %u\n", len);
2209 ok(!lstrcmpW(name, unkW), "got %s\n", wine_dbgstr_w(name));
2211 name[0] = 0;
2212 len = 0xdeadbeef;
2213 hr = WICMapGuidToShortName(&GUID_MetadataFormatUnknown, 0, name, &len);
2214 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2215 ok(len == 0xdeadbeef, "got %u\n", len);
2216 ok(!name[0], "got %s\n", wine_dbgstr_w(name));
2218 hr = WICMapGuidToShortName(NULL, 8, name, NULL);
2219 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2222 static void test_WICMapShortNameToGuid(void)
2224 static const WCHAR unkW[] = { 'u','n','k',0 };
2225 static const WCHAR xmpW[] = { 'x','m','p',0 };
2226 static const WCHAR XmPW[] = { 'X','m','P',0 };
2227 static const WCHAR unknownW[] = { 'u','n','k','n','o','w','n',0 };
2228 HRESULT hr;
2229 GUID guid;
2231 hr = WICMapShortNameToGuid(NULL, NULL);
2232 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2234 hr = WICMapShortNameToGuid(NULL, &guid);
2235 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2237 hr = WICMapShortNameToGuid(unknownW, NULL);
2238 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2240 hr = WICMapShortNameToGuid(unkW, &guid);
2241 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "got %#x\n", hr);
2243 hr = WICMapShortNameToGuid(unknownW, &guid);
2244 ok(hr == S_OK, "got %#x\n", hr);
2245 ok(IsEqualGUID(&guid, &GUID_MetadataFormatUnknown), "got %s\n", wine_dbgstr_guid(&guid));
2247 hr = WICMapShortNameToGuid(xmpW, &guid);
2248 ok(hr == S_OK, "got %#x\n", hr);
2249 ok(IsEqualGUID(&guid, &GUID_MetadataFormatXMP), "got %s\n", wine_dbgstr_guid(&guid));
2251 guid = GUID_NULL;
2252 hr = WICMapShortNameToGuid(XmPW, &guid);
2253 ok(hr == S_OK, "got %#x\n", hr);
2254 ok(IsEqualGUID(&guid, &GUID_MetadataFormatXMP), "got %s\n", wine_dbgstr_guid(&guid));
2257 static const GUID *guid_list[] =
2259 &GUID_ContainerFormatBmp,
2260 &GUID_ContainerFormatPng,
2261 &GUID_ContainerFormatIco,
2262 &GUID_ContainerFormatJpeg,
2263 &GUID_ContainerFormatTiff,
2264 &GUID_ContainerFormatGif,
2265 &GUID_ContainerFormatWmp,
2266 &GUID_MetadataFormatUnknown,
2267 &GUID_MetadataFormatIfd,
2268 &GUID_MetadataFormatSubIfd,
2269 &GUID_MetadataFormatExif,
2270 &GUID_MetadataFormatGps,
2271 &GUID_MetadataFormatInterop,
2272 &GUID_MetadataFormatApp0,
2273 &GUID_MetadataFormatApp1,
2274 &GUID_MetadataFormatApp13,
2275 &GUID_MetadataFormatIPTC,
2276 &GUID_MetadataFormatIRB,
2277 &GUID_MetadataFormat8BIMIPTC,
2278 &GUID_MetadataFormat8BIMResolutionInfo,
2279 &GUID_MetadataFormat8BIMIPTCDigest,
2280 &GUID_MetadataFormatXMP,
2281 &GUID_MetadataFormatThumbnail,
2282 &GUID_MetadataFormatChunktEXt,
2283 &GUID_MetadataFormatXMPStruct,
2284 &GUID_MetadataFormatXMPBag,
2285 &GUID_MetadataFormatXMPSeq,
2286 &GUID_MetadataFormatXMPAlt,
2287 &GUID_MetadataFormatLSD,
2288 &GUID_MetadataFormatIMD,
2289 &GUID_MetadataFormatGCE,
2290 &GUID_MetadataFormatAPE,
2291 &GUID_MetadataFormatJpegChrominance,
2292 &GUID_MetadataFormatJpegLuminance,
2293 &GUID_MetadataFormatJpegComment,
2294 &GUID_MetadataFormatGifComment,
2295 &GUID_MetadataFormatChunkgAMA,
2296 &GUID_MetadataFormatChunkbKGD,
2297 &GUID_MetadataFormatChunkiTXt,
2298 &GUID_MetadataFormatChunkcHRM,
2299 &GUID_MetadataFormatChunkhIST,
2300 &GUID_MetadataFormatChunkiCCP,
2301 &GUID_MetadataFormatChunksRGB,
2302 &GUID_MetadataFormatChunktIME
2305 static WCHAR rdf_scheme[] = { 'h','t','t','p',':','/','/','w','w','w','.','w','3','.','o','r','g','/','1','9','9','9','/','0','2','/','2','2','-','r','d','f','-','s','y','n','t','a','x','-','n','s','#',0 };
2306 static WCHAR dc_scheme[] = { 'h','t','t','p',':','/','/','p','u','r','l','.','o','r','g','/','d','c','/','e','l','e','m','e','n','t','s','/','1','.','1','/',0 };
2307 static WCHAR xmp_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/',0 };
2308 static WCHAR xmpidq_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','m','p','/','I','d','e','n','t','i','f','i','e','r','/','q','u','a','l','/','1','.','0','/',0 };
2309 static WCHAR xmpRights_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','r','i','g','h','t','s','/',0 };
2310 static WCHAR xmpMM_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','m','m','/',0 };
2311 static WCHAR xmpBJ_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','b','j','/',0 };
2312 static WCHAR xmpTPg_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','t','/','p','g','/',0 };
2313 static WCHAR pdf_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','p','d','f','/','1','.','3','/',0 };
2314 static WCHAR photoshop_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','p','h','o','t','o','s','h','o','p','/','1','.','0','/',0 };
2315 static WCHAR tiff_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','t','i','f','f','/','1','.','0','/',0 };
2316 static WCHAR exif_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','e','x','i','f','/','1','.','0','/',0 };
2317 static WCHAR stDim_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','D','i','m','e','n','s','i','o','n','s','#',0 };
2318 static WCHAR xapGImg_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','g','/','i','m','g','/',0 };
2319 static WCHAR stEvt_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','R','e','s','o','u','r','c','e','E','v','e','n','t','#',0 };
2320 static WCHAR stRef_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','R','e','s','o','u','r','c','e','R','e','f','#',0 };
2321 static WCHAR stVer_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','V','e','r','s','i','o','n','#',0 };
2322 static WCHAR stJob_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/','s','T','y','p','e','/','J','o','b','#',0 };
2323 static WCHAR aux_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','e','x','i','f','/','1','.','0','/','a','u','x','/',0 };
2324 static WCHAR crs_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','c','a','m','e','r','a','-','r','a','w','-','s','e','t','t','i','n','g','s','/','1','.','0','/',0 };
2325 static WCHAR xmpDM_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','m','p','/','1','.','0','/','D','y','n','a','m','i','c','M','e','d','i','a','/',0 };
2326 static WCHAR Iptc4xmpCore_scheme[] = { 'h','t','t','p',':','/','/','i','p','t','c','.','o','r','g','/','s','t','d','/','I','p','t','c','4','x','m','p','C','o','r','e','/','1','.','0','/','x','m','l','n','s','/',0 };
2327 static WCHAR MicrosoftPhoto_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','p','h','o','t','o','/','1','.','0','/',0 };
2328 static WCHAR MP_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','p','h','o','t','o','/','1','.','2','/',0 };
2329 static WCHAR MPRI_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','p','h','o','t','o','/','1','.','2','/','t','/','R','e','g','i','o','n','I','n','f','o','#',0 };
2330 static WCHAR MPReg_scheme[] = { 'h','t','t','p',':','/','/','n','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','p','h','o','t','o','/','1','.','2','/','t','/','R','e','g','i','o','n','#',0 };
2332 static WCHAR *schema_list[] =
2334 aux_scheme,
2335 rdf_scheme,
2336 dc_scheme,
2337 xmp_scheme,
2338 xmpidq_scheme,
2339 xmpRights_scheme,
2340 xmpMM_scheme,
2341 xmpBJ_scheme,
2342 xmpTPg_scheme,
2343 pdf_scheme,
2344 photoshop_scheme,
2345 tiff_scheme,
2346 exif_scheme,
2347 stDim_scheme,
2348 xapGImg_scheme,
2349 stEvt_scheme,
2350 stRef_scheme,
2351 stVer_scheme,
2352 stJob_scheme,
2353 crs_scheme,
2354 xmpDM_scheme,
2355 Iptc4xmpCore_scheme,
2356 MicrosoftPhoto_scheme,
2357 MP_scheme,
2358 MPRI_scheme,
2359 MPReg_scheme
2362 static void test_WICMapSchemaToName(void)
2364 static const WCHAR xmW[] = { 'x','m',0 };
2365 static const WCHAR xmpW[] = { 'x','m','p',0 };
2366 static WCHAR schemaW[] = { 'h','t','t','p',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/',0 };
2367 static WCHAR SCHEMAW[] = { 'H','T','T','P',':','/','/','n','s','.','a','d','o','b','e','.','c','o','m','/','x','a','p','/','1','.','0','/',0 };
2368 HRESULT hr;
2369 UINT len, i, j;
2370 WCHAR name[16];
2372 hr = WICMapSchemaToName(&GUID_MetadataFormatUnknown, NULL, 0, NULL, NULL);
2373 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2375 hr = WICMapSchemaToName(&GUID_MetadataFormatUnknown, schemaW, 0, NULL, NULL);
2376 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2378 hr = WICMapSchemaToName(&GUID_MetadataFormatUnknown, schemaW, 0, NULL, &len);
2379 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "got %#x\n", hr);
2381 hr = WICMapSchemaToName(NULL, schemaW, 0, NULL, &len);
2382 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2384 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 0, NULL, NULL);
2385 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2387 len = 0xdeadbeef;
2388 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 0, NULL, &len);
2389 ok(hr == S_OK, "got %#x\n", hr);
2390 ok(len == 4, "got %u\n", len);
2392 len = 0xdeadbeef;
2393 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 4, NULL, &len);
2394 ok(hr == S_OK, "got %#x\n", hr);
2395 ok(len == 4, "got %u\n", len);
2397 len = 0xdeadbeef;
2398 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, SCHEMAW, 0, NULL, &len);
2399 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "got %#x\n", hr);
2400 ok(len == 0xdeadbeef, "got %u\n", len);
2402 name[0] = 0;
2403 len = 0xdeadbeef;
2404 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 4, name, &len);
2405 ok(hr == S_OK, "got %#x\n", hr);
2406 ok(len == 4, "got %u\n", len);
2407 ok(!lstrcmpW(name, xmpW), "got %s\n", wine_dbgstr_w(name));
2409 len = 0xdeadbeef;
2410 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 0, name, &len);
2411 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2412 ok(len == 0xdeadbeef, "got %u\n", len);
2414 name[0] = 0;
2415 len = 0xdeadbeef;
2416 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 3, name, &len);
2417 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "got %#x\n", hr);
2418 ok(len == 0xdeadbeef, "got %u\n", len);
2419 ok(!lstrcmpW(name, xmW), "got %s\n", wine_dbgstr_w(name));
2421 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schemaW, 4, name, NULL);
2422 ok(hr == E_INVALIDARG, "got %#x\n", hr);
2424 /* Check whether modern schemas are supported */
2425 hr = WICMapSchemaToName(&GUID_MetadataFormatXMP, schema_list[0], 0, NULL, &len);
2426 if (hr == WINCODEC_ERR_PROPERTYNOTFOUND)
2428 win_skip("Modern schemas are not supported\n");
2429 return;
2432 for (i = 0; i < ARRAY_SIZE(guid_list); i++)
2434 for (j = 0; j < ARRAY_SIZE(schema_list); j++)
2436 hr = WICMapSchemaToName(guid_list[i], schema_list[j], 0, NULL, &len);
2437 if (IsEqualGUID(guid_list[i], &GUID_MetadataFormatXMP) ||
2438 IsEqualGUID(guid_list[i], &GUID_MetadataFormatXMPStruct))
2440 ok(hr == S_OK, "%u: %u: format %s does not support schema %s\n",
2441 i, j, wine_dbgstr_guid(guid_list[i]), wine_dbgstr_w(schema_list[j]));
2443 else
2445 ok(hr == WINCODEC_ERR_PROPERTYNOTFOUND, "%u: %u: format %s supports schema %s\n",
2446 i, j, wine_dbgstr_guid(guid_list[i]), wine_dbgstr_w(schema_list[j]));
2452 struct metadata_item
2454 const char *schema, *id_str;
2455 UINT id, type, value;
2458 struct metadata_block
2460 const GUID *metadata_format;
2461 UINT count;
2462 const struct metadata_item *item;
2465 struct metadata
2467 const GUID *container_format;
2468 UINT count;
2469 const struct metadata_block *block;
2472 static const struct metadata *current_metadata;
2473 static const struct metadata_block *current_metadata_block;
2475 static char the_best[] = "The Best";
2476 static char the_worst[] = "The Worst";
2478 static HRESULT WINAPI mdr_QueryInterface(IWICMetadataReader *iface, REFIID iid, void **out)
2480 trace("%p,%s,%p\n", iface, wine_dbgstr_guid(iid), out);
2482 if (IsEqualIID(iid, &IID_IUnknown) ||
2483 IsEqualIID(iid, &IID_IWICMetadataReader))
2485 *out = iface;
2486 return S_OK;
2489 ok(0, "unknown iid %s\n", wine_dbgstr_guid(iid));
2491 *out = NULL;
2492 return E_NOINTERFACE;
2495 static ULONG WINAPI mdr_AddRef(IWICMetadataReader *iface)
2497 return 2;
2500 static ULONG WINAPI mdr_Release(IWICMetadataReader *iface)
2502 return 1;
2505 static HRESULT WINAPI mdr_GetMetadataFormat(IWICMetadataReader *iface, GUID *format)
2507 trace("%p,%p\n", iface, format);
2509 ok(current_metadata_block != NULL, "current_metadata_block can't be NULL\n");
2510 if (!current_metadata_block) return E_POINTER;
2512 *format = *current_metadata_block->metadata_format;
2513 return S_OK;
2516 static HRESULT WINAPI mdr_GetMetadataHandlerInfo(IWICMetadataReader *iface, IWICMetadataHandlerInfo **handler)
2518 ok(0, "not implemented\n");
2519 return E_NOTIMPL;
2522 static HRESULT WINAPI mdr_GetCount(IWICMetadataReader *iface, UINT *count)
2524 trace("%p,%p\n", iface, count);
2526 ok(current_metadata_block != NULL, "current_metadata_block can't be NULL\n");
2527 if (!current_metadata_block) return E_POINTER;
2529 *count = current_metadata_block->count;
2530 return S_OK;
2533 static HRESULT WINAPI mdr_GetValueByIndex(IWICMetadataReader *iface, UINT index, PROPVARIANT *schema, PROPVARIANT *id, PROPVARIANT *value)
2535 ok(0, "not implemented\n");
2536 return E_NOTIMPL;
2539 static char *get_temp_buffer(int size)
2541 static char buf[16][256];
2542 static int idx;
2543 char *p;
2545 assert(size < 256);
2547 p = buf[idx & 0x0f];
2548 idx++;
2549 return p;
2552 static const char *wine_dbgstr_propvariant(const PROPVARIANT *var)
2554 char *ret;
2556 if (!var) return "(null)";
2558 switch (var->vt)
2560 case VT_LPWSTR:
2561 ret = get_temp_buffer(lstrlenW(U(*var).pwszVal) + 16);
2562 sprintf(ret, "(VT_LPWSTR:%s)", wine_dbgstr_w(U(*var).pwszVal));
2563 break;
2565 case VT_LPSTR:
2566 ret = get_temp_buffer(lstrlenA(U(*var).pszVal) + 16);
2567 sprintf(ret, "(VT_LPSTR:%s)", U(*var).pszVal);
2568 break;
2570 default:
2571 ret = get_temp_buffer(16);
2572 sprintf(ret, "(vt:%u)", var->vt);
2573 break;
2576 return ret;
2579 static int propvar_cmp(const PROPVARIANT *v1, LONGLONG value2)
2581 LONGLONG value1;
2583 if (PropVariantToInt64(v1, &value1) != S_OK) return -1;
2585 value1 -= value2;
2586 if (value1) return value1 < 0 ? -1 : 1;
2587 return 0;
2590 static HRESULT WINAPI mdr_GetValue(IWICMetadataReader *iface, const PROPVARIANT *schema, const PROPVARIANT *id, PROPVARIANT *value)
2592 UINT i;
2594 trace("%p,%s,%s,%s\n", iface, wine_dbgstr_propvariant(schema), wine_dbgstr_propvariant(id), wine_dbgstr_propvariant(value));
2596 ok(current_metadata_block != NULL, "current_metadata_block can't be NULL\n");
2597 if (!current_metadata_block) return E_POINTER;
2599 ok(schema != NULL && id != NULL && value != NULL, "%p, %p, %p should not be NULL\n", schema, id, value);
2601 for (i = 0; i < current_metadata_block->count; i++)
2603 if (schema->vt != VT_EMPTY)
2605 if (!current_metadata_block->item[i].schema)
2606 continue;
2608 switch (schema->vt)
2610 case VT_LPSTR:
2611 if (lstrcmpA(U(*schema).pszVal, current_metadata_block->item[i].schema) != 0)
2612 continue;
2613 break;
2615 case VT_LPWSTR:
2617 char schemaA[256];
2618 WideCharToMultiByte(CP_ACP, 0, U(*schema).pwszVal, -1, schemaA, sizeof(schemaA), NULL, NULL);
2619 if (lstrcmpA(schemaA, current_metadata_block->item[i].schema) != 0)
2620 continue;
2621 break;
2624 default:
2625 ok(0, "unsupported schema vt %u\n", schema->vt);
2626 continue;
2629 else if (current_metadata_block->item[i].schema)
2630 continue;
2632 switch (id->vt)
2634 case VT_LPSTR:
2635 if (current_metadata_block->item[i].id_str)
2637 if (!lstrcmpA(U(*id).pszVal, current_metadata_block->item[i].id_str))
2639 value->vt = VT_LPSTR;
2640 U(*value).pszVal = the_best;
2641 return S_OK;
2643 break;
2645 break;
2647 case VT_LPWSTR:
2648 if (current_metadata_block->item[i].id_str)
2650 char idA[256];
2651 WideCharToMultiByte(CP_ACP, 0, U(*id).pwszVal, -1, idA, sizeof(idA), NULL, NULL);
2652 if (!lstrcmpA(idA, current_metadata_block->item[i].id_str))
2654 value->vt = VT_LPSTR;
2655 U(*value).pszVal = the_worst;
2656 return S_OK;
2658 break;
2660 break;
2662 case VT_CLSID:
2663 if (IsEqualGUID(U(*id).puuid, &GUID_MetadataFormatXMP) ||
2664 IsEqualGUID(U(*id).puuid, &GUID_ContainerFormatTiff))
2666 value->vt = VT_UNKNOWN;
2667 value->punkVal = (IUnknown *)iface;
2668 return S_OK;
2670 break;
2672 default:
2673 if (!propvar_cmp(id, current_metadata_block->item[i].id))
2675 value->vt = current_metadata_block->item[i].type;
2676 U(*value).uiVal = current_metadata_block->item[i].value;
2677 return S_OK;
2679 break;
2683 return 0xdeadbeef;
2686 static HRESULT WINAPI mdr_GetEnumerator(IWICMetadataReader *iface, IWICEnumMetadataItem **enumerator)
2688 ok(0, "not implemented\n");
2689 return E_NOTIMPL;
2692 static const IWICMetadataReaderVtbl mdr_vtbl =
2694 mdr_QueryInterface,
2695 mdr_AddRef,
2696 mdr_Release,
2697 mdr_GetMetadataFormat,
2698 mdr_GetMetadataHandlerInfo,
2699 mdr_GetCount,
2700 mdr_GetValueByIndex,
2701 mdr_GetValue,
2702 mdr_GetEnumerator
2705 static IWICMetadataReader mdr = { &mdr_vtbl };
2707 static HRESULT WINAPI mdbr_QueryInterface(IWICMetadataBlockReader *iface, REFIID iid, void **out)
2709 if (IsEqualIID(iid, &IID_IUnknown) ||
2710 IsEqualIID(iid, &IID_IWICMetadataBlockReader))
2712 *out = iface;
2713 return S_OK;
2716 /* Windows 8/10 query for some undocumented IID */
2717 if (!IsEqualIID(iid, &IID_MdbrUnknown))
2718 ok(0, "unknown iid %s\n", wine_dbgstr_guid(iid));
2720 *out = NULL;
2721 return E_NOINTERFACE;
2724 static ULONG WINAPI mdbr_AddRef(IWICMetadataBlockReader *iface)
2726 return 2;
2729 static ULONG WINAPI mdbr_Release(IWICMetadataBlockReader *iface)
2731 return 1;
2734 static HRESULT WINAPI mdbr_GetContainerFormat(IWICMetadataBlockReader *iface, GUID *format)
2736 trace("%p,%p\n", iface, format);
2738 ok(current_metadata != NULL, "current_metadata can't be NULL\n");
2739 if (!current_metadata) return E_POINTER;
2741 *format = *current_metadata->container_format;
2742 return S_OK;
2745 static HRESULT WINAPI mdbr_GetCount(IWICMetadataBlockReader *iface, UINT *count)
2747 trace("%p,%p\n", iface, count);
2749 ok(current_metadata != NULL, "current_metadata can't be NULL\n");
2750 if (!current_metadata) return E_POINTER;
2752 *count = current_metadata->count;
2753 return S_OK;
2756 static HRESULT WINAPI mdbr_GetReaderByIndex(IWICMetadataBlockReader *iface, UINT index, IWICMetadataReader **out)
2758 trace("%p,%u,%p\n", iface, index, out);
2760 *out = NULL;
2762 ok(current_metadata != NULL, "current_metadata can't be NULL\n");
2763 if (!current_metadata) return E_POINTER;
2765 if (index < current_metadata->count)
2767 current_metadata_block = &current_metadata->block[index];
2768 *out = &mdr;
2769 return S_OK;
2772 current_metadata_block = NULL;
2773 return E_INVALIDARG;
2776 static HRESULT WINAPI mdbr_GetEnumerator(IWICMetadataBlockReader *iface, IEnumUnknown **enumerator)
2778 ok(0, "not implemented\n");
2779 return E_NOTIMPL;
2782 static const IWICMetadataBlockReaderVtbl mdbr_vtbl =
2784 mdbr_QueryInterface,
2785 mdbr_AddRef,
2786 mdbr_Release,
2787 mdbr_GetContainerFormat,
2788 mdbr_GetCount,
2789 mdbr_GetReaderByIndex,
2790 mdbr_GetEnumerator
2793 static IWICMetadataBlockReader mdbr = { &mdbr_vtbl };
2795 static const char xmp[] = "http://ns.adobe.com/xap/1.0/";
2796 static const char dc[] = "http://purl.org/dc/elements/1.1/";
2797 static const char tiff[] = "http://ns.adobe.com/tiff/1.0/";
2799 static const struct metadata_item item1[] =
2801 { NULL, NULL, 1, 2, 3 }
2804 static const struct metadata_item item2[] =
2806 { NULL, NULL, 1, 2, 3 },
2807 { "xmp", "Rating", 4, 5, 6 },
2808 { NULL, "Rating", 7, 8, 9 }
2811 static const struct metadata_item item3[] =
2813 { NULL, NULL, 1, 2, 3 },
2814 { NULL, NULL, 4, 5, 6 },
2815 { NULL, NULL, 7, 8, 9 },
2816 { NULL, NULL, 10, 11, 12 }
2819 static const struct metadata_item item4[] =
2821 { NULL, NULL, 1, 2, 3 },
2822 { xmp, "Rating", 4, 5, 6 },
2823 { dc, NULL, 7, 8, 9 },
2824 { tiff, NULL, 10, 11, 12 },
2825 { NULL, "RATING", 13, 14, 15 },
2826 { NULL, "R}ATING", 16, 17, 18 },
2827 { NULL, "xmp", 19, 20, 21 }
2830 static const struct metadata_block block1[] =
2832 { &GUID_MetadataFormatIfd, 1, item1 }
2835 static const struct metadata_block block2[] =
2837 { &GUID_MetadataFormatXMP, 1, item1 },
2838 { &GUID_MetadataFormatIfd, 3, item2 }
2841 static const struct metadata_block block3[] =
2843 { &GUID_MetadataFormatXMP, 1, item1 },
2844 { &GUID_MetadataFormatIfd, 3, item2 },
2845 { &GUID_MetadataFormatXMP, 4, item3 },
2846 { &GUID_MetadataFormatXMP, 7, item4 },
2847 { &GUID_MetadataFormatIfd, 7, item4 }
2850 static const struct metadata data1 =
2852 &GUID_ContainerFormatGif,
2853 1, block1
2856 static const struct metadata data2 =
2858 &GUID_ContainerFormatTiff,
2859 2, block2
2862 static const struct metadata data3 =
2864 &GUID_ContainerFormatPng,
2865 5, block3
2868 static void test_queryreader(void)
2870 static const char q1[] = "/ifd/{uchar=1}";
2871 static const char q2[] = "/ifd/xmp:{long=4}";
2872 static const char q3[] = "/ifd/{str=xmp}:{uint=4}";
2873 static const char q4[] = "/xmp/{char=7}";
2874 static const char q5[] = "/[1]xmp/{short=7}";
2875 static const char q6[] = "/[1]ifd/{str=dc}:{uint=7}";
2876 static const char q7[] = "/[1]ifd/{str=http://purl.org/dc/elements/1.1/}:{longlong=7}";
2877 static const char q8[] = "/[1]ifd/{str=http://ns.adobe.com/tiff/1.0/}:{int=10}";
2878 static const char q9[] = "/[2]xmp/xmp:{ulong=4}";
2879 static const char q10[] = "/[2]xmp/{str=xmp}:{ulong=4}";
2880 static const char q11[] = "/xmp";
2881 static const char q12[] = "/ifd/xmp";
2882 static const char q13[] = "/ifd/xmp/tiff";
2883 static const char q14[] = "/[0]ifd/[0]xmp/[0]tiff";
2884 static const char q15[] = "/[*]xmp";
2886 static const char q20[] = "/ifd/\\Rating";
2887 static const char q21[] = "/[0]ifd/Rating";
2888 static const char q22[] = "/[2]xmp/xmp:{str=Rating}";
2889 static const char q23[] = "/[2]xmp/xmp:Rating";
2891 static const char q24[] = "/[1]ifd/{str=http://ns.adobe.com/xap/1.0/}:Rating";
2892 static const char q25[] = "/[1]ifd/{str=http://ns.adobe.com/xap/1.0/}:{str=Rating}";
2893 static const char q26[] = "/[1]ifd/{wstr=\\RATING}";
2894 static const char q27[] = "/[1]ifd/{str=R\\ATING}";
2895 static const char q28[] = "/[1]ifd/{str=R\\}ATING}";
2897 static const char q40[] = "[0]/ifd/Rating";
2898 static const char q41[] = "/[+1]ifd/Rating";
2899 static const char q42[] = "/[-1]ifd/Rating";
2900 static const char q43[] = "/ifd/{\\str=Rating}";
2901 static const char q44[] = "/ifd/{badtype=0}";
2902 static const char q45[] = "/ifd/{uint=0x1234}";
2903 static const char q46[] = "/ifd/[0]Rating";
2904 static const char q47[] = "/ifd/[*]Rating";
2905 static const struct
2907 BOOL todo;
2908 const struct metadata *data;
2909 const char *query;
2910 HRESULT hr;
2911 UINT vt, value;
2912 const char *str_value;
2913 } test_data[] =
2915 { FALSE, &data1, q1, S_OK, 2, 3, NULL },
2916 { FALSE, &data2, q2, S_OK, 5, 6, NULL },
2917 { FALSE, &data2, q3, S_OK, 5, 6, NULL },
2918 { FALSE, &data3, q4, 0xdeadbeef },
2919 { FALSE, &data3, q5, S_OK, 8, 9, NULL },
2920 { FALSE, &data3, q6, 0xdeadbeef },
2921 { FALSE, &data3, q7, S_OK, 8, 9, NULL },
2922 { FALSE, &data3, q8, S_OK, 11, 12, NULL },
2923 { FALSE, &data3, q9, S_OK, 5, 6, NULL },
2924 { FALSE, &data3, q10, 0xdeadbeef },
2926 { FALSE, &data3, q11, S_OK, VT_UNKNOWN, 0, NULL },
2927 { FALSE, &data3, q12, S_OK, VT_UNKNOWN, 0, NULL },
2928 { FALSE, &data3, q13, S_OK, VT_UNKNOWN, 0, NULL },
2929 { FALSE, &data3, q14, S_OK, VT_UNKNOWN, 0, NULL },
2930 { TRUE, &data3, q15, S_OK, VT_LPSTR, 0, the_worst },
2932 { FALSE, &data3, q20, S_OK, VT_LPSTR, 0, the_worst },
2933 { FALSE, &data3, q21, S_OK, VT_LPSTR, 0, the_worst },
2934 { FALSE, &data3, q22, S_OK, VT_LPSTR, 0, the_best },
2935 { FALSE, &data3, q23, S_OK, VT_LPSTR, 0, the_worst },
2936 { FALSE, &data3, q24, S_OK, VT_LPSTR, 0, the_worst },
2937 { FALSE, &data3, q25, S_OK, VT_LPSTR, 0, the_best },
2938 { FALSE, &data3, q26, S_OK, VT_LPSTR, 0, the_worst },
2939 { FALSE, &data3, q27, S_OK, VT_LPSTR, 0, the_best },
2940 { FALSE, &data3, q28, S_OK, VT_LPSTR, 0, the_best },
2942 { FALSE, &data1, q40, WINCODEC_ERR_PROPERTYNOTSUPPORTED },
2943 { TRUE, &data1, q41, WINCODEC_ERR_INVALIDQUERYCHARACTER },
2944 { TRUE, &data1, q42, WINCODEC_ERR_INVALIDQUERYCHARACTER },
2945 { FALSE, &data1, q43, WINCODEC_ERR_WRONGSTATE },
2946 { FALSE, &data1, q44, WINCODEC_ERR_WRONGSTATE },
2947 { TRUE, &data1, q45, DISP_E_TYPEMISMATCH },
2948 { TRUE, &data1, q46, E_INVALIDARG },
2949 { TRUE, &data1, q47, WINCODEC_ERR_REQUESTONLYVALIDATMETADATAROOT },
2951 WCHAR queryW[256];
2952 HRESULT hr;
2953 IWICComponentFactory *factory;
2954 IWICMetadataQueryReader *reader;
2955 GUID format;
2956 PROPVARIANT value;
2957 UINT i;
2959 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
2960 &IID_IWICComponentFactory, (void **)&factory);
2961 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
2963 hr = IWICComponentFactory_CreateQueryReaderFromBlockReader(factory, &mdbr, &reader);
2964 ok(hr == S_OK, "CreateQueryReaderFromBlockReader error %#x\n", hr);
2966 for (i = 0; i < ARRAY_SIZE(test_data); i++)
2968 current_metadata = test_data[i].data;
2970 hr = IWICMetadataQueryReader_GetContainerFormat(reader, &format);
2971 ok(hr == S_OK, "%u: GetContainerFormat error %#x\n", i, hr);
2972 ok(IsEqualGUID(&format, test_data[i].data->container_format), "%u: expected %s, got %s\n",
2973 i, wine_dbgstr_guid(test_data[i].data->container_format), wine_dbgstr_guid(&format));
2975 MultiByteToWideChar(CP_ACP, 0, test_data[i].query, -1, queryW, 256);
2976 PropVariantInit(&value);
2977 hr = IWICMetadataQueryReader_GetMetadataByName(reader, queryW, &value);
2978 todo_wine_if(test_data[i].todo)
2979 ok(hr == test_data[i].hr, "%u: expected %#x, got %#x\n", i, test_data[i].hr, hr);
2980 if (hr == S_OK)
2982 ok(value.vt == test_data[i].vt, "%u: expected %u, got %u\n", i, test_data[i].vt, value.vt);
2983 if (test_data[i].vt == value.vt)
2985 if (value.vt == VT_UNKNOWN)
2987 IWICMetadataQueryReader *new_reader;
2988 WCHAR location[256];
2989 UINT len;
2991 hr = IUnknown_QueryInterface(value.punkVal, &IID_IWICMetadataQueryReader, (void **)&new_reader);
2992 ok(hr == S_OK, "QueryInterface error %#x\n", hr);
2994 location[0] = 0;
2995 len = 0xdeadbeef;
2996 hr = IWICMetadataQueryReader_GetLocation(new_reader, 256, location, &len);
2997 ok(hr == S_OK, "GetLocation error %#x\n", hr);
2998 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len);
2999 ok(!lstrcmpW(location, queryW), "expected %s, got %s\n", wine_dbgstr_w(queryW), wine_dbgstr_w(location));
3001 hr = IWICMetadataQueryReader_GetLocation(new_reader, 256, location, NULL);
3002 ok(hr == E_INVALIDARG, "got %#x\n", hr);
3004 location[0] = 0;
3005 len = 0xdeadbeef;
3006 hr = IWICMetadataQueryReader_GetLocation(new_reader, 3, location, &len);
3007 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "got %#x\n", hr);
3008 ok(len == 0xdeadbeef, "got %u\n", len);
3009 ok(!location[0], "got %s\n", wine_dbgstr_w(location));
3011 location[0] = 0;
3012 len = 0xdeadbeef;
3013 hr = IWICMetadataQueryReader_GetLocation(new_reader, 0, location, &len);
3014 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "got %#x\n", hr);
3015 ok(len == 0xdeadbeef, "got %u\n", len);
3016 ok(!location[0], "got %s\n", wine_dbgstr_w(location));
3018 len = 0xdeadbeef;
3019 hr = IWICMetadataQueryReader_GetLocation(new_reader, 0, NULL, &len);
3020 ok(hr == S_OK, "GetLocation error %#x\n", hr);
3021 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len);
3023 len = 0xdeadbeef;
3024 hr = IWICMetadataQueryReader_GetLocation(new_reader, 3, NULL, &len);
3025 ok(hr == S_OK, "GetLocation error %#x\n", hr);
3026 ok(len == lstrlenW(queryW) + 1, "expected %u, got %u\n", lstrlenW(queryW) + 1, len);
3028 hr = IWICMetadataQueryReader_GetLocation(new_reader, 0, NULL, NULL);
3029 ok(hr == E_INVALIDARG, "got %#x\n", hr);
3031 IWICMetadataQueryReader_Release(new_reader);
3032 PropVariantClear(&value);
3034 else if (value.vt == VT_LPSTR)
3035 ok(!lstrcmpA(U(value).pszVal, test_data[i].str_value), "%u: expected %s, got %s\n",
3036 i, test_data[i].str_value, U(value).pszVal);
3037 else
3038 ok(U(value).uiVal == test_data[i].value, "%u: expected %u, got %u\n",
3039 i, test_data[i].value, U(value).uiVal);
3043 * Do NOT call PropVariantClear(&value) for fake value types.
3048 IWICMetadataQueryReader_Release(reader);
3049 IWICComponentFactory_Release(factory);
3052 static void test_metadata_writer(void)
3054 static struct
3056 REFCLSID rclsid;
3057 BOOL wine_supports_encoder;
3058 BOOL metadata_supported;
3059 BOOL succeeds_uninitialized;
3061 tests[] =
3063 {&CLSID_WICBmpEncoder, TRUE, FALSE},
3064 {&CLSID_WICPngEncoder, TRUE, TRUE},
3065 {&CLSID_WICJpegEncoder, TRUE, TRUE},
3066 {&CLSID_WICGifEncoder, TRUE, TRUE},
3067 {&CLSID_WICTiffEncoder, TRUE, TRUE},
3068 {&CLSID_WICWmpEncoder, FALSE, TRUE, TRUE},
3071 IWICMetadataQueryWriter *querywriter, *querywriter2;
3072 IWICMetadataBlockWriter *blockwriter;
3073 IWICBitmapFrameEncode *frameencode;
3074 IWICComponentFactory *factory;
3075 IWICBitmapEncoder *encoder;
3076 IStream *stream;
3077 unsigned int i;
3078 HRESULT hr;
3080 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3082 hr = CoCreateInstance(tests[i].rclsid, NULL, CLSCTX_INPROC_SERVER,
3083 &IID_IWICBitmapEncoder, (void **)&encoder);
3084 todo_wine_if(!tests[i].wine_supports_encoder) ok(hr == S_OK, "Got unexpected hr %#x, i %u.\n", hr, i);
3085 if (FAILED(hr))
3086 continue;
3088 blockwriter = NULL;
3089 querywriter = querywriter2 = NULL;
3091 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
3092 ok(hr == S_OK, "Got unexpected hr %#x, i %u.\n", hr, i);
3093 hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
3094 ok(hr == S_OK, "Got unexpected hr %#x, i %u.\n", hr, i);
3095 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frameencode, NULL);
3096 ok(hr == S_OK, "Got unexpected hr %#x, i %u.\n", hr, i);
3098 hr = IWICBitmapFrameEncode_QueryInterface(frameencode, &IID_IWICMetadataBlockWriter, (void**)&blockwriter);
3099 ok(hr == (tests[i].metadata_supported ? S_OK : E_NOINTERFACE), "Got unexpected hr %#x, i %u.\n", hr, i);
3101 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
3102 &IID_IWICComponentFactory, (void**)&factory);
3103 ok(hr == S_OK, "Got unexpected hr %#x, i %u.\n", hr, i);
3105 hr = IWICComponentFactory_CreateQueryWriterFromBlockWriter(factory, blockwriter, &querywriter);
3106 ok(hr == (tests[i].metadata_supported ? S_OK : E_INVALIDARG), "Got unexpected hr %#x, i %u.\n", hr, i);
3108 hr = IWICBitmapFrameEncode_GetMetadataQueryWriter(frameencode, &querywriter2);
3109 ok(hr == (tests[i].succeeds_uninitialized ? S_OK : WINCODEC_ERR_NOTINITIALIZED),
3110 "Got unexpected hr %#x, i %u.\n", hr, i);
3111 if (hr == S_OK)
3112 IWICMetadataQueryWriter_Release(querywriter2);
3114 hr = IWICBitmapFrameEncode_Initialize(frameencode, NULL);
3115 ok(hr == S_OK, "Got unexpected hr %#x, i %u.\n", hr, i);
3117 hr = IWICBitmapFrameEncode_GetMetadataQueryWriter(frameencode, &querywriter2);
3118 ok(hr == (tests[i].metadata_supported ? S_OK : WINCODEC_ERR_UNSUPPORTEDOPERATION),
3119 "Got unexpected hr %#x, i %u.\n", hr, i);
3121 if (tests[i].metadata_supported)
3122 ok(querywriter2 != querywriter, "Got unexpected interfaces %p, %p, i %u.\n", querywriter, querywriter2, i);
3124 IWICComponentFactory_Release(factory);
3125 if (querywriter)
3127 IWICMetadataQueryWriter_Release(querywriter);
3128 IWICMetadataQueryWriter_Release(querywriter2);
3129 IWICMetadataBlockWriter_Release(blockwriter);
3131 IWICBitmapFrameEncode_Release(frameencode);
3132 IStream_Release(stream);
3133 IWICBitmapEncoder_Release(encoder);
3137 START_TEST(metadata)
3139 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
3141 test_queryreader();
3142 test_WICMapGuidToShortName();
3143 test_WICMapShortNameToGuid();
3144 test_WICMapSchemaToName();
3145 test_metadata_unknown();
3146 test_metadata_tEXt();
3147 test_metadata_gAMA();
3148 test_metadata_cHRM();
3149 test_metadata_IFD();
3150 test_metadata_Exif();
3151 test_create_reader();
3152 test_metadata_png();
3153 test_metadata_gif();
3154 test_metadata_LSD();
3155 test_metadata_IMD();
3156 test_metadata_GCE();
3157 test_metadata_APE();
3158 test_metadata_GIF_comment();
3159 test_metadata_writer();
3161 CoUninitialize();