ReactOS 0.4.15-dev-7953-g1f49173
pngformat.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "wincodec.h"
#include "wine/test.h"
#include "shlwapi.h"
Include dependency graph for pngformat.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 
#define PNG_COLOR_TYPE_GRAY   0
 
#define PNG_COLOR_TYPE_RGB   2
 
#define PNG_COLOR_TYPE_PALETTE   3
 
#define PNG_COLOR_TYPE_GRAY_ALPHA   4
 
#define PNG_COLOR_TYPE_RGB_ALPHA   6
 

Functions

static HRESULT create_decoder (const void *image_data, UINT image_size, IWICBitmapDecoder **decoder)
 
static WCHARsave_profile (BYTE *buffer, UINT size)
 
static void test_color_contexts (void)
 
static void test_png_palette (void)
 
static BOOL is_valid_png_type_depth (int color_type, int bit_depth, BOOL plte)
 
static void test_color_formats (void)
 
 START_TEST (pngformat)
 

Variables

static const char png_no_color_profile []
 
static const char png_color_profile []
 
static IWICImagingFactoryfactory
 
static const char png_PLTE_tRNS []
 
static const char png_gray_tRNS []
 
static const char png_1x1_data []
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 23 of file pngformat.c.

◆ PNG_COLOR_TYPE_GRAY

#define PNG_COLOR_TYPE_GRAY   0

Definition at line 697 of file pngformat.c.

◆ PNG_COLOR_TYPE_GRAY_ALPHA

#define PNG_COLOR_TYPE_GRAY_ALPHA   4

Definition at line 700 of file pngformat.c.

◆ PNG_COLOR_TYPE_PALETTE

#define PNG_COLOR_TYPE_PALETTE   3

Definition at line 699 of file pngformat.c.

◆ PNG_COLOR_TYPE_RGB

#define PNG_COLOR_TYPE_RGB   2

Definition at line 698 of file pngformat.c.

◆ PNG_COLOR_TYPE_RGB_ALPHA

#define PNG_COLOR_TYPE_RGB_ALPHA   6

Definition at line 701 of file pngformat.c.

Function Documentation

◆ create_decoder()

static HRESULT create_decoder ( const void image_data,
UINT  image_size,
IWICBitmapDecoder **  decoder 
)
static

Definition at line 279 of file pngformat.c.

280{
281 HRESULT hr;
283 GUID format;
284 LONG refcount;
287
288 *decoder = NULL;
289
290 stream = SHCreateMemStream (image_data, image_size);
291 ok(stream != NULL, "SHCreateMemStream error\n");
292
293 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, decoder);
294 if (hr == S_OK)
295 {
296 hr = IWICBitmapDecoder_GetContainerFormat(*decoder, &format);
297 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
298 ok(IsEqualGUID(&format, &GUID_ContainerFormatPng),
299 "wrong container format %s\n", wine_dbgstr_guid(&format));
300
301 zero.QuadPart = 0;
302 IStream_Seek (stream, zero, STREAM_SEEK_CUR, &pos);
303 ok(pos.QuadPart < image_size, "seek beyond the end of stream: %x%08x >= %x\n",
304 (UINT)(pos.QuadPart >> 32), (UINT)pos.QuadPart, image_size);
305
306 refcount = IStream_Release(stream);
307 ok(refcount > 0, "expected stream refcount > 0\n");
308 }
309 else
310 IStream_Release(stream);
311
312 return hr;
313}
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define S_OK
Definition: intsafe.h:52
static GLint image_size(GLint width, GLint height, GLenum format, GLenum type)
Definition: mipmap.c:4858
unsigned int UINT
Definition: ndis.h:50
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
IStream *WINAPI SHCreateMemStream(const BYTE *lpbData, UINT dwDataLen)
Definition: regstream.c:652
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:197
int zero
Definition: sehframes.cpp:29
HRESULT hr
Definition: shlfolder.c:183
Definition: main.c:439
Definition: parse.h:23

Referenced by test_color_contexts(), test_color_formats(), and test_png_palette().

◆ is_valid_png_type_depth()

static BOOL is_valid_png_type_depth ( int  color_type,
int  bit_depth,
BOOL  plte 
)
static

Definition at line 703 of file pngformat.c.

