2 * Copyright 2009 Vincent Povirk for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
28 #define NONAMELESSUNION
35 #include "wincodecs_private.h"
37 #include "wine/debug.h"
38 #include "wine/library.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
42 static inline ULONG
read_ulong_be(BYTE
* data
)
44 return data
[0] << 24 | data
[1] << 16 | data
[2] << 8 | data
[3];
47 static HRESULT
read_png_chunk(IStream
*stream
, BYTE
*type
, BYTE
**data
, ULONG
*data_size
)
53 hr
= IStream_Read(stream
, header
, 8, &bytesread
);
54 if (FAILED(hr
) || bytesread
< 8)
61 *data_size
= read_ulong_be(&header
[0]);
63 memcpy(type
, &header
[4], 4);
67 *data
= HeapAlloc(GetProcessHeap(), 0, *data_size
);
71 hr
= IStream_Read(stream
, *data
, *data_size
, &bytesread
);
73 if (FAILED(hr
) || bytesread
< *data_size
)
77 HeapFree(GetProcessHeap(), 0, *data
);
82 /* Windows ignores CRC of the chunk */
88 static HRESULT
LoadTextMetadata(IStream
*stream
, const GUID
*preferred_vendor
,
89 DWORD persist_options
, MetadataItem
**items
, DWORD
*item_count
)
95 ULONG name_len
, value_len
;
100 hr
= read_png_chunk(stream
, type
, &data
, &data_size
);
101 if (FAILED(hr
)) return hr
;
103 name_end_ptr
= memchr(data
, 0, data_size
);
105 name_len
= name_end_ptr
- data
;
107 if (!name_end_ptr
|| name_len
> 79)
109 HeapFree(GetProcessHeap(), 0, data
);
113 value_len
= data_size
- name_len
- 1;
115 result
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MetadataItem
));
116 name
= HeapAlloc(GetProcessHeap(), 0, name_len
+ 1);
117 value
= HeapAlloc(GetProcessHeap(), 0, value_len
+ 1);
118 if (!result
|| !name
|| !value
)
120 HeapFree(GetProcessHeap(), 0, data
);
121 HeapFree(GetProcessHeap(), 0, result
);
122 HeapFree(GetProcessHeap(), 0, name
);
123 HeapFree(GetProcessHeap(), 0, value
);
124 return E_OUTOFMEMORY
;
127 PropVariantInit(&result
[0].schema
);
128 PropVariantInit(&result
[0].id
);
129 PropVariantInit(&result
[0].value
);
131 memcpy(name
, data
, name_len
+ 1);
132 memcpy(value
, name_end_ptr
+ 1, value_len
);
133 value
[value_len
] = 0;
135 result
[0].id
.vt
= VT_LPSTR
;
136 result
[0].id
.u
.pszVal
= name
;
137 result
[0].value
.vt
= VT_LPSTR
;
138 result
[0].value
.u
.pszVal
= value
;
143 HeapFree(GetProcessHeap(), 0, data
);
148 static const MetadataHandlerVtbl TextReader_Vtbl
= {
150 &CLSID_WICPngTextMetadataReader
,
154 HRESULT
PngTextReader_CreateInstance(REFIID iid
, void** ppv
)
156 return MetadataReader_Create(&TextReader_Vtbl
, iid
, ppv
);
159 static HRESULT
LoadGamaMetadata(IStream
*stream
, const GUID
*preferred_vendor
,
160 DWORD persist_options
, MetadataItem
**items
, DWORD
*item_count
)
167 static const WCHAR ImageGamma
[] = {'I','m','a','g','e','G','a','m','m','a',0};
169 MetadataItem
*result
;
171 hr
= read_png_chunk(stream
, type
, &data
, &data_size
);
172 if (FAILED(hr
)) return hr
;
176 HeapFree(GetProcessHeap(), 0, data
);
180 gamma
= read_ulong_be(data
);
182 HeapFree(GetProcessHeap(), 0, data
);
184 result
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MetadataItem
));
185 name
= HeapAlloc(GetProcessHeap(), 0, sizeof(ImageGamma
));
186 if (!result
|| !name
)
188 HeapFree(GetProcessHeap(), 0, result
);
189 HeapFree(GetProcessHeap(), 0, name
);
190 return E_OUTOFMEMORY
;
193 PropVariantInit(&result
[0].schema
);
194 PropVariantInit(&result
[0].id
);
195 PropVariantInit(&result
[0].value
);
197 memcpy(name
, ImageGamma
, sizeof(ImageGamma
));
199 result
[0].id
.vt
= VT_LPWSTR
;
200 result
[0].id
.u
.pwszVal
= name
;
201 result
[0].value
.vt
= VT_UI4
;
202 result
[0].value
.u
.ulVal
= gamma
;
210 static const MetadataHandlerVtbl GamaReader_Vtbl
= {
212 &CLSID_WICPngGamaMetadataReader
,
216 HRESULT
PngGamaReader_CreateInstance(REFIID iid
, void** ppv
)
218 return MetadataReader_Create(&GamaReader_Vtbl
, iid
, ppv
);
221 static HRESULT
LoadChrmMetadata(IStream
*stream
, const GUID
*preferred_vendor
,
222 DWORD persist_options
, MetadataItem
**items
, DWORD
*item_count
)
228 static const WCHAR names
[8][12] = {
229 {'W','h','i','t','e','P','o','i','n','t','X',0},
230 {'W','h','i','t','e','P','o','i','n','t','Y',0},
233 {'G','r','e','e','n','X',0},
234 {'G','r','e','e','n','Y',0},
235 {'B','l','u','e','X',0},
236 {'B','l','u','e','Y',0},
238 LPWSTR dyn_names
[8] = {0};
239 MetadataItem
*result
;
242 hr
= read_png_chunk(stream
, type
, &data
, &data_size
);
243 if (FAILED(hr
)) return hr
;
247 HeapFree(GetProcessHeap(), 0, data
);
251 result
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MetadataItem
)*8);
254 dyn_names
[i
] = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(lstrlenW(names
[i
])+1));
255 if (!dyn_names
[i
]) break;
257 if (!result
|| i
< 8)
259 HeapFree(GetProcessHeap(), 0, result
);
261 HeapFree(GetProcessHeap(), 0, dyn_names
[i
]);
262 HeapFree(GetProcessHeap(), 0, data
);
263 return E_OUTOFMEMORY
;
268 PropVariantInit(&result
[i
].schema
);
270 PropVariantInit(&result
[i
].id
);
271 result
[i
].id
.vt
= VT_LPWSTR
;
272 result
[i
].id
.u
.pwszVal
= dyn_names
[i
];
273 lstrcpyW(dyn_names
[i
], names
[i
]);
275 PropVariantInit(&result
[i
].value
);
276 result
[i
].value
.vt
= VT_UI4
;
277 result
[i
].value
.u
.ulVal
= read_ulong_be(&data
[i
*4]);
283 HeapFree(GetProcessHeap(), 0, data
);
288 static const MetadataHandlerVtbl ChrmReader_Vtbl
= {
290 &CLSID_WICPngChrmMetadataReader
,
294 HRESULT
PngChrmReader_CreateInstance(REFIID iid
, void** ppv
)
296 return MetadataReader_Create(&ChrmReader_Vtbl
, iid
, ppv
);
301 static void *libpng_handle
;
302 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
303 MAKE_FUNCPTR(png_create_read_struct
);
304 MAKE_FUNCPTR(png_create_info_struct
);
305 MAKE_FUNCPTR(png_create_write_struct
);
306 MAKE_FUNCPTR(png_destroy_read_struct
);
307 MAKE_FUNCPTR(png_destroy_write_struct
);
308 MAKE_FUNCPTR(png_error
);
309 MAKE_FUNCPTR(png_get_bit_depth
);
310 MAKE_FUNCPTR(png_get_color_type
);
311 MAKE_FUNCPTR(png_get_error_ptr
);
312 MAKE_FUNCPTR(png_get_iCCP
);
313 MAKE_FUNCPTR(png_get_image_height
);
314 MAKE_FUNCPTR(png_get_image_width
);
315 MAKE_FUNCPTR(png_get_io_ptr
);
316 MAKE_FUNCPTR(png_get_pHYs
);
317 MAKE_FUNCPTR(png_get_PLTE
);
318 MAKE_FUNCPTR(png_get_tRNS
);
319 MAKE_FUNCPTR(png_set_bgr
);
320 MAKE_FUNCPTR(png_set_crc_action
);
321 MAKE_FUNCPTR(png_set_error_fn
);
322 #ifdef HAVE_PNG_SET_EXPAND_GRAY_1_2_4_TO_8
323 MAKE_FUNCPTR(png_set_expand_gray_1_2_4_to_8
);
325 MAKE_FUNCPTR(png_set_gray_1_2_4_to_8
);
327 MAKE_FUNCPTR(png_set_filler
);
328 MAKE_FUNCPTR(png_set_filter
);
329 MAKE_FUNCPTR(png_set_gray_to_rgb
);
330 MAKE_FUNCPTR(png_set_interlace_handling
);
331 MAKE_FUNCPTR(png_set_IHDR
);
332 MAKE_FUNCPTR(png_set_pHYs
);
333 MAKE_FUNCPTR(png_set_read_fn
);
334 MAKE_FUNCPTR(png_set_strip_16
);
335 MAKE_FUNCPTR(png_set_tRNS_to_alpha
);
336 MAKE_FUNCPTR(png_set_write_fn
);
337 MAKE_FUNCPTR(png_read_end
);
338 MAKE_FUNCPTR(png_read_image
);
339 MAKE_FUNCPTR(png_read_info
);
340 MAKE_FUNCPTR(png_write_end
);
341 MAKE_FUNCPTR(png_write_info
);
342 MAKE_FUNCPTR(png_write_rows
);
345 static CRITICAL_SECTION init_png_cs
;
346 static CRITICAL_SECTION_DEBUG init_png_cs_debug
=
349 { &init_png_cs_debug
.ProcessLocksList
,
350 &init_png_cs_debug
.ProcessLocksList
},
351 0, 0, { (DWORD_PTR
)(__FILE__
": init_png_cs") }
353 static CRITICAL_SECTION init_png_cs
= { &init_png_cs_debug
, -1, 0, 0, 0, 0 };
355 static const WCHAR wszPngInterlaceOption
[] = {'I','n','t','e','r','l','a','c','e','O','p','t','i','o','n',0};
356 static const WCHAR wszPngFilterOption
[] = {'F','i','l','t','e','r','O','p','t','i','o','n',0};
358 static void *load_libpng(void)
362 EnterCriticalSection(&init_png_cs
);
364 if(!libpng_handle
&& (libpng_handle
= wine_dlopen(SONAME_LIBPNG
, RTLD_NOW
, NULL
, 0)) != NULL
) {
366 #define LOAD_FUNCPTR(f) \
367 if((p##f = wine_dlsym(libpng_handle, #f, NULL, 0)) == NULL) { \
368 libpng_handle = NULL; \
369 LeaveCriticalSection(&init_png_cs); \
372 LOAD_FUNCPTR(png_create_read_struct
);
373 LOAD_FUNCPTR(png_create_info_struct
);
374 LOAD_FUNCPTR(png_create_write_struct
);
375 LOAD_FUNCPTR(png_destroy_read_struct
);
376 LOAD_FUNCPTR(png_destroy_write_struct
);
377 LOAD_FUNCPTR(png_error
);
378 LOAD_FUNCPTR(png_get_bit_depth
);
379 LOAD_FUNCPTR(png_get_color_type
);
380 LOAD_FUNCPTR(png_get_error_ptr
);
381 LOAD_FUNCPTR(png_get_iCCP
);
382 LOAD_FUNCPTR(png_get_image_height
);
383 LOAD_FUNCPTR(png_get_image_width
);
384 LOAD_FUNCPTR(png_get_io_ptr
);
385 LOAD_FUNCPTR(png_get_pHYs
);
386 LOAD_FUNCPTR(png_get_PLTE
);
387 LOAD_FUNCPTR(png_get_tRNS
);
388 LOAD_FUNCPTR(png_set_bgr
);
389 LOAD_FUNCPTR(png_set_crc_action
);
390 LOAD_FUNCPTR(png_set_error_fn
);
391 #ifdef HAVE_PNG_SET_EXPAND_GRAY_1_2_4_TO_8
392 LOAD_FUNCPTR(png_set_expand_gray_1_2_4_to_8
);
394 LOAD_FUNCPTR(png_set_gray_1_2_4_to_8
);
396 LOAD_FUNCPTR(png_set_filler
);
397 LOAD_FUNCPTR(png_set_filter
);
398 LOAD_FUNCPTR(png_set_gray_to_rgb
);
399 LOAD_FUNCPTR(png_set_interlace_handling
);
400 LOAD_FUNCPTR(png_set_IHDR
);
401 LOAD_FUNCPTR(png_set_pHYs
);
402 LOAD_FUNCPTR(png_set_read_fn
);
403 LOAD_FUNCPTR(png_set_strip_16
);
404 LOAD_FUNCPTR(png_set_tRNS_to_alpha
);
405 LOAD_FUNCPTR(png_set_write_fn
);
406 LOAD_FUNCPTR(png_read_end
);
407 LOAD_FUNCPTR(png_read_image
);
408 LOAD_FUNCPTR(png_read_info
);
409 LOAD_FUNCPTR(png_write_end
);
410 LOAD_FUNCPTR(png_write_info
);
411 LOAD_FUNCPTR(png_write_rows
);
416 result
= libpng_handle
;
418 LeaveCriticalSection(&init_png_cs
);
423 static void user_error_fn(png_structp png_ptr
, png_const_charp error_message
)
427 /* This uses setjmp/longjmp just like the default. We can't use the
428 * default because there's no way to access the jmp buffer in the png_struct
429 * that works in 1.2 and 1.4 and allows us to dynamically load libpng. */
430 WARN("PNG error: %s\n", debugstr_a(error_message
));
431 pjmpbuf
= ppng_get_error_ptr(png_ptr
);
432 longjmp(*pjmpbuf
, 1);
435 static void user_warning_fn(png_structp png_ptr
, png_const_charp warning_message
)
437 WARN("PNG warning: %s\n", debugstr_a(warning_message
));
441 ULARGE_INTEGER ofs
, len
;
442 IWICMetadataReader
* reader
;
443 } metadata_block_info
;
446 IWICBitmapDecoder IWICBitmapDecoder_iface
;
447 IWICBitmapFrameDecode IWICBitmapFrameDecode_iface
;
448 IWICMetadataBlockReader IWICMetadataBlockReader_iface
;
458 const WICPixelFormatGUID
*format
;
460 CRITICAL_SECTION lock
; /* must be held when png structures are accessed or initialized is set */
461 ULONG metadata_count
;
462 metadata_block_info
* metadata_blocks
;
465 static inline PngDecoder
*impl_from_IWICBitmapDecoder(IWICBitmapDecoder
*iface
)
467 return CONTAINING_RECORD(iface
, PngDecoder
, IWICBitmapDecoder_iface
);
470 static inline PngDecoder
*impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode
*iface
)
472 return CONTAINING_RECORD(iface
, PngDecoder
, IWICBitmapFrameDecode_iface
);
475 static inline PngDecoder
*impl_from_IWICMetadataBlockReader(IWICMetadataBlockReader
*iface
)
477 return CONTAINING_RECORD(iface
, PngDecoder
, IWICMetadataBlockReader_iface
);
480 static const IWICBitmapFrameDecodeVtbl PngDecoder_FrameVtbl
;
482 static HRESULT WINAPI
PngDecoder_QueryInterface(IWICBitmapDecoder
*iface
, REFIID iid
,
485 PngDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
486 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
488 if (!ppv
) return E_INVALIDARG
;
490 if (IsEqualIID(&IID_IUnknown
, iid
) || IsEqualIID(&IID_IWICBitmapDecoder
, iid
))
492 *ppv
= &This
->IWICBitmapDecoder_iface
;
497 return E_NOINTERFACE
;
500 IUnknown_AddRef((IUnknown
*)*ppv
);
504 static ULONG WINAPI
PngDecoder_AddRef(IWICBitmapDecoder
*iface
)
506 PngDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
507 ULONG ref
= InterlockedIncrement(&This
->ref
);
509 TRACE("(%p) refcount=%u\n", iface
, ref
);
514 static ULONG WINAPI
PngDecoder_Release(IWICBitmapDecoder
*iface
)
516 PngDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
517 ULONG ref
= InterlockedDecrement(&This
->ref
);
520 TRACE("(%p) refcount=%u\n", iface
, ref
);
525 IStream_Release(This
->stream
);
527 ppng_destroy_read_struct(&This
->png_ptr
, &This
->info_ptr
, &This
->end_info
);
528 This
->lock
.DebugInfo
->Spare
[0] = 0;
529 DeleteCriticalSection(&This
->lock
);
530 HeapFree(GetProcessHeap(), 0, This
->image_bits
);
531 for (i
=0; i
<This
->metadata_count
; i
++)
533 if (This
->metadata_blocks
[i
].reader
)
534 IWICMetadataReader_Release(This
->metadata_blocks
[i
].reader
);
536 HeapFree(GetProcessHeap(), 0, This
->metadata_blocks
);
537 HeapFree(GetProcessHeap(), 0, This
);
543 static HRESULT WINAPI
PngDecoder_QueryCapability(IWICBitmapDecoder
*iface
, IStream
*stream
,
548 TRACE("(%p,%p,%p)\n", iface
, stream
, capability
);
550 if (!stream
|| !capability
) return E_INVALIDARG
;
552 hr
= IWICBitmapDecoder_Initialize(iface
, stream
, WICDecodeMetadataCacheOnDemand
);
553 if (hr
!= S_OK
) return hr
;
555 *capability
= WICBitmapDecoderCapabilityCanDecodeAllImages
|
556 WICBitmapDecoderCapabilityCanDecodeSomeImages
;
557 /* FIXME: WICBitmapDecoderCapabilityCanEnumerateMetadata */
561 static void user_read_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
563 IStream
*stream
= ppng_get_io_ptr(png_ptr
);
567 hr
= IStream_Read(stream
, data
, length
, &bytesread
);
568 if (FAILED(hr
) || bytesread
!= length
)
570 ppng_error(png_ptr
, "failed reading data");
574 static HRESULT WINAPI
PngDecoder_Initialize(IWICBitmapDecoder
*iface
, IStream
*pIStream
,
575 WICDecodeOptions cacheOptions
)
577 PngDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
580 png_bytep
*row_pointers
=NULL
;
583 int color_type
, bit_depth
;
586 png_uint_32 transparency
;
587 png_color_16p trans_values
;
591 ULARGE_INTEGER chunk_start
;
592 ULONG metadata_blocks_size
= 0;
594 TRACE("(%p,%p,%x)\n", iface
, pIStream
, cacheOptions
);
596 EnterCriticalSection(&This
->lock
);
598 /* initialize libpng */
599 This
->png_ptr
= ppng_create_read_struct(PNG_LIBPNG_VER_STRING
, NULL
, NULL
, NULL
);
606 This
->info_ptr
= ppng_create_info_struct(This
->png_ptr
);
609 ppng_destroy_read_struct(&This
->png_ptr
, NULL
, NULL
);
610 This
->png_ptr
= NULL
;
615 This
->end_info
= ppng_create_info_struct(This
->png_ptr
);
618 ppng_destroy_read_struct(&This
->png_ptr
, &This
->info_ptr
, NULL
);
619 This
->png_ptr
= NULL
;
624 /* set up setjmp/longjmp error handling */
627 ppng_destroy_read_struct(&This
->png_ptr
, &This
->info_ptr
, &This
->end_info
);
628 HeapFree(GetProcessHeap(), 0, row_pointers
);
629 This
->png_ptr
= NULL
;
633 ppng_set_error_fn(This
->png_ptr
, jmpbuf
, user_error_fn
, user_warning_fn
);
634 ppng_set_crc_action(This
->png_ptr
, PNG_CRC_QUIET_USE
, PNG_CRC_QUIET_USE
);
636 /* seek to the start of the stream */
638 hr
= IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
);
639 if (FAILED(hr
)) goto end
;
641 /* set up custom i/o handling */
642 ppng_set_read_fn(This
->png_ptr
, pIStream
, user_read_data
);
644 /* read the header */
645 ppng_read_info(This
->png_ptr
, This
->info_ptr
);
647 /* choose a pixel format */
648 color_type
= ppng_get_color_type(This
->png_ptr
, This
->info_ptr
);
649 bit_depth
= ppng_get_bit_depth(This
->png_ptr
, This
->info_ptr
);
651 /* check for color-keyed alpha */
652 transparency
= ppng_get_tRNS(This
->png_ptr
, This
->info_ptr
, &trans
, &num_trans
, &trans_values
);
654 if (transparency
&& color_type
!= PNG_COLOR_TYPE_PALETTE
)
657 if (color_type
== PNG_COLOR_TYPE_GRAY
)
661 #ifdef HAVE_PNG_SET_EXPAND_GRAY_1_2_4_TO_8
662 ppng_set_expand_gray_1_2_4_to_8(This
->png_ptr
);
664 ppng_set_gray_1_2_4_to_8(This
->png_ptr
);
668 ppng_set_gray_to_rgb(This
->png_ptr
);
670 ppng_set_tRNS_to_alpha(This
->png_ptr
);
671 color_type
= PNG_COLOR_TYPE_RGB_ALPHA
;
676 case PNG_COLOR_TYPE_GRAY
:
677 This
->bpp
= bit_depth
;
680 case 1: This
->format
= &GUID_WICPixelFormatBlackWhite
; break;
681 case 2: This
->format
= &GUID_WICPixelFormat2bppGray
; break;
682 case 4: This
->format
= &GUID_WICPixelFormat4bppGray
; break;
683 case 8: This
->format
= &GUID_WICPixelFormat8bppGray
; break;
684 case 16: This
->format
= &GUID_WICPixelFormat16bppGray
; break;
686 ERR("invalid grayscale bit depth: %i\n", bit_depth
);
691 case PNG_COLOR_TYPE_GRAY_ALPHA
:
692 /* WIC does not support grayscale alpha formats so use RGBA */
693 ppng_set_gray_to_rgb(This
->png_ptr
);
695 case PNG_COLOR_TYPE_RGB_ALPHA
:
696 This
->bpp
= bit_depth
* 4;
700 ppng_set_bgr(This
->png_ptr
);
701 This
->format
= &GUID_WICPixelFormat32bppBGRA
;
703 case 16: This
->format
= &GUID_WICPixelFormat64bppRGBA
; break;
705 ERR("invalid RGBA bit depth: %i\n", bit_depth
);
710 case PNG_COLOR_TYPE_PALETTE
:
711 This
->bpp
= bit_depth
;
714 case 1: This
->format
= &GUID_WICPixelFormat1bppIndexed
; break;
715 case 2: This
->format
= &GUID_WICPixelFormat2bppIndexed
; break;
716 case 4: This
->format
= &GUID_WICPixelFormat4bppIndexed
; break;
717 case 8: This
->format
= &GUID_WICPixelFormat8bppIndexed
; break;
719 ERR("invalid indexed color bit depth: %i\n", bit_depth
);
724 case PNG_COLOR_TYPE_RGB
:
725 This
->bpp
= bit_depth
* 3;
729 ppng_set_bgr(This
->png_ptr
);
730 This
->format
= &GUID_WICPixelFormat24bppBGR
;
732 case 16: This
->format
= &GUID_WICPixelFormat48bppRGB
; break;
734 ERR("invalid RGB color bit depth: %i\n", bit_depth
);
740 ERR("invalid color type %i\n", color_type
);
745 /* read the image data */
746 This
->width
= ppng_get_image_width(This
->png_ptr
, This
->info_ptr
);
747 This
->height
= ppng_get_image_height(This
->png_ptr
, This
->info_ptr
);
748 This
->stride
= (This
->width
* This
->bpp
+ 7) / 8;
749 image_size
= This
->stride
* This
->height
;
751 This
->image_bits
= HeapAlloc(GetProcessHeap(), 0, image_size
);
752 if (!This
->image_bits
)
758 row_pointers
= HeapAlloc(GetProcessHeap(), 0, sizeof(png_bytep
)*This
->height
);
765 for (i
=0; i
<This
->height
; i
++)
766 row_pointers
[i
] = This
->image_bits
+ i
* This
->stride
;
768 ppng_read_image(This
->png_ptr
, row_pointers
);
770 HeapFree(GetProcessHeap(), 0, row_pointers
);
773 ppng_read_end(This
->png_ptr
, This
->end_info
);
775 /* Find the metadata chunks in the file. */
777 hr
= IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, &chunk_start
);
778 if (FAILED(hr
)) goto end
;
782 hr
= read_png_chunk(pIStream
, chunk_type
, NULL
, &chunk_size
);
783 if (FAILED(hr
)) goto end
;
785 if (chunk_type
[0] >= 'a' && chunk_type
[0] <= 'z' &&
786 memcmp(chunk_type
, "tRNS", 4) && memcmp(chunk_type
, "pHYs", 4))
788 /* This chunk is considered metadata. */
789 if (This
->metadata_count
== metadata_blocks_size
)
791 metadata_block_info
* new_metadata_blocks
;
792 ULONG new_metadata_blocks_size
;
794 new_metadata_blocks_size
= 4 + metadata_blocks_size
* 2;
795 new_metadata_blocks
= HeapAlloc(GetProcessHeap(), 0,
796 new_metadata_blocks_size
* sizeof(*new_metadata_blocks
));
798 if (!new_metadata_blocks
)
804 memcpy(new_metadata_blocks
, This
->metadata_blocks
,
805 This
->metadata_count
* sizeof(*new_metadata_blocks
));
807 HeapFree(GetProcessHeap(), 0, This
->metadata_blocks
);
808 This
->metadata_blocks
= new_metadata_blocks
;
809 metadata_blocks_size
= new_metadata_blocks_size
;
812 This
->metadata_blocks
[This
->metadata_count
].ofs
= chunk_start
;
813 This
->metadata_blocks
[This
->metadata_count
].len
.QuadPart
= chunk_size
+ 12;
814 This
->metadata_blocks
[This
->metadata_count
].reader
= NULL
;
815 This
->metadata_count
++;
818 seek
.QuadPart
= chunk_start
.QuadPart
+ chunk_size
+ 12; /* skip data and CRC */
819 hr
= IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, &chunk_start
);
820 if (FAILED(hr
)) goto end
;
821 } while (memcmp(chunk_type
, "IEND", 4));
823 This
->stream
= pIStream
;
824 IStream_AddRef(This
->stream
);
826 This
->initialized
= TRUE
;
829 LeaveCriticalSection(&This
->lock
);
834 static HRESULT WINAPI
PngDecoder_GetContainerFormat(IWICBitmapDecoder
*iface
,
835 GUID
*pguidContainerFormat
)
837 memcpy(pguidContainerFormat
, &GUID_ContainerFormatPng
, sizeof(GUID
));
841 static HRESULT WINAPI
PngDecoder_GetDecoderInfo(IWICBitmapDecoder
*iface
,
842 IWICBitmapDecoderInfo
**ppIDecoderInfo
)
845 IWICComponentInfo
*compinfo
;
847 TRACE("(%p,%p)\n", iface
, ppIDecoderInfo
);
849 hr
= CreateComponentInfo(&CLSID_WICPngDecoder
, &compinfo
);
850 if (FAILED(hr
)) return hr
;
852 hr
= IWICComponentInfo_QueryInterface(compinfo
, &IID_IWICBitmapDecoderInfo
,
853 (void**)ppIDecoderInfo
);
855 IWICComponentInfo_Release(compinfo
);
860 static HRESULT WINAPI
PngDecoder_CopyPalette(IWICBitmapDecoder
*iface
,
861 IWICPalette
*pIPalette
)
863 FIXME("(%p,%p): stub\n", iface
, pIPalette
);
867 static HRESULT WINAPI
PngDecoder_GetMetadataQueryReader(IWICBitmapDecoder
*iface
,
868 IWICMetadataQueryReader
**ppIMetadataQueryReader
)
870 FIXME("(%p,%p): stub\n", iface
, ppIMetadataQueryReader
);
874 static HRESULT WINAPI
PngDecoder_GetPreview(IWICBitmapDecoder
*iface
,
875 IWICBitmapSource
**ppIBitmapSource
)
877 TRACE("(%p,%p)\n", iface
, ppIBitmapSource
);
879 if (!ppIBitmapSource
) return E_INVALIDARG
;
881 *ppIBitmapSource
= NULL
;
882 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
885 static HRESULT WINAPI
PngDecoder_GetColorContexts(IWICBitmapDecoder
*iface
,
886 UINT cCount
, IWICColorContext
**ppIColorContexts
, UINT
*pcActualCount
)
888 TRACE("(%p,%u,%p,%p)\n", iface
, cCount
, ppIColorContexts
, pcActualCount
);
889 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
892 static HRESULT WINAPI
PngDecoder_GetThumbnail(IWICBitmapDecoder
*iface
,
893 IWICBitmapSource
**ppIThumbnail
)
895 TRACE("(%p,%p)\n", iface
, ppIThumbnail
);
897 if (!ppIThumbnail
) return E_INVALIDARG
;
899 *ppIThumbnail
= NULL
;
900 return WINCODEC_ERR_CODECNOTHUMBNAIL
;
903 static HRESULT WINAPI
PngDecoder_GetFrameCount(IWICBitmapDecoder
*iface
,
906 if (!pCount
) return E_INVALIDARG
;
912 static HRESULT WINAPI
PngDecoder_GetFrame(IWICBitmapDecoder
*iface
,
913 UINT index
, IWICBitmapFrameDecode
**ppIBitmapFrame
)
915 PngDecoder
*This
= impl_from_IWICBitmapDecoder(iface
);
916 TRACE("(%p,%u,%p)\n", iface
, index
, ppIBitmapFrame
);
918 if (!This
->initialized
) return WINCODEC_ERR_FRAMEMISSING
;
920 if (index
!= 0) return E_INVALIDARG
;
922 IWICBitmapDecoder_AddRef(iface
);
924 *ppIBitmapFrame
= &This
->IWICBitmapFrameDecode_iface
;
929 static const IWICBitmapDecoderVtbl PngDecoder_Vtbl
= {
930 PngDecoder_QueryInterface
,
933 PngDecoder_QueryCapability
,
934 PngDecoder_Initialize
,
935 PngDecoder_GetContainerFormat
,
936 PngDecoder_GetDecoderInfo
,
937 PngDecoder_CopyPalette
,
938 PngDecoder_GetMetadataQueryReader
,
939 PngDecoder_GetPreview
,
940 PngDecoder_GetColorContexts
,
941 PngDecoder_GetThumbnail
,
942 PngDecoder_GetFrameCount
,
946 static HRESULT WINAPI
PngDecoder_Frame_QueryInterface(IWICBitmapFrameDecode
*iface
, REFIID iid
,
949 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
950 if (!ppv
) return E_INVALIDARG
;
952 if (IsEqualIID(&IID_IUnknown
, iid
) ||
953 IsEqualIID(&IID_IWICBitmapSource
, iid
) ||
954 IsEqualIID(&IID_IWICBitmapFrameDecode
, iid
))
956 *ppv
= &This
->IWICBitmapFrameDecode_iface
;
958 else if (IsEqualIID(&IID_IWICMetadataBlockReader
, iid
))
960 *ppv
= &This
->IWICMetadataBlockReader_iface
;
965 return E_NOINTERFACE
;
968 IUnknown_AddRef((IUnknown
*)*ppv
);
972 static ULONG WINAPI
PngDecoder_Frame_AddRef(IWICBitmapFrameDecode
*iface
)
974 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
975 return IWICBitmapDecoder_AddRef(&This
->IWICBitmapDecoder_iface
);
978 static ULONG WINAPI
PngDecoder_Frame_Release(IWICBitmapFrameDecode
*iface
)
980 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
981 return IWICBitmapDecoder_Release(&This
->IWICBitmapDecoder_iface
);
984 static HRESULT WINAPI
PngDecoder_Frame_GetSize(IWICBitmapFrameDecode
*iface
,
985 UINT
*puiWidth
, UINT
*puiHeight
)
987 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
988 *puiWidth
= This
->width
;
989 *puiHeight
= This
->height
;
990 TRACE("(%p)->(%u,%u)\n", iface
, *puiWidth
, *puiHeight
);
994 static HRESULT WINAPI
PngDecoder_Frame_GetPixelFormat(IWICBitmapFrameDecode
*iface
,
995 WICPixelFormatGUID
*pPixelFormat
)
997 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
998 TRACE("(%p,%p)\n", iface
, pPixelFormat
);
1000 memcpy(pPixelFormat
, This
->format
, sizeof(GUID
));
1005 static HRESULT WINAPI
PngDecoder_Frame_GetResolution(IWICBitmapFrameDecode
*iface
,
1006 double *pDpiX
, double *pDpiY
)
1008 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
1009 png_uint_32 ret
, xres
, yres
;
1012 EnterCriticalSection(&This
->lock
);
1014 ret
= ppng_get_pHYs(This
->png_ptr
, This
->info_ptr
, &xres
, &yres
, &unit_type
);
1016 if (ret
&& unit_type
== PNG_RESOLUTION_METER
)
1018 *pDpiX
= xres
* 0.0254;
1019 *pDpiY
= yres
* 0.0254;
1023 WARN("no pHYs block present\n");
1024 *pDpiX
= *pDpiY
= 96.0;
1027 LeaveCriticalSection(&This
->lock
);
1029 TRACE("(%p)->(%0.2f,%0.2f)\n", iface
, *pDpiX
, *pDpiY
);
1034 static HRESULT WINAPI
PngDecoder_Frame_CopyPalette(IWICBitmapFrameDecode
*iface
,
1035 IWICPalette
*pIPalette
)
1037 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
1039 png_colorp png_palette
;
1041 WICColor palette
[256];
1042 png_bytep trans_alpha
;
1044 png_color_16p trans_values
;
1048 TRACE("(%p,%p)\n", iface
, pIPalette
);
1050 EnterCriticalSection(&This
->lock
);
1052 ret
= ppng_get_PLTE(This
->png_ptr
, This
->info_ptr
, &png_palette
, &num_palette
);
1055 hr
= WINCODEC_ERR_PALETTEUNAVAILABLE
;
1059 if (num_palette
> 256)
1061 ERR("palette has %i colors?!\n", num_palette
);
1066 ret
= ppng_get_tRNS(This
->png_ptr
, This
->info_ptr
, &trans_alpha
, &num_trans
, &trans_values
);
1067 if (!ret
) num_trans
= 0;
1069 for (i
=0; i
<num_palette
; i
++)
1071 BYTE alpha
= (i
< num_trans
) ? trans_alpha
[i
] : 0xff;
1072 palette
[i
] = (alpha
<< 24 |
1073 png_palette
[i
].red
<< 16|
1074 png_palette
[i
].green
<< 8|
1075 png_palette
[i
].blue
);
1080 LeaveCriticalSection(&This
->lock
);
1083 hr
= IWICPalette_InitializeCustom(pIPalette
, palette
, num_palette
);
1088 static HRESULT WINAPI
PngDecoder_Frame_CopyPixels(IWICBitmapFrameDecode
*iface
,
1089 const WICRect
*prc
, UINT cbStride
, UINT cbBufferSize
, BYTE
*pbBuffer
)
1091 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
1092 TRACE("(%p,%p,%u,%u,%p)\n", iface
, prc
, cbStride
, cbBufferSize
, pbBuffer
);
1094 return copy_pixels(This
->bpp
, This
->image_bits
,
1095 This
->width
, This
->height
, This
->stride
,
1096 prc
, cbStride
, cbBufferSize
, pbBuffer
);
1099 static HRESULT WINAPI
PngDecoder_Frame_GetMetadataQueryReader(IWICBitmapFrameDecode
*iface
,
1100 IWICMetadataQueryReader
**ppIMetadataQueryReader
)
1102 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
1104 TRACE("(%p,%p)\n", iface
, ppIMetadataQueryReader
);
1106 if (!ppIMetadataQueryReader
)
1107 return E_INVALIDARG
;
1109 return MetadataQueryReader_CreateInstance(&This
->IWICMetadataBlockReader_iface
, ppIMetadataQueryReader
);
1112 static HRESULT WINAPI
PngDecoder_Frame_GetColorContexts(IWICBitmapFrameDecode
*iface
,
1113 UINT cCount
, IWICColorContext
**ppIColorContexts
, UINT
*pcActualCount
)
1115 PngDecoder
*This
= impl_from_IWICBitmapFrameDecode(iface
);
1119 int compression_type
;
1122 TRACE("(%p,%u,%p,%p)\n", iface
, cCount
, ppIColorContexts
, pcActualCount
);
1124 if (!pcActualCount
) return E_INVALIDARG
;
1126 EnterCriticalSection(&This
->lock
);
1128 if (ppng_get_iCCP(This
->png_ptr
, This
->info_ptr
, &name
, &compression_type
, (void *)&profile
, &len
))
1130 if (cCount
&& ppIColorContexts
)
1132 hr
= IWICColorContext_InitializeFromMemory(*ppIColorContexts
, profile
, len
);
1135 LeaveCriticalSection(&This
->lock
);
1144 LeaveCriticalSection(&This
->lock
);
1149 static HRESULT WINAPI
PngDecoder_Frame_GetThumbnail(IWICBitmapFrameDecode
*iface
,
1150 IWICBitmapSource
**ppIThumbnail
)
1152 TRACE("(%p,%p)\n", iface
, ppIThumbnail
);
1154 if (!ppIThumbnail
) return E_INVALIDARG
;
1156 *ppIThumbnail
= NULL
;
1157 return WINCODEC_ERR_CODECNOTHUMBNAIL
;
1160 static const IWICBitmapFrameDecodeVtbl PngDecoder_FrameVtbl
= {
1161 PngDecoder_Frame_QueryInterface
,
1162 PngDecoder_Frame_AddRef
,
1163 PngDecoder_Frame_Release
,
1164 PngDecoder_Frame_GetSize
,
1165 PngDecoder_Frame_GetPixelFormat
,
1166 PngDecoder_Frame_GetResolution
,
1167 PngDecoder_Frame_CopyPalette
,
1168 PngDecoder_Frame_CopyPixels
,
1169 PngDecoder_Frame_GetMetadataQueryReader
,
1170 PngDecoder_Frame_GetColorContexts
,
1171 PngDecoder_Frame_GetThumbnail
1174 static HRESULT WINAPI
PngDecoder_Block_QueryInterface(IWICMetadataBlockReader
*iface
, REFIID iid
,
1177 PngDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1178 return IWICBitmapFrameDecode_QueryInterface(&This
->IWICBitmapFrameDecode_iface
, iid
, ppv
);
1181 static ULONG WINAPI
PngDecoder_Block_AddRef(IWICMetadataBlockReader
*iface
)
1183 PngDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1184 return IWICBitmapDecoder_AddRef(&This
->IWICBitmapDecoder_iface
);
1187 static ULONG WINAPI
PngDecoder_Block_Release(IWICMetadataBlockReader
*iface
)
1189 PngDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1190 return IWICBitmapDecoder_Release(&This
->IWICBitmapDecoder_iface
);
1193 static HRESULT WINAPI
PngDecoder_Block_GetContainerFormat(IWICMetadataBlockReader
*iface
,
1194 GUID
*pguidContainerFormat
)
1196 if (!pguidContainerFormat
) return E_INVALIDARG
;
1197 memcpy(pguidContainerFormat
, &GUID_ContainerFormatPng
, sizeof(GUID
));
1201 static HRESULT WINAPI
PngDecoder_Block_GetCount(IWICMetadataBlockReader
*iface
,
1204 PngDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1206 TRACE("%p,%p\n", iface
, pcCount
);
1208 if (!pcCount
) return E_INVALIDARG
;
1210 *pcCount
= This
->metadata_count
;
1215 static HRESULT WINAPI
PngDecoder_Block_GetReaderByIndex(IWICMetadataBlockReader
*iface
,
1216 UINT nIndex
, IWICMetadataReader
**ppIMetadataReader
)
1218 PngDecoder
*This
= impl_from_IWICMetadataBlockReader(iface
);
1220 IWICComponentFactory
* factory
;
1223 TRACE("%p,%d,%p\n", iface
, nIndex
, ppIMetadataReader
);
1225 if (nIndex
>= This
->metadata_count
|| !ppIMetadataReader
)
1226 return E_INVALIDARG
;
1228 if (!This
->metadata_blocks
[nIndex
].reader
)
1230 hr
= StreamImpl_Create(&stream
);
1234 hr
= IWICStream_InitializeFromIStreamRegion(stream
, This
->stream
,
1235 This
->metadata_blocks
[nIndex
].ofs
, This
->metadata_blocks
[nIndex
].len
);
1238 hr
= ComponentFactory_CreateInstance(&IID_IWICComponentFactory
, (void**)&factory
);
1242 hr
= IWICComponentFactory_CreateMetadataReaderFromContainer(factory
,
1243 &GUID_ContainerFormatPng
, NULL
, WICMetadataCreationAllowUnknown
,
1244 (IStream
*)stream
, &This
->metadata_blocks
[nIndex
].reader
);
1246 IWICComponentFactory_Release(factory
);
1249 IWICStream_Release(stream
);
1254 *ppIMetadataReader
= NULL
;
1259 *ppIMetadataReader
= This
->metadata_blocks
[nIndex
].reader
;
1260 IWICMetadataReader_AddRef(*ppIMetadataReader
);
1265 static HRESULT WINAPI
PngDecoder_Block_GetEnumerator(IWICMetadataBlockReader
*iface
,
1266 IEnumUnknown
**ppIEnumMetadata
)
1268 FIXME("%p,%p\n", iface
, ppIEnumMetadata
);
1272 static const IWICMetadataBlockReaderVtbl PngDecoder_BlockVtbl
= {
1273 PngDecoder_Block_QueryInterface
,
1274 PngDecoder_Block_AddRef
,
1275 PngDecoder_Block_Release
,
1276 PngDecoder_Block_GetContainerFormat
,
1277 PngDecoder_Block_GetCount
,
1278 PngDecoder_Block_GetReaderByIndex
,
1279 PngDecoder_Block_GetEnumerator
,
1282 HRESULT
PngDecoder_CreateInstance(REFIID iid
, void** ppv
)
1287 TRACE("(%s,%p)\n", debugstr_guid(iid
), ppv
);
1293 ERR("Failed reading PNG because unable to find %s\n",SONAME_LIBPNG
);
1297 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(PngDecoder
));
1298 if (!This
) return E_OUTOFMEMORY
;
1300 This
->IWICBitmapDecoder_iface
.lpVtbl
= &PngDecoder_Vtbl
;
1301 This
->IWICBitmapFrameDecode_iface
.lpVtbl
= &PngDecoder_FrameVtbl
;
1302 This
->IWICMetadataBlockReader_iface
.lpVtbl
= &PngDecoder_BlockVtbl
;
1304 This
->png_ptr
= NULL
;
1305 This
->info_ptr
= NULL
;
1306 This
->end_info
= NULL
;
1307 This
->stream
= NULL
;
1308 This
->initialized
= FALSE
;
1309 This
->image_bits
= NULL
;
1310 InitializeCriticalSection(&This
->lock
);
1311 This
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": PngDecoder.lock");
1312 This
->metadata_count
= 0;
1313 This
->metadata_blocks
= NULL
;
1315 ret
= IWICBitmapDecoder_QueryInterface(&This
->IWICBitmapDecoder_iface
, iid
, ppv
);
1316 IWICBitmapDecoder_Release(&This
->IWICBitmapDecoder_iface
);
1321 struct png_pixelformat
{
1322 const WICPixelFormatGUID
*guid
;
1330 static const struct png_pixelformat formats
[] = {
1331 {&GUID_WICPixelFormat24bppBGR
, 24, 8, PNG_COLOR_TYPE_RGB
, 0, 1},
1332 {&GUID_WICPixelFormatBlackWhite
, 1, 1, PNG_COLOR_TYPE_GRAY
, 0, 0},
1333 {&GUID_WICPixelFormat2bppGray
, 2, 2, PNG_COLOR_TYPE_GRAY
, 0, 0},
1334 {&GUID_WICPixelFormat4bppGray
, 4, 4, PNG_COLOR_TYPE_GRAY
, 0, 0},
1335 {&GUID_WICPixelFormat8bppGray
, 8, 8, PNG_COLOR_TYPE_GRAY
, 0, 0},
1336 {&GUID_WICPixelFormat16bppGray
, 16, 16, PNG_COLOR_TYPE_GRAY
, 0, 0},
1337 {&GUID_WICPixelFormat32bppBGR
, 32, 8, PNG_COLOR_TYPE_RGB
, 1, 1},
1338 {&GUID_WICPixelFormat32bppBGRA
, 32, 8, PNG_COLOR_TYPE_RGB_ALPHA
, 0, 1},
1339 {&GUID_WICPixelFormat48bppRGB
, 48, 16, PNG_COLOR_TYPE_RGB
, 0, 0},
1340 {&GUID_WICPixelFormat64bppRGBA
, 64, 16, PNG_COLOR_TYPE_RGB_ALPHA
, 0, 0},
1344 typedef struct PngEncoder
{
1345 IWICBitmapEncoder IWICBitmapEncoder_iface
;
1346 IWICBitmapFrameEncode IWICBitmapFrameEncode_iface
;
1349 png_structp png_ptr
;
1352 BOOL frame_initialized
;
1353 const struct png_pixelformat
*format
;
1358 BOOL frame_committed
;
1360 CRITICAL_SECTION lock
;
1362 WICPngFilterOption filter
;
1368 static inline PngEncoder
*impl_from_IWICBitmapEncoder(IWICBitmapEncoder
*iface
)
1370 return CONTAINING_RECORD(iface
, PngEncoder
, IWICBitmapEncoder_iface
);
1373 static inline PngEncoder
*impl_from_IWICBitmapFrameEncode(IWICBitmapFrameEncode
*iface
)
1375 return CONTAINING_RECORD(iface
, PngEncoder
, IWICBitmapFrameEncode_iface
);
1378 static HRESULT WINAPI
PngFrameEncode_QueryInterface(IWICBitmapFrameEncode
*iface
, REFIID iid
,
1381 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1382 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
1384 if (!ppv
) return E_INVALIDARG
;
1386 if (IsEqualIID(&IID_IUnknown
, iid
) ||
1387 IsEqualIID(&IID_IWICBitmapFrameEncode
, iid
))
1389 *ppv
= &This
->IWICBitmapFrameEncode_iface
;
1394 return E_NOINTERFACE
;
1397 IUnknown_AddRef((IUnknown
*)*ppv
);
1401 static ULONG WINAPI
PngFrameEncode_AddRef(IWICBitmapFrameEncode
*iface
)
1403 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1404 return IWICBitmapEncoder_AddRef(&This
->IWICBitmapEncoder_iface
);
1407 static ULONG WINAPI
PngFrameEncode_Release(IWICBitmapFrameEncode
*iface
)
1409 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1410 return IWICBitmapEncoder_Release(&This
->IWICBitmapEncoder_iface
);
1413 static HRESULT WINAPI
PngFrameEncode_Initialize(IWICBitmapFrameEncode
*iface
,
1414 IPropertyBag2
*pIEncoderOptions
)
1416 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1417 WICPngFilterOption filter
;
1419 PROPBAG2 opts
[2]= {{0}};
1420 VARIANT opt_values
[2];
1421 HRESULT opt_hres
[2];
1424 TRACE("(%p,%p)\n", iface
, pIEncoderOptions
);
1426 opts
[0].pstrName
= (LPOLESTR
)wszPngInterlaceOption
;
1427 opts
[0].vt
= VT_BOOL
;
1428 opts
[1].pstrName
= (LPOLESTR
)wszPngFilterOption
;
1429 opts
[1].vt
= VT_UI1
;
1431 if (pIEncoderOptions
)
1433 hr
= IPropertyBag2_Read(pIEncoderOptions
, sizeof(opts
)/sizeof(opts
[0]), opts
, NULL
, opt_values
, opt_hres
);
1438 if (V_VT(&opt_values
[0]) == VT_EMPTY
)
1441 interlace
= (V_BOOL(&opt_values
[0]) != 0);
1443 filter
= V_UI1(&opt_values
[1]);
1444 if (filter
> WICPngFilterAdaptive
)
1446 WARN("Unrecognized filter option value %u.\n", filter
);
1447 filter
= WICPngFilterUnspecified
;
1453 filter
= WICPngFilterUnspecified
;
1456 EnterCriticalSection(&This
->lock
);
1458 if (This
->frame_initialized
)
1460 LeaveCriticalSection(&This
->lock
);
1461 return WINCODEC_ERR_WRONGSTATE
;
1464 This
->interlace
= interlace
;
1465 This
->filter
= filter
;
1467 This
->frame_initialized
= TRUE
;
1469 LeaveCriticalSection(&This
->lock
);
1474 static HRESULT WINAPI
PngFrameEncode_SetSize(IWICBitmapFrameEncode
*iface
,
1475 UINT uiWidth
, UINT uiHeight
)
1477 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1478 TRACE("(%p,%u,%u)\n", iface
, uiWidth
, uiHeight
);
1480 EnterCriticalSection(&This
->lock
);
1482 if (!This
->frame_initialized
|| This
->info_written
)
1484 LeaveCriticalSection(&This
->lock
);
1485 return WINCODEC_ERR_WRONGSTATE
;
1488 This
->width
= uiWidth
;
1489 This
->height
= uiHeight
;
1491 LeaveCriticalSection(&This
->lock
);
1496 static HRESULT WINAPI
PngFrameEncode_SetResolution(IWICBitmapFrameEncode
*iface
,
1497 double dpiX
, double dpiY
)
1499 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1500 TRACE("(%p,%0.2f,%0.2f)\n", iface
, dpiX
, dpiY
);
1502 EnterCriticalSection(&This
->lock
);
1504 if (!This
->frame_initialized
|| This
->info_written
)
1506 LeaveCriticalSection(&This
->lock
);
1507 return WINCODEC_ERR_WRONGSTATE
;
1513 LeaveCriticalSection(&This
->lock
);
1518 static HRESULT WINAPI
PngFrameEncode_SetPixelFormat(IWICBitmapFrameEncode
*iface
,
1519 WICPixelFormatGUID
*pPixelFormat
)
1521 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1523 TRACE("(%p,%s)\n", iface
, debugstr_guid(pPixelFormat
));
1525 EnterCriticalSection(&This
->lock
);
1527 if (!This
->frame_initialized
|| This
->info_written
)
1529 LeaveCriticalSection(&This
->lock
);
1530 return WINCODEC_ERR_WRONGSTATE
;
1533 for (i
=0; formats
[i
].guid
; i
++)
1535 if (memcmp(formats
[i
].guid
, pPixelFormat
, sizeof(GUID
)) == 0)
1539 if (!formats
[i
].guid
) i
= 0;
1541 This
->format
= &formats
[i
];
1542 memcpy(pPixelFormat
, This
->format
->guid
, sizeof(GUID
));
1544 LeaveCriticalSection(&This
->lock
);
1549 static HRESULT WINAPI
PngFrameEncode_SetColorContexts(IWICBitmapFrameEncode
*iface
,
1550 UINT cCount
, IWICColorContext
**ppIColorContext
)
1552 FIXME("(%p,%u,%p): stub\n", iface
, cCount
, ppIColorContext
);
1556 static HRESULT WINAPI
PngFrameEncode_SetPalette(IWICBitmapFrameEncode
*iface
,
1557 IWICPalette
*pIPalette
)
1559 FIXME("(%p,%p): stub\n", iface
, pIPalette
);
1560 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
1563 static HRESULT WINAPI
PngFrameEncode_SetThumbnail(IWICBitmapFrameEncode
*iface
,
1564 IWICBitmapSource
*pIThumbnail
)
1566 FIXME("(%p,%p): stub\n", iface
, pIThumbnail
);
1567 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
1570 static HRESULT WINAPI
PngFrameEncode_WritePixels(IWICBitmapFrameEncode
*iface
,
1571 UINT lineCount
, UINT cbStride
, UINT cbBufferSize
, BYTE
*pbPixels
)
1573 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1574 png_byte
**row_pointers
=NULL
;
1577 TRACE("(%p,%u,%u,%u,%p)\n", iface
, lineCount
, cbStride
, cbBufferSize
, pbPixels
);
1579 EnterCriticalSection(&This
->lock
);
1581 if (!This
->frame_initialized
|| !This
->width
|| !This
->height
|| !This
->format
)
1583 LeaveCriticalSection(&This
->lock
);
1584 return WINCODEC_ERR_WRONGSTATE
;
1587 if (lineCount
== 0 || lineCount
+ This
->lines_written
> This
->height
)
1589 LeaveCriticalSection(&This
->lock
);
1590 return E_INVALIDARG
;
1593 /* set up setjmp/longjmp error handling */
1596 LeaveCriticalSection(&This
->lock
);
1597 HeapFree(GetProcessHeap(), 0, row_pointers
);
1600 ppng_set_error_fn(This
->png_ptr
, jmpbuf
, user_error_fn
, user_warning_fn
);
1602 if (!This
->info_written
)
1604 if (This
->interlace
)
1606 /* libpng requires us to write all data multiple times in this case. */
1607 This
->stride
= (This
->format
->bpp
* This
->width
+ 7)/8;
1608 This
->data
= HeapAlloc(GetProcessHeap(), 0, This
->height
* This
->stride
);
1611 LeaveCriticalSection(&This
->lock
);
1612 return E_OUTOFMEMORY
;
1616 ppng_set_IHDR(This
->png_ptr
, This
->info_ptr
, This
->width
, This
->height
,
1617 This
->format
->bit_depth
, This
->format
->color_type
,
1618 This
->interlace
? PNG_INTERLACE_ADAM7
: PNG_INTERLACE_NONE
,
1619 PNG_COMPRESSION_TYPE_DEFAULT
, PNG_FILTER_TYPE_DEFAULT
);
1621 if (This
->xres
!= 0.0 && This
->yres
!= 0.0)
1623 ppng_set_pHYs(This
->png_ptr
, This
->info_ptr
, (This
->xres
+0.0127) / 0.0254,
1624 (This
->yres
+0.0127) / 0.0254, PNG_RESOLUTION_METER
);
1627 ppng_write_info(This
->png_ptr
, This
->info_ptr
);
1629 if (This
->format
->remove_filler
)
1630 ppng_set_filler(This
->png_ptr
, 0, PNG_FILLER_AFTER
);
1632 if (This
->format
->swap_rgb
)
1633 ppng_set_bgr(This
->png_ptr
);
1635 if (This
->interlace
)
1636 This
->passes
= ppng_set_interlace_handling(This
->png_ptr
);
1638 if (This
->filter
!= WICPngFilterUnspecified
)
1640 static const int png_filter_map
[] =
1642 /* WICPngFilterUnspecified */ PNG_NO_FILTERS
,
1643 /* WICPngFilterNone */ PNG_FILTER_NONE
,
1644 /* WICPngFilterSub */ PNG_FILTER_SUB
,
1645 /* WICPngFilterUp */ PNG_FILTER_UP
,
1646 /* WICPngFilterAverage */ PNG_FILTER_AVG
,
1647 /* WICPngFilterPaeth */ PNG_FILTER_PAETH
,
1648 /* WICPngFilterAdaptive */ PNG_ALL_FILTERS
,
1651 ppng_set_filter(This
->png_ptr
, 0, png_filter_map
[This
->filter
]);
1654 This
->info_written
= TRUE
;
1657 if (This
->interlace
)
1659 /* Just store the data so we can write it in multiple passes in Commit. */
1660 for (i
=0; i
<lineCount
; i
++)
1661 memcpy(This
->data
+ This
->stride
* (This
->lines_written
+ i
),
1662 pbPixels
+ cbStride
* i
,
1665 This
->lines_written
+= lineCount
;
1667 LeaveCriticalSection(&This
->lock
);
1671 row_pointers
= HeapAlloc(GetProcessHeap(), 0, lineCount
* sizeof(png_byte
*));
1674 LeaveCriticalSection(&This
->lock
);
1675 return E_OUTOFMEMORY
;
1678 for (i
=0; i
<lineCount
; i
++)
1679 row_pointers
[i
] = pbPixels
+ cbStride
* i
;
1681 ppng_write_rows(This
->png_ptr
, row_pointers
, lineCount
);
1682 This
->lines_written
+= lineCount
;
1684 LeaveCriticalSection(&This
->lock
);
1686 HeapFree(GetProcessHeap(), 0, row_pointers
);
1691 static HRESULT WINAPI
PngFrameEncode_WriteSource(IWICBitmapFrameEncode
*iface
,
1692 IWICBitmapSource
*pIBitmapSource
, WICRect
*prc
)
1694 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1696 TRACE("(%p,%p,%p)\n", iface
, pIBitmapSource
, prc
);
1698 if (!This
->frame_initialized
)
1699 return WINCODEC_ERR_WRONGSTATE
;
1701 hr
= configure_write_source(iface
, pIBitmapSource
, prc
,
1702 This
->format
? This
->format
->guid
: NULL
, This
->width
, This
->height
,
1703 This
->xres
, This
->yres
);
1707 hr
= write_source(iface
, pIBitmapSource
, prc
,
1708 This
->format
->guid
, This
->format
->bpp
, This
->width
, This
->height
);
1714 static HRESULT WINAPI
PngFrameEncode_Commit(IWICBitmapFrameEncode
*iface
)
1716 PngEncoder
*This
= impl_from_IWICBitmapFrameEncode(iface
);
1717 png_byte
**row_pointers
=NULL
;
1719 TRACE("(%p)\n", iface
);
1721 EnterCriticalSection(&This
->lock
);
1723 if (!This
->info_written
|| This
->lines_written
!= This
->height
|| This
->frame_committed
)
1725 LeaveCriticalSection(&This
->lock
);
1726 return WINCODEC_ERR_WRONGSTATE
;
1729 /* set up setjmp/longjmp error handling */
1732 LeaveCriticalSection(&This
->lock
);
1733 HeapFree(GetProcessHeap(), 0, row_pointers
);
1736 ppng_set_error_fn(This
->png_ptr
, jmpbuf
, user_error_fn
, user_warning_fn
);
1738 if (This
->interlace
)
1742 row_pointers
= HeapAlloc(GetProcessHeap(), 0, This
->height
* sizeof(png_byte
*));
1745 LeaveCriticalSection(&This
->lock
);
1746 return E_OUTOFMEMORY
;
1749 for (i
=0; i
<This
->height
; i
++)
1750 row_pointers
[i
] = This
->data
+ This
->stride
* i
;
1752 for (i
=0; i
<This
->passes
; i
++)
1753 ppng_write_rows(This
->png_ptr
, row_pointers
, This
->height
);
1756 ppng_write_end(This
->png_ptr
, This
->info_ptr
);
1758 This
->frame_committed
= TRUE
;
1760 HeapFree(GetProcessHeap(), 0, row_pointers
);
1762 LeaveCriticalSection(&This
->lock
);
1767 static HRESULT WINAPI
PngFrameEncode_GetMetadataQueryWriter(IWICBitmapFrameEncode
*iface
,
1768 IWICMetadataQueryWriter
**ppIMetadataQueryWriter
)
1770 FIXME("(%p, %p): stub\n", iface
, ppIMetadataQueryWriter
);
1774 static const IWICBitmapFrameEncodeVtbl PngEncoder_FrameVtbl
= {
1775 PngFrameEncode_QueryInterface
,
1776 PngFrameEncode_AddRef
,
1777 PngFrameEncode_Release
,
1778 PngFrameEncode_Initialize
,
1779 PngFrameEncode_SetSize
,
1780 PngFrameEncode_SetResolution
,
1781 PngFrameEncode_SetPixelFormat
,
1782 PngFrameEncode_SetColorContexts
,
1783 PngFrameEncode_SetPalette
,
1784 PngFrameEncode_SetThumbnail
,
1785 PngFrameEncode_WritePixels
,
1786 PngFrameEncode_WriteSource
,
1787 PngFrameEncode_Commit
,
1788 PngFrameEncode_GetMetadataQueryWriter
1791 static HRESULT WINAPI
PngEncoder_QueryInterface(IWICBitmapEncoder
*iface
, REFIID iid
,
1794 PngEncoder
*This
= impl_from_IWICBitmapEncoder(iface
);
1795 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
1797 if (!ppv
) return E_INVALIDARG
;
1799 if (IsEqualIID(&IID_IUnknown
, iid
) ||
1800 IsEqualIID(&IID_IWICBitmapEncoder
, iid
))
1802 *ppv
= &This
->IWICBitmapEncoder_iface
;
1807 return E_NOINTERFACE
;
1810 IUnknown_AddRef((IUnknown
*)*ppv
);
1814 static ULONG WINAPI
PngEncoder_AddRef(IWICBitmapEncoder
*iface
)
1816 PngEncoder
*This
= impl_from_IWICBitmapEncoder(iface
);
1817 ULONG ref
= InterlockedIncrement(&This
->ref
);
1819 TRACE("(%p) refcount=%u\n", iface
, ref
);
1824 static ULONG WINAPI
PngEncoder_Release(IWICBitmapEncoder
*iface
)
1826 PngEncoder
*This
= impl_from_IWICBitmapEncoder(iface
);
1827 ULONG ref
= InterlockedDecrement(&This
->ref
);
1829 TRACE("(%p) refcount=%u\n", iface
, ref
);
1833 This
->lock
.DebugInfo
->Spare
[0] = 0;
1834 DeleteCriticalSection(&This
->lock
);
1836 ppng_destroy_write_struct(&This
->png_ptr
, &This
->info_ptr
);
1838 IStream_Release(This
->stream
);
1839 HeapFree(GetProcessHeap(), 0, This
->data
);
1840 HeapFree(GetProcessHeap(), 0, This
);
1846 static void user_write_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
1848 PngEncoder
*This
= ppng_get_io_ptr(png_ptr
);
1852 hr
= IStream_Write(This
->stream
, data
, length
, &byteswritten
);
1853 if (FAILED(hr
) || byteswritten
!= length
)
1855 ppng_error(png_ptr
, "failed writing data");
1859 static void user_flush(png_structp png_ptr
)
1863 static HRESULT WINAPI
PngEncoder_Initialize(IWICBitmapEncoder
*iface
,
1864 IStream
*pIStream
, WICBitmapEncoderCacheOption cacheOption
)
1866 PngEncoder
*This
= impl_from_IWICBitmapEncoder(iface
);
1869 TRACE("(%p,%p,%u)\n", iface
, pIStream
, cacheOption
);
1871 EnterCriticalSection(&This
->lock
);
1875 LeaveCriticalSection(&This
->lock
);
1876 return WINCODEC_ERR_WRONGSTATE
;
1879 /* initialize libpng */
1880 This
->png_ptr
= ppng_create_write_struct(PNG_LIBPNG_VER_STRING
, NULL
, NULL
, NULL
);
1883 LeaveCriticalSection(&This
->lock
);
1887 This
->info_ptr
= ppng_create_info_struct(This
->png_ptr
);
1888 if (!This
->info_ptr
)
1890 ppng_destroy_write_struct(&This
->png_ptr
, NULL
);
1891 This
->png_ptr
= NULL
;
1892 LeaveCriticalSection(&This
->lock
);
1896 IStream_AddRef(pIStream
);
1897 This
->stream
= pIStream
;
1899 /* set up setjmp/longjmp error handling */
1902 ppng_destroy_write_struct(&This
->png_ptr
, &This
->info_ptr
);
1903 This
->png_ptr
= NULL
;
1904 IStream_Release(This
->stream
);
1905 This
->stream
= NULL
;
1906 LeaveCriticalSection(&This
->lock
);
1909 ppng_set_error_fn(This
->png_ptr
, jmpbuf
, user_error_fn
, user_warning_fn
);
1911 /* set up custom i/o handling */
1912 ppng_set_write_fn(This
->png_ptr
, This
, user_write_data
, user_flush
);
1914 LeaveCriticalSection(&This
->lock
);
1919 static HRESULT WINAPI
PngEncoder_GetContainerFormat(IWICBitmapEncoder
*iface
,
1920 GUID
*pguidContainerFormat
)
1922 FIXME("(%p,%s): stub\n", iface
, debugstr_guid(pguidContainerFormat
));
1926 static HRESULT WINAPI
PngEncoder_GetEncoderInfo(IWICBitmapEncoder
*iface
,
1927 IWICBitmapEncoderInfo
**ppIEncoderInfo
)
1929 FIXME("(%p,%p): stub\n", iface
, ppIEncoderInfo
);
1933 static HRESULT WINAPI
PngEncoder_SetColorContexts(IWICBitmapEncoder
*iface
,
1934 UINT cCount
, IWICColorContext
**ppIColorContext
)
1936 FIXME("(%p,%u,%p): stub\n", iface
, cCount
, ppIColorContext
);
1940 static HRESULT WINAPI
PngEncoder_SetPalette(IWICBitmapEncoder
*iface
, IWICPalette
*pIPalette
)
1942 TRACE("(%p,%p)\n", iface
, pIPalette
);
1943 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
1946 static HRESULT WINAPI
PngEncoder_SetThumbnail(IWICBitmapEncoder
*iface
, IWICBitmapSource
*pIThumbnail
)
1948 TRACE("(%p,%p)\n", iface
, pIThumbnail
);
1949 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
1952 static HRESULT WINAPI
PngEncoder_SetPreview(IWICBitmapEncoder
*iface
, IWICBitmapSource
*pIPreview
)
1954 TRACE("(%p,%p)\n", iface
, pIPreview
);
1955 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
1958 static HRESULT WINAPI
PngEncoder_CreateNewFrame(IWICBitmapEncoder
*iface
,
1959 IWICBitmapFrameEncode
**ppIFrameEncode
, IPropertyBag2
**ppIEncoderOptions
)
1961 PngEncoder
*This
= impl_from_IWICBitmapEncoder(iface
);
1963 PROPBAG2 opts
[2]= {{0}};
1965 TRACE("(%p,%p,%p)\n", iface
, ppIFrameEncode
, ppIEncoderOptions
);
1967 EnterCriticalSection(&This
->lock
);
1969 if (This
->frame_count
!= 0)
1971 LeaveCriticalSection(&This
->lock
);
1972 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
1977 LeaveCriticalSection(&This
->lock
);
1978 return WINCODEC_ERR_NOTINITIALIZED
;
1981 opts
[0].pstrName
= (LPOLESTR
)wszPngInterlaceOption
;
1982 opts
[0].vt
= VT_BOOL
;
1983 opts
[0].dwType
= PROPBAG2_TYPE_DATA
;
1984 opts
[1].pstrName
= (LPOLESTR
)wszPngFilterOption
;
1985 opts
[1].vt
= VT_UI1
;
1986 opts
[1].dwType
= PROPBAG2_TYPE_DATA
;
1988 hr
= CreatePropertyBag2(opts
, sizeof(opts
)/sizeof(opts
[0]), ppIEncoderOptions
);
1991 LeaveCriticalSection(&This
->lock
);
1995 This
->frame_count
= 1;
1997 LeaveCriticalSection(&This
->lock
);
1999 IWICBitmapEncoder_AddRef(iface
);
2000 *ppIFrameEncode
= &This
->IWICBitmapFrameEncode_iface
;
2005 static HRESULT WINAPI
PngEncoder_Commit(IWICBitmapEncoder
*iface
)
2007 PngEncoder
*This
= impl_from_IWICBitmapEncoder(iface
);
2008 TRACE("(%p)\n", iface
);
2010 EnterCriticalSection(&This
->lock
);
2012 if (!This
->frame_committed
|| This
->committed
)
2014 LeaveCriticalSection(&This
->lock
);
2015 return WINCODEC_ERR_WRONGSTATE
;
2018 This
->committed
= TRUE
;
2020 LeaveCriticalSection(&This
->lock
);
2025 static HRESULT WINAPI
PngEncoder_GetMetadataQueryWriter(IWICBitmapEncoder
*iface
,
2026 IWICMetadataQueryWriter
**ppIMetadataQueryWriter
)
2028 FIXME("(%p,%p): stub\n", iface
, ppIMetadataQueryWriter
);
2032 static const IWICBitmapEncoderVtbl PngEncoder_Vtbl
= {
2033 PngEncoder_QueryInterface
,
2036 PngEncoder_Initialize
,
2037 PngEncoder_GetContainerFormat
,
2038 PngEncoder_GetEncoderInfo
,
2039 PngEncoder_SetColorContexts
,
2040 PngEncoder_SetPalette
,
2041 PngEncoder_SetThumbnail
,
2042 PngEncoder_SetPreview
,
2043 PngEncoder_CreateNewFrame
,
2045 PngEncoder_GetMetadataQueryWriter
2048 HRESULT
PngEncoder_CreateInstance(REFIID iid
, void** ppv
)
2053 TRACE("(%s,%p)\n", debugstr_guid(iid
), ppv
);
2059 ERR("Failed writing PNG because unable to find %s\n",SONAME_LIBPNG
);
2063 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(PngEncoder
));
2064 if (!This
) return E_OUTOFMEMORY
;
2066 This
->IWICBitmapEncoder_iface
.lpVtbl
= &PngEncoder_Vtbl
;
2067 This
->IWICBitmapFrameEncode_iface
.lpVtbl
= &PngEncoder_FrameVtbl
;
2069 This
->png_ptr
= NULL
;
2070 This
->info_ptr
= NULL
;
2071 This
->stream
= NULL
;
2072 This
->frame_count
= 0;
2073 This
->frame_initialized
= FALSE
;
2074 This
->format
= NULL
;
2075 This
->info_written
= FALSE
;
2080 This
->lines_written
= 0;
2081 This
->frame_committed
= FALSE
;
2082 This
->committed
= FALSE
;
2084 InitializeCriticalSection(&This
->lock
);
2085 This
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": PngEncoder.lock");
2087 ret
= IWICBitmapEncoder_QueryInterface(&This
->IWICBitmapEncoder_iface
, iid
, ppv
);
2088 IWICBitmapEncoder_Release(&This
->IWICBitmapEncoder_iface
);
2093 #else /* !HAVE_PNG_H */
2095 HRESULT
PngDecoder_CreateInstance(REFIID iid
, void** ppv
)
2097 ERR("Trying to load PNG picture, but PNG support is not compiled in.\n");
2101 HRESULT
PngEncoder_CreateInstance(REFIID iid
, void** ppv
)
2103 ERR("Trying to save PNG picture, but PNG support is not compiled in.\n");