windowscodecs: Directly use patterns stored in component info object in IWICMetadataReaderInfo::MatchesPattern implementation.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Vincent Povirk <vincent@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2018-04-02 20:49:40 +02:00 committed by Alexandre Julliard
parent 8be7a1057e
commit ca9d03a7ac
1 changed files with 17 additions and 25 deletions

View File

@ -1758,11 +1758,11 @@ static HRESULT WINAPI MetadataReaderInfo_GetPatterns(IWICMetadataReaderInfo *ifa
} }
static HRESULT WINAPI MetadataReaderInfo_MatchesPattern(IWICMetadataReaderInfo *iface, static HRESULT WINAPI MetadataReaderInfo_MatchesPattern(IWICMetadataReaderInfo *iface,
REFGUID container, IStream *stream, BOOL *matches) REFGUID container_guid, IStream *stream, BOOL *matches)
{ {
MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
struct metadata_container *container;
HRESULT hr; HRESULT hr;
WICMetadataPattern *patterns;
UINT pattern_count=0, patterns_size=0;
ULONG datasize=0; ULONG datasize=0;
BYTE *data=NULL; BYTE *data=NULL;
ULONG bytesread; ULONG bytesread;
@ -1770,24 +1770,18 @@ static HRESULT WINAPI MetadataReaderInfo_MatchesPattern(IWICMetadataReaderInfo *
LARGE_INTEGER seekpos; LARGE_INTEGER seekpos;
ULONG pos; ULONG pos;
TRACE("(%p,%s,%p,%p)\n", iface, debugstr_guid(container), stream, matches); TRACE("(%p,%s,%p,%p)\n", iface, debugstr_guid(container_guid), stream, matches);
hr = MetadataReaderInfo_GetPatterns(iface, container, 0, NULL, &pattern_count, &patterns_size); if (!(container = get_metadata_container(This, container_guid)))
if (FAILED(hr)) return hr; return WINCODEC_ERR_COMPONENTNOTFOUND;
patterns = HeapAlloc(GetProcessHeap(), 0, patterns_size); for (i=0; i < container->pattern_count; i++)
if (!patterns) return E_OUTOFMEMORY;
hr = MetadataReaderInfo_GetPatterns(iface, container, patterns_size, patterns, &pattern_count, &patterns_size);
if (FAILED(hr)) goto end;
for (i=0; i<pattern_count; i++)
{ {
if (datasize < patterns[i].Length) if (datasize < container->patterns[i].Length)
{ {
HeapFree(GetProcessHeap(), 0, data); HeapFree(GetProcessHeap(), 0, data);
datasize = patterns[i].Length; datasize = container->patterns[i].Length;
data = HeapAlloc(GetProcessHeap(), 0, patterns[i].Length); data = HeapAlloc(GetProcessHeap(), 0, container->patterns[i].Length);
if (!data) if (!data)
{ {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
@ -1795,21 +1789,21 @@ static HRESULT WINAPI MetadataReaderInfo_MatchesPattern(IWICMetadataReaderInfo *
} }
} }
seekpos.QuadPart = patterns[i].Position.QuadPart; seekpos.QuadPart = container->patterns[i].Position.QuadPart;
hr = IStream_Seek(stream, seekpos, STREAM_SEEK_SET, NULL); hr = IStream_Seek(stream, seekpos, STREAM_SEEK_SET, NULL);
if (FAILED(hr)) break; if (FAILED(hr)) break;
hr = IStream_Read(stream, data, patterns[i].Length, &bytesread); hr = IStream_Read(stream, data, container->patterns[i].Length, &bytesread);
if (hr == S_FALSE || (hr == S_OK && bytesread != patterns[i].Length)) /* past end of stream */ if (hr == S_FALSE || (hr == S_OK && bytesread != container->patterns[i].Length)) /* past end of stream */
continue; continue;
if (FAILED(hr)) break; if (FAILED(hr)) break;
for (pos=0; pos<patterns[i].Length; pos++) for (pos=0; pos < container->patterns[i].Length; pos++)
{ {
if ((data[pos] & patterns[i].Mask[pos]) != patterns[i].Pattern[pos]) if ((data[pos] & container->patterns[i].Mask[pos]) != container->patterns[i].Pattern[pos])
break; break;
} }
if (pos == patterns[i].Length) /* matches pattern */ if (pos == container->patterns[i].Length) /* matches pattern */
{ {
hr = S_OK; hr = S_OK;
*matches = TRUE; *matches = TRUE;
@ -1817,14 +1811,12 @@ static HRESULT WINAPI MetadataReaderInfo_MatchesPattern(IWICMetadataReaderInfo *
} }
} }
if (i == pattern_count) /* does not match any pattern */ if (i == container->pattern_count) /* does not match any pattern */
{ {
hr = S_OK; hr = S_OK;
*matches = FALSE; *matches = FALSE;
} }
end:
HeapFree(GetProcessHeap(), 0, patterns);
HeapFree(GetProcessHeap(), 0, data); HeapFree(GetProcessHeap(), 0, data);
return hr; return hr;