704{
705 switch (color_type)
706 {
708 return bit_depth == 1 || bit_depth == 2 || bit_depth == 4 || bit_depth == 8 || bit_depth == 16;
709
711 return bit_depth == 8 || bit_depth == 16;
712
714 return (bit_depth == 1 || bit_depth == 2 || bit_depth == 4 || bit_depth == 8) && plte;
715
717 return bit_depth == 8 || bit_depth == 16;
718
720 return bit_depth == 8 || bit_depth == 16;
721
722 default:
723 ok(0, "unknown PNG type %d, depth %d\n", color_type, bit_depth);
724 return FALSE;
725 }
726}
#define FALSE
Definition: types.h:117
#define PNG_COLOR_TYPE_RGB
Definition: pngformat.c:698
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: pngformat.c:701
#define PNG_COLOR_TYPE_GRAY_ALPHA
Definition: pngformat.c:700
#define PNG_COLOR_TYPE_GRAY
Definition: pngformat.c:697
#define PNG_COLOR_TYPE_PALETTE
Definition: pngformat.c:699

Referenced by test_color_formats().

◆ save_profile()

static WCHAR * save_profile ( BYTE buffer,
UINT  size 
)
static

Definition at line 315 of file pngformat.c.

316{
317 static const WCHAR tstW[] = {'t','s','t',0};
320 DWORD count;
321
323 GetTempFileNameW(path, tstW, 0, filename);
324
326 if (handle == INVALID_HANDLE_VALUE) return NULL;
327
330
331 ret = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(filename) + 1) * sizeof(WCHAR));
333 return ret;
334}
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLuint buffer
Definition: glext.h:5915
const char * filename
Definition: ioapi.h:137
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by test_color_contexts().

◆ START_TEST()

START_TEST ( pngformat  )

Definition at line 925 of file pngformat.c.

926{
927 HRESULT hr;
928
930 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
931 &IID_IWICImagingFactory, (void **)&factory);
932 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
933 if (FAILED(hr)) return;
934
938
939 IWICImagingFactory_Release(factory);
941}
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
#define FAILED(hr)
Definition: intsafe.h:51
static void test_png_palette(void)
Definition: pngformat.c:553
static void test_color_formats(void)
Definition: pngformat.c:728
static void test_color_contexts(void)
Definition: pngformat.c:336
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:278

◆ test_color_contexts()

static void test_color_contexts ( void  )
static

Definition at line 336 of file pngformat.c.

