2 * Copyright 2012 Vincent Povirk for CodeWeavers
3 * Copyright 2012 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define NONAMELESSUNION
33 #include "wincodecsdk.h"
35 #include "wincodecs_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
41 typedef struct MetadataHandler
{
42 IWICMetadataWriter IWICMetadataWriter_iface
;
44 IWICPersistStream IWICPersistStream_iface
;
45 const MetadataHandlerVtbl
*vtable
;
48 CRITICAL_SECTION lock
;
51 static inline MetadataHandler
*impl_from_IWICMetadataWriter(IWICMetadataWriter
*iface
)
53 return CONTAINING_RECORD(iface
, MetadataHandler
, IWICMetadataWriter_iface
);
56 static inline MetadataHandler
*impl_from_IWICPersistStream(IWICPersistStream
*iface
)
58 return CONTAINING_RECORD(iface
, MetadataHandler
, IWICPersistStream_iface
);
61 static void MetadataHandler_FreeItems(MetadataHandler
*This
)
65 for (i
=0; i
<This
->item_count
; i
++)
67 PropVariantClear(&This
->items
[i
].schema
);
68 PropVariantClear(&This
->items
[i
].id
);
69 PropVariantClear(&This
->items
[i
].value
);
72 HeapFree(GetProcessHeap(), 0, This
->items
);
75 static HRESULT
MetadataHandlerEnum_Create(MetadataHandler
*parent
, DWORD index
,
76 IWICEnumMetadataItem
**ppIEnumMetadataItem
);
78 static HRESULT WINAPI
MetadataHandler_QueryInterface(IWICMetadataWriter
*iface
, REFIID iid
,
81 MetadataHandler
*This
= impl_from_IWICMetadataWriter(iface
);
82 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
84 if (!ppv
) return E_INVALIDARG
;
86 if (IsEqualIID(&IID_IUnknown
, iid
) ||
87 IsEqualIID(&IID_IWICMetadataReader
, iid
) ||
88 (IsEqualIID(&IID_IWICMetadataWriter
, iid
) && This
->vtable
->is_writer
))
90 *ppv
= &This
->IWICMetadataWriter_iface
;
92 else if (IsEqualIID(&IID_IPersist
, iid
) ||
93 IsEqualIID(&IID_IPersistStream
, iid
) ||
94 IsEqualIID(&IID_IWICPersistStream
, iid
))
96 *ppv
= &This
->IWICPersistStream_iface
;
101 return E_NOINTERFACE
;
104 IUnknown_AddRef((IUnknown
*)*ppv
);
108 static ULONG WINAPI
MetadataHandler_AddRef(IWICMetadataWriter
*iface
)
110 MetadataHandler
*This
= impl_from_IWICMetadataWriter(iface
);
111 ULONG ref
= InterlockedIncrement(&This
->ref
);
113 TRACE("(%p) refcount=%u\n", iface
, ref
);
118 static ULONG WINAPI
MetadataHandler_Release(IWICMetadataWriter
*iface
)
120 MetadataHandler
*This
= impl_from_IWICMetadataWriter(iface
);
121 ULONG ref
= InterlockedDecrement(&This
->ref
);
123 TRACE("(%p) refcount=%u\n", iface
, ref
);
127 MetadataHandler_FreeItems(This
);
128 This
->lock
.DebugInfo
->Spare
[0] = 0;
129 DeleteCriticalSection(&This
->lock
);
130 HeapFree(GetProcessHeap(), 0, This
);
136 static HRESULT WINAPI
MetadataHandler_GetMetadataFormat(IWICMetadataWriter
*iface
,
137 GUID
*pguidMetadataFormat
)
139 if (!pguidMetadataFormat
) return E_INVALIDARG
;
141 FIXME("(%p,%s): stub\n", iface
, debugstr_guid(pguidMetadataFormat
));
145 static HRESULT WINAPI
MetadataHandler_GetMetadataHandlerInfo(IWICMetadataWriter
*iface
,
146 IWICMetadataHandlerInfo
**ppIHandler
)
148 FIXME("(%p,%p): stub\n", iface
, ppIHandler
);
152 static HRESULT WINAPI
MetadataHandler_GetCount(IWICMetadataWriter
*iface
,
155 MetadataHandler
*This
= impl_from_IWICMetadataWriter(iface
);
157 TRACE("%p,%p\n", iface
, pcCount
);
159 if (!pcCount
) return E_INVALIDARG
;
161 *pcCount
= This
->item_count
;
165 static HRESULT WINAPI
MetadataHandler_GetValueByIndex(IWICMetadataWriter
*iface
,
166 UINT nIndex
, PROPVARIANT
*pvarSchema
, PROPVARIANT
*pvarId
, PROPVARIANT
*pvarValue
)
168 FIXME("(%p,%u,%p,%p,%p): stub\n", iface
, nIndex
, pvarSchema
, pvarId
, pvarValue
);
172 static HRESULT WINAPI
MetadataHandler_GetValue(IWICMetadataWriter
*iface
,
173 const PROPVARIANT
*pvarSchema
, const PROPVARIANT
*pvarId
, PROPVARIANT
*pvarValue
)
175 FIXME("(%p,%p,%p,%p): stub\n", iface
, pvarSchema
, pvarId
, pvarValue
);
179 static HRESULT WINAPI
MetadataHandler_GetEnumerator(IWICMetadataWriter
*iface
,
180 IWICEnumMetadataItem
**ppIEnumMetadata
)
182 MetadataHandler
*This
= impl_from_IWICMetadataWriter(iface
);
183 TRACE("(%p,%p)\n", iface
, ppIEnumMetadata
);
184 return MetadataHandlerEnum_Create(This
, 0, ppIEnumMetadata
);
187 static HRESULT WINAPI
MetadataHandler_SetValue(IWICMetadataWriter
*iface
,
188 const PROPVARIANT
*pvarSchema
, const PROPVARIANT
*pvarId
, const PROPVARIANT
*pvarValue
)
190 FIXME("(%p,%p,%p,%p): stub\n", iface
, pvarSchema
, pvarId
, pvarValue
);
194 static HRESULT WINAPI
MetadataHandler_SetValueByIndex(IWICMetadataWriter
*iface
,
195 UINT nIndex
, const PROPVARIANT
*pvarSchema
, const PROPVARIANT
*pvarId
, const PROPVARIANT
*pvarValue
)
197 FIXME("(%p,%u,%p,%p,%p): stub\n", iface
, nIndex
, pvarSchema
, pvarId
, pvarValue
);
201 static HRESULT WINAPI
MetadataHandler_RemoveValue(IWICMetadataWriter
*iface
,
202 const PROPVARIANT
*pvarSchema
, const PROPVARIANT
*pvarId
)
204 FIXME("(%p,%p,%p): stub\n", iface
, pvarSchema
, pvarId
);
208 static HRESULT WINAPI
MetadataHandler_RemoveValueByIndex(IWICMetadataWriter
*iface
,
211 FIXME("(%p,%u): stub\n", iface
, nIndex
);
215 static const IWICMetadataWriterVtbl MetadataHandler_Vtbl
= {
216 MetadataHandler_QueryInterface
,
217 MetadataHandler_AddRef
,
218 MetadataHandler_Release
,
219 MetadataHandler_GetMetadataFormat
,
220 MetadataHandler_GetMetadataHandlerInfo
,
221 MetadataHandler_GetCount
,
222 MetadataHandler_GetValueByIndex
,
223 MetadataHandler_GetValue
,
224 MetadataHandler_GetEnumerator
,
225 MetadataHandler_SetValue
,
226 MetadataHandler_SetValueByIndex
,
227 MetadataHandler_RemoveValue
,
228 MetadataHandler_RemoveValueByIndex
231 static HRESULT WINAPI
MetadataHandler_PersistStream_QueryInterface(IWICPersistStream
*iface
,
232 REFIID iid
, void **ppv
)
234 MetadataHandler
*This
= impl_from_IWICPersistStream(iface
);
235 return IWICMetadataWriter_QueryInterface(&This
->IWICMetadataWriter_iface
, iid
, ppv
);
238 static ULONG WINAPI
MetadataHandler_PersistStream_AddRef(IWICPersistStream
*iface
)
240 MetadataHandler
*This
= impl_from_IWICPersistStream(iface
);
241 return IWICMetadataWriter_AddRef(&This
->IWICMetadataWriter_iface
);
244 static ULONG WINAPI
MetadataHandler_PersistStream_Release(IWICPersistStream
*iface
)
246 MetadataHandler
*This
= impl_from_IWICPersistStream(iface
);
247 return IWICMetadataWriter_Release(&This
->IWICMetadataWriter_iface
);
250 static HRESULT WINAPI
MetadataHandler_GetClassID(IWICPersistStream
*iface
,
253 FIXME("(%p,%p): stub\n", iface
, pClassID
);
257 static HRESULT WINAPI
MetadataHandler_IsDirty(IWICPersistStream
*iface
)
259 FIXME("(%p): stub\n", iface
);
263 static HRESULT WINAPI
MetadataHandler_Load(IWICPersistStream
*iface
,
266 FIXME("(%p,%p): stub\n", iface
, pStm
);
270 static HRESULT WINAPI
MetadataHandler_Save(IWICPersistStream
*iface
,
271 IStream
*pStm
, BOOL fClearDirty
)
273 FIXME("(%p,%p,%i): stub\n", iface
, pStm
, fClearDirty
);
277 static HRESULT WINAPI
MetadataHandler_GetSizeMax(IWICPersistStream
*iface
,
278 ULARGE_INTEGER
*pcbSize
)
280 FIXME("(%p,%p): stub\n", iface
, pcbSize
);
284 static HRESULT WINAPI
MetadataHandler_LoadEx(IWICPersistStream
*iface
,
285 IStream
*pIStream
, const GUID
*pguidPreferredVendor
, DWORD dwPersistOptions
)
287 MetadataHandler
*This
= impl_from_IWICPersistStream(iface
);
289 MetadataItem
*new_items
=NULL
;
292 TRACE("(%p,%p,%s,%x)\n", iface
, pIStream
, debugstr_guid(pguidPreferredVendor
), dwPersistOptions
);
294 EnterCriticalSection(&This
->lock
);
296 hr
= This
->vtable
->fnLoad(pIStream
, pguidPreferredVendor
, dwPersistOptions
,
297 &new_items
, &item_count
);
301 MetadataHandler_FreeItems(This
);
302 This
->items
= new_items
;
303 This
->item_count
= item_count
;
306 LeaveCriticalSection(&This
->lock
);
311 static HRESULT WINAPI
MetadataHandler_SaveEx(IWICPersistStream
*iface
,
312 IStream
*pIStream
, DWORD dwPersistOptions
, BOOL fClearDirty
)
314 FIXME("(%p,%p,%x,%i): stub\n", iface
, pIStream
, dwPersistOptions
, fClearDirty
);
318 static const IWICPersistStreamVtbl MetadataHandler_PersistStream_Vtbl
= {
319 MetadataHandler_PersistStream_QueryInterface
,
320 MetadataHandler_PersistStream_AddRef
,
321 MetadataHandler_PersistStream_Release
,
322 MetadataHandler_GetClassID
,
323 MetadataHandler_IsDirty
,
324 MetadataHandler_Load
,
325 MetadataHandler_Save
,
326 MetadataHandler_GetSizeMax
,
327 MetadataHandler_LoadEx
,
328 MetadataHandler_SaveEx
331 static HRESULT
MetadataReader_Create(const MetadataHandlerVtbl
*vtable
, IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
333 MetadataHandler
*This
;
336 TRACE("%s\n", debugstr_guid(vtable
->clsid
));
340 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
342 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(MetadataHandler
));
343 if (!This
) return E_OUTOFMEMORY
;
345 This
->IWICMetadataWriter_iface
.lpVtbl
= &MetadataHandler_Vtbl
;
346 This
->IWICPersistStream_iface
.lpVtbl
= &MetadataHandler_PersistStream_Vtbl
;
348 This
->vtable
= vtable
;
350 This
->item_count
= 0;
352 InitializeCriticalSection(&This
->lock
);
353 This
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": MetadataHandler.lock");
355 hr
= IWICMetadataWriter_QueryInterface(&This
->IWICMetadataWriter_iface
, iid
, ppv
);
357 IWICMetadataWriter_Release(&This
->IWICMetadataWriter_iface
);
362 typedef struct MetadataHandlerEnum
{
363 IWICEnumMetadataItem IWICEnumMetadataItem_iface
;
365 MetadataHandler
*parent
;
367 } MetadataHandlerEnum
;
369 static inline MetadataHandlerEnum
*impl_from_IWICEnumMetadataItem(IWICEnumMetadataItem
*iface
)
371 return CONTAINING_RECORD(iface
, MetadataHandlerEnum
, IWICEnumMetadataItem_iface
);
374 static HRESULT WINAPI
MetadataHandlerEnum_QueryInterface(IWICEnumMetadataItem
*iface
, REFIID iid
,
377 MetadataHandlerEnum
*This
= impl_from_IWICEnumMetadataItem(iface
);
378 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
380 if (!ppv
) return E_INVALIDARG
;
382 if (IsEqualIID(&IID_IUnknown
, iid
) ||
383 IsEqualIID(&IID_IWICEnumMetadataItem
, iid
))
385 *ppv
= &This
->IWICEnumMetadataItem_iface
;
390 return E_NOINTERFACE
;
393 IUnknown_AddRef((IUnknown
*)*ppv
);
397 static ULONG WINAPI
MetadataHandlerEnum_AddRef(IWICEnumMetadataItem
*iface
)
399 MetadataHandlerEnum
*This
= impl_from_IWICEnumMetadataItem(iface
);
400 ULONG ref
= InterlockedIncrement(&This
->ref
);
402 TRACE("(%p) refcount=%u\n", iface
, ref
);
407 static ULONG WINAPI
MetadataHandlerEnum_Release(IWICEnumMetadataItem
*iface
)
409 MetadataHandlerEnum
*This
= impl_from_IWICEnumMetadataItem(iface
);
410 ULONG ref
= InterlockedDecrement(&This
->ref
);
412 TRACE("(%p) refcount=%u\n", iface
, ref
);
416 IWICMetadataWriter_Release(&This
->parent
->IWICMetadataWriter_iface
);
417 HeapFree(GetProcessHeap(), 0, This
);
423 static HRESULT WINAPI
MetadataHandlerEnum_Next(IWICEnumMetadataItem
*iface
,
424 ULONG celt
, PROPVARIANT
*rgeltSchema
, PROPVARIANT
*rgeltId
,
425 PROPVARIANT
*rgeltValue
, ULONG
*pceltFetched
)
427 MetadataHandlerEnum
*This
= impl_from_IWICEnumMetadataItem(iface
);
432 TRACE("(%p,%i)\n", iface
, celt
);
434 EnterCriticalSection(&This
->parent
->lock
);
436 if (This
->index
>= This
->parent
->item_count
)
439 LeaveCriticalSection(&This
->parent
->lock
);
443 new_index
= min(This
->parent
->item_count
, This
->index
+ celt
);
444 *pceltFetched
= new_index
- This
->index
;
448 for (i
=0; SUCCEEDED(hr
) && i
< *pceltFetched
; i
++)
449 hr
= PropVariantCopy(&rgeltSchema
[i
], &This
->parent
->items
[i
+This
->index
].schema
);
452 for (i
=0; SUCCEEDED(hr
) && i
< *pceltFetched
; i
++)
453 hr
= PropVariantCopy(&rgeltId
[i
], &This
->parent
->items
[i
+This
->index
].id
);
457 for (i
=0; SUCCEEDED(hr
) && i
< *pceltFetched
; i
++)
458 hr
= PropVariantCopy(&rgeltValue
[i
], &This
->parent
->items
[i
+This
->index
].value
);
463 This
->index
= new_index
;
466 LeaveCriticalSection(&This
->parent
->lock
);
471 static HRESULT WINAPI
MetadataHandlerEnum_Skip(IWICEnumMetadataItem
*iface
,
474 MetadataHandlerEnum
*This
= impl_from_IWICEnumMetadataItem(iface
);
476 EnterCriticalSection(&This
->parent
->lock
);
480 LeaveCriticalSection(&This
->parent
->lock
);
485 static HRESULT WINAPI
MetadataHandlerEnum_Reset(IWICEnumMetadataItem
*iface
)
487 MetadataHandlerEnum
*This
= impl_from_IWICEnumMetadataItem(iface
);
489 EnterCriticalSection(&This
->parent
->lock
);
493 LeaveCriticalSection(&This
->parent
->lock
);
498 static HRESULT WINAPI
MetadataHandlerEnum_Clone(IWICEnumMetadataItem
*iface
,
499 IWICEnumMetadataItem
**ppIEnumMetadataItem
)
501 MetadataHandlerEnum
*This
= impl_from_IWICEnumMetadataItem(iface
);
504 EnterCriticalSection(&This
->parent
->lock
);
506 hr
= MetadataHandlerEnum_Create(This
->parent
, This
->index
, ppIEnumMetadataItem
);
508 LeaveCriticalSection(&This
->parent
->lock
);
513 static const IWICEnumMetadataItemVtbl MetadataHandlerEnum_Vtbl
= {
514 MetadataHandlerEnum_QueryInterface
,
515 MetadataHandlerEnum_AddRef
,
516 MetadataHandlerEnum_Release
,
517 MetadataHandlerEnum_Next
,
518 MetadataHandlerEnum_Skip
,
519 MetadataHandlerEnum_Reset
,
520 MetadataHandlerEnum_Clone
523 static HRESULT
MetadataHandlerEnum_Create(MetadataHandler
*parent
, DWORD index
,
524 IWICEnumMetadataItem
**ppIEnumMetadataItem
)
526 MetadataHandlerEnum
*This
;
528 if (!ppIEnumMetadataItem
) return E_INVALIDARG
;
530 *ppIEnumMetadataItem
= NULL
;
532 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(MetadataHandlerEnum
));
533 if (!This
) return E_OUTOFMEMORY
;
535 IWICMetadataWriter_AddRef(&parent
->IWICMetadataWriter_iface
);
537 This
->IWICEnumMetadataItem_iface
.lpVtbl
= &MetadataHandlerEnum_Vtbl
;
539 This
->parent
= parent
;
542 *ppIEnumMetadataItem
= &This
->IWICEnumMetadataItem_iface
;
547 static HRESULT
LoadUnknownMetadata(IStream
*input
, const GUID
*preferred_vendor
,
548 DWORD persist_options
, MetadataItem
**items
, DWORD
*item_count
)
551 MetadataItem
*result
;
558 hr
= IStream_Stat(input
, &stat
, STATFLAG_NONAME
);
562 data
= HeapAlloc(GetProcessHeap(), 0, stat
.cbSize
.QuadPart
);
563 if (!data
) return E_OUTOFMEMORY
;
565 hr
= IStream_Read(input
, data
, stat
.cbSize
.QuadPart
, &bytesread
);
568 HeapFree(GetProcessHeap(), 0, data
);
572 result
= HeapAlloc(GetProcessHeap(), 0, sizeof(MetadataItem
));
575 HeapFree(GetProcessHeap(), 0, data
);
576 return E_OUTOFMEMORY
;
579 PropVariantInit(&result
[0].schema
);
580 PropVariantInit(&result
[0].id
);
581 PropVariantInit(&result
[0].value
);
583 result
[0].value
.vt
= VT_BLOB
;
584 result
[0].value
.u
.blob
.cbSize
= bytesread
;
585 result
[0].value
.u
.blob
.pBlobData
= data
;
593 static const MetadataHandlerVtbl UnknownMetadataReader_Vtbl
= {
595 &CLSID_WICUnknownMetadataReader
,
599 HRESULT
UnknownMetadataReader_CreateInstance(IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
601 return MetadataReader_Create(&UnknownMetadataReader_Vtbl
, pUnkOuter
, iid
, ppv
);
604 #define SWAP_USHORT(x) do { if (!native_byte_order) (x) = RtlUshortByteSwap(x); } while(0)
605 #define SWAP_ULONG(x) do { if (!native_byte_order) (x) = RtlUlongByteSwap(x); } while(0)
606 #define SWAP_ULONGLONG(x) do { if (!native_byte_order) (x) = RtlUlonglongByteSwap(x); } while(0)
608 #include "pshpack2.h"
628 #define IFD_RATIONAL 5
630 #define IFD_UNDEFINED 7
633 #define IFD_SRATIONAL 10
635 #define IFD_DOUBLE 12
638 static HRESULT
load_IFD_entry(IStream
*input
, const struct IFD_entry
*entry
,
639 MetadataItem
*item
, BOOL native_byte_order
)
644 item
->schema
.vt
= VT_EMPTY
;
645 item
->id
.vt
= VT_UI2
;
646 item
->id
.u
.uiVal
= entry
->id
;
647 SWAP_USHORT(item
->id
.u
.uiVal
);
649 count
= entry
->count
;
653 value
= entry
->value
;
661 item
->value
.vt
= VT_UI2
;
662 item
->value
.u
.uiVal
= value
;
665 FIXME("loading multiple short fields is not implemented\n");
670 item
->value
.vt
= VT_UI4
;
671 item
->value
.u
.ulVal
= value
;
674 FIXME("loading multiple long fields is not implemented\n");
681 struct IFD_rational rational
;
683 pos
.QuadPart
= value
;
684 hr
= IStream_Seek(input
, pos
, SEEK_SET
, NULL
);
685 if (FAILED(hr
)) return hr
;
687 item
->value
.vt
= VT_UI8
;
688 hr
= IStream_Read(input
, &rational
, sizeof(rational
), NULL
);
689 if (FAILED(hr
)) return hr
;
690 item
->value
.u
.uhVal
.QuadPart
= ((LONGLONG
)rational
.denominator
<< 32) | rational
.numerator
;
691 SWAP_ULONGLONG(item
->value
.u
.uhVal
.QuadPart
);
694 FIXME("loading multiple rational fields is not implemented\n");
697 FIXME("loading field of type %d is not implemented\n", entry
->type
);
703 static HRESULT
LoadIfdMetadata(IStream
*input
, const GUID
*preferred_vendor
,
704 DWORD persist_options
, MetadataItem
**items
, DWORD
*item_count
)
707 MetadataItem
*result
;
709 struct IFD_entry
*entry
;
710 BOOL native_byte_order
= TRUE
;
714 #ifdef WORDS_BIGENDIAN
715 if (persist_options
& WICPersistOptionsLittleEndian
)
717 if (persist_options
& WICPersistOptionsBigEndian
)
719 native_byte_order
= FALSE
;
721 hr
= IStream_Read(input
, &count
, sizeof(count
), NULL
);
722 if (FAILED(hr
)) return hr
;
726 entry
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(*entry
));
727 if (!entry
) return E_OUTOFMEMORY
;
729 hr
= IStream_Read(input
, entry
, count
* sizeof(*entry
), NULL
);
732 HeapFree(GetProcessHeap(), 0, entry
);
736 /* limit number of IFDs to 4096 to avoid infinite loop */
737 for (i
= 0; i
< 4096; i
++)
739 ULONG next_ifd_offset
;
741 USHORT next_ifd_count
;
743 hr
= IStream_Read(input
, &next_ifd_offset
, sizeof(next_ifd_offset
), NULL
);
744 if (FAILED(hr
)) break;
746 SWAP_ULONG(next_ifd_offset
);
747 if (!next_ifd_offset
) break;
749 pos
.QuadPart
= next_ifd_offset
;
750 hr
= IStream_Seek(input
, pos
, SEEK_SET
, NULL
);
751 if (FAILED(hr
)) break;
753 hr
= IStream_Read(input
, &next_ifd_count
, sizeof(next_ifd_count
), NULL
);
754 if (FAILED(hr
)) break;
756 SWAP_USHORT(next_ifd_count
);
758 pos
.QuadPart
= next_ifd_count
* sizeof(*entry
);
759 hr
= IStream_Seek(input
, pos
, SEEK_CUR
, NULL
);
760 if (FAILED(hr
)) break;
763 if (FAILED(hr
) || i
== 4096)
765 HeapFree(GetProcessHeap(), 0, entry
);
766 return WINCODEC_ERR_BADMETADATAHEADER
;
769 result
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(*result
));
772 HeapFree(GetProcessHeap(), 0, entry
);
773 return E_OUTOFMEMORY
;
776 for (i
= 0; i
< count
; i
++)
778 hr
= load_IFD_entry(input
, &entry
[i
], &result
[i
], native_byte_order
);
781 HeapFree(GetProcessHeap(), 0, entry
);
782 HeapFree(GetProcessHeap(), 0, result
);
787 HeapFree(GetProcessHeap(), 0, entry
);
795 static const MetadataHandlerVtbl IfdMetadataReader_Vtbl
= {
797 &CLSID_WICIfdMetadataReader
,
801 HRESULT
IfdMetadataReader_CreateInstance(IUnknown
*pUnkOuter
, REFIID iid
, void **ppv
)
803 return MetadataReader_Create(&IfdMetadataReader_Vtbl
, pUnkOuter
, iid
, ppv
);