mfplat: Implement GetScanline0AndPitch() for d3d11 buffers.
[wine/zf.git] / dlls / windowscodecs / metadataquery.c
blob29ec6fd51604a422657a501d0ba20848e4b795b9
1 /*
2 * Copyright 2016 Andrew Eikum for CodeWeavers
3 * Copyright 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 <stdarg.h>
21 #include <wchar.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29 #include "propvarutil.h"
31 #include "wincodecs_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
37 static const WCHAR *map_shortname_to_schema(const GUID *format, const WCHAR *name);
39 typedef struct {
40 IWICMetadataQueryReader IWICMetadataQueryReader_iface;
41 LONG ref;
42 IWICMetadataBlockReader *block;
43 WCHAR *root;
44 } QueryReader;
46 static inline QueryReader *impl_from_IWICMetadataQueryReader(IWICMetadataQueryReader *iface)
48 return CONTAINING_RECORD(iface, QueryReader, IWICMetadataQueryReader_iface);
51 static HRESULT WINAPI mqr_QueryInterface(IWICMetadataQueryReader *iface, REFIID riid,
52 void **ppvObject)
54 QueryReader *This = impl_from_IWICMetadataQueryReader(iface);
56 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppvObject);
58 if (IsEqualGUID(riid, &IID_IUnknown) ||
59 IsEqualGUID(riid, &IID_IWICMetadataQueryReader))
60 *ppvObject = &This->IWICMetadataQueryReader_iface;
61 else
62 *ppvObject = NULL;
64 if (*ppvObject)
66 IUnknown_AddRef((IUnknown*)*ppvObject);
67 return S_OK;
70 return E_NOINTERFACE;
73 static ULONG WINAPI mqr_AddRef(IWICMetadataQueryReader *iface)
75 QueryReader *This = impl_from_IWICMetadataQueryReader(iface);
76 ULONG ref = InterlockedIncrement(&This->ref);
77 TRACE("(%p) refcount=%u\n", This, ref);
78 return ref;
81 static ULONG WINAPI mqr_Release(IWICMetadataQueryReader *iface)
83 QueryReader *This = impl_from_IWICMetadataQueryReader(iface);
84 ULONG ref = InterlockedDecrement(&This->ref);
85 TRACE("(%p) refcount=%u\n", This, ref);
86 if (!ref)
88 IWICMetadataBlockReader_Release(This->block);
89 HeapFree(GetProcessHeap(), 0, This->root);
90 HeapFree(GetProcessHeap(), 0, This);
92 return ref;
95 static HRESULT WINAPI mqr_GetContainerFormat(IWICMetadataQueryReader *iface, GUID *format)
97 QueryReader *This = impl_from_IWICMetadataQueryReader(iface);
99 TRACE("(%p,%p)\n", This, format);
101 return IWICMetadataBlockReader_GetContainerFormat(This->block, format);
104 static HRESULT WINAPI mqr_GetLocation(IWICMetadataQueryReader *iface, UINT len, WCHAR *location, UINT *ret_len)
106 QueryReader *This = impl_from_IWICMetadataQueryReader(iface);
107 const WCHAR *root;
108 UINT actual_len;
110 TRACE("(%p,%u,%p,%p)\n", This, len, location, ret_len);
112 if (!ret_len) return E_INVALIDARG;
114 root = This->root ? This->root : L"/";
115 actual_len = lstrlenW(root) + 1;
117 if (location)
119 if (len < actual_len)
120 return WINCODEC_ERR_INSUFFICIENTBUFFER;
122 memcpy(location, root, actual_len * sizeof(WCHAR));
125 *ret_len = actual_len;
127 return S_OK;
130 struct string_t
132 const WCHAR *str;
133 int len;
136 static const struct
138 int len;
139 WCHAR str[10];
140 VARTYPE vt;
141 } str2vt[] =
143 { 4, {'c','h','a','r'}, VT_I1 },
144 { 5, {'u','c','h','a','r'}, VT_UI1 },
145 { 5, {'s','h','o','r','t'}, VT_I2 },
146 { 6, {'u','s','h','o','r','t'}, VT_UI2 },
147 { 4, {'l','o','n','g'}, VT_I4 },
148 { 5, {'u','l','o','n','g'}, VT_UI4 },
149 { 3, {'i','n','t'}, VT_I4 },
150 { 4, {'u','i','n','t'}, VT_UI4 },
151 { 8, {'l','o','n','g','l','o','n','g'}, VT_I8 },
152 { 9, {'u','l','o','n','g','l','o','n','g'}, VT_UI8 },
153 { 5, {'f','l','o','a','t'}, VT_R4 },
154 { 6, {'d','o','u','b','l','e'}, VT_R8 },
155 { 3, {'s','t','r'}, VT_LPSTR },
156 { 4, {'w','s','t','r'}, VT_LPWSTR },
157 { 4, {'g','u','i','d'}, VT_CLSID },
158 { 4, {'b','o','o','l'}, VT_BOOL }
161 static VARTYPE map_type(struct string_t *str)
163 UINT i;
165 for (i = 0; i < ARRAY_SIZE(str2vt); i++)
167 if (str2vt[i].len == str->len)
169 if (CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
170 str->str, str->len, str2vt[i].str, str2vt[i].len) == CSTR_EQUAL)
171 return str2vt[i].vt;
175 WARN("type %s is not recognized\n", wine_dbgstr_wn(str->str, str->len));
177 return VT_ILLEGAL;
180 static HRESULT get_token(struct string_t *elem, PROPVARIANT *id, PROPVARIANT *schema, int *idx)
182 const WCHAR *start, *end, *p;
183 WCHAR *bstr;
184 struct string_t next_elem;
185 HRESULT hr;
187 TRACE("%s, len %d\n", wine_dbgstr_wn(elem->str, elem->len), elem->len);
189 PropVariantInit(id);
190 PropVariantInit(schema);
192 if (!elem->len) return S_OK;
194 start = elem->str;
196 if (*start == '[')
198 WCHAR *idx_end;
200 if (start[1] < '0' || start[1] > '9') return DISP_E_TYPEMISMATCH;
202 *idx = wcstol(start + 1, &idx_end, 10);
203 if (idx_end > elem->str + elem->len) return WINCODEC_ERR_INVALIDQUERYREQUEST;
204 if (*idx_end != ']') return WINCODEC_ERR_INVALIDQUERYREQUEST;
205 if (*idx < 0) return WINCODEC_ERR_INVALIDQUERYREQUEST;
206 end = idx_end + 1;
208 next_elem.str = end;
209 next_elem.len = elem->len - (end - start);
210 hr = get_token(&next_elem, id, schema, idx);
211 if (hr != S_OK)
213 TRACE("get_token error %#x\n", hr);
214 return hr;
216 elem->len = (end - start) + next_elem.len;
218 TRACE("indexed %s [%d]\n", wine_dbgstr_wn(elem->str, elem->len), *idx);
219 return S_OK;
221 else if (*start == '{')
223 VARTYPE vt;
224 PROPVARIANT next_token;
226 end = wmemchr(start + 1, '=', elem->len - 1);
227 if (!end) return WINCODEC_ERR_INVALIDQUERYREQUEST;
228 if (end > elem->str + elem->len) return WINCODEC_ERR_INVALIDQUERYREQUEST;
230 next_elem.str = start + 1;
231 next_elem.len = end - start - 1;
232 vt = map_type(&next_elem);
233 TRACE("type %s => %d\n", wine_dbgstr_wn(next_elem.str, next_elem.len), vt);
234 if (vt == VT_ILLEGAL) return WINCODEC_ERR_WRONGSTATE;
236 next_token.vt = VT_BSTR;
237 next_token.bstrVal = SysAllocStringLen(NULL, elem->len - (end - start) + 1);
238 if (!next_token.bstrVal) return E_OUTOFMEMORY;
240 bstr = next_token.bstrVal;
242 end++;
243 while (*end && *end != '}' && end - start < elem->len)
245 if (*end == '\\') end++;
246 *bstr++ = *end++;
248 if (*end != '}')
250 PropVariantClear(&next_token);
251 return WINCODEC_ERR_INVALIDQUERYREQUEST;
253 *bstr = 0;
254 TRACE("schema/id %s\n", wine_dbgstr_w(next_token.bstrVal));
256 if (vt == VT_CLSID)
258 id->vt = VT_CLSID;
259 id->puuid = CoTaskMemAlloc(sizeof(GUID));
260 if (!id->puuid)
262 PropVariantClear(&next_token);
263 return E_OUTOFMEMORY;
266 hr = UuidFromStringW(next_token.bstrVal, id->puuid);
268 else
269 hr = PropVariantChangeType(id, &next_token, 0, vt);
270 PropVariantClear(&next_token);
271 if (hr != S_OK)
273 PropVariantClear(id);
274 PropVariantClear(schema);
275 return hr;
278 end++;
279 if (*end == ':')
281 PROPVARIANT next_id, next_schema;
282 int next_idx = 0;
284 next_elem.str = end + 1;
285 next_elem.len = elem->len - (end - start + 1);
286 hr = get_token(&next_elem, &next_id, &next_schema, &next_idx);
287 if (hr != S_OK)
289 TRACE("get_token error %#x\n", hr);
290 return hr;
292 elem->len = (end - start + 1) + next_elem.len;
294 TRACE("id %s [%d]\n", wine_dbgstr_wn(elem->str, elem->len), *idx);
296 if (next_schema.vt != VT_EMPTY)
298 PropVariantClear(&next_id);
299 PropVariantClear(&next_schema);
300 return WINCODEC_ERR_WRONGSTATE;
303 *schema = *id;
304 *id = next_id;
306 return S_OK;
309 elem->len = end - start;
310 return S_OK;
313 end = wmemchr(start, '/', elem->len);
314 if (!end) end = start + elem->len;
316 p = wmemchr(start, ':', end - start);
317 if (p)
319 next_elem.str = p + 1;
320 next_elem.len = end - p - 1;
322 elem->len = p - start;
324 else
325 elem->len = end - start;
327 id->vt = VT_BSTR;
328 id->bstrVal = SysAllocStringLen(NULL, elem->len + 1);
329 if (!id->bstrVal) return E_OUTOFMEMORY;
331 bstr = id->bstrVal;
332 p = elem->str;
333 while (p - elem->str < elem->len)
335 if (*p == '\\') p++;
336 *bstr++ = *p++;
338 *bstr = 0;
339 TRACE("%s [%d]\n", wine_dbgstr_variant((VARIANT *)id), *idx);
341 if (*p == ':')
343 PROPVARIANT next_id, next_schema;
344 int next_idx = 0;
346 hr = get_token(&next_elem, &next_id, &next_schema, &next_idx);
347 if (hr != S_OK)
349 TRACE("get_token error %#x\n", hr);
350 PropVariantClear(id);
351 PropVariantClear(schema);
352 return hr;
354 elem->len += next_elem.len + 1;
356 TRACE("id %s [%d]\n", wine_dbgstr_wn(elem->str, elem->len), *idx);
358 if (next_schema.vt != VT_EMPTY)
360 PropVariantClear(&next_id);
361 PropVariantClear(&next_schema);
362 PropVariantClear(id);
363 PropVariantClear(schema);
364 return WINCODEC_ERR_WRONGSTATE;
367 *schema = *id;
368 *id = next_id;
371 return S_OK;
374 static HRESULT find_reader_from_block(IWICMetadataBlockReader *block_reader, UINT index,
375 GUID *guid, IWICMetadataReader **reader)
377 HRESULT hr;
378 GUID format;
379 IWICMetadataReader *new_reader;
380 UINT count, i, matched_index;
382 *reader = NULL;
384 hr = IWICMetadataBlockReader_GetCount(block_reader, &count);
385 if (hr != S_OK) return hr;
387 matched_index = 0;
389 for (i = 0; i < count; i++)
391 hr = IWICMetadataBlockReader_GetReaderByIndex(block_reader, i, &new_reader);
392 if (hr != S_OK) return hr;
394 hr = IWICMetadataReader_GetMetadataFormat(new_reader, &format);
395 if (hr == S_OK)
397 if (IsEqualGUID(&format, guid))
399 if (matched_index == index)
401 *reader = new_reader;
402 return S_OK;
405 matched_index++;
409 IWICMetadataReader_Release(new_reader);
410 if (hr != S_OK) return hr;
413 return WINCODEC_ERR_PROPERTYNOTFOUND;
416 static HRESULT get_next_reader(IWICMetadataReader *reader, UINT index,
417 GUID *guid, IWICMetadataReader **new_reader)
419 HRESULT hr;
420 PROPVARIANT schema, id, value;
422 *new_reader = NULL;
424 PropVariantInit(&schema);
425 PropVariantInit(&id);
426 PropVariantInit(&value);
428 if (index)
430 schema.vt = VT_UI2;
431 schema.uiVal = index;
434 id.vt = VT_CLSID;
435 id.puuid = guid;
436 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &value);
437 if (hr != S_OK) return hr;
439 if (value.vt == VT_UNKNOWN)
440 hr = IUnknown_QueryInterface(value.punkVal, &IID_IWICMetadataReader, (void **)new_reader);
441 else
442 hr = WINCODEC_ERR_UNEXPECTEDMETADATATYPE;
444 PropVariantClear(&value);
445 return hr;
448 static HRESULT WINAPI mqr_GetMetadataByName(IWICMetadataQueryReader *iface, LPCWSTR query, PROPVARIANT *value)
450 QueryReader *This = impl_from_IWICMetadataQueryReader(iface);
451 struct string_t elem;
452 WCHAR *full_query;
453 const WCHAR *p;
454 int index, len;
455 PROPVARIANT tk_id, tk_schema, new_value;
456 GUID guid;
457 IWICMetadataReader *reader;
458 HRESULT hr = S_OK;
460 TRACE("(%p,%s,%p)\n", This, wine_dbgstr_w(query), value);
462 len = lstrlenW(query) + 1;
463 if (This->root) len += lstrlenW(This->root);
464 full_query = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
465 full_query[0] = 0;
466 if (This->root)
467 lstrcpyW(full_query, This->root);
468 lstrcatW(full_query, query);
470 PropVariantInit(&tk_id);
471 PropVariantInit(&tk_schema);
472 PropVariantInit(&new_value);
474 reader = NULL;
475 p = full_query;
477 while (*p)
479 if (*p != '/')
481 WARN("query should start with '/'\n");
482 hr = WINCODEC_ERR_PROPERTYNOTSUPPORTED;
483 break;
486 p++;
488 index = 0;
489 elem.str = p;
490 elem.len = lstrlenW(p);
491 hr = get_token(&elem, &tk_id, &tk_schema, &index);
492 if (hr != S_OK)
494 WARN("get_token error %#x\n", hr);
495 break;
497 TRACE("parsed %d characters: %s, index %d\n", elem.len, wine_dbgstr_wn(elem.str, elem.len), index);
498 TRACE("id %s, schema %s\n", wine_dbgstr_variant((VARIANT *)&tk_id), wine_dbgstr_variant((VARIANT *)&tk_schema));
500 if (!elem.len) break;
502 if (tk_id.vt == VT_CLSID || (tk_id.vt == VT_BSTR && WICMapShortNameToGuid(tk_id.bstrVal, &guid) == S_OK))
504 WCHAR *root;
506 if (tk_schema.vt != VT_EMPTY)
508 FIXME("unsupported schema vt %u\n", tk_schema.vt);
509 PropVariantClear(&tk_schema);
512 if (tk_id.vt == VT_CLSID) guid = *tk_id.puuid;
514 if (reader)
516 IWICMetadataReader *new_reader;
518 hr = get_next_reader(reader, index, &guid, &new_reader);
519 IWICMetadataReader_Release(reader);
520 reader = new_reader;
522 else
523 hr = find_reader_from_block(This->block, index, &guid, &reader);
525 if (hr != S_OK) break;
527 root = SysAllocStringLen(NULL, elem.str + elem.len - full_query + 2);
528 if (!root)
530 hr = E_OUTOFMEMORY;
531 break;
533 lstrcpynW(root, full_query, p - full_query + elem.len + 1);
535 PropVariantClear(&new_value);
536 new_value.vt = VT_UNKNOWN;
537 hr = MetadataQueryReader_CreateInstance(This->block, root, (IWICMetadataQueryReader **)&new_value.punkVal);
538 SysFreeString(root);
539 if (hr != S_OK) break;
541 else
543 PROPVARIANT schema, id;
545 if (!reader)
547 hr = WINCODEC_ERR_INVALIDQUERYREQUEST;
548 break;
551 if (tk_schema.vt == VT_BSTR)
553 hr = IWICMetadataReader_GetMetadataFormat(reader, &guid);
554 if (hr != S_OK) break;
556 schema.vt = VT_LPWSTR;
557 schema.pwszVal = (LPWSTR)map_shortname_to_schema(&guid, tk_schema.bstrVal);
558 if (!schema.pwszVal)
559 schema.pwszVal = tk_schema.bstrVal;
561 else
562 schema = tk_schema;
564 if (tk_id.vt == VT_BSTR)
566 id.vt = VT_LPWSTR;
567 id.pwszVal = tk_id.bstrVal;
569 else
570 id = tk_id;
572 PropVariantClear(&new_value);
573 hr = IWICMetadataReader_GetValue(reader, &schema, &id, &new_value);
574 if (hr != S_OK) break;
577 p += elem.len;
579 PropVariantClear(&tk_id);
580 PropVariantClear(&tk_schema);
583 if (reader)
584 IWICMetadataReader_Release(reader);
586 PropVariantClear(&tk_id);
587 PropVariantClear(&tk_schema);
589 if (hr == S_OK && value)
590 *value = new_value;
591 else
592 PropVariantClear(&new_value);
594 HeapFree(GetProcessHeap(), 0, full_query);
596 return hr;
599 static HRESULT WINAPI mqr_GetEnumerator(IWICMetadataQueryReader *iface,
600 IEnumString **ppIEnumString)
602 QueryReader *This = impl_from_IWICMetadataQueryReader(iface);
603 FIXME("(%p,%p)\n", This, ppIEnumString);
604 return E_NOTIMPL;
607 static IWICMetadataQueryReaderVtbl mqr_vtbl = {
608 mqr_QueryInterface,
609 mqr_AddRef,
610 mqr_Release,
611 mqr_GetContainerFormat,
612 mqr_GetLocation,
613 mqr_GetMetadataByName,
614 mqr_GetEnumerator
617 HRESULT MetadataQueryReader_CreateInstance(IWICMetadataBlockReader *mbr, const WCHAR *root, IWICMetadataQueryReader **out)
619 QueryReader *obj;
621 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj));
622 if (!obj)
623 return E_OUTOFMEMORY;
625 obj->IWICMetadataQueryReader_iface.lpVtbl = &mqr_vtbl;
626 obj->ref = 1;
628 IWICMetadataBlockReader_AddRef(mbr);
629 obj->block = mbr;
631 obj->root = root ? heap_strdupW(root) : NULL;
633 *out = &obj->IWICMetadataQueryReader_iface;
635 return S_OK;
638 typedef struct
640 IWICMetadataQueryWriter IWICMetadataQueryWriter_iface;
641 LONG ref;
642 IWICMetadataBlockWriter *block;
643 WCHAR *root;
645 QueryWriter;
647 static inline QueryWriter *impl_from_IWICMetadataQueryWriter(IWICMetadataQueryWriter *iface)
649 return CONTAINING_RECORD(iface, QueryWriter, IWICMetadataQueryWriter_iface);
652 static HRESULT WINAPI mqw_QueryInterface(IWICMetadataQueryWriter *iface, REFIID riid,
653 void **object)
655 QueryWriter *writer = impl_from_IWICMetadataQueryWriter(iface);
657 TRACE("writer %p, riid %s, object %p.\n", writer, debugstr_guid(riid), object);
659 if (IsEqualGUID(riid, &IID_IUnknown)
660 || IsEqualGUID(riid, &IID_IWICMetadataQueryWriter)
661 || IsEqualGUID(riid, &IID_IWICMetadataQueryReader))
662 *object = &writer->IWICMetadataQueryWriter_iface;
663 else
664 *object = NULL;
666 if (*object)
668 IUnknown_AddRef((IUnknown *)*object);
669 return S_OK;
672 return E_NOINTERFACE;
675 static ULONG WINAPI mqw_AddRef(IWICMetadataQueryWriter *iface)
677 QueryWriter *writer = impl_from_IWICMetadataQueryWriter(iface);
678 ULONG ref = InterlockedIncrement(&writer->ref);
680 TRACE("writer %p, refcount=%u\n", writer, ref);
682 return ref;
685 static ULONG WINAPI mqw_Release(IWICMetadataQueryWriter *iface)
687 QueryWriter *writer = impl_from_IWICMetadataQueryWriter(iface);
688 ULONG ref = InterlockedDecrement(&writer->ref);
690 TRACE("writer %p, refcount=%u.\n", writer, ref);
692 if (!ref)
694 IWICMetadataBlockWriter_Release(writer->block);
695 HeapFree(GetProcessHeap(), 0, writer->root);
696 HeapFree(GetProcessHeap(), 0, writer);
698 return ref;
701 static HRESULT WINAPI mqw_GetContainerFormat(IWICMetadataQueryWriter *iface, GUID *container_format)
703 FIXME("iface %p, container_format %p stub.\n", iface, container_format);
705 return E_NOTIMPL;
708 static HRESULT WINAPI mqw_GetEnumerator(IWICMetadataQueryWriter *iface, IEnumString **enum_string)
710 FIXME("iface %p, enum_string %p stub.\n", iface, enum_string);
712 return E_NOTIMPL;
715 static HRESULT WINAPI mqw_GetLocation(IWICMetadataQueryWriter *iface, UINT max_length, WCHAR *namespace, UINT *actual_length)
717 FIXME("iface %p, max_length %u, namespace %s, actual_length %p stub.\n",
718 iface, max_length, debugstr_w(namespace), actual_length);
720 return E_NOTIMPL;
723 static HRESULT WINAPI mqw_GetMetadataByName(IWICMetadataQueryWriter *iface, LPCWSTR name, PROPVARIANT *value)
725 FIXME("name %s, value %p stub.\n", debugstr_w(name), value);
727 return E_NOTIMPL;
730 static HRESULT WINAPI mqw_SetMetadataByName(IWICMetadataQueryWriter *iface, LPCWSTR name, const PROPVARIANT *value)
732 FIXME("iface %p, name %s, value %p stub.\n", iface, debugstr_w(name), value);
734 return E_NOTIMPL;
737 static HRESULT WINAPI mqw_RemoveMetadataByName(IWICMetadataQueryWriter *iface, LPCWSTR name)
739 FIXME("iface %p, name %s stub.\n", iface, debugstr_w(name));
741 return E_NOTIMPL;
744 static const IWICMetadataQueryWriterVtbl mqw_vtbl =
746 mqw_QueryInterface,
747 mqw_AddRef,
748 mqw_Release,
749 mqw_GetContainerFormat,
750 mqw_GetLocation,
751 mqw_GetMetadataByName,
752 mqw_GetEnumerator,
753 mqw_SetMetadataByName,
754 mqw_RemoveMetadataByName,
757 HRESULT MetadataQueryWriter_CreateInstance(IWICMetadataBlockWriter *mbw, const WCHAR *root, IWICMetadataQueryWriter **out)
759 QueryWriter *obj;
761 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj));
762 if (!obj)
763 return E_OUTOFMEMORY;
765 obj->IWICMetadataQueryWriter_iface.lpVtbl = &mqw_vtbl;
766 obj->ref = 1;
768 IWICMetadataBlockWriter_AddRef(mbw);
769 obj->block = mbw;
771 obj->root = root ? heap_strdupW(root) : NULL;
773 *out = &obj->IWICMetadataQueryWriter_iface;
775 return S_OK;
778 static const struct
780 const GUID *guid;
781 const WCHAR *name;
782 } guid2name[] =
784 { &GUID_ContainerFormatBmp, L"bmp" },
785 { &GUID_ContainerFormatPng, L"png" },
786 { &GUID_ContainerFormatIco, L"ico" },
787 { &GUID_ContainerFormatJpeg, L"jpg" },
788 { &GUID_ContainerFormatTiff, L"tiff" },
789 { &GUID_ContainerFormatGif, L"gif" },
790 { &GUID_ContainerFormatWmp, L"wmphoto" },
791 { &GUID_MetadataFormatUnknown, L"unknown" },
792 { &GUID_MetadataFormatIfd, L"ifd" },
793 { &GUID_MetadataFormatSubIfd, L"sub" },
794 { &GUID_MetadataFormatExif, L"exif" },
795 { &GUID_MetadataFormatGps, L"gps" },
796 { &GUID_MetadataFormatInterop, L"interop" },
797 { &GUID_MetadataFormatApp0, L"app0" },
798 { &GUID_MetadataFormatApp1, L"app1" },
799 { &GUID_MetadataFormatApp13, L"app13" },
800 { &GUID_MetadataFormatIPTC, L"iptc" },
801 { &GUID_MetadataFormatIRB, L"irb" },
802 { &GUID_MetadataFormat8BIMIPTC, L"8bimiptc" },
803 { &GUID_MetadataFormat8BIMResolutionInfo, L"8bimResInfo" },
804 { &GUID_MetadataFormat8BIMIPTCDigest, L"8bimiptcdigest" },
805 { &GUID_MetadataFormatXMP, L"xmp" },
806 { &GUID_MetadataFormatThumbnail, L"thumb" },
807 { &GUID_MetadataFormatChunktEXt, L"tEXt" },
808 { &GUID_MetadataFormatXMPStruct, L"xmpstruct" },
809 { &GUID_MetadataFormatXMPBag, L"xmpbag" },
810 { &GUID_MetadataFormatXMPSeq, L"xmpseq" },
811 { &GUID_MetadataFormatXMPAlt, L"xmpalt" },
812 { &GUID_MetadataFormatLSD, L"logscrdesc" },
813 { &GUID_MetadataFormatIMD, L"imgdesc" },
814 { &GUID_MetadataFormatGCE, L"grctlext" },
815 { &GUID_MetadataFormatAPE, L"appext" },
816 { &GUID_MetadataFormatJpegChrominance, L"chrominance" },
817 { &GUID_MetadataFormatJpegLuminance, L"luminance" },
818 { &GUID_MetadataFormatJpegComment, L"com" },
819 { &GUID_MetadataFormatGifComment, L"commentext" },
820 { &GUID_MetadataFormatChunkgAMA, L"gAMA" },
821 { &GUID_MetadataFormatChunkbKGD, L"bKGD" },
822 { &GUID_MetadataFormatChunkiTXt, L"iTXt" },
823 { &GUID_MetadataFormatChunkcHRM, L"cHRM" },
824 { &GUID_MetadataFormatChunkhIST, L"hIST" },
825 { &GUID_MetadataFormatChunkiCCP, L"iCCP" },
826 { &GUID_MetadataFormatChunksRGB, L"sRGB" },
827 { &GUID_MetadataFormatChunktIME, L"tIME" }
830 HRESULT WINAPI WICMapGuidToShortName(REFGUID guid, UINT len, WCHAR *name, UINT *ret_len)
832 UINT i;
834 TRACE("%s,%u,%p,%p\n", wine_dbgstr_guid(guid), len, name, ret_len);
836 if (!guid) return E_INVALIDARG;
838 for (i = 0; i < ARRAY_SIZE(guid2name); i++)
840 if (IsEqualGUID(guid, guid2name[i].guid))
842 if (name)
844 if (!len) return E_INVALIDARG;
846 len = min(len - 1, lstrlenW(guid2name[i].name));
847 memcpy(name, guid2name[i].name, len * sizeof(WCHAR));
848 name[len] = 0;
850 if (len < lstrlenW(guid2name[i].name))
851 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
853 if (ret_len) *ret_len = lstrlenW(guid2name[i].name) + 1;
854 return S_OK;
858 return WINCODEC_ERR_PROPERTYNOTFOUND;
861 HRESULT WINAPI WICMapShortNameToGuid(PCWSTR name, GUID *guid)
863 UINT i;
865 TRACE("%s,%p\n", debugstr_w(name), guid);
867 if (!name || !guid) return E_INVALIDARG;
869 for (i = 0; i < ARRAY_SIZE(guid2name); i++)
871 if (!lstrcmpiW(name, guid2name[i].name))
873 *guid = *guid2name[i].guid;
874 return S_OK;
878 return WINCODEC_ERR_PROPERTYNOTFOUND;
881 static const struct
883 const WCHAR *name;
884 const WCHAR *schema;
885 } name2schema[] =
887 { L"rdf", L"http://www.w3.org/1999/02/22-rdf-syntax-ns#" },
888 { L"dc", L"http://purl.org/dc/elements/1.1/" },
889 { L"xmp", L"http://ns.adobe.com/xap/1.0/" },
890 { L"xmpidq", L"http://ns.adobe.com/xmp/Identifier/qual/1.0/" },
891 { L"xmpRights", L"http://ns.adobe.com/xap/1.0/rights/" },
892 { L"xmpMM", L"http://ns.adobe.com/xap/1.0/mm/" },
893 { L"xmpBJ", L"http://ns.adobe.com/xap/1.0/bj/" },
894 { L"xmpTPg", L"http://ns.adobe.com/xap/1.0/t/pg/" },
895 { L"pdf", L"http://ns.adobe.com/pdf/1.3/" },
896 { L"photoshop", L"http://ns.adobe.com/photoshop/1.0/" },
897 { L"tiff", L"http://ns.adobe.com/tiff/1.0/" },
898 { L"exif", L"http://ns.adobe.com/exif/1.0/" },
899 { L"stDim", L"http://ns.adobe.com/xap/1.0/sType/Dimensions#" },
900 { L"xapGImg", L"http://ns.adobe.com/xap/1.0/g/img/" },
901 { L"stEvt", L"http://ns.adobe.com/xap/1.0/sType/ResourceEvent#" },
902 { L"stRef", L"http://ns.adobe.com/xap/1.0/sType/ResourceRef#" },
903 { L"stVer", L"http://ns.adobe.com/xap/1.0/sType/Version#" },
904 { L"stJob", L"http://ns.adobe.com/xap/1.0/sType/Job#" },
905 { L"aux", L"http://ns.adobe.com/exif/1.0/aux/" },
906 { L"crs", L"http://ns.adobe.com/camera-raw-settings/1.0/" },
907 { L"xmpDM", L"http://ns.adobe.com/xmp/1.0/DynamicMedia/" },
908 { L"Iptc4xmpCore", L"http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/" },
909 { L"MicrosoftPhoto", L"http://ns.microsoft.com/photo/1.0/" },
910 { L"MP", L"http://ns.microsoft.com/photo/1.2/" },
911 { L"MPRI", L"http://ns.microsoft.com/photo/1.2/t/RegionInfo#" },
912 { L"MPReg", L"http://ns.microsoft.com/photo/1.2/t/Region#" }
915 static const WCHAR *map_shortname_to_schema(const GUID *format, const WCHAR *name)
917 UINT i;
919 /* It appears that the only metadata formats
920 * that support schemas are xmp and xmpstruct.
922 if (!IsEqualGUID(format, &GUID_MetadataFormatXMP) &&
923 !IsEqualGUID(format, &GUID_MetadataFormatXMPStruct))
924 return NULL;
926 for (i = 0; i < ARRAY_SIZE(name2schema); i++)
928 if (!wcscmp(name2schema[i].name, name))
929 return name2schema[i].schema;
932 return NULL;
935 HRESULT WINAPI WICMapSchemaToName(REFGUID format, LPWSTR schema, UINT len, WCHAR *name, UINT *ret_len)
937 UINT i;
939 TRACE("%s,%s,%u,%p,%p\n", wine_dbgstr_guid(format), debugstr_w(schema), len, name, ret_len);
941 if (!format || !schema || !ret_len)
942 return E_INVALIDARG;
944 /* It appears that the only metadata formats
945 * that support schemas are xmp and xmpstruct.
947 if (!IsEqualGUID(format, &GUID_MetadataFormatXMP) &&
948 !IsEqualGUID(format, &GUID_MetadataFormatXMPStruct))
949 return WINCODEC_ERR_PROPERTYNOTFOUND;
951 for (i = 0; i < ARRAY_SIZE(name2schema); i++)
953 if (!wcscmp(name2schema[i].schema, schema))
955 if (name)
957 if (!len) return E_INVALIDARG;
959 len = min(len - 1, lstrlenW(name2schema[i].name));
960 memcpy(name, name2schema[i].name, len * sizeof(WCHAR));
961 name[len] = 0;
963 if (len < lstrlenW(name2schema[i].name))
964 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
967 *ret_len = lstrlenW(name2schema[i].name) + 1;
968 return S_OK;
972 return WINCODEC_ERR_PROPERTYNOTFOUND;