337{
338 HRESULT hr;
339 IWICBitmapDecoder *decoder;
344 WCHAR *tmpfile;
345 BYTE *buffer;
346 BOOL ret;
347
349 ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
350 if (hr != S_OK) return;
351
352 /* global color context */
353 hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, NULL);
354 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts error %#x\n", hr);
355
356 count = 0xdeadbeef;
357 hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, &count);
358 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts error %#x\n", hr);
359 ok(count == 0xdeadbeef, "unexpected count %u\n", count);
360
361 /* frame color context */
362 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
363 ok(hr == S_OK, "GetFrame error %#x\n", hr);
364
365 hr = IWICBitmapFrameDecode_GetColorContexts(frame, 0, NULL, NULL);
366 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
367
368 count = 0xdeadbeef;
369 hr = IWICBitmapFrameDecode_GetColorContexts(frame, 0, NULL, &count);
370 ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
371 ok(!count, "unexpected count %u\n", count);
372
373 IWICBitmapFrameDecode_Release(frame);
374 IWICBitmapDecoder_Release(decoder);
375
377 ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
378 if (hr != S_OK) return;
379
380 /* global color context */
381 count = 0xdeadbeef;
382 hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, &count);
383 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts error %#x\n", hr);
384 ok(count == 0xdeadbeef, "unexpected count %u\n", count);
385
386 /* frame color context */
387 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
388 ok(hr == S_OK, "GetFrame error %#x\n", hr);
389
390 count = 0xdeadbeef;
391 hr = IWICBitmapFrameDecode_GetColorContexts(frame, 0, NULL, &count);
392 ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
393 ok(count == 1, "unexpected count %u\n", count);
394
395 hr = IWICImagingFactory_CreateColorContext(factory, NULL);
396 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
397
398 hr = IWICImagingFactory_CreateColorContext(factory, &context);
399 ok(hr == S_OK, "CreateColorContext error %#x\n", hr);
400
401 hr = IWICColorContext_GetType(context, NULL);
402 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
403
404 type = 0xdeadbeef;
405 hr = IWICColorContext_GetType(context, &type);
406 ok(hr == S_OK, "GetType error %#x\n", hr);
407 ok(type == WICColorContextUninitialized, "unexpected type %u\n", type);
408
409 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, NULL);
410 ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetProfileBytes error %#x\n", hr);
411
412 size = 0;
413 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
414 ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetProfileBytes error %#x\n", hr);
415 ok(!size, "unexpected size %u\n", size);
416
417 hr = IWICColorContext_GetExifColorSpace(context, NULL);
418 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
419
420 colorspace = 0xdeadbeef;
421 hr = IWICColorContext_GetExifColorSpace(context, &colorspace);
422 ok(hr == S_OK, "GetExifColorSpace error %#x\n", hr);
423 ok(colorspace == 0xffffffff, "unexpected color space %u\n", colorspace);
424
425 hr = IWICColorContext_InitializeFromExifColorSpace(context, 0);
426 ok(hr == S_OK, "InitializeFromExifColorSpace error %#x\n", hr);
427
428 hr = IWICColorContext_InitializeFromExifColorSpace(context, 1);
429 ok(hr == S_OK, "InitializeFromExifColorSpace error %#x\n", hr);
430
431 hr = IWICColorContext_InitializeFromExifColorSpace(context, 2);
432 ok(hr == S_OK, "InitializeFromExifColorSpace error %#x\n", hr);
433
434 colorspace = 0xdeadbeef;
435 hr = IWICColorContext_GetExifColorSpace(context, &colorspace);
436 ok(hr == S_OK, "GetExifColorSpace error %#x\n", hr);
437 ok(colorspace == 2, "unexpected color space %u\n", colorspace);
438
439 size = 0;
440 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
441 ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetProfileBytes error %#x\n", hr);
442 ok(!size, "unexpected size %u\n", size);
443
444 type = 0xdeadbeef;
445 hr = IWICColorContext_GetType(context, &type);
446 ok(hr == S_OK, "GetType error %#x\n", hr);
447 ok(type == WICColorContextExifColorSpace, "unexpected type %u\n", type);
448
449 hr = IWICBitmapFrameDecode_GetColorContexts(frame, count, &context, &count);
450 ok(hr == WINCODEC_ERR_WRONGSTATE, "GetColorContexts error %#x\n", hr);
451
452 IWICColorContext_Release(context);
453 IWICBitmapFrameDecode_Release(frame);
454
455 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
456 ok(hr == S_OK, "GetFrame error %#x\n", hr);
457
458 hr = IWICImagingFactory_CreateColorContext(factory, &context);
459 ok(hr == S_OK, "CreateColorContext error %#x\n", hr);
460
461 count = 1;
462 hr = IWICBitmapFrameDecode_GetColorContexts(frame, count, &context, &count);
463 ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
464
465 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, NULL);
466 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
467
468 size = 0;
469 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
470 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
471 ok(size, "unexpected size %u\n", size);
472
474 hr = IWICColorContext_GetProfileBytes(context, size, buffer, &size);
475 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
476
479
480 type = 0xdeadbeef;
481 hr = IWICColorContext_GetType(context, &type);
482 ok(hr == S_OK, "GetType error %#x\n", hr);
483 ok(type == WICColorContextProfile, "unexpected type %u\n", type);
484
485 colorspace = 0xdeadbeef;
486 hr = IWICColorContext_GetExifColorSpace(context, &colorspace);
487 ok(hr == S_OK, "GetExifColorSpace error %#x\n", hr);
488 ok(colorspace == 0xffffffff, "unexpected color space %u\n", colorspace);
489
490 hr = IWICColorContext_InitializeFromExifColorSpace(context, 1);
491 ok(hr == WINCODEC_ERR_WRONGSTATE, "InitializeFromExifColorSpace error %#x\n", hr);
492
493 if (tmpfile)
494 {
495 hr = IWICColorContext_InitializeFromFilename(context, NULL);
496 ok(hr == E_INVALIDARG, "InitializeFromFilename error %#x\n", hr);
497
498 hr = IWICColorContext_InitializeFromFilename(context, tmpfile);
499 ok(hr == S_OK, "InitializeFromFilename error %#x\n", hr);
500
502 ok(ret, "DeleteFileW failed %u\n", GetLastError());
503
504 type = 0xdeadbeef;
505 hr = IWICColorContext_GetType(context, &type);
506 ok(hr == S_OK, "GetType error %#x\n", hr);
507 ok(type == WICColorContextProfile, "unexpected type %u\n", type);
508
509 colorspace = 0xdeadbeef;
510 hr = IWICColorContext_GetExifColorSpace(context, &colorspace);
511 ok(hr == S_OK, "GetExifColorSpace error %#x\n", hr);
512 ok(colorspace == 0xffffffff, "unexpected color space %u\n", colorspace);
513
514 hr = IWICColorContext_InitializeFromExifColorSpace(context, 1);
515 ok(hr == WINCODEC_ERR_WRONGSTATE, "InitializeFromExifColorSpace error %#x\n", hr);
516
517 size = 0;
518 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
519 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
520 ok(size, "unexpected size %u\n", size);
521
523 hr = IWICColorContext_GetProfileBytes(context, size, buffer, &size);
524 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
525
528 }
529 IWICColorContext_Release(context);
530 IWICBitmapFrameDecode_Release(frame);
531 IWICBitmapDecoder_Release(decoder);
532}
#define E_INVALIDARG
Definition: ddrawi.h:101
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
_Check_return_ _CRTIMP FILE *__cdecl tmpfile(void)
Definition: file.c:3914
J_COLOR_SPACE colorspace
Definition: jpeglib.h:990
static WCHAR * save_profile(BYTE *buffer, UINT size)
Definition: pngformat.c:315
static const char png_color_profile[]
Definition: pngformat.c:45
static HRESULT create_decoder(const void *image_data, UINT image_size, IWICBitmapDecoder **decoder)
Definition: pngformat.c:279
static const char png_no_color_profile[]
Definition: pngformat.c:31
Definition: http.c:7252
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
WICColorContextType
Definition: wincodec.idl:118
@ WICColorContextUninitialized
Definition: wincodec.idl:119
@ WICColorContextExifColorSpace
Definition: wincodec.idl:121
@ WICColorContextProfile
Definition: wincodec.idl:120
#define WINCODEC_ERR_WRONGSTATE
Definition: winerror.h:3281
#define WINCODEC_ERR_UNSUPPORTEDOPERATION
Definition: winerror.h:3308
#define WINCODEC_ERR_NOTINITIALIZED
Definition: winerror.h:3285
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ test_color_formats()

