2 * Copyright 2009 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
25 #define NONAMELESSUNION
33 #include "wincodecs_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
39 static LPWSTR
strdupAtoW(const char *src
)
41 int len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0);
42 LPWSTR dst
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
43 if (dst
) MultiByteToWideChar(CP_ACP
, 0, src
, -1, dst
, len
);
47 static HRESULT
load_LSD_metadata(IStream
*stream
, const GUID
*vendor
, DWORD options
,
48 MetadataItem
**items
, DWORD
*count
)
51 struct logical_screen_descriptor
57 /* global_color_table_flag : 1;
58 * color_resolution : 3;
60 * global_color_table_size : 3;
62 BYTE background_color_index
;
63 BYTE pixel_aspect_ratio
;
73 hr
= IStream_Read(stream
, &lsd_data
, sizeof(lsd_data
), &bytesread
);
74 if (FAILED(hr
) || bytesread
!= sizeof(lsd_data
)) return S_OK
;
76 result
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MetadataItem
) * 9);
77 if (!result
) return E_OUTOFMEMORY
;
79 for (i
= 0; i
< 9; i
++)
81 PropVariantInit(&result
[i
].schema
);
82 PropVariantInit(&result
[i
].id
);
83 PropVariantInit(&result
[i
].value
);
86 result
[0].id
.vt
= VT_LPWSTR
;
87 result
[0].id
.u
.pwszVal
= strdupAtoW("Signature");
88 result
[0].value
.vt
= VT_UI1
|VT_VECTOR
;
89 result
[0].value
.u
.caub
.cElems
= sizeof(lsd_data
.signature
);
90 result
[0].value
.u
.caub
.pElems
= HeapAlloc(GetProcessHeap(), 0, sizeof(lsd_data
.signature
));
91 memcpy(result
[0].value
.u
.caub
.pElems
, lsd_data
.signature
, sizeof(lsd_data
.signature
));
93 result
[1].id
.vt
= VT_LPWSTR
;
94 result
[1].id
.u
.pwszVal
= strdupAtoW("Width");
95 result
[1].value
.vt
= VT_UI2
;
96 result
[1].value
.u
.uiVal
= lsd_data
.width
;
98 result
[2].id
.vt
= VT_LPWSTR
;
99 result
[2].id
.u
.pwszVal
= strdupAtoW("Height");
100 result
[2].value
.vt
= VT_UI2
;
101 result
[2].value
.u
.uiVal
= lsd_data
.height
;
103 result
[3].id
.vt
= VT_LPWSTR
;
104 result
[3].id
.u
.pwszVal
= strdupAtoW("GlobalColorTableFlag");
105 result
[3].value
.vt
= VT_BOOL
;
106 result
[3].value
.u
.boolVal
= (lsd_data
.packed
>> 7) & 1;
108 result
[4].id
.vt
= VT_LPWSTR
;
109 result
[4].id
.u
.pwszVal
= strdupAtoW("ColorResolution");
110 result
[4].value
.vt
= VT_UI1
;
111 result
[4].value
.u
.bVal
= (lsd_data
.packed
>> 4) & 7;
113 result
[5].id
.vt
= VT_LPWSTR
;
114 result
[5].id
.u
.pwszVal
= strdupAtoW("SortFlag");
115 result
[5].value
.vt
= VT_BOOL
;
116 result
[5].value
.u
.boolVal
= (lsd_data
.packed
>> 3) & 1;
118 result
[6].id
.vt
= VT_LPWSTR
;
119 result
[6].id
.u
.pwszVal
= strdupAtoW("GlobalColorTableSize");
120 result
[6].value
.vt
= VT_UI1
;
121 result
[6].value
.u
.bVal
= lsd_data
.packed
& 7;
123 result
[7].id
.vt
= VT_LPWSTR
;
124 result
[7].id
.u
.pwszVal
= strdupAtoW("BackgroundColorIndex");
125 result
[7].value
.vt
= VT_UI1
;
126 result
[7].value
.u
.bVal
= lsd_data
.background_color_index
;
128 result
[8].id
.vt
= VT_LPWSTR
;
129 result
[8].id
.u
.pwszVal
= strdupAtoW("PixelAspectRatio");
130 result
[8].value
.vt
= VT_UI1
;
131 result
[8].value
.u
.bVal
= lsd_data
.pixel_aspect_ratio
;
139 static const MetadataHandlerVtbl LSDReader_Vtbl
= {
141 &CLSID_WICLSDMetadataReader
,
145 HRESULT
LSDReader_CreateInstance(REFIID iid
, void **ppv
)
147 return MetadataReader_Create(&LSDReader_Vtbl
, iid
, ppv
);
150 #include "pshpack1.h"
151 struct image_descriptor
158 /* local_color_table_flag : 1;
159 * interlace_flag : 1;
162 * local_color_table_size : 3;
167 static HRESULT
load_IMD_metadata(IStream
*stream
, const GUID
*vendor
, DWORD options
,
168 MetadataItem
**items
, DWORD
*count
)
170 struct image_descriptor imd_data
;
173 MetadataItem
*result
;
178 hr
= IStream_Read(stream
, &imd_data
, sizeof(imd_data
), &bytesread
);
179 if (FAILED(hr
) || bytesread
!= sizeof(imd_data
)) return S_OK
;
181 result
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MetadataItem
) * 8);
182 if (!result
) return E_OUTOFMEMORY
;
184 for (i
= 0; i
< 8; i
++)
186 PropVariantInit(&result
[i
].schema
);
187 PropVariantInit(&result
[i
].id
);
188 PropVariantInit(&result
[i
].value
);
191 result
[0].id
.vt
= VT_LPWSTR
;
192 result
[0].id
.u
.pwszVal
= strdupAtoW("Left");
193 result
[0].value
.vt
= VT_UI2
;
194 result
[0].value
.u
.uiVal
= imd_data
.left
;
196 result
[1].id
.vt
= VT_LPWSTR
;
197 result
[1].id
.u
.pwszVal
= strdupAtoW("Top");
198 result
[1].value
.vt
= VT_UI2
;
199 result
[1].value
.u
.uiVal
= imd_data
.top
;
201 result
[2].id
.vt
= VT_LPWSTR
;
202 result
[2].id
.u
.pwszVal
= strdupAtoW("Width");
203 result
[2].value
.vt
= VT_UI2
;
204 result
[2].value
.u
.uiVal
= imd_data
.width
;
206 result
[3].id
.vt
= VT_LPWSTR
;
207 result
[3].id
.u
.pwszVal
= strdupAtoW("Height");
208 result
[3].value
.vt
= VT_UI2
;
209 result
[3].value
.u
.uiVal
= imd_data
.height
;
211 result
[4].id
.vt
= VT_LPWSTR
;
212 result
[4].id
.u
.pwszVal
= strdupAtoW("LocalColorTableFlag");
213 result
[4].value
.vt
= VT_BOOL
;
214 result
[4].value
.u
.boolVal
= (imd_data
.packed
>> 7) & 1;
216 result
[5].id
.vt
= VT_LPWSTR
;
217 result
[5].id
.u
.pwszVal
= strdupAtoW("InterlaceFlag");
218 result
[5].value
.vt
= VT_BOOL
;
219 result
[5].value
.u
.boolVal
= (imd_data
.packed
>> 6) & 1;
221 result
[6].id
.vt
= VT_LPWSTR
;
222 result
[6].id
.u
.pwszVal
= strdupAtoW("SortFlag");
223 result
[6].value
.vt
= VT_BOOL
;
224 result
[6].value
.u
.boolVal
= (imd_data
.packed
>> 5) & 1;
226 result
[7].id
.vt
= VT_LPWSTR
;
227 result
[7].id
.u
.pwszVal
= strdupAtoW("LocalColorTableSize");
228 result
[7].value
.vt
= VT_UI1
;
229 result
[7].value
.u
.bVal
= imd_data
.packed
& 7;
237 static const MetadataHandlerVtbl IMDReader_Vtbl
= {
239 &CLSID_WICIMDMetadataReader
,
243 HRESULT
IMDReader_CreateInstance(REFIID iid
, void **ppv
)
245 return MetadataReader_Create(&IMDReader_Vtbl
, iid
, ppv
);
248 static HRESULT
load_GCE_metadata(IStream
*stream
, const GUID
*vendor
, DWORD options
,
249 MetadataItem
**items
, DWORD
*count
)
251 #include "pshpack1.h"
252 struct graphic_control_extension
257 * user_input_flag : 1;
258 * transparency_flag : 1;
261 BYTE transparent_color_index
;
266 MetadataItem
*result
;
271 hr
= IStream_Read(stream
, &gce_data
, sizeof(gce_data
), &bytesread
);
272 if (FAILED(hr
) || bytesread
!= sizeof(gce_data
)) return S_OK
;
274 result
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MetadataItem
) * 5);
275 if (!result
) return E_OUTOFMEMORY
;
277 for (i
= 0; i
< 5; i
++)
279 PropVariantInit(&result
[i
].schema
);
280 PropVariantInit(&result
[i
].id
);
281 PropVariantInit(&result
[i
].value
);
284 result
[0].id
.vt
= VT_LPWSTR
;
285 result
[0].id
.u
.pwszVal
= strdupAtoW("Disposal");
286 result
[0].value
.vt
= VT_UI1
;
287 result
[0].value
.u
.bVal
= (gce_data
.packed
>> 2) & 7;
289 result
[1].id
.vt
= VT_LPWSTR
;
290 result
[1].id
.u
.pwszVal
= strdupAtoW("UserInputFlag");
291 result
[1].value
.vt
= VT_BOOL
;
292 result
[1].value
.u
.boolVal
= (gce_data
.packed
>> 1) & 1;
294 result
[2].id
.vt
= VT_LPWSTR
;
295 result
[2].id
.u
.pwszVal
= strdupAtoW("TransparencyFlag");
296 result
[2].value
.vt
= VT_BOOL
;
297 result
[2].value
.u
.boolVal
= gce_data
.packed
& 1;
299 result
[3].id
.vt
= VT_LPWSTR
;
300 result
[3].id
.u
.pwszVal
= strdupAtoW("Delay");
301 result
[3].value
.vt
= VT_UI2
;
302 result
[3].value
.u
.uiVal
= gce_data
.delay
;
304 result
[4].id
.vt
= VT_LPWSTR
;
305 result
[4].id
.u
.pwszVal
= strdupAtoW("TransparentColorIndex");
306 result
[4].value
.vt
= VT_UI1
;
307 result
[4].value
.u
.bVal
= gce_data
.transparent_color_index
;
315 static const MetadataHandlerVtbl GCEReader_Vtbl
= {
317 &CLSID_WICGCEMetadataReader
,
321 HRESULT
GCEReader_CreateInstance(REFIID iid
, void **ppv
)
323 return MetadataReader_Create(&GCEReader_Vtbl
, iid
, ppv
);
326 static HRESULT
load_APE_metadata(IStream
*stream
, const GUID
*vendor
, DWORD options
,
327 MetadataItem
**items
, DWORD
*count
)
329 #include "pshpack1.h"
330 struct application_extension
332 BYTE extension_introducer
;
333 BYTE extension_label
;
335 BYTE application
[11];
339 ULONG bytesread
, data_size
, i
;
340 MetadataItem
*result
;
347 hr
= IStream_Read(stream
, &ape_data
, sizeof(ape_data
), &bytesread
);
348 if (FAILED(hr
) || bytesread
!= sizeof(ape_data
)) return S_OK
;
349 if (ape_data
.extension_introducer
!= 0x21 ||
350 ape_data
.extension_label
!= APPLICATION_EXT_FUNC_CODE
||
351 ape_data
.block_size
!= 11)
359 hr
= IStream_Read(stream
, &subblock_size
, sizeof(subblock_size
), &bytesread
);
360 if (FAILED(hr
) || bytesread
!= sizeof(subblock_size
))
362 HeapFree(GetProcessHeap(), 0, data
);
365 if (!subblock_size
) break;
368 data
= HeapAlloc(GetProcessHeap(), 0, subblock_size
+ 1);
371 BYTE
*new_data
= HeapReAlloc(GetProcessHeap(), 0, data
, data_size
+ subblock_size
+ 1);
374 HeapFree(GetProcessHeap(), 0, data
);
379 data
[data_size
] = subblock_size
;
380 hr
= IStream_Read(stream
, data
+ data_size
+ 1, subblock_size
, &bytesread
);
381 if (FAILED(hr
) || bytesread
!= subblock_size
)
383 HeapFree(GetProcessHeap(), 0, data
);
386 data_size
+= subblock_size
+ 1;
389 result
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MetadataItem
) * 2);
392 HeapFree(GetProcessHeap(), 0, data
);
393 return E_OUTOFMEMORY
;
396 for (i
= 0; i
< 2; i
++)
398 PropVariantInit(&result
[i
].schema
);
399 PropVariantInit(&result
[i
].id
);
400 PropVariantInit(&result
[i
].value
);
403 result
[0].id
.vt
= VT_LPWSTR
;
404 result
[0].id
.u
.pwszVal
= strdupAtoW("Application");
405 result
[0].value
.vt
= VT_UI1
|VT_VECTOR
;
406 result
[0].value
.u
.caub
.cElems
= sizeof(ape_data
.application
);
407 result
[0].value
.u
.caub
.pElems
= HeapAlloc(GetProcessHeap(), 0, sizeof(ape_data
.application
));
408 memcpy(result
[0].value
.u
.caub
.pElems
, ape_data
.application
, sizeof(ape_data
.application
));
410 result
[1].id
.vt
= VT_LPWSTR
;
411 result
[1].id
.u
.pwszVal
= strdupAtoW("Data");
412 result
[1].value
.vt
= VT_UI1
|VT_VECTOR
;
413 result
[1].value
.u
.caub
.cElems
= data_size
;
414 result
[1].value
.u
.caub
.pElems
= data
;
422 static const MetadataHandlerVtbl APEReader_Vtbl
= {
424 &CLSID_WICAPEMetadataReader
,
428 HRESULT
APEReader_CreateInstance(REFIID iid
, void **ppv
)
430 return MetadataReader_Create(&APEReader_Vtbl
, iid
, ppv
);
433 static HRESULT
load_GifComment_metadata(IStream
*stream
, const GUID
*vendor
, DWORD options
,
434 MetadataItem
**items
, DWORD
*count
)
436 #include "pshpack1.h"
439 BYTE extension_introducer
;
440 BYTE extension_label
;
444 ULONG bytesread
, data_size
;
445 MetadataItem
*result
;
452 hr
= IStream_Read(stream
, &ext_data
, sizeof(ext_data
), &bytesread
);
453 if (FAILED(hr
) || bytesread
!= sizeof(ext_data
)) return S_OK
;
454 if (ext_data
.extension_introducer
!= 0x21 ||
455 ext_data
.extension_label
!= COMMENT_EXT_FUNC_CODE
)
463 hr
= IStream_Read(stream
, &subblock_size
, sizeof(subblock_size
), &bytesread
);
464 if (FAILED(hr
) || bytesread
!= sizeof(subblock_size
))
466 HeapFree(GetProcessHeap(), 0, data
);
469 if (!subblock_size
) break;
472 data
= HeapAlloc(GetProcessHeap(), 0, subblock_size
+ 1);
475 char *new_data
= HeapReAlloc(GetProcessHeap(), 0, data
, data_size
+ subblock_size
+ 1);
478 HeapFree(GetProcessHeap(), 0, data
);
483 hr
= IStream_Read(stream
, data
+ data_size
, subblock_size
, &bytesread
);
484 if (FAILED(hr
) || bytesread
!= subblock_size
)
486 HeapFree(GetProcessHeap(), 0, data
);
489 data_size
+= subblock_size
;
494 result
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MetadataItem
));
497 HeapFree(GetProcessHeap(), 0, data
);
498 return E_OUTOFMEMORY
;
501 PropVariantInit(&result
->schema
);
502 PropVariantInit(&result
->id
);
503 PropVariantInit(&result
->value
);
505 result
->id
.vt
= VT_LPWSTR
;
506 result
->id
.u
.pwszVal
= strdupAtoW("TextEntry");
507 result
->value
.vt
= VT_LPSTR
;
508 result
->value
.u
.pszVal
= data
;
516 static const MetadataHandlerVtbl GifCommentReader_Vtbl
= {
518 &CLSID_WICGifCommentMetadataReader
,
519 load_GifComment_metadata
522 HRESULT
GifCommentReader_CreateInstance(REFIID iid
, void **ppv
)
524 return MetadataReader_Create(&GifCommentReader_Vtbl
, iid
, ppv
);
527 static IStream
*create_stream(const void *data
, int data_size
)
534 hdata
= GlobalAlloc(GMEM_MOVEABLE
, data_size
);
535 if (!hdata
) return NULL
;
537 locked_data
= GlobalLock(hdata
);
538 memcpy(locked_data
, data
, data_size
);
541 hr
= CreateStreamOnHGlobal(hdata
, TRUE
, &stream
);
542 return FAILED(hr
) ? NULL
: stream
;
545 static HRESULT
create_metadata_reader(const void *data
, int data_size
,
546 class_constructor constructor
,
547 IWICMetadataReader
**reader
)
550 IWICMetadataReader
*metadata_reader
;
551 IWICPersistStream
*persist
;
554 /* FIXME: Use IWICComponentFactory_CreateMetadataReader once it's implemented */
556 hr
= constructor(&IID_IWICMetadataReader
, (void**)&metadata_reader
);
557 if (FAILED(hr
)) return hr
;
559 hr
= IWICMetadataReader_QueryInterface(metadata_reader
, &IID_IWICPersistStream
, (void **)&persist
);
562 IWICMetadataReader_Release(metadata_reader
);
566 stream
= create_stream(data
, data_size
);
567 IWICPersistStream_LoadEx(persist
, stream
, NULL
, WICPersistOptionDefault
);
568 IStream_Release(stream
);
570 IWICPersistStream_Release(persist
);
572 *reader
= metadata_reader
;
577 IWICBitmapDecoder IWICBitmapDecoder_iface
;
578 IWICMetadataBlockReader IWICMetadataBlockReader_iface
;
580 BYTE LSD_data
[13]; /* Logical Screen Descriptor */
585 CRITICAL_SECTION lock
;
589 IWICBitmapFrameDecode IWICBitmapFrameDecode_iface
;
590 IWICMetadataBlockReader IWICMetadataBlockReader_iface
;
596 static inline GifDecoder
*impl_from_IWICBitmapDecoder(IWICBitmapDecoder
*iface
)
598 return CONTAINING_RECORD(iface
, GifDecoder
, IWICBitmapDecoder_iface
);
601 static inline GifDecoder
*impl_from_IWICMetadataBlockReader(IWICMetadataBlockReader
*iface
)
603 return CONTAINING_RECORD(iface
, GifDecoder
, IWICMetadataBlockReader_iface
);
606 static inline GifFrameDecode
*impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode
*iface
)
608 return CONTAINING_RECORD(iface
, GifFrameDecode
, IWICBitmapFrameDecode_iface
);
611 static inline GifFrameDecode
*frame_from_IWICMetadataBlockReader(IWICMetadataBlockReader
*iface
)
613 return CONTAINING_RECORD(iface
, GifFrameDecode
, IWICMetadataBlockReader_iface
);
616 static HRESULT WINAPI
GifFrameDecode_QueryInterface(IWICBitmapFrameDecode
*iface
, REFIID iid
,
619 GifFrameDecode
*This
= impl_from_IWICBitmapFrameDecode(iface
);
620 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
622 if (!ppv
) return E_INVALIDARG
;
624 if (IsEqualIID(&IID_IUnknown
, iid
) ||
625 IsEqualIID(&IID_IWICBitmapSource
, iid
) ||
626 IsEqualIID(&IID_IWICBitmapFrameDecode
, iid
))
628 *ppv
= &This
->IWICBitmapFrameDecode_iface
;
630 else if (IsEqualIID(&IID_IWICMetadataBlockReader
, iid
))
632 *ppv
= &This
->IWICMetadataBlockReader_iface
;
637 return E_NOINTERFACE
;
640 IUnknown_AddRef((IUnknown
*)*ppv
);
644 static ULONG WINAPI
GifFrameDecode_AddRef(IWICBitmapFrameDecode
*iface
)
646 GifFrameDecode
*This
= impl_from_IWICBitmapFrameDecode(iface
);
647 ULONG ref
= InterlockedIncrement(&This
->ref
);
649 TRACE("(%p) refcount=%u\n", iface
, ref
);
654 static ULONG WINAPI
GifFrameDecode_Release(IWICBitmapFrameDecode
*iface
)
656 GifFrameDecode
*This
= impl_from_IWICBitmapFrameDecode(iface
);
657 ULONG ref
= InterlockedDecrement(&This
->ref
);
659 TRACE("(%p) refcount=%u\n", iface
, ref
);
663 IWICBitmapDecoder_Release(&This
->parent
->IWICBitmapDecoder_iface
);
664 HeapFree(GetProcessHeap(), 0, This
);
670 static HRESULT WINAPI
GifFrameDecode_GetSize(IWICBitmapFrameDecode
*iface
,
671 UINT
*puiWidth
, UINT
*puiHeight
)
673 GifFrameDecode
*This
= impl_from_IWICBitmapFrameDecode(iface
);
674 TRACE("(%p,%p,%p)\n", iface
, puiWidth
, puiHeight
);
676 *puiWidth
= This
->frame
->ImageDesc
.Width
;
677 *puiHeight
= This
->frame
->ImageDesc
.Height
;
682 static HRESULT WINAPI
GifFrameDecode_GetPixelFormat(IWICBitmapFrameDecode
*iface
,
683 WICPixelFormatGUID
*pPixelFormat
)
685 memcpy(pPixelFormat
, &GUID_WICPixelFormat8bppIndexed
, sizeof(GUID
));
690 static HRESULT WINAPI
GifFrameDecode_GetResolution(IWICBitmapFrameDecode
*iface
,
691 double *pDpiX
, double *pDpiY
)
693 GifFrameDecode
*This
= impl_from_IWICBitmapFrameDecode(iface
);
694 const GifWord aspect_word
= This
->parent
->gif
->SAspectRatio
;
695 const double aspect
= (aspect_word
> 0) ? ((aspect_word
+ 15.0) / 64.0) : 1.0;
696 TRACE("(%p,%p,%p)\n", iface
, pDpiX
, pDpiY
);
698 *pDpiX
= 96.0 / aspect
;
704 static HRESULT WINAPI
GifFrameDecode_CopyPalette(IWICBitmapFrameDecode
*iface
,
705 IWICPalette
*pIPalette
)
707 GifFrameDecode
*This
= impl_from_IWICBitmapFrameDecode(iface
);
708 WICColor colors
[256];
709 ColorMapObject
*cm
= This
->frame
->ImageDesc
.ColorMap
;
712 TRACE("(%p,%p)\n", iface
, pIPalette
);
714 if (!cm
) cm
= This
->parent
->gif
->SColorMap
;
716 if (cm
->ColorCount
> 256)
718 ERR("GIF contains %i colors???\n", cm
->ColorCount
);
722 for (i
= 0; i
< cm
->ColorCount
; i
++) {
723 colors
[i
] = 0xff000000| /* alpha */
724 cm
->Colors
[i
].Red
<< 16|
725 cm
->Colors
[i
].Green
<< 8|
729 /* look for the transparent color extension */
730 for (i
= 0; i
< This
->frame
->Extensions
.ExtensionBlockCount
; ++i
) {
731 eb
= This
->frame
->Extensions
.ExtensionBlocks
+ i
;
732 if (eb
->Function
== GRAPHICS_EXT_FUNC_CODE
&& eb
->ByteCount
== 8) {
733 if (eb
->Bytes
[3] & 1) {
734 trans
= (unsigned char)eb
->Bytes
[6];
735 colors
[trans
] &= 0xffffff; /* set alpha to 0 */
741 return IWICPalette_InitializeCustom(pIPalette
, colors
, cm
->ColorCount
);
744 static HRESULT
copy_interlaced_pixels(const BYTE
*srcbuffer
,
745 UINT srcwidth
, UINT srcheight
, INT srcstride
, const WICRect
*rc
,
746 UINT dststride
, UINT dstbuffersize
, BYTE
*dstbuffer
)
748 UINT row_offset
; /* number of bytes into the source rows where the data starts */
758 rect
.Width
= srcwidth
;
759 rect
.Height
= srcheight
;
764 if (rc
->X
< 0 || rc
->Y
< 0 || rc
->X
+rc
->Width
> srcwidth
|| rc
->Y
+rc
->Height
> srcheight
)
768 if (dststride
< rc
->Width
)
771 if ((dststride
* rc
->Height
) > dstbuffersize
)
777 for (y
=rc
->Y
; y
-rc
->Y
< rc
->Height
; y
++)
780 src
= srcbuffer
+ srcstride
* (y
/8);
782 src
= srcbuffer
+ srcstride
* ((srcheight
+7)/8 + y
/8);
784 src
= srcbuffer
+ srcstride
* ((srcheight
+3)/4 + y
/4);
786 src
= srcbuffer
+ srcstride
* ((srcheight
+1)/2 + y
/2);
788 memcpy(dst
, src
, rc
->Width
);
794 static HRESULT WINAPI
GifFrameDecode_CopyPixels(IWICBitmapFrameDecode
*iface
,
795 const WICRect
*prc
, UINT cbStride
, UINT cbBufferSize
, BYTE
*pbBuffer
)
797 GifFrameDecode
*This
= impl_from_IWICBitmapFrameDecode(iface
);
798 TRACE("(%p,%p,%u,%u,%p)\n", iface
, prc
, cbStride
, cbBufferSize
, pbBuffer
);
800 if (This
->frame
->ImageDesc
.Interlace
)
802 return copy_interlaced_pixels(This
->frame
->RasterBits
, This
->frame
->ImageDesc
.Width
,
803 This
->frame
->ImageDesc
.Height
, This
->frame
->ImageDesc
.Width
,
804 prc
, cbStride
, cbBufferSize
, pbBuffer
);
808 return copy_pixels(8, This
->frame
->RasterBits
, This
->frame
->ImageDesc
.Width
,
809 This
->frame
->ImageDesc
.Height
, This
->frame
->ImageDesc
.Width
,
810 prc
, cbStride
, cbBufferSize
, pbBuffer
);
814 static HRESULT WINAPI
GifFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode
*iface
,
815 IWICMetadataQueryReader
**ppIMetadataQueryReader
)
817 GifFrameDecode
*This
= impl_from_IWICBitmapFrameDecode(iface
);
819 TRACE("(%p,%p)\n", iface
, ppIMetadataQueryReader
);
821 if (!ppIMetadataQueryReader
)
824 return MetadataQueryReader_CreateInstance(&This
->IWICMetadataBlockReader_iface
, NULL
, ppIMetadataQueryReader
);
827 static HRESULT WINAPI
GifFrameDecode_GetColorContexts(IWICBitmapFrameDecode
*iface
,
828 UINT cCount
, IWICColorContext
**ppIColorContexts
, UINT
*pcActualCount
)
830 TRACE("(%p,%u,%p,%p)\n", iface
, cCount
, ppIColorContexts
, pcActualCount
);
831 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
834 static HRESULT WINAPI
GifFrameDecode_GetThumbnail(IWICBitmapFrameDecode
*iface
,
835 IWICBitmapSource
**ppIThumbnail
)
837 TRACE("(%p,%p)\n", iface
, ppIThumbnail
);
838 return WINCODEC_ERR_CODECNOTHUMBNAIL
;
841 static const IWICBitmapFrameDecodeVtbl GifFrameDecode_Vtbl
= {
842 GifFrameDecode_QueryInterface
,
843 GifFrameDecode_AddRef
,
844 GifFrameDecode_Release
,
845 GifFrameDecode_GetSize
,
846 GifFrameDecode_GetPixelFormat
,
847 GifFrameDecode_GetResolution
,
848 GifFrameDecode_CopyPalette
,
849 GifFrameDecode_CopyPixels
,
850 GifFrameDecode_GetMetadataQueryReader
,
851 GifFrameDecode_GetColorContexts
,
852 GifFrameDecode_GetThumbnail
855 static HRESULT WINAPI
GifFrameDecode_Block_QueryInterface(IWICMetadataBlockReader
*iface
,
856 REFIID iid
, void **ppv
)
858 GifFrameDecode
*This
= frame_from_IWICMetadataBlockReader(iface
);
859 return IWICBitmapFrameDecode_QueryInterface(&This
->IWICBitmapFrameDecode_iface
, iid
, ppv
);
862 static ULONG WINAPI
GifFrameDecode_Block_AddRef(IWICMetadataBlockReader
*iface
)
864 GifFrameDecode
*This
= frame_from_IWICMetadataBlockReader(iface
);
865 return IWICBitmapFrameDecode_AddRef(&This
->IWICBitmapFrameDecode_iface
);
868 static ULONG WINAPI
GifFrameDecode_Block_Release(IWICMetadataBlockReader
*iface
)
870 GifFrameDecode
*This
= frame_from_IWICMetadataBlockReader(iface
);
871 return IWICBitmapFrameDecode_Release(&This
->IWICBitmapFrameDecode_iface
);
874 static HRESULT WINAPI
GifFrameDecode_Block_GetContainerFormat(IWICMetadataBlockReader
*iface
,
877 TRACE("(%p,%p)\n", iface
, guid
);
879 if (!guid
) return E_INVALIDARG
;
881 *guid
= GUID_ContainerFormatGif
;
885 static HRESULT WINAPI
GifFrameDecode_Block_GetCount(IWICMetadataBlockReader
*iface
,
888 GifFrameDecode
*This
= frame_from_IWICMetadataBlockReader(iface
);
890 TRACE("%p,%p\n", iface
, count
);
892 if (!count
) return E_INVALIDARG
;
894 *count
= This
->frame
->Extensions
.ExtensionBlockCount
+ 1;
898 static HRESULT
create_IMD_metadata_reader(GifFrameDecode
*This
, IWICMetadataReader
**reader
)
901 IWICMetadataReader
*metadata_reader
;
902 IWICPersistStream
*persist
;
904 struct image_descriptor IMD_data
;
906 /* FIXME: Use IWICComponentFactory_CreateMetadataReader once it's implemented */
908 hr
= IMDReader_CreateInstance(&IID_IWICMetadataReader
, (void **)&metadata_reader
);
909 if (FAILED(hr
)) return hr
;
911 hr
= IWICMetadataReader_QueryInterface(metadata_reader
, &IID_IWICPersistStream
, (void **)&persist
);
914 IWICMetadataReader_Release(metadata_reader
);
918 /* recreate IMD structure from GIF decoder data */
919 IMD_data
.left
= This
->frame
->ImageDesc
.Left
;
920 IMD_data
.top
= This
->frame
->ImageDesc
.Top
;
921 IMD_data
.width
= This
->frame
->ImageDesc
.Width
;
922 IMD_data
.height
= This
->frame
->ImageDesc
.Height
;
925 IMD_data
.packed
|= This
->frame
->ImageDesc
.Interlace
? (1 << 6) : 0;
926 if (This
->frame
->ImageDesc
.ColorMap
)
928 /* local_color_table_flag */
929 IMD_data
.packed
|= 1 << 7;
930 /* local_color_table_size */
931 IMD_data
.packed
|= This
->frame
->ImageDesc
.ColorMap
->BitsPerPixel
- 1;
933 IMD_data
.packed
|= This
->frame
->ImageDesc
.ColorMap
->SortFlag
? 0x20 : 0;
936 stream
= create_stream(&IMD_data
, sizeof(IMD_data
));
937 IWICPersistStream_LoadEx(persist
, stream
, NULL
, WICPersistOptionDefault
);
938 IStream_Release(stream
);
940 IWICPersistStream_Release(persist
);
942 *reader
= metadata_reader
;
946 static HRESULT WINAPI
GifFrameDecode_Block_GetReaderByIndex(IWICMetadataBlockReader
*iface
,
947 UINT index
, IWICMetadataReader
**reader
)
949 GifFrameDecode
*This
= frame_from_IWICMetadataBlockReader(iface
);
950 int i
, gce_index
= -1, gce_skipped
= 0;
952 TRACE("(%p,%u,%p)\n", iface
, index
, reader
);
954 if (!reader
) return E_INVALIDARG
;
957 return create_IMD_metadata_reader(This
, reader
);
959 if (index
>= This
->frame
->Extensions
.ExtensionBlockCount
+ 1)
962 for (i
= 0; i
< This
->frame
->Extensions
.ExtensionBlockCount
; i
++)
964 class_constructor constructor
;
968 if (index
!= i
+ 1 - gce_skipped
) continue;
970 if (This
->frame
->Extensions
.ExtensionBlocks
[i
].Function
== GRAPHICS_EXT_FUNC_CODE
)
976 else if (This
->frame
->Extensions
.ExtensionBlocks
[i
].Function
== COMMENT_EXT_FUNC_CODE
)
978 constructor
= GifCommentReader_CreateInstance
;
979 data
= This
->frame
->Extensions
.ExtensionBlocks
[i
].Bytes
;
980 data_size
= This
->frame
->Extensions
.ExtensionBlocks
[i
].ByteCount
;
984 constructor
= UnknownMetadataReader_CreateInstance
;
985 data
= This
->frame
->Extensions
.ExtensionBlocks
[i
].Bytes
;
986 data_size
= This
->frame
->Extensions
.ExtensionBlocks
[i
].ByteCount
;
988 return create_metadata_reader(data
, data_size
, constructor
, reader
);
991 if (gce_index
== -1) return E_INVALIDARG
;
993 return create_metadata_reader(This
->frame
->Extensions
.ExtensionBlocks
[gce_index
].Bytes
+ 3,
994 This
->frame
->Extensions
.ExtensionBlocks
[gce_index
].ByteCount
- 4,
995 GCEReader_CreateInstance
, reader
);
998 static HRESULT WINAPI
GifFrameDecode_Block_GetEnumerator(IWICMetadataBlockReader
*iface
,
999 IEnumUnknown
**enumerator
)
1001 FIXME("(%p,%p): stub\n", iface
, enumerator
);
1005 static const IWICMetadataBlockReaderVtbl GifFrameDecode_BlockVtbl
=
1007 GifFrameDecode_Block_QueryInterface
,
1008 GifFrameDecode_Block_AddRef
,
1009 GifFrameDecode_Block_Release
,
1010 GifFrameDecode_Block_GetContainerFormat
,
1011 GifFrameDecode_Block_GetCount
,
1012 GifFrameDecode_Block_GetReaderByIndex
,
1013 GifFrameDecode_Block_GetEnumerator
1016 static HRESULT WINAPI
GifDecoder_QueryInterface(IWICBitmapDecoder
*iface
, REFIID iid
,
1019 GifDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
1020 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
1022 if (!ppv
) return E_INVALIDARG
;
1024 if (IsEqualIID(&IID_IUnknown
, iid
) ||
1025 IsEqualIID(&IID_IWICBitmapDecoder
, iid
))
1027 *ppv
= &This
->IWICBitmapDecoder_iface
;
1029 else if (IsEqualIID(&IID_IWICMetadataBlockReader
, iid
))
1031 *ppv
= &This
->IWICMetadataBlockReader_iface
;
1036 return E_NOINTERFACE
;
1039 IUnknown_AddRef((IUnknown
*)*ppv
);
1043 static ULONG WINAPI
GifDecoder_AddRef(IWICBitmapDecoder
*iface
)
1045 GifDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
1046 ULONG ref
= InterlockedIncrement(&This
->ref
);
1048 TRACE("(%p) refcount=%u\n", iface
, ref
);
1053 static ULONG WINAPI
GifDecoder_Release(IWICBitmapDecoder
*iface
)
1055 GifDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
1056 ULONG ref
= InterlockedDecrement(&This
->ref
);
1058 TRACE("(%p) refcount=%u\n", iface
, ref
);
1064 IStream_Release(This
->stream
);
1065 DGifCloseFile(This
->gif
);
1067 This
->lock
.DebugInfo
->Spare
[0] = 0;
1068 DeleteCriticalSection(&This
->lock
);
1069 HeapFree(GetProcessHeap(), 0, This
);
1075 static HRESULT WINAPI
GifDecoder_QueryCapability(IWICBitmapDecoder
*iface
, IStream
*stream
,
1080 TRACE("(%p,%p,%p)\n", iface
, stream
, capability
);
1082 if (!stream
|| !capability
) return E_INVALIDARG
;
1084 hr
= IWICBitmapDecoder_Initialize(iface
, stream
, WICDecodeMetadataCacheOnDemand
);
1085 if (hr
!= S_OK
) return hr
;
1087 *capability
= WICBitmapDecoderCapabilityCanDecodeAllImages
|
1088 WICBitmapDecoderCapabilityCanDecodeSomeImages
|
1089 WICBitmapDecoderCapabilityCanEnumerateMetadata
;
1093 static int _gif_inputfunc(GifFileType
*gif
, GifByteType
*data
, int len
) {
1094 IStream
*stream
= gif
->UserData
;
1100 ERR("attempting to read file after initialization\n");
1104 hr
= IStream_Read(stream
, data
, len
, &bytesread
);
1105 if (FAILED(hr
)) bytesread
= 0;
1109 static HRESULT WINAPI
GifDecoder_Initialize(IWICBitmapDecoder
*iface
, IStream
*pIStream
,
1110 WICDecodeOptions cacheOptions
)
1112 GifDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
1116 TRACE("(%p,%p,%x)\n", iface
, pIStream
, cacheOptions
);
1118 EnterCriticalSection(&This
->lock
);
1120 if (This
->initialized
|| This
->gif
)
1122 WARN("already initialized\n");
1123 LeaveCriticalSection(&This
->lock
);
1124 return WINCODEC_ERR_WRONGSTATE
;
1127 /* seek to start of stream */
1129 IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
);
1131 /* read all data from the stream */
1132 This
->gif
= DGifOpen((void*)pIStream
, _gif_inputfunc
);
1135 LeaveCriticalSection(&This
->lock
);
1139 ret
= DGifSlurp(This
->gif
);
1140 if (ret
== GIF_ERROR
)
1142 LeaveCriticalSection(&This
->lock
);
1146 /* make sure we don't use the stream after this method returns */
1147 This
->gif
->UserData
= NULL
;
1150 IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
);
1151 IStream_Read(pIStream
, This
->LSD_data
, sizeof(This
->LSD_data
), NULL
);
1153 This
->stream
= pIStream
;
1154 IStream_AddRef(This
->stream
);
1156 This
->initialized
= TRUE
;
1158 LeaveCriticalSection(&This
->lock
);
1163 static HRESULT WINAPI
GifDecoder_GetContainerFormat(IWICBitmapDecoder
*iface
,
1164 GUID
*pguidContainerFormat
)
1166 memcpy(pguidContainerFormat
, &GUID_ContainerFormatGif
, sizeof(GUID
));
1170 static HRESULT WINAPI
GifDecoder_GetDecoderInfo(IWICBitmapDecoder
*iface
,
1171 IWICBitmapDecoderInfo
**ppIDecoderInfo
)
1173 TRACE("(%p,%p)\n", iface
, ppIDecoderInfo
);
1175 return get_decoder_info(&CLSID_WICGifDecoder
, ppIDecoderInfo
);
1178 static HRESULT WINAPI
GifDecoder_CopyPalette(IWICBitmapDecoder
*iface
, IWICPalette
*palette
)
1180 GifDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
1181 WICColor colors
[256];
1183 int i
, trans
, count
;
1186 TRACE("(%p,%p)\n", iface
, palette
);
1188 cm
= This
->gif
->SColorMap
;
1191 if (cm
->ColorCount
> 256)
1193 ERR("GIF contains invalid number of colors: %d\n", cm
->ColorCount
);
1197 for (i
= 0; i
< cm
->ColorCount
; i
++)
1199 colors
[i
] = 0xff000000 | /* alpha */
1200 cm
->Colors
[i
].Red
<< 16 |
1201 cm
->Colors
[i
].Green
<< 8 |
1205 count
= cm
->ColorCount
;
1209 colors
[0] = 0xff000000;
1210 colors
[1] = 0xffffffff;
1212 for (i
= 2; i
< 256; i
++)
1213 colors
[i
] = 0xff000000;
1218 /* look for the transparent color extension */
1219 for (i
= 0; i
< This
->gif
->SavedImages
[This
->current_frame
].Extensions
.ExtensionBlockCount
; i
++)
1221 eb
= This
->gif
->SavedImages
[This
->current_frame
].Extensions
.ExtensionBlocks
+ i
;
1222 if (eb
->Function
== GRAPHICS_EXT_FUNC_CODE
&& eb
->ByteCount
== 8)
1224 if (eb
->Bytes
[3] & 1)
1226 trans
= (unsigned char)eb
->Bytes
[6];
1227 colors
[trans
] &= 0xffffff; /* set alpha to 0 */
1233 return IWICPalette_InitializeCustom(palette
, colors
, count
);
1236 static HRESULT WINAPI
GifDecoder_GetMetadataQueryReader(IWICBitmapDecoder
*iface
,
1237 IWICMetadataQueryReader
**ppIMetadataQueryReader
)
1239 GifDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
1241 TRACE("(%p,%p)\n", iface
, ppIMetadataQueryReader
);
1243 if (!ppIMetadataQueryReader
) return E_INVALIDARG
;
1245 return MetadataQueryReader_CreateInstance(&This
->IWICMetadataBlockReader_iface
, NULL
, ppIMetadataQueryReader
);
1248 static HRESULT WINAPI
GifDecoder_GetPreview(IWICBitmapDecoder
*iface
,
1249 IWICBitmapSource
**ppIBitmapSource
)
1251 TRACE("(%p,%p)\n", iface
, ppIBitmapSource
);
1252 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
1255 static HRESULT WINAPI
GifDecoder_GetColorContexts(IWICBitmapDecoder
*iface
,
1256 UINT cCount
, IWICColorContext
**ppIColorContexts
, UINT
*pcActualCount
)
1258 TRACE("(%p,%u,%p,%p)\n", iface
, cCount
, ppIColorContexts
, pcActualCount
);
1259 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
1262 static HRESULT WINAPI
GifDecoder_GetThumbnail(IWICBitmapDecoder
*iface
,
1263 IWICBitmapSource
**ppIThumbnail
)
1265 TRACE("(%p,%p)\n", iface
, ppIThumbnail
);
1266 return WINCODEC_ERR_CODECNOTHUMBNAIL
;
1269 static HRESULT WINAPI
GifDecoder_GetFrameCount(IWICBitmapDecoder
*iface
,
1272 GifDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
1274 if (!pCount
) return E_INVALIDARG
;
1276 EnterCriticalSection(&This
->lock
);
1277 *pCount
= This
->gif
? This
->gif
->ImageCount
: 0;
1278 LeaveCriticalSection(&This
->lock
);
1280 TRACE("(%p) <-- %d\n", iface
, *pCount
);
1285 static HRESULT WINAPI
GifDecoder_GetFrame(IWICBitmapDecoder
*iface
,
1286 UINT index
, IWICBitmapFrameDecode
**ppIBitmapFrame
)
1288 GifDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
1289 GifFrameDecode
*result
;
1290 TRACE("(%p,%u,%p)\n", iface
, index
, ppIBitmapFrame
);
1292 if (!This
->initialized
) return WINCODEC_ERR_FRAMEMISSING
;
1294 if (index
>= This
->gif
->ImageCount
) return E_INVALIDARG
;
1296 result
= HeapAlloc(GetProcessHeap(), 0, sizeof(GifFrameDecode
));
1297 if (!result
) return E_OUTOFMEMORY
;
1299 result
->IWICBitmapFrameDecode_iface
.lpVtbl
= &GifFrameDecode_Vtbl
;
1300 result
->IWICMetadataBlockReader_iface
.lpVtbl
= &GifFrameDecode_BlockVtbl
;
1302 result
->frame
= &This
->gif
->SavedImages
[index
];
1303 IWICBitmapDecoder_AddRef(iface
);
1304 result
->parent
= This
;
1305 This
->current_frame
= index
;
1307 *ppIBitmapFrame
= &result
->IWICBitmapFrameDecode_iface
;
1312 static const IWICBitmapDecoderVtbl GifDecoder_Vtbl
= {
1313 GifDecoder_QueryInterface
,
1316 GifDecoder_QueryCapability
,
1317 GifDecoder_Initialize
,
1318 GifDecoder_GetContainerFormat
,
1319 GifDecoder_GetDecoderInfo
,
1320 GifDecoder_CopyPalette
,
1321 GifDecoder_GetMetadataQueryReader
,
1322 GifDecoder_GetPreview
,
1323 GifDecoder_GetColorContexts
,
1324 GifDecoder_GetThumbnail
,
1325 GifDecoder_GetFrameCount
,
1329 static HRESULT WINAPI
GifDecoder_Block_QueryInterface(IWICMetadataBlockReader
*iface
,
1330 REFIID iid
, void **ppv
)
1332 GifDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1333 return IWICBitmapDecoder_QueryInterface(&This
->IWICBitmapDecoder_iface
, iid
, ppv
);
1336 static ULONG WINAPI
GifDecoder_Block_AddRef(IWICMetadataBlockReader
*iface
)
1338 GifDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1339 return IWICBitmapDecoder_AddRef(&This
->IWICBitmapDecoder_iface
);
1342 static ULONG WINAPI
GifDecoder_Block_Release(IWICMetadataBlockReader
*iface
)
1344 GifDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1345 return IWICBitmapDecoder_Release(&This
->IWICBitmapDecoder_iface
);
1348 static HRESULT WINAPI
GifDecoder_Block_GetContainerFormat(IWICMetadataBlockReader
*iface
,
1351 TRACE("(%p,%p)\n", iface
, guid
);
1353 if (!guid
) return E_INVALIDARG
;
1355 *guid
= GUID_ContainerFormatGif
;
1359 static HRESULT WINAPI
GifDecoder_Block_GetCount(IWICMetadataBlockReader
*iface
,
1362 GifDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1364 TRACE("%p,%p\n", iface
, count
);
1366 if (!count
) return E_INVALIDARG
;
1368 *count
= This
->gif
->Extensions
.ExtensionBlockCount
+ 1;
1372 static HRESULT WINAPI
GifDecoder_Block_GetReaderByIndex(IWICMetadataBlockReader
*iface
,
1373 UINT index
, IWICMetadataReader
**reader
)
1375 GifDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1378 TRACE("(%p,%u,%p)\n", iface
, index
, reader
);
1380 if (!reader
) return E_INVALIDARG
;
1383 return create_metadata_reader(This
->LSD_data
, sizeof(This
->LSD_data
),
1384 LSDReader_CreateInstance
, reader
);
1386 for (i
= 0; i
< This
->gif
->Extensions
.ExtensionBlockCount
; i
++)
1388 class_constructor constructor
;
1390 if (index
!= i
+ 1) continue;
1392 if (This
->gif
->Extensions
.ExtensionBlocks
[i
].Function
== APPLICATION_EXT_FUNC_CODE
)
1393 constructor
= APEReader_CreateInstance
;
1394 else if (This
->gif
->Extensions
.ExtensionBlocks
[i
].Function
== COMMENT_EXT_FUNC_CODE
)
1395 constructor
= GifCommentReader_CreateInstance
;
1397 constructor
= UnknownMetadataReader_CreateInstance
;
1399 return create_metadata_reader(This
->gif
->Extensions
.ExtensionBlocks
[i
].Bytes
,
1400 This
->gif
->Extensions
.ExtensionBlocks
[i
].ByteCount
,
1401 constructor
, reader
);
1404 return E_INVALIDARG
;
1407 static HRESULT WINAPI
GifDecoder_Block_GetEnumerator(IWICMetadataBlockReader
*iface
,
1408 IEnumUnknown
**enumerator
)
1410 FIXME("(%p,%p): stub\n", iface
, enumerator
);
1414 static const IWICMetadataBlockReaderVtbl GifDecoder_BlockVtbl
=
1416 GifDecoder_Block_QueryInterface
,
1417 GifDecoder_Block_AddRef
,
1418 GifDecoder_Block_Release
,
1419 GifDecoder_Block_GetContainerFormat
,
1420 GifDecoder_Block_GetCount
,
1421 GifDecoder_Block_GetReaderByIndex
,
1422 GifDecoder_Block_GetEnumerator
1425 HRESULT
GifDecoder_CreateInstance(REFIID iid
, void** ppv
)
1430 TRACE("(%s,%p)\n", debugstr_guid(iid
), ppv
);
1434 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(GifDecoder
));
1435 if (!This
) return E_OUTOFMEMORY
;
1437 This
->IWICBitmapDecoder_iface
.lpVtbl
= &GifDecoder_Vtbl
;
1438 This
->IWICMetadataBlockReader_iface
.lpVtbl
= &GifDecoder_BlockVtbl
;
1439 This
->stream
= NULL
;
1441 This
->initialized
= FALSE
;
1443 This
->current_frame
= 0;
1444 InitializeCriticalSection(&This
->lock
);
1445 This
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": GifDecoder.lock");
1447 ret
= IWICBitmapDecoder_QueryInterface(&This
->IWICBitmapDecoder_iface
, iid
, ppv
);
1448 IWICBitmapDecoder_Release(&This
->IWICBitmapDecoder_iface
);