2012-01-11 23:03:24 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Vincent Povirk for CodeWeavers
|
2012-06-13 11:31:02 +02:00
|
|
|
* Copyright 2012 Dmitry Timoshkov
|
2012-01-11 23:03:24 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2012-06-13 11:30:54 +02:00
|
|
|
#include <stdio.h>
|
2012-01-11 23:03:24 +01:00
|
|
|
|
|
|
|
#define COBJMACROS
|
2012-01-15 21:08:06 +01:00
|
|
|
#define NONAMELESSUNION
|
2012-01-11 23:03:24 +01:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2012-06-13 11:31:02 +02:00
|
|
|
#include "winternl.h"
|
2012-01-11 23:03:24 +01:00
|
|
|
#include "objbase.h"
|
2017-06-22 05:38:51 +02:00
|
|
|
#include "propvarutil.h"
|
2012-01-11 23:03:24 +01:00
|
|
|
|
|
|
|
#include "wincodecs_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
|
|
|
|
|
|
|
|
typedef struct MetadataHandler {
|
|
|
|
IWICMetadataWriter IWICMetadataWriter_iface;
|
|
|
|
LONG ref;
|
|
|
|
IWICPersistStream IWICPersistStream_iface;
|
|
|
|
const MetadataHandlerVtbl *vtable;
|
2012-01-11 23:36:49 +01:00
|
|
|
MetadataItem *items;
|
|
|
|
DWORD item_count;
|
|
|
|
CRITICAL_SECTION lock;
|
2012-01-11 23:03:24 +01:00
|
|
|
} MetadataHandler;
|
|
|
|
|
|
|
|
static inline MetadataHandler *impl_from_IWICMetadataWriter(IWICMetadataWriter *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, MetadataHandler, IWICMetadataWriter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline MetadataHandler *impl_from_IWICPersistStream(IWICPersistStream *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, MetadataHandler, IWICPersistStream_iface);
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:36:49 +01:00
|
|
|
static void MetadataHandler_FreeItems(MetadataHandler *This)
|
|
|
|
{
|
2013-03-02 16:37:47 +01:00
|
|
|
DWORD i;
|
2012-01-11 23:36:49 +01:00
|
|
|
|
|
|
|
for (i=0; i<This->item_count; i++)
|
|
|
|
{
|
|
|
|
PropVariantClear(&This->items[i].schema);
|
|
|
|
PropVariantClear(&This->items[i].id);
|
|
|
|
PropVariantClear(&This->items[i].value);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->items);
|
|
|
|
}
|
|
|
|
|
2012-01-12 00:16:41 +01:00
|
|
|
static HRESULT MetadataHandlerEnum_Create(MetadataHandler *parent, DWORD index,
|
|
|
|
IWICEnumMetadataItem **ppIEnumMetadataItem);
|
|
|
|
|
2012-01-11 23:03:24 +01:00
|
|
|
static HRESULT WINAPI MetadataHandler_QueryInterface(IWICMetadataWriter *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
|
|
|
MetadataHandler *This = impl_from_IWICMetadataWriter(iface);
|
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICMetadataReader, iid) ||
|
|
|
|
(IsEqualIID(&IID_IWICMetadataWriter, iid) && This->vtable->is_writer))
|
|
|
|
{
|
|
|
|
*ppv = &This->IWICMetadataWriter_iface;
|
|
|
|
}
|
|
|
|
else if (IsEqualIID(&IID_IPersist, iid) ||
|
|
|
|
IsEqualIID(&IID_IPersistStream, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICPersistStream, iid))
|
|
|
|
{
|
|
|
|
*ppv = &This->IWICPersistStream_iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MetadataHandler_AddRef(IWICMetadataWriter *iface)
|
|
|
|
{
|
|
|
|
MetadataHandler *This = impl_from_IWICMetadataWriter(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MetadataHandler_Release(IWICMetadataWriter *iface)
|
|
|
|
{
|
|
|
|
MetadataHandler *This = impl_from_IWICMetadataWriter(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2012-01-11 23:36:49 +01:00
|
|
|
MetadataHandler_FreeItems(This);
|
|
|
|
This->lock.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->lock);
|
2012-01-11 23:03:24 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_GetMetadataHandlerInfo(IWICMetadataWriter *iface,
|
|
|
|
IWICMetadataHandlerInfo **ppIHandler)
|
|
|
|
{
|
2012-06-20 07:00:08 +02:00
|
|
|
HRESULT hr;
|
|
|
|
IWICComponentInfo *component_info;
|
|
|
|
MetadataHandler *This = impl_from_IWICMetadataWriter(iface);
|
|
|
|
|
|
|
|
TRACE("%p,%p\n", iface, ppIHandler);
|
|
|
|
|
|
|
|
hr = CreateComponentInfo(This->vtable->clsid, &component_info);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IWICComponentInfo_QueryInterface(component_info, &IID_IWICMetadataHandlerInfo,
|
|
|
|
(void **)ppIHandler);
|
|
|
|
|
|
|
|
IWICComponentInfo_Release(component_info);
|
|
|
|
return hr;
|
2012-01-11 23:03:24 +01:00
|
|
|
}
|
|
|
|
|
2012-06-20 07:00:17 +02:00
|
|
|
static HRESULT WINAPI MetadataHandler_GetMetadataFormat(IWICMetadataWriter *iface,
|
|
|
|
GUID *pguidMetadataFormat)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICMetadataHandlerInfo *metadata_info;
|
|
|
|
|
|
|
|
TRACE("%p,%p\n", iface, pguidMetadataFormat);
|
|
|
|
|
|
|
|
if (!pguidMetadataFormat) return E_INVALIDARG;
|
|
|
|
|
|
|
|
hr = MetadataHandler_GetMetadataHandlerInfo(iface, &metadata_info);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IWICMetadataHandlerInfo_GetMetadataFormat(metadata_info, pguidMetadataFormat);
|
|
|
|
IWICMetadataHandlerInfo_Release(metadata_info);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:03:24 +01:00
|
|
|
static HRESULT WINAPI MetadataHandler_GetCount(IWICMetadataWriter *iface,
|
|
|
|
UINT *pcCount)
|
|
|
|
{
|
2012-06-08 07:08:42 +02:00
|
|
|
MetadataHandler *This = impl_from_IWICMetadataWriter(iface);
|
|
|
|
|
|
|
|
TRACE("%p,%p\n", iface, pcCount);
|
|
|
|
|
2012-06-08 07:08:28 +02:00
|
|
|
if (!pcCount) return E_INVALIDARG;
|
|
|
|
|
2012-06-08 07:08:42 +02:00
|
|
|
*pcCount = This->item_count;
|
|
|
|
return S_OK;
|
2012-01-11 23:03:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_GetValueByIndex(IWICMetadataWriter *iface,
|
2012-06-20 07:00:25 +02:00
|
|
|
UINT index, PROPVARIANT *schema, PROPVARIANT *id, PROPVARIANT *value)
|
2012-01-11 23:03:24 +01:00
|
|
|
{
|
2012-06-20 07:00:25 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
MetadataHandler *This = impl_from_IWICMetadataWriter(iface);
|
|
|
|
|
|
|
|
TRACE("%p,%u,%p,%p,%p\n", iface, index, schema, id, value);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
if (index >= This->item_count)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (schema)
|
|
|
|
hr = PropVariantCopy(schema, &This->items[index].schema);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && id)
|
|
|
|
hr = PropVariantCopy(id, &This->items[index].id);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && value)
|
|
|
|
hr = PropVariantCopy(value, &This->items[index].value);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
return hr;
|
2012-01-11 23:03:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_GetValue(IWICMetadataWriter *iface,
|
2012-06-28 06:25:05 +02:00
|
|
|
const PROPVARIANT *schema, const PROPVARIANT *id, PROPVARIANT *value)
|
2012-01-11 23:03:24 +01:00
|
|
|
{
|
2012-06-28 06:25:05 +02:00
|
|
|
UINT i;
|
|
|
|
HRESULT hr = WINCODEC_ERR_PROPERTYNOTFOUND;
|
|
|
|
MetadataHandler *This = impl_from_IWICMetadataWriter(iface);
|
|
|
|
|
2017-06-22 05:38:51 +02:00
|
|
|
TRACE("(%p,%s,%s,%p)\n", iface, wine_dbgstr_variant((const VARIANT *)schema), wine_dbgstr_variant((const VARIANT *)id), value);
|
2012-06-28 06:25:05 +02:00
|
|
|
|
|
|
|
if (!id) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
for (i = 0; i < This->item_count; i++)
|
|
|
|
{
|
|
|
|
if (schema && This->items[i].schema.vt != VT_EMPTY)
|
|
|
|
{
|
2017-06-22 05:38:51 +02:00
|
|
|
if (PropVariantCompareEx(schema, &This->items[i].schema, 0, PVCF_USESTRCMPI) != 0) continue;
|
2012-06-28 06:25:05 +02:00
|
|
|
}
|
|
|
|
|
2017-06-22 05:38:51 +02:00
|
|
|
if (PropVariantCompareEx(id, &This->items[i].id, 0, PVCF_USESTRCMPI) != 0) continue;
|
2012-06-28 06:25:05 +02:00
|
|
|
|
|
|
|
hr = value ? PropVariantCopy(value, &This->items[i].value) : S_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
return hr;
|
2012-01-11 23:03:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_GetEnumerator(IWICMetadataWriter *iface,
|
|
|
|
IWICEnumMetadataItem **ppIEnumMetadata)
|
|
|
|
{
|
2012-01-12 00:16:41 +01:00
|
|
|
MetadataHandler *This = impl_from_IWICMetadataWriter(iface);
|
|
|
|
TRACE("(%p,%p)\n", iface, ppIEnumMetadata);
|
|
|
|
return MetadataHandlerEnum_Create(This, 0, ppIEnumMetadata);
|
2012-01-11 23:03:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_SetValue(IWICMetadataWriter *iface,
|
|
|
|
const PROPVARIANT *pvarSchema, const PROPVARIANT *pvarId, const PROPVARIANT *pvarValue)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%p,%p): stub\n", iface, pvarSchema, pvarId, pvarValue);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_SetValueByIndex(IWICMetadataWriter *iface,
|
|
|
|
UINT nIndex, const PROPVARIANT *pvarSchema, const PROPVARIANT *pvarId, const PROPVARIANT *pvarValue)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%u,%p,%p,%p): stub\n", iface, nIndex, pvarSchema, pvarId, pvarValue);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_RemoveValue(IWICMetadataWriter *iface,
|
|
|
|
const PROPVARIANT *pvarSchema, const PROPVARIANT *pvarId)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%p): stub\n", iface, pvarSchema, pvarId);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_RemoveValueByIndex(IWICMetadataWriter *iface,
|
|
|
|
UINT nIndex)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%u): stub\n", iface, nIndex);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICMetadataWriterVtbl MetadataHandler_Vtbl = {
|
|
|
|
MetadataHandler_QueryInterface,
|
|
|
|
MetadataHandler_AddRef,
|
|
|
|
MetadataHandler_Release,
|
|
|
|
MetadataHandler_GetMetadataFormat,
|
|
|
|
MetadataHandler_GetMetadataHandlerInfo,
|
|
|
|
MetadataHandler_GetCount,
|
|
|
|
MetadataHandler_GetValueByIndex,
|
|
|
|
MetadataHandler_GetValue,
|
|
|
|
MetadataHandler_GetEnumerator,
|
|
|
|
MetadataHandler_SetValue,
|
|
|
|
MetadataHandler_SetValueByIndex,
|
|
|
|
MetadataHandler_RemoveValue,
|
|
|
|
MetadataHandler_RemoveValueByIndex
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_PersistStream_QueryInterface(IWICPersistStream *iface,
|
|
|
|
REFIID iid, void **ppv)
|
|
|
|
{
|
|
|
|
MetadataHandler *This = impl_from_IWICPersistStream(iface);
|
|
|
|
return IWICMetadataWriter_QueryInterface(&This->IWICMetadataWriter_iface, iid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MetadataHandler_PersistStream_AddRef(IWICPersistStream *iface)
|
|
|
|
{
|
|
|
|
MetadataHandler *This = impl_from_IWICPersistStream(iface);
|
|
|
|
return IWICMetadataWriter_AddRef(&This->IWICMetadataWriter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MetadataHandler_PersistStream_Release(IWICPersistStream *iface)
|
|
|
|
{
|
|
|
|
MetadataHandler *This = impl_from_IWICPersistStream(iface);
|
|
|
|
return IWICMetadataWriter_Release(&This->IWICMetadataWriter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_GetClassID(IWICPersistStream *iface,
|
|
|
|
CLSID *pClassID)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): stub\n", iface, pClassID);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_IsDirty(IWICPersistStream *iface)
|
|
|
|
{
|
|
|
|
FIXME("(%p): stub\n", iface);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_Load(IWICPersistStream *iface,
|
|
|
|
IStream *pStm)
|
|
|
|
{
|
2012-07-24 08:00:29 +02:00
|
|
|
MetadataHandler *This = impl_from_IWICPersistStream(iface);
|
|
|
|
TRACE("(%p,%p)\n", iface, pStm);
|
2017-05-10 18:20:10 +02:00
|
|
|
return IWICPersistStream_LoadEx(&This->IWICPersistStream_iface, pStm, NULL, WICPersistOptionDefault);
|
2012-01-11 23:03:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_Save(IWICPersistStream *iface,
|
|
|
|
IStream *pStm, BOOL fClearDirty)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%i): stub\n", iface, pStm, fClearDirty);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_GetSizeMax(IWICPersistStream *iface,
|
|
|
|
ULARGE_INTEGER *pcbSize)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): stub\n", iface, pcbSize);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_LoadEx(IWICPersistStream *iface,
|
|
|
|
IStream *pIStream, const GUID *pguidPreferredVendor, DWORD dwPersistOptions)
|
|
|
|
{
|
2012-01-11 23:36:49 +01:00
|
|
|
MetadataHandler *This = impl_from_IWICPersistStream(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
MetadataItem *new_items=NULL;
|
|
|
|
DWORD item_count=0;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%s,%x)\n", iface, pIStream, debugstr_guid(pguidPreferredVendor), dwPersistOptions);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
hr = This->vtable->fnLoad(pIStream, pguidPreferredVendor, dwPersistOptions,
|
|
|
|
&new_items, &item_count);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
MetadataHandler_FreeItems(This);
|
|
|
|
This->items = new_items;
|
|
|
|
This->item_count = item_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
return hr;
|
2012-01-11 23:03:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandler_SaveEx(IWICPersistStream *iface,
|
|
|
|
IStream *pIStream, DWORD dwPersistOptions, BOOL fClearDirty)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%x,%i): stub\n", iface, pIStream, dwPersistOptions, fClearDirty);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICPersistStreamVtbl MetadataHandler_PersistStream_Vtbl = {
|
|
|
|
MetadataHandler_PersistStream_QueryInterface,
|
|
|
|
MetadataHandler_PersistStream_AddRef,
|
|
|
|
MetadataHandler_PersistStream_Release,
|
|
|
|
MetadataHandler_GetClassID,
|
|
|
|
MetadataHandler_IsDirty,
|
|
|
|
MetadataHandler_Load,
|
|
|
|
MetadataHandler_Save,
|
|
|
|
MetadataHandler_GetSizeMax,
|
|
|
|
MetadataHandler_LoadEx,
|
|
|
|
MetadataHandler_SaveEx
|
|
|
|
};
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
HRESULT MetadataReader_Create(const MetadataHandlerVtbl *vtable, REFIID iid, void** ppv)
|
2012-01-11 23:03:24 +01:00
|
|
|
{
|
|
|
|
MetadataHandler *This;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_guid(vtable->clsid));
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(MetadataHandler));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IWICMetadataWriter_iface.lpVtbl = &MetadataHandler_Vtbl;
|
|
|
|
This->IWICPersistStream_iface.lpVtbl = &MetadataHandler_PersistStream_Vtbl;
|
|
|
|
This->ref = 1;
|
|
|
|
This->vtable = vtable;
|
2012-01-11 23:36:49 +01:00
|
|
|
This->items = NULL;
|
|
|
|
This->item_count = 0;
|
|
|
|
|
|
|
|
InitializeCriticalSection(&This->lock);
|
|
|
|
This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": MetadataHandler.lock");
|
2012-01-11 23:03:24 +01:00
|
|
|
|
|
|
|
hr = IWICMetadataWriter_QueryInterface(&This->IWICMetadataWriter_iface, iid, ppv);
|
|
|
|
|
|
|
|
IWICMetadataWriter_Release(&This->IWICMetadataWriter_iface);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-01-12 00:16:41 +01:00
|
|
|
typedef struct MetadataHandlerEnum {
|
|
|
|
IWICEnumMetadataItem IWICEnumMetadataItem_iface;
|
|
|
|
LONG ref;
|
|
|
|
MetadataHandler *parent;
|
|
|
|
DWORD index;
|
|
|
|
} MetadataHandlerEnum;
|
|
|
|
|
|
|
|
static inline MetadataHandlerEnum *impl_from_IWICEnumMetadataItem(IWICEnumMetadataItem *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, MetadataHandlerEnum, IWICEnumMetadataItem_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandlerEnum_QueryInterface(IWICEnumMetadataItem *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
|
|
|
MetadataHandlerEnum *This = impl_from_IWICEnumMetadataItem(iface);
|
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICEnumMetadataItem, iid))
|
|
|
|
{
|
|
|
|
*ppv = &This->IWICEnumMetadataItem_iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MetadataHandlerEnum_AddRef(IWICEnumMetadataItem *iface)
|
|
|
|
{
|
|
|
|
MetadataHandlerEnum *This = impl_from_IWICEnumMetadataItem(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MetadataHandlerEnum_Release(IWICEnumMetadataItem *iface)
|
|
|
|
{
|
|
|
|
MetadataHandlerEnum *This = impl_from_IWICEnumMetadataItem(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
IWICMetadataWriter_Release(&This->parent->IWICMetadataWriter_iface);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandlerEnum_Next(IWICEnumMetadataItem *iface,
|
|
|
|
ULONG celt, PROPVARIANT *rgeltSchema, PROPVARIANT *rgeltId,
|
|
|
|
PROPVARIANT *rgeltValue, ULONG *pceltFetched)
|
|
|
|
{
|
|
|
|
MetadataHandlerEnum *This = impl_from_IWICEnumMetadataItem(iface);
|
|
|
|
ULONG new_index;
|
|
|
|
HRESULT hr=S_FALSE;
|
2013-03-02 16:37:47 +01:00
|
|
|
ULONG i;
|
2012-01-12 00:16:41 +01:00
|
|
|
|
|
|
|
TRACE("(%p,%i)\n", iface, celt);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (This->index >= This->parent->item_count)
|
|
|
|
{
|
|
|
|
*pceltFetched = 0;
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_index = min(This->parent->item_count, This->index + celt);
|
|
|
|
*pceltFetched = new_index - This->index;
|
|
|
|
|
|
|
|
if (rgeltSchema)
|
|
|
|
{
|
|
|
|
for (i=0; SUCCEEDED(hr) && i < *pceltFetched; i++)
|
|
|
|
hr = PropVariantCopy(&rgeltSchema[i], &This->parent->items[i+This->index].schema);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; SUCCEEDED(hr) && i < *pceltFetched; i++)
|
|
|
|
hr = PropVariantCopy(&rgeltId[i], &This->parent->items[i+This->index].id);
|
|
|
|
|
|
|
|
if (rgeltValue)
|
|
|
|
{
|
|
|
|
for (i=0; SUCCEEDED(hr) && i < *pceltFetched; i++)
|
|
|
|
hr = PropVariantCopy(&rgeltValue[i], &This->parent->items[i+This->index].value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
This->index = new_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandlerEnum_Skip(IWICEnumMetadataItem *iface,
|
|
|
|
ULONG celt)
|
|
|
|
{
|
|
|
|
MetadataHandlerEnum *This = impl_from_IWICEnumMetadataItem(iface);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
This->index += celt;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandlerEnum_Reset(IWICEnumMetadataItem *iface)
|
|
|
|
{
|
|
|
|
MetadataHandlerEnum *This = impl_from_IWICEnumMetadataItem(iface);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
This->index = 0;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MetadataHandlerEnum_Clone(IWICEnumMetadataItem *iface,
|
|
|
|
IWICEnumMetadataItem **ppIEnumMetadataItem)
|
|
|
|
{
|
|
|
|
MetadataHandlerEnum *This = impl_from_IWICEnumMetadataItem(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
hr = MetadataHandlerEnum_Create(This->parent, This->index, ppIEnumMetadataItem);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICEnumMetadataItemVtbl MetadataHandlerEnum_Vtbl = {
|
|
|
|
MetadataHandlerEnum_QueryInterface,
|
|
|
|
MetadataHandlerEnum_AddRef,
|
|
|
|
MetadataHandlerEnum_Release,
|
|
|
|
MetadataHandlerEnum_Next,
|
|
|
|
MetadataHandlerEnum_Skip,
|
|
|
|
MetadataHandlerEnum_Reset,
|
|
|
|
MetadataHandlerEnum_Clone
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT MetadataHandlerEnum_Create(MetadataHandler *parent, DWORD index,
|
|
|
|
IWICEnumMetadataItem **ppIEnumMetadataItem)
|
|
|
|
{
|
|
|
|
MetadataHandlerEnum *This;
|
|
|
|
|
2012-06-08 07:08:28 +02:00
|
|
|
if (!ppIEnumMetadataItem) return E_INVALIDARG;
|
|
|
|
|
2012-01-12 00:16:41 +01:00
|
|
|
*ppIEnumMetadataItem = NULL;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(MetadataHandlerEnum));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
IWICMetadataWriter_AddRef(&parent->IWICMetadataWriter_iface);
|
|
|
|
|
|
|
|
This->IWICEnumMetadataItem_iface.lpVtbl = &MetadataHandlerEnum_Vtbl;
|
|
|
|
This->ref = 1;
|
|
|
|
This->parent = parent;
|
|
|
|
This->index = index;
|
|
|
|
|
|
|
|
*ppIEnumMetadataItem = &This->IWICEnumMetadataItem_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:03:24 +01:00
|
|
|
static HRESULT LoadUnknownMetadata(IStream *input, const GUID *preferred_vendor,
|
|
|
|
DWORD persist_options, MetadataItem **items, DWORD *item_count)
|
|
|
|
{
|
2012-01-11 23:36:49 +01:00
|
|
|
HRESULT hr;
|
|
|
|
MetadataItem *result;
|
|
|
|
STATSTG stat;
|
|
|
|
BYTE *data;
|
|
|
|
ULONG bytesread;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
hr = IStream_Stat(input, &stat, STATFLAG_NONAME);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
data = HeapAlloc(GetProcessHeap(), 0, stat.cbSize.QuadPart);
|
|
|
|
if (!data) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = IStream_Read(input, data, stat.cbSize.QuadPart, &bytesread);
|
2012-08-06 04:07:49 +02:00
|
|
|
if (bytesread != stat.cbSize.QuadPart) hr = E_FAIL;
|
|
|
|
if (hr != S_OK)
|
2012-01-11 23:36:49 +01:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-03-05 12:12:50 +01:00
|
|
|
result = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MetadataItem));
|
2012-01-15 00:35:47 +01:00
|
|
|
if (!result)
|
2012-01-11 23:36:49 +01:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropVariantInit(&result[0].schema);
|
|
|
|
PropVariantInit(&result[0].id);
|
|
|
|
PropVariantInit(&result[0].value);
|
|
|
|
|
|
|
|
result[0].value.vt = VT_BLOB;
|
2021-03-24 18:37:50 +01:00
|
|
|
result[0].value.blob.cbSize = bytesread;
|
|
|
|
result[0].value.blob.pBlobData = data;
|
2012-01-11 23:36:49 +01:00
|
|
|
|
|
|
|
*items = result;
|
|
|
|
*item_count = 1;
|
|
|
|
|
|
|
|
return S_OK;
|
2012-01-11 23:03:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const MetadataHandlerVtbl UnknownMetadataReader_Vtbl = {
|
|
|
|
0,
|
|
|
|
&CLSID_WICUnknownMetadataReader,
|
|
|
|
LoadUnknownMetadata
|
|
|
|
};
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
HRESULT UnknownMetadataReader_CreateInstance(REFIID iid, void** ppv)
|
2012-01-11 23:03:24 +01:00
|
|
|
{
|
2014-01-14 12:18:11 +01:00
|
|
|
return MetadataReader_Create(&UnknownMetadataReader_Vtbl, iid, ppv);
|
2012-01-11 23:03:24 +01:00
|
|
|
}
|
2012-06-08 07:08:52 +02:00
|
|
|
|
2012-06-13 11:31:02 +02:00
|
|
|
#define SWAP_USHORT(x) do { if (!native_byte_order) (x) = RtlUshortByteSwap(x); } while(0)
|
|
|
|
#define SWAP_ULONG(x) do { if (!native_byte_order) (x) = RtlUlongByteSwap(x); } while(0)
|
|
|
|
#define SWAP_ULONGLONG(x) do { if (!native_byte_order) (x) = RtlUlonglongByteSwap(x); } while(0)
|
|
|
|
|
2012-06-13 11:30:54 +02:00
|
|
|
struct IFD_entry
|
|
|
|
{
|
|
|
|
SHORT id;
|
|
|
|
SHORT type;
|
2012-06-13 11:31:02 +02:00
|
|
|
ULONG count;
|
2012-06-13 11:30:54 +02:00
|
|
|
LONG value;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define IFD_BYTE 1
|
|
|
|
#define IFD_ASCII 2
|
|
|
|
#define IFD_SHORT 3
|
|
|
|
#define IFD_LONG 4
|
|
|
|
#define IFD_RATIONAL 5
|
|
|
|
#define IFD_SBYTE 6
|
|
|
|
#define IFD_UNDEFINED 7
|
|
|
|
#define IFD_SSHORT 8
|
|
|
|
#define IFD_SLONG 9
|
|
|
|
#define IFD_SRATIONAL 10
|
|
|
|
#define IFD_FLOAT 11
|
|
|
|
#define IFD_DOUBLE 12
|
|
|
|
#define IFD_IFD 13
|
|
|
|
|
2012-06-21 04:20:31 +02:00
|
|
|
static int tag_to_vt(SHORT tag)
|
|
|
|
{
|
|
|
|
static const int tag2vt[] =
|
|
|
|
{
|
|
|
|
VT_EMPTY, /* 0 */
|
|
|
|
VT_UI1, /* IFD_BYTE 1 */
|
|
|
|
VT_LPSTR, /* IFD_ASCII 2 */
|
|
|
|
VT_UI2, /* IFD_SHORT 3 */
|
|
|
|
VT_UI4, /* IFD_LONG 4 */
|
|
|
|
VT_UI8, /* IFD_RATIONAL 5 */
|
|
|
|
VT_I1, /* IFD_SBYTE 6 */
|
|
|
|
VT_BLOB, /* IFD_UNDEFINED 7 */
|
|
|
|
VT_I2, /* IFD_SSHORT 8 */
|
|
|
|
VT_I4, /* IFD_SLONG 9 */
|
|
|
|
VT_I8, /* IFD_SRATIONAL 10 */
|
|
|
|
VT_R4, /* IFD_FLOAT 11 */
|
|
|
|
VT_R8, /* IFD_DOUBLE 12 */
|
|
|
|
VT_BLOB, /* IFD_IFD 13 */
|
|
|
|
};
|
|
|
|
return (tag > 0 && tag <= 13) ? tag2vt[tag] : VT_BLOB;
|
|
|
|
}
|
|
|
|
|
2012-06-13 11:31:02 +02:00
|
|
|
static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry,
|
|
|
|
MetadataItem *item, BOOL native_byte_order)
|
2012-06-13 11:30:54 +02:00
|
|
|
{
|
2012-08-06 04:07:49 +02:00
|
|
|
ULONG count, value, i, bytesread;
|
2012-06-13 11:31:02 +02:00
|
|
|
SHORT type;
|
2012-06-21 04:20:39 +02:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
HRESULT hr;
|
2012-06-13 11:31:02 +02:00
|
|
|
|
2012-06-13 11:30:54 +02:00
|
|
|
item->schema.vt = VT_EMPTY;
|
|
|
|
item->id.vt = VT_UI2;
|
2021-03-24 18:37:50 +01:00
|
|
|
item->id.uiVal = entry->id;
|
|
|
|
SWAP_USHORT(item->id.uiVal);
|
2012-06-13 11:30:54 +02:00
|
|
|
|
2012-06-13 11:31:02 +02:00
|
|
|
count = entry->count;
|
|
|
|
SWAP_ULONG(count);
|
|
|
|
type = entry->type;
|
|
|
|
SWAP_USHORT(type);
|
2012-06-21 04:20:31 +02:00
|
|
|
item->value.vt = tag_to_vt(type);
|
2012-06-13 11:31:02 +02:00
|
|
|
value = entry->value;
|
|
|
|
SWAP_ULONG(value);
|
|
|
|
|
|
|
|
switch (type)
|
2012-06-13 11:30:54 +02:00
|
|
|
{
|
2012-06-21 04:20:31 +02:00
|
|
|
case IFD_BYTE:
|
|
|
|
case IFD_SBYTE:
|
2012-06-21 04:21:13 +02:00
|
|
|
if (!count) count = 1;
|
|
|
|
|
2012-06-21 04:20:39 +02:00
|
|
|
if (count <= 4)
|
2012-06-21 04:20:31 +02:00
|
|
|
{
|
2012-06-21 04:20:39 +02:00
|
|
|
const BYTE *data = (const BYTE *)&entry->value;
|
|
|
|
|
|
|
|
if (count == 1)
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.bVal = data[0];
|
2012-06-21 04:20:39 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
item->value.vt |= VT_VECTOR;
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.caub.cElems = count;
|
|
|
|
item->value.caub.pElems = HeapAlloc(GetProcessHeap(), 0, count);
|
|
|
|
memcpy(item->value.caub.pElems, data, count);
|
2012-06-21 04:20:39 +02:00
|
|
|
}
|
2012-06-21 04:20:31 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-06-21 04:20:39 +02:00
|
|
|
|
|
|
|
item->value.vt |= VT_VECTOR;
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.caub.cElems = count;
|
|
|
|
item->value.caub.pElems = HeapAlloc(GetProcessHeap(), 0, count);
|
|
|
|
if (!item->value.caub.pElems) return E_OUTOFMEMORY;
|
2012-06-21 04:20:39 +02:00
|
|
|
|
|
|
|
pos.QuadPart = value;
|
|
|
|
hr = IStream_Seek(input, pos, SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.caub.pElems);
|
2012-06-21 04:20:39 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2021-03-24 18:37:50 +01:00
|
|
|
hr = IStream_Read(input, item->value.caub.pElems, count, &bytesread);
|
2012-08-06 04:07:49 +02:00
|
|
|
if (bytesread != count) hr = E_FAIL;
|
|
|
|
if (hr != S_OK)
|
2012-06-21 04:20:39 +02:00
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.caub.pElems);
|
2012-06-21 04:20:39 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2012-06-21 04:20:31 +02:00
|
|
|
break;
|
2012-06-13 11:30:54 +02:00
|
|
|
case IFD_SHORT:
|
2012-06-21 04:20:31 +02:00
|
|
|
case IFD_SSHORT:
|
2012-06-21 04:21:13 +02:00
|
|
|
if (!count) count = 1;
|
|
|
|
|
2012-06-21 04:20:39 +02:00
|
|
|
if (count <= 2)
|
2012-06-13 11:30:54 +02:00
|
|
|
{
|
2012-06-21 04:20:39 +02:00
|
|
|
const SHORT *data = (const SHORT *)&entry->value;
|
|
|
|
|
|
|
|
if (count == 1)
|
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.uiVal = data[0];
|
|
|
|
SWAP_USHORT(item->value.uiVal);
|
2012-06-21 04:20:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->value.vt |= VT_VECTOR;
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.caui.cElems = count;
|
|
|
|
item->value.caui.pElems = HeapAlloc(GetProcessHeap(), 0, count * 2);
|
|
|
|
memcpy(item->value.caui.pElems, data, count * 2);
|
2012-06-21 04:20:39 +02:00
|
|
|
for (i = 0; i < count; i++)
|
2021-03-24 18:37:50 +01:00
|
|
|
SWAP_USHORT(item->value.caui.pElems[i]);
|
2012-06-21 04:20:39 +02:00
|
|
|
}
|
2012-06-13 11:30:54 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-06-21 04:20:39 +02:00
|
|
|
|
|
|
|
item->value.vt |= VT_VECTOR;
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.caui.cElems = count;
|
|
|
|
item->value.caui.pElems = HeapAlloc(GetProcessHeap(), 0, count * 2);
|
|
|
|
if (!item->value.caui.pElems) return E_OUTOFMEMORY;
|
2012-06-21 04:20:39 +02:00
|
|
|
|
|
|
|
pos.QuadPart = value;
|
|
|
|
hr = IStream_Seek(input, pos, SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.caui.pElems);
|
2012-06-21 04:20:39 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2021-03-24 18:37:50 +01:00
|
|
|
hr = IStream_Read(input, item->value.caui.pElems, count * 2, &bytesread);
|
2012-08-06 04:07:49 +02:00
|
|
|
if (bytesread != count * 2) hr = E_FAIL;
|
|
|
|
if (hr != S_OK)
|
2012-06-21 04:20:39 +02:00
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.caui.pElems);
|
2012-06-21 04:20:39 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++)
|
2021-03-24 18:37:50 +01:00
|
|
|
SWAP_USHORT(item->value.caui.pElems[i]);
|
2012-06-13 11:30:54 +02:00
|
|
|
break;
|
|
|
|
case IFD_LONG:
|
2012-06-21 04:20:31 +02:00
|
|
|
case IFD_SLONG:
|
|
|
|
case IFD_FLOAT:
|
2012-06-21 04:21:13 +02:00
|
|
|
if (!count) count = 1;
|
|
|
|
|
2012-06-13 11:31:02 +02:00
|
|
|
if (count == 1)
|
2012-06-13 11:30:54 +02:00
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.ulVal = value;
|
2012-06-13 11:30:54 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-06-21 04:20:39 +02:00
|
|
|
|
|
|
|
item->value.vt |= VT_VECTOR;
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.caul.cElems = count;
|
|
|
|
item->value.caul.pElems = HeapAlloc(GetProcessHeap(), 0, count * 4);
|
|
|
|
if (!item->value.caul.pElems) return E_OUTOFMEMORY;
|
2012-06-21 04:20:39 +02:00
|
|
|
|
|
|
|
pos.QuadPart = value;
|
|
|
|
hr = IStream_Seek(input, pos, SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.caul.pElems);
|
2012-06-21 04:20:39 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2021-03-24 18:37:50 +01:00
|
|
|
hr = IStream_Read(input, item->value.caul.pElems, count * 4, &bytesread);
|
2012-08-06 04:07:49 +02:00
|
|
|
if (bytesread != count * 4) hr = E_FAIL;
|
|
|
|
if (hr != S_OK)
|
2012-06-21 04:20:39 +02:00
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.caul.pElems);
|
2012-06-21 04:20:39 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++)
|
2021-03-24 18:37:50 +01:00
|
|
|
SWAP_ULONG(item->value.caul.pElems[i]);
|
2012-06-13 11:30:54 +02:00
|
|
|
break;
|
|
|
|
case IFD_RATIONAL:
|
2012-06-21 04:20:31 +02:00
|
|
|
case IFD_SRATIONAL:
|
|
|
|
case IFD_DOUBLE:
|
2012-06-21 04:21:13 +02:00
|
|
|
if (!count)
|
|
|
|
{
|
|
|
|
FIXME("IFD field type %d, count 0\n", type);
|
|
|
|
item->value.vt = VT_EMPTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-13 11:31:02 +02:00
|
|
|
if (count == 1)
|
2012-06-13 11:30:54 +02:00
|
|
|
{
|
2012-06-21 04:20:46 +02:00
|
|
|
ULONGLONG ull;
|
2012-06-13 11:30:54 +02:00
|
|
|
|
2012-06-13 11:31:02 +02:00
|
|
|
pos.QuadPart = value;
|
2012-06-13 11:30:54 +02:00
|
|
|
hr = IStream_Seek(input, pos, SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2012-08-06 04:07:49 +02:00
|
|
|
hr = IStream_Read(input, &ull, sizeof(ull), &bytesread);
|
|
|
|
if (bytesread != sizeof(ull)) hr = E_FAIL;
|
|
|
|
if (hr != S_OK) return hr;
|
2012-06-21 04:20:46 +02:00
|
|
|
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.uhVal.QuadPart = ull;
|
2012-06-21 04:20:46 +02:00
|
|
|
|
|
|
|
if (type == IFD_DOUBLE)
|
2021-03-24 18:37:50 +01:00
|
|
|
SWAP_ULONGLONG(item->value.uhVal.QuadPart);
|
2012-06-21 04:20:46 +02:00
|
|
|
else
|
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
SWAP_ULONG(item->value.uhVal.LowPart);
|
|
|
|
SWAP_ULONG(item->value.uhVal.HighPart);
|
2012-06-21 04:20:46 +02:00
|
|
|
}
|
2012-06-13 11:30:54 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-06-21 04:21:26 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
item->value.vt |= VT_VECTOR;
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.cauh.cElems = count;
|
|
|
|
item->value.cauh.pElems = HeapAlloc(GetProcessHeap(), 0, count * 8);
|
|
|
|
if (!item->value.cauh.pElems) return E_OUTOFMEMORY;
|
2012-06-21 04:21:26 +02:00
|
|
|
|
|
|
|
pos.QuadPart = value;
|
|
|
|
hr = IStream_Seek(input, pos, SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.cauh.pElems);
|
2012-06-21 04:21:26 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2021-03-24 18:37:50 +01:00
|
|
|
hr = IStream_Read(input, item->value.cauh.pElems, count * 8, &bytesread);
|
2012-08-06 04:07:49 +02:00
|
|
|
if (bytesread != count * 8) hr = E_FAIL;
|
|
|
|
if (hr != S_OK)
|
2012-06-21 04:21:26 +02:00
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.cauh.pElems);
|
2012-06-21 04:21:26 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (type == IFD_DOUBLE)
|
2021-03-24 18:37:50 +01:00
|
|
|
SWAP_ULONGLONG(item->value.cauh.pElems[i].QuadPart);
|
2012-06-21 04:21:26 +02:00
|
|
|
else
|
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
SWAP_ULONG(item->value.cauh.pElems[i].LowPart);
|
|
|
|
SWAP_ULONG(item->value.cauh.pElems[i].HighPart);
|
2012-06-21 04:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-13 11:30:54 +02:00
|
|
|
break;
|
2012-06-21 04:20:59 +02:00
|
|
|
case IFD_ASCII:
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.pszVal = HeapAlloc(GetProcessHeap(), 0, count + 1);
|
|
|
|
if (!item->value.pszVal) return E_OUTOFMEMORY;
|
2012-06-21 04:20:59 +02:00
|
|
|
|
|
|
|
if (count <= 4)
|
|
|
|
{
|
|
|
|
const char *data = (const char *)&entry->value;
|
2021-03-24 18:37:50 +01:00
|
|
|
memcpy(item->value.pszVal, data, count);
|
|
|
|
item->value.pszVal[count] = 0;
|
2012-06-21 04:20:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.QuadPart = value;
|
|
|
|
hr = IStream_Seek(input, pos, SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.pszVal);
|
2012-06-21 04:20:59 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2021-03-24 18:37:50 +01:00
|
|
|
hr = IStream_Read(input, item->value.pszVal, count, &bytesread);
|
2012-08-06 04:07:49 +02:00
|
|
|
if (bytesread != count) hr = E_FAIL;
|
|
|
|
if (hr != S_OK)
|
2012-06-21 04:20:59 +02:00
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.pszVal);
|
2012-06-21 04:20:59 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.pszVal[count] = 0;
|
2012-06-21 04:20:59 +02:00
|
|
|
break;
|
2012-06-21 04:21:06 +02:00
|
|
|
case IFD_UNDEFINED:
|
2012-06-21 04:21:13 +02:00
|
|
|
if (!count)
|
|
|
|
{
|
|
|
|
FIXME("IFD field type %d, count 0\n", type);
|
|
|
|
item->value.vt = VT_EMPTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.blob.pBlobData = HeapAlloc(GetProcessHeap(), 0, count);
|
|
|
|
if (!item->value.blob.pBlobData) return E_OUTOFMEMORY;
|
2012-06-21 04:21:06 +02:00
|
|
|
|
2021-03-24 18:37:50 +01:00
|
|
|
item->value.blob.cbSize = count;
|
2012-06-21 04:21:06 +02:00
|
|
|
|
|
|
|
if (count <= 4)
|
|
|
|
{
|
|
|
|
const char *data = (const char *)&entry->value;
|
2021-03-24 18:37:50 +01:00
|
|
|
memcpy(item->value.blob.pBlobData, data, count);
|
2012-06-21 04:21:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.QuadPart = value;
|
|
|
|
hr = IStream_Seek(input, pos, SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.blob.pBlobData);
|
2012-06-21 04:21:06 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2021-03-24 18:37:50 +01:00
|
|
|
hr = IStream_Read(input, item->value.blob.pBlobData, count, &bytesread);
|
2012-08-06 04:07:49 +02:00
|
|
|
if (bytesread != count) hr = E_FAIL;
|
|
|
|
if (hr != S_OK)
|
2012-06-21 04:21:06 +02:00
|
|
|
{
|
2021-03-24 18:37:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, item->value.blob.pBlobData);
|
2012-06-21 04:21:06 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
break;
|
2012-06-13 11:30:54 +02:00
|
|
|
default:
|
2012-06-21 04:20:39 +02:00
|
|
|
FIXME("loading field of type %d, count %u is not implemented\n", type, count);
|
2012-06-13 11:30:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-08 07:08:52 +02:00
|
|
|
static HRESULT LoadIfdMetadata(IStream *input, const GUID *preferred_vendor,
|
|
|
|
DWORD persist_options, MetadataItem **items, DWORD *item_count)
|
|
|
|
{
|
2012-06-13 11:30:54 +02:00
|
|
|
HRESULT hr;
|
|
|
|
MetadataItem *result;
|
|
|
|
USHORT count, i;
|
|
|
|
struct IFD_entry *entry;
|
2012-06-13 11:31:02 +02:00
|
|
|
BOOL native_byte_order = TRUE;
|
2012-08-06 04:07:49 +02:00
|
|
|
ULONG bytesread;
|
2012-06-13 11:30:54 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-06-13 11:31:02 +02:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
2017-05-10 18:20:10 +02:00
|
|
|
if (persist_options & WICPersistOptionLittleEndian)
|
2012-06-13 11:31:02 +02:00
|
|
|
#else
|
2017-05-10 18:20:10 +02:00
|
|
|
if (persist_options & WICPersistOptionBigEndian)
|
2012-06-13 11:31:02 +02:00
|
|
|
#endif
|
|
|
|
native_byte_order = FALSE;
|
|
|
|
|
2012-08-06 04:07:49 +02:00
|
|
|
hr = IStream_Read(input, &count, sizeof(count), &bytesread);
|
|
|
|
if (bytesread != sizeof(count)) hr = E_FAIL;
|
|
|
|
if (hr != S_OK) return hr;
|
2012-06-13 11:30:54 +02:00
|
|
|
|
2012-06-13 11:31:02 +02:00
|
|
|
SWAP_USHORT(count);
|
|
|
|
|
2012-06-13 11:30:54 +02:00
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*entry));
|
|
|
|
if (!entry) return E_OUTOFMEMORY;
|
2012-06-08 07:08:52 +02:00
|
|
|
|
2012-08-06 04:07:49 +02:00
|
|
|
hr = IStream_Read(input, entry, count * sizeof(*entry), &bytesread);
|
|
|
|
if (bytesread != count * sizeof(*entry)) hr = E_FAIL;
|
|
|
|
if (hr != S_OK)
|
2012-06-13 11:30:54 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-06-13 11:31:09 +02:00
|
|
|
/* limit number of IFDs to 4096 to avoid infinite loop */
|
|
|
|
for (i = 0; i < 4096; i++)
|
|
|
|
{
|
|
|
|
ULONG next_ifd_offset;
|
|
|
|
LARGE_INTEGER pos;
|
|
|
|
USHORT next_ifd_count;
|
|
|
|
|
2012-08-06 04:07:49 +02:00
|
|
|
hr = IStream_Read(input, &next_ifd_offset, sizeof(next_ifd_offset), &bytesread);
|
|
|
|
if (bytesread != sizeof(next_ifd_offset)) hr = E_FAIL;
|
|
|
|
if (hr != S_OK) break;
|
2012-06-13 11:31:09 +02:00
|
|
|
|
|
|
|
SWAP_ULONG(next_ifd_offset);
|
|
|
|
if (!next_ifd_offset) break;
|
|
|
|
|
|
|
|
pos.QuadPart = next_ifd_offset;
|
|
|
|
hr = IStream_Seek(input, pos, SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr)) break;
|
|
|
|
|
2012-08-06 04:07:49 +02:00
|
|
|
hr = IStream_Read(input, &next_ifd_count, sizeof(next_ifd_count), &bytesread);
|
|
|
|
if (bytesread != sizeof(next_ifd_count)) hr = E_FAIL;
|
|
|
|
if (hr != S_OK) break;
|
2012-06-13 11:31:09 +02:00
|
|
|
|
|
|
|
SWAP_USHORT(next_ifd_count);
|
|
|
|
|
|
|
|
pos.QuadPart = next_ifd_count * sizeof(*entry);
|
|
|
|
hr = IStream_Seek(input, pos, SEEK_CUR, NULL);
|
|
|
|
if (FAILED(hr)) break;
|
|
|
|
}
|
|
|
|
|
2012-08-06 04:07:49 +02:00
|
|
|
if (hr != S_OK || i == 4096)
|
2012-06-13 11:31:09 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
return WINCODEC_ERR_BADMETADATAHEADER;
|
|
|
|
}
|
|
|
|
|
2015-03-05 12:12:50 +01:00
|
|
|
result = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(*result));
|
2012-06-13 11:30:54 +02:00
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2012-06-13 11:31:02 +02:00
|
|
|
hr = load_IFD_entry(input, &entry[i], &result[i], native_byte_order);
|
2012-06-13 11:30:54 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, result);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
|
|
|
|
*items = result;
|
|
|
|
*item_count = count;
|
2012-06-08 07:08:52 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MetadataHandlerVtbl IfdMetadataReader_Vtbl = {
|
|
|
|
0,
|
|
|
|
&CLSID_WICIfdMetadataReader,
|
|
|
|
LoadIfdMetadata
|
|
|
|
};
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
HRESULT IfdMetadataReader_CreateInstance(REFIID iid, void **ppv)
|
2012-06-08 07:08:52 +02:00
|
|
|
{
|
2014-01-14 12:18:11 +01:00
|
|
|
return MetadataReader_Create(&IfdMetadataReader_Vtbl, iid, ppv);
|
2012-06-08 07:08:52 +02:00
|
|
|
}
|