static void test_color_formats ( void  )
static

Definition at line 728 of file pngformat.c.

729{
730 static const struct
731 {
732 char bit_depth, color_type;
733 const GUID *format;
734 const GUID *format_PLTE;
735 const GUID *format_PLTE_tRNS;
736 BOOL todo;
737 BOOL todo_load;
738 } td[] =
739 {
740 /* 2 - PNG_COLOR_TYPE_RGB */
745 &GUID_WICPixelFormat24bppBGR, &GUID_WICPixelFormat24bppBGR, &GUID_WICPixelFormat24bppBGR },
746 /* libpng refuses to load our test image complaining about extra compressed data,
747 * but libpng is still able to load the image with other combination of type/depth
748 * making RGB 16 bpp case special for some reason. Therefore todo = TRUE.
749 */
750 { 16, PNG_COLOR_TYPE_RGB,
751 &GUID_WICPixelFormat48bppRGB, &GUID_WICPixelFormat48bppRGB, &GUID_WICPixelFormat48bppRGB, TRUE, TRUE },
752 { 24, PNG_COLOR_TYPE_RGB, NULL, NULL, NULL },
753 { 32, PNG_COLOR_TYPE_RGB, NULL, NULL, NULL },
754 /* 0 - PNG_COLOR_TYPE_GRAY */
756 &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormat1bppIndexed },
758 &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppIndexed },
760 &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppIndexed },
762 &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppIndexed },
764 &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat64bppRGBA },
767 /* 3 - PNG_COLOR_TYPE_PALETTE */
769 &GUID_WICPixelFormat1bppIndexed, &GUID_WICPixelFormat1bppIndexed, &GUID_WICPixelFormat1bppIndexed },
771 &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat2bppIndexed },
773 &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed },
775 &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed },
779 };
780 char buf[sizeof(png_1x1_data)];
781 HRESULT hr;
782 IWICBitmapDecoder *decoder;
784 GUID format;
785 int i, PLTE_off = 0, tRNS_off = 0;
786
788 for (i = 0; i < sizeof(png_1x1_data) - 4; i++)
789 {
790 if (!memcmp(buf + i, "tRNS", 4))
791 tRNS_off = i;
792 else if (!memcmp(buf + i, "PLTE", 4))
793 PLTE_off = i;
794 }
795
796 ok(PLTE_off && tRNS_off, "PLTE offset %d, tRNS offset %d\n", PLTE_off, tRNS_off);
797 if (!PLTE_off || !tRNS_off) return;
798
799 /* In order to test the image data with and without PLTE and tRNS chunks
800 * it's been decided to simply sero out the chunk id for testing puposes,
801 * and under Windows such images get loaded just fine. But unfortunately
802 * libpng refuses to load such images complaining about unknown chunk type.
803 * A workaround for this libpng limitation is to mark the "disabled" chunks
804 * with tEXt id.
805 */
806
807 for (i = 0; i < ARRAY_SIZE(td); i++)
808 {
809 /* with the tRNS and PLTE chunks */
811 buf[24] = td[i].bit_depth;
812 buf[25] = td[i].color_type;
813
814 hr = create_decoder(buf, sizeof(buf), &decoder);
815 if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE))
816 ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
817 else
818todo_wine_if(td[i].todo_load)
819 ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr);
820 if (hr != S_OK) goto next_1;
821
822 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
823 ok(hr == S_OK, "GetFrame error %#x\n", hr);
824
825 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
826 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
828 ok(IsEqualGUID(&format, td[i].format_PLTE_tRNS),
829 "PLTE+tRNS: expected %s, got %s (type %d, bpp %d)\n",
830 wine_dbgstr_guid(td[i].format_PLTE_tRNS), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth);
831
832 IWICBitmapFrameDecode_Release(frame);
833 IWICBitmapDecoder_Release(decoder);
834
835next_1:
836 /* without the tRNS chunk */
838 buf[24] = td[i].bit_depth;
839 buf[25] = td[i].color_type;
840 memcpy(buf + tRNS_off, "tEXt", 4);
841
842 hr = create_decoder(buf, sizeof(buf), &decoder);
843 if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, TRUE))
844 ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
845 else
846todo_wine_if(td[i].todo_load)
847 ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr);
848 if (hr != S_OK) goto next_2;
849
850 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
851 ok(hr == S_OK, "GetFrame error %#x\n", hr);
852
853 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
854 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
855 ok(IsEqualGUID(&format, td[i].format_PLTE),
856 "PLTE: expected %s, got %s (type %d, bpp %d)\n",
857 wine_dbgstr_guid(td[i].format_PLTE), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth);
858
859 IWICBitmapFrameDecode_Release(frame);
860 IWICBitmapDecoder_Release(decoder);
861
862next_2:
863 /* without the tRNS and PLTE chunks */
865 buf[24] = td[i].bit_depth;
866 buf[25] = td[i].color_type;
867 memcpy(buf + PLTE_off, "tEXt", 4);
868 memcpy(buf + tRNS_off, "tEXt", 4);
869
870 hr = create_decoder(buf, sizeof(buf), &decoder);
871 if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE))
872 ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
873 else
874todo_wine_if(td[i].todo_load)
875 ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr);
876 if (hr != S_OK) goto next_3;
877
878 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
879 ok(hr == S_OK, "GetFrame error %#x\n", hr);
880
881 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
882 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
884 "expected %s, got %s (type %d, bpp %d)\n",
885 wine_dbgstr_guid(td[i].format), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth);
886
887 IWICBitmapFrameDecode_Release(frame);
888 IWICBitmapDecoder_Release(decoder);
889
890next_3:
891 /* without the PLTE chunk */
893 buf[24] = td[i].bit_depth;
894 buf[25] = td[i].color_type;
895 memcpy(buf + PLTE_off, "tEXt", 4);
896
897 hr = create_decoder(buf, sizeof(buf), &decoder);
898 if (!is_valid_png_type_depth(td[i].color_type, td[i].bit_depth, FALSE))
899 ok(hr == WINCODEC_ERR_UNKNOWNIMAGEFORMAT, "%d: wrong error %#x\n", i, hr);
900 else
901todo_wine_if(td[i].todo_load)
902 ok(hr == S_OK, "%d: Failed to load PNG image data (type %d, bpp %d) %#x\n", i, td[i].color_type, td[i].bit_depth, hr);
903 if (hr != S_OK) continue;
904
905 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
906 ok(hr == S_OK, "GetFrame error %#x\n", hr);
907
908 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
909 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
911 ok(IsEqualGUID(&format, td[i].format_PLTE_tRNS),
912 "tRNS: expected %s, got %s (type %d, bpp %d)\n",
913 wine_dbgstr_guid(td[i].format_PLTE_tRNS), wine_dbgstr_guid(&format), td[i].color_type, td[i].bit_depth);
914
915 IWICBitmapFrameDecode_Release(frame);
916 IWICBitmapDecoder_Release(decoder);
917 }
918}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ARRAY_SIZE(A)
Definition: main.h:33
#define TRUE
Definition: types.h:120
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BOOL todo
Definition: filedlg.c:313
#define todo_wine_if(is_todo)
Definition: custom.c:76
static BOOL is_valid_png_type_depth(int color_type, int bit_depth, BOOL plte)
Definition: pngformat.c:703
static const char png_1x1_data[]
Definition: pngformat.c:655
#define WINCODEC_ERR_UNKNOWNIMAGEFORMAT
Definition: winerror.h:3283

Referenced by START_TEST().

◆ test_png_palette()

static void test_png_palette ( void  )
static

Definition at line 553 of file pngformat.c.

554{
555 HRESULT hr;
556 IWICBitmapDecoder *decoder;
559 GUID format;
560 UINT count, ret;
561 WICColor color[256];
562 char *buf;
563
564 hr = create_decoder(png_PLTE_tRNS, sizeof(png_PLTE_tRNS), &decoder);
565 ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
566 if (hr != S_OK) return;
567
568 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
569 ok(hr == S_OK, "GetFrame error %#x\n", hr);
570
571 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
572 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
573 ok(IsEqualGUID(&format, &GUID_WICPixelFormat1bppIndexed),
574 "got wrong format %s\n", wine_dbgstr_guid(&format));
575
576 hr = IWICImagingFactory_CreatePalette(factory, &palette);
577 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
578 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
579 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
580
581 hr = IWICPalette_GetColorCount(palette, &count);
582 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
583 ok(count == 2, "expected 2, got %u\n", count);
584
585 hr = IWICPalette_GetColors(palette, 256, color, &ret);
586 ok(hr == S_OK, "GetColors error %#x\n", hr);
587 ok(ret == count, "expected %u, got %u\n", count, ret);
588 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
589 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
590
591 IWICPalette_Release(palette);
592 IWICBitmapFrameDecode_Release(frame);
593 IWICBitmapDecoder_Release(decoder);
594
595 hr = create_decoder(png_gray_tRNS, sizeof(png_gray_tRNS), &decoder);
596 ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
597 if (hr != S_OK) return;
598
599 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
600 ok(hr == S_OK, "GetFrame error %#x\n", hr);
601
602 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
603 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
604 ok(IsEqualGUID(&format, &GUID_WICPixelFormat64bppRGBA),
605 "got wrong format %s\n", wine_dbgstr_guid(&format));
606
607 hr = IWICImagingFactory_CreatePalette(factory, &palette);
608 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
609 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
610 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "CopyPalette error %#x\n", hr);
611
612 IWICPalette_Release(palette);
613 IWICBitmapFrameDecode_Release(frame);
614 IWICBitmapDecoder_Release(decoder);
615
616 /* test 8 bpp grayscale PNG image with tRNS chunk */
617 buf = HeapAlloc(GetProcessHeap(), 0, sizeof(png_gray_tRNS));
619 buf[24] = 8; /* override bit depth */
620
621 hr = create_decoder(buf, sizeof(png_gray_tRNS), &decoder);
622 ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
623 if (hr != S_OK) return;
624
625 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
626 ok(hr == S_OK, "GetFrame error %#x\n", hr);
627
628 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
629 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
630 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
631 "got wrong format %s\n", wine_dbgstr_guid(&format));
632
633 hr = IWICImagingFactory_CreatePalette(factory, &palette);
634 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
635 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
636 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
637
638 hr = IWICPalette_GetColorCount(palette, &count);
639 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
640 ok(count == 256, "expected 256, got %u\n", count);
641
642 hr = IWICPalette_GetColors(palette, 256, color, &ret);
643 ok(hr == S_OK, "GetColors error %#x\n", hr);
644 ok(ret == count, "expected %u, got %u\n", count, ret);
645 ok(color[0] == 0x00000000, "expected 0x00000000, got %#x\n", color[0]);
646 ok(color[1] == 0xff010101, "expected 0xff010101, got %#x\n", color[1]);
647
649 IWICPalette_Release(palette);
650 IWICBitmapFrameDecode_Release(frame);
651 IWICBitmapDecoder_Release(decoder);
652}
GLuint color
Definition: glext.h:6243
static HPALETTE palette
Definition: clipboard.c:1345
static const char png_gray_tRNS[]
Definition: pngformat.c:545
static const char png_PLTE_tRNS[]
Definition: pngformat.c:535
UINT32 WICColor
Definition: wincodec.idl:312
#define WINCODEC_ERR_PALETTEUNAVAILABLE
Definition: winerror.h:3292

Referenced by START_TEST().

Variable Documentation

◆ factory

Definition at line 277 of file pngformat.c.

◆ png_1x1_data

const char png_1x1_data[]
static

Definition at line 655 of file pngformat.c.

Referenced by test_color_formats().

◆ png_color_profile

const char png_color_profile[]
static

Definition at line 45 of file pngformat.c.

Referenced by test_color_contexts().

◆ png_gray_tRNS

const char png_gray_tRNS[]
static
Initial value:
= {
0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,
0x00,0x00,0x00,0x0d,'I','H','D','R',0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x10,0x00,0x00,0x00,0x00,0x6a,0xee,0x47,0x16,
0x00,0x00,0x00,0x02,'t','R','N','S',0x00,0x00,0x76,0x93,0xcd,0x38,
0x00,0x00,0x00,0x0b,'I','D','A','T',0x78,0x9c,0x63,0x60,0x60,0x00,0x00,0x00,0x03,0x00,0x01,0xb8,0xad,0x3a,0x63,
0x00,0x00,0x00,0x00,'I','E','N','D',0xae,0x42,0x60,0x82
}

Definition at line 545 of file pngformat.c.

Referenced by test_png_palette().

◆ png_no_color_profile

const char png_no_color_profile[]
static
Initial value:
= {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xde, 0x00, 0x00, 0x00,
0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 0x0b,
0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49,
0x4d, 0x45, 0x07, 0xdc, 0x0b, 0x0e, 0x0e, 0x22, 0x17, 0x10, 0xd8, 0xde,
0x3b, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63,
0xf8, 0xff, 0xff, 0x3f, 0x00, 0x05, 0xfe, 0x02, 0xfe, 0xdc, 0xcc, 0x59,
0xe7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
0x82
}

Definition at line 31 of file pngformat.c.

Referenced by test_color_contexts().

◆ png_PLTE_tRNS

const char png_PLTE_tRNS[]
static
Initial value:
= {
0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,
0x00,0x00,0x00,0x0d,'I','H','D','R',0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x00,0x00,0x25,0xdb,0x56,0xca,
0x00,0x00,0x00,0x06,'P','L','T','E',0x01,0x02,0x03,0x04,0x05,0x06,0x95,0x53,0x6f,0x48,
0x00,0x00,0x00,0x02,'t','R','N','S',0xff,0x00,0xe5,0xb7,0x30,0x4a,
0x00,0x00,0x00,0x0a,'I','D','A','T',0x18,0xd3,0x63,0x68,0x00,0x00,0x00,0x82,0x00,0x81,0xa7,0x01,0xba,0x10,
0x00,0x00,0x00,0x00,'I','E','N','D',0xae,0x42,0x60,0x82
}

Definition at line 535 of file pngformat.c.

Referenced by test_png_palette().