mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / windowscodecs / tests / pngformat.c
blob8c33d3b9645ebb4cbbc0ad01a7096d58eb49dfa5
1 /*
2 * Copyright 2012, 2016 Dmitry Timoshkov
3 * Copyright 2012 Hans Leidekker for CodeWeavers
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
20 #include <stdarg.h>
21 #include <stdio.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "wincodec.h"
27 #include "wine/test.h"
28 #include "shlwapi.h"
30 /* 1x1 pixel PNG image */
31 static const char png_no_color_profile[] = {
32 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
33 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
34 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xde, 0x00, 0x00, 0x00,
35 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 0x0b,
36 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49,
37 0x4d, 0x45, 0x07, 0xdc, 0x0b, 0x0e, 0x0e, 0x22, 0x17, 0x10, 0xd8, 0xde,
38 0x3b, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63,
39 0xf8, 0xff, 0xff, 0x3f, 0x00, 0x05, 0xfe, 0x02, 0xfe, 0xdc, 0xcc, 0x59,
40 0xe7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
41 0x82
44 /* 1x1 pixel PNG image with embedded sRGB profile */
45 static const char png_color_profile[] = {
46 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
47 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
48 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xde, 0x00, 0x00, 0x0a,
49 0x43, 0x69, 0x43, 0x43, 0x50, 0x49, 0x43, 0x43, 0x20, 0x70, 0x72, 0x6f,
50 0x66, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x78, 0xda, 0x9d, 0x53, 0x77, 0x58,
51 0x93, 0xf7, 0x16, 0x3e, 0xdf, 0xf7, 0x65, 0x0f, 0x56, 0x42, 0xd8, 0xf0,
52 0xb1, 0x97, 0x6c, 0x81, 0x00, 0x22, 0x23, 0xac, 0x08, 0xc8, 0x10, 0x59,
53 0xa2, 0x10, 0x92, 0x00, 0x61, 0x84, 0x10, 0x12, 0x40, 0xc5, 0x85, 0x88,
54 0x0a, 0x56, 0x14, 0x15, 0x11, 0x9c, 0x48, 0x55, 0xc4, 0x82, 0xd5, 0x0a,
55 0x48, 0x9d, 0x88, 0xe2, 0xa0, 0x28, 0xb8, 0x67, 0x41, 0x8a, 0x88, 0x5a,
56 0x8b, 0x55, 0x5c, 0x38, 0xee, 0x1f, 0xdc, 0xa7, 0xb5, 0x7d, 0x7a, 0xef,
57 0xed, 0xed, 0xfb, 0xd7, 0xfb, 0xbc, 0xe7, 0x9c, 0xe7, 0xfc, 0xce, 0x79,
58 0xcf, 0x0f, 0x80, 0x11, 0x12, 0x26, 0x91, 0xe6, 0xa2, 0x6a, 0x00, 0x39,
59 0x52, 0x85, 0x3c, 0x3a, 0xd8, 0x1f, 0x8f, 0x4f, 0x48, 0xc4, 0xc9, 0xbd,
60 0x80, 0x02, 0x15, 0x48, 0xe0, 0x04, 0x20, 0x10, 0xe6, 0xcb, 0xc2, 0x67,
61 0x05, 0xc5, 0x00, 0x00, 0xf0, 0x03, 0x79, 0x78, 0x7e, 0x74, 0xb0, 0x3f,
62 0xfc, 0x01, 0xaf, 0x6f, 0x00, 0x02, 0x00, 0x70, 0xd5, 0x2e, 0x24, 0x12,
63 0xc7, 0xe1, 0xff, 0x83, 0xba, 0x50, 0x26, 0x57, 0x00, 0x20, 0x91, 0x00,
64 0xe0, 0x22, 0x12, 0xe7, 0x0b, 0x01, 0x90, 0x52, 0x00, 0xc8, 0x2e, 0x54,
65 0xc8, 0x14, 0x00, 0xc8, 0x18, 0x00, 0xb0, 0x53, 0xb3, 0x64, 0x0a, 0x00,
66 0x94, 0x00, 0x00, 0x6c, 0x79, 0x7c, 0x42, 0x22, 0x00, 0xaa, 0x0d, 0x00,
67 0xec, 0xf4, 0x49, 0x3e, 0x05, 0x00, 0xd8, 0xa9, 0x93, 0xdc, 0x17, 0x00,
68 0xd8, 0xa2, 0x1c, 0xa9, 0x08, 0x00, 0x8d, 0x01, 0x00, 0x99, 0x28, 0x47,
69 0x24, 0x02, 0x40, 0xbb, 0x00, 0x60, 0x55, 0x81, 0x52, 0x2c, 0x02, 0xc0,
70 0xc2, 0x00, 0xa0, 0xac, 0x40, 0x22, 0x2e, 0x04, 0xc0, 0xae, 0x01, 0x80,
71 0x59, 0xb6, 0x32, 0x47, 0x02, 0x80, 0xbd, 0x05, 0x00, 0x76, 0x8e, 0x58,
72 0x90, 0x0f, 0x40, 0x60, 0x00, 0x80, 0x99, 0x42, 0x2c, 0xcc, 0x00, 0x20,
73 0x38, 0x02, 0x00, 0x43, 0x1e, 0x13, 0xcd, 0x03, 0x20, 0x4c, 0x03, 0xa0,
74 0x30, 0xd2, 0xbf, 0xe0, 0x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 0xae, 0x52, 0x8e, 0xe7, 0xcb, 0x04, 0x42, 0x31, 0x6e, 0xf7,
90 0xe7, 0x23, 0xfe, 0xc7, 0x85, 0x7f, 0xfd, 0x8e, 0x29, 0xd1, 0xe2, 0x34,
91 0xb1, 0x5c, 0x2c, 0x15, 0x8a, 0xf1, 0x58, 0x89, 0xb8, 0x50, 0x22, 0x4d,
92 0xc7, 0x79, 0xb9, 0x52, 0x91, 0x44, 0x21, 0xc9, 0x95, 0xe2, 0x12, 0xe9,
93 0x7f, 0x32, 0xf1, 0x1f, 0x96, 0xfd, 0x09, 0x93, 0x77, 0x0d, 0x00, 0xac,
94 0x86, 0x4f, 0xc0, 0x4e, 0xb6, 0x07, 0xb5, 0xcb, 0x6c, 0xc0, 0x7e, 0xee,
95 0x01, 0x02, 0x8b, 0x0e, 0x58, 0xd2, 0x76, 0x00, 0x40, 0x7e, 0xf3, 0x2d,
96 0x8c, 0x1a, 0x0b, 0x91, 0x00, 0x10, 0x67, 0x34, 0x32, 0x79, 0xf7, 0x00,
97 0x00, 0x93, 0xbf, 0xf9, 0x8f, 0x40, 0x2b, 0x01, 0x00, 0xcd, 0x97, 0xa4,
98 0xe3, 0x00, 0x00, 0xbc, 0xe8, 0x18, 0x5c, 0xa8, 0x94, 0x17, 0x4c, 0xc6,
99 0x08, 0x00, 0x00, 0x44, 0xa0, 0x81, 0x2a, 0xb0, 0x41, 0x07, 0x0c, 0xc1,
100 0x14, 0xac, 0xc0, 0x0e, 0x9c, 0xc1, 0x1d, 0xbc, 0xc0, 0x17, 0x02, 0x61,
101 0x06, 0x44, 0x40, 0x0c, 0x24, 0xc0, 0x3c, 0x10, 0x42, 0x06, 0xe4, 0x80,
102 0x1c, 0x0a, 0xa1, 0x18, 0x96, 0x41, 0x19, 0x54, 0xc0, 0x3a, 0xd8, 0x04,
103 0xb5, 0xb0, 0x03, 0x1a, 0xa0, 0x11, 0x9a, 0xe1, 0x10, 0xb4, 0xc1, 0x31,
104 0x38, 0x0d, 0xe7, 0xe0, 0x12, 0x5c, 0x81, 0xeb, 0x70, 0x17, 0x06, 0x60,
105 0x18, 0x9e, 0xc2, 0x18, 0xbc, 0x86, 0x09, 0x04, 0x41, 0xc8, 0x08, 0x13,
106 0x61, 0x21, 0x3a, 0x88, 0x11, 0x62, 0x8e, 0xd8, 0x22, 0xce, 0x08, 0x17,
107 0x99, 0x8e, 0x04, 0x22, 0x61, 0x48, 0x34, 0x92, 0x80, 0xa4, 0x20, 0xe9,
108 0x88, 0x14, 0x51, 0x22, 0xc5, 0xc8, 0x72, 0xa4, 0x02, 0xa9, 0x42, 0x6a,
109 0x91, 0x5d, 0x48, 0x23, 0xf2, 0x2d, 0x72, 0x14, 0x39, 0x8d, 0x5c, 0x40,
110 0xfa, 0x90, 0xdb, 0xc8, 0x20, 0x32, 0x8a, 0xfc, 0x8a, 0xbc, 0x47, 0x31,
111 0x94, 0x81, 0xb2, 0x51, 0x03, 0xd4, 0x02, 0x75, 0x40, 0xb9, 0xa8, 0x1f,
112 0x1a, 0x8a, 0xc6, 0xa0, 0x73, 0xd1, 0x74, 0x34, 0x0f, 0x5d, 0x80, 0x96,
113 0xa2, 0x6b, 0xd1, 0x1a, 0xb4, 0x1e, 0x3d, 0x80, 0xb6, 0xa2, 0xa7, 0xd1,
114 0x4b, 0xe8, 0x75, 0x74, 0x00, 0x7d, 0x8a, 0x8e, 0x63, 0x80, 0xd1, 0x31,
115 0x0e, 0x66, 0x8c, 0xd9, 0x61, 0x5c, 0x8c, 0x87, 0x45, 0x60, 0x89, 0x58,
116 0x1a, 0x26, 0xc7, 0x16, 0x63, 0xe5, 0x58, 0x35, 0x56, 0x8f, 0x35, 0x63,
117 0x1d, 0x58, 0x37, 0x76, 0x15, 0x1b, 0xc0, 0x9e, 0x61, 0xef, 0x08, 0x24,
118 0x02, 0x8b, 0x80, 0x13, 0xec, 0x08, 0x5e, 0x84, 0x10, 0xc2, 0x6c, 0x82,
119 0x90, 0x90, 0x47, 0x58, 0x4c, 0x58, 0x43, 0xa8, 0x25, 0xec, 0x23, 0xb4,
120 0x12, 0xba, 0x08, 0x57, 0x09, 0x83, 0x84, 0x31, 0xc2, 0x27, 0x22, 0x93,
121 0xa8, 0x4f, 0xb4, 0x25, 0x7a, 0x12, 0xf9, 0xc4, 0x78, 0x62, 0x3a, 0xb1,
122 0x90, 0x58, 0x46, 0xac, 0x26, 0xee, 0x21, 0x1e, 0x21, 0x9e, 0x25, 0x5e,
123 0x27, 0x0e, 0x13, 0x5f, 0x93, 0x48, 0x24, 0x0e, 0xc9, 0x92, 0xe4, 0x4e,
124 0x0a, 0x21, 0x25, 0x90, 0x32, 0x49, 0x0b, 0x49, 0x6b, 0x48, 0xdb, 0x48,
125 0x2d, 0xa4, 0x53, 0xa4, 0x3e, 0xd2, 0x10, 0x69, 0x9c, 0x4c, 0x26, 0xeb,
126 0x90, 0x6d, 0xc9, 0xde, 0xe4, 0x08, 0xb2, 0x80, 0xac, 0x20, 0x97, 0x91,
127 0xb7, 0x90, 0x0f, 0x90, 0x4f, 0x92, 0xfb, 0xc9, 0xc3, 0xe4, 0xb7, 0x14,
128 0x3a, 0xc5, 0x88, 0xe2, 0x4c, 0x09, 0xa2, 0x24, 0x52, 0xa4, 0x94, 0x12,
129 0x4a, 0x35, 0x65, 0x3f, 0xe5, 0x04, 0xa5, 0x9f, 0x32, 0x42, 0x99, 0xa0,
130 0xaa, 0x51, 0xcd, 0xa9, 0x9e, 0xd4, 0x08, 0xaa, 0x88, 0x3a, 0x9f, 0x5a,
131 0x49, 0x6d, 0xa0, 0x76, 0x50, 0x2f, 0x53, 0x87, 0xa9, 0x13, 0x34, 0x75,
132 0x9a, 0x25, 0xcd, 0x9b, 0x16, 0x43, 0xcb, 0xa4, 0x2d, 0xa3, 0xd5, 0xd0,
133 0x9a, 0x69, 0x67, 0x69, 0xf7, 0x68, 0x2f, 0xe9, 0x74, 0xba, 0x09, 0xdd,
134 0x83, 0x1e, 0x45, 0x97, 0xd0, 0x97, 0xd2, 0x6b, 0xe8, 0x07, 0xe9, 0xe7,
135 0xe9, 0x83, 0xf4, 0x77, 0x0c, 0x0d, 0x86, 0x0d, 0x83, 0xc7, 0x48, 0x62,
136 0x28, 0x19, 0x6b, 0x19, 0x7b, 0x19, 0xa7, 0x18, 0xb7, 0x19, 0x2f, 0x99,
137 0x4c, 0xa6, 0x05, 0xd3, 0x97, 0x99, 0xc8, 0x54, 0x30, 0xd7, 0x32, 0x1b,
138 0x99, 0x67, 0x98, 0x0f, 0x98, 0x6f, 0x55, 0x58, 0x2a, 0xf6, 0x2a, 0x7c,
139 0x15, 0x91, 0xca, 0x12, 0x95, 0x3a, 0x95, 0x56, 0x95, 0x7e, 0x95, 0xe7,
140 0xaa, 0x54, 0x55, 0x73, 0x55, 0x3f, 0xd5, 0x79, 0xaa, 0x0b, 0x54, 0xab,
141 0x55, 0x0f, 0xab, 0x5e, 0x56, 0x7d, 0xa6, 0x46, 0x55, 0xb3, 0x50, 0xe3,
142 0xa9, 0x09, 0xd4, 0x16, 0xab, 0xd5, 0xa9, 0x1d, 0x55, 0xbb, 0xa9, 0x36,
143 0xae, 0xce, 0x52, 0x77, 0x52, 0x8f, 0x50, 0xcf, 0x51, 0x5f, 0xa3, 0xbe,
144 0x5f, 0xfd, 0x82, 0xfa, 0x63, 0x0d, 0xb2, 0x86, 0x85, 0x46, 0xa0, 0x86,
145 0x48, 0xa3, 0x54, 0x63, 0xb7, 0xc6, 0x19, 0x8d, 0x21, 0x16, 0xc6, 0x32,
146 0x65, 0xf1, 0x58, 0x42, 0xd6, 0x72, 0x56, 0x03, 0xeb, 0x2c, 0x6b, 0x98,
147 0x4d, 0x62, 0x5b, 0xb2, 0xf9, 0xec, 0x4c, 0x76, 0x05, 0xfb, 0x1b, 0x76,
148 0x2f, 0x7b, 0x4c, 0x53, 0x43, 0x73, 0xaa, 0x66, 0xac, 0x66, 0x91, 0x66,
149 0x9d, 0xe6, 0x71, 0xcd, 0x01, 0x0e, 0xc6, 0xb1, 0xe0, 0xf0, 0x39, 0xd9,
150 0x9c, 0x4a, 0xce, 0x21, 0xce, 0x0d, 0xce, 0x7b, 0x2d, 0x03, 0x2d, 0x3f,
151 0x2d, 0xb1, 0xd6, 0x6a, 0xad, 0x66, 0xad, 0x7e, 0xad, 0x37, 0xda, 0x7a,
152 0xda, 0xbe, 0xda, 0x62, 0xed, 0x72, 0xed, 0x16, 0xed, 0xeb, 0xda, 0xef,
153 0x75, 0x70, 0x9d, 0x40, 0x9d, 0x2c, 0x9d, 0xf5, 0x3a, 0x6d, 0x3a, 0xf7,
154 0x75, 0x09, 0xba, 0x36, 0xba, 0x51, 0xba, 0x85, 0xba, 0xdb, 0x75, 0xcf,
155 0xea, 0x3e, 0xd3, 0x63, 0xeb, 0x79, 0xe9, 0x09, 0xf5, 0xca, 0xf5, 0x0e,
156 0xe9, 0xdd, 0xd1, 0x47, 0xf5, 0x6d, 0xf4, 0xa3, 0xf5, 0x17, 0xea, 0xef,
157 0xd6, 0xef, 0xd1, 0x1f, 0x37, 0x30, 0x34, 0x08, 0x36, 0x90, 0x19, 0x6c,
158 0x31, 0x38, 0x63, 0xf0, 0xcc, 0x90, 0x63, 0xe8, 0x6b, 0x98, 0x69, 0xb8,
159 0xd1, 0xf0, 0x84, 0xe1, 0xa8, 0x11, 0xcb, 0x68, 0xba, 0x91, 0xc4, 0x68,
160 0xa3, 0xd1, 0x49, 0xa3, 0x27, 0xb8, 0x26, 0xee, 0x87, 0x67, 0xe3, 0x35,
161 0x78, 0x17, 0x3e, 0x66, 0xac, 0x6f, 0x1c, 0x62, 0xac, 0x34, 0xde, 0x65,
162 0xdc, 0x6b, 0x3c, 0x61, 0x62, 0x69, 0x32, 0xdb, 0xa4, 0xc4, 0xa4, 0xc5,
163 0xe4, 0xbe, 0x29, 0xcd, 0x94, 0x6b, 0x9a, 0x66, 0xba, 0xd1, 0xb4, 0xd3,
164 0x74, 0xcc, 0xcc, 0xc8, 0x2c, 0xdc, 0xac, 0xd8, 0xac, 0x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86, 0xcf, 0x08, 0xdf, 0x10, 0x7e, 0x6f, 0xa6, 0xf9, 0x4c, 0xe9,
195 0xcc, 0xb6, 0x08, 0x88, 0xe0, 0x47, 0x6c, 0x88, 0xb8, 0x1f, 0x69, 0x19,
196 0x99, 0x17, 0xf9, 0x7d, 0x14, 0x29, 0x2a, 0x32, 0xaa, 0x2e, 0xea, 0x51,
197 0xb4, 0x53, 0x74, 0x71, 0x74, 0xf7, 0x2c, 0xd6, 0xac, 0xe4, 0x59, 0xfb,
198 0x67, 0xbd, 0x8e, 0xf1, 0x8f, 0xa9, 0x8c, 0xb9, 0x3b, 0xdb, 0x6a, 0xb6,
199 0x72, 0x76, 0x67, 0xac, 0x6a, 0x6c, 0x52, 0x6c, 0x63, 0xec, 0x9b, 0xb8,
200 0x80, 0xb8, 0xaa, 0xb8, 0x81, 0x78, 0x87, 0xf8, 0x45, 0xf1, 0x97, 0x12,
201 0x74, 0x13, 0x24, 0x09, 0xed, 0x89, 0xe4, 0xc4, 0xd8, 0xc4, 0x3d, 0x89,
202 0xe3, 0x73, 0x02, 0xe7, 0x6c, 0x9a, 0x33, 0x9c, 0xe4, 0x9a, 0x54, 0x96,
203 0x74, 0x63, 0xae, 0xe5, 0xdc, 0xa2, 0xb9, 0x17, 0xe6, 0xe9, 0xce, 0xcb,
204 0x9e, 0x77, 0x3c, 0x59, 0x35, 0x59, 0x90, 0x7c, 0x38, 0x85, 0x98, 0x12,
205 0x97, 0xb2, 0x3f, 0xe5, 0x83, 0x20, 0x42, 0x50, 0x2f, 0x18, 0x4f, 0xe5,
206 0xa7, 0x6e, 0x4d, 0x1d, 0x13, 0xf2, 0x84, 0x9b, 0x85, 0x4f, 0x45, 0xbe,
207 0xa2, 0x8d, 0xa2, 0x51, 0xb1, 0xb7, 0xb8, 0x4a, 0x3c, 0x92, 0xe6, 0x9d,
208 0x56, 0x95, 0xf6, 0x38, 0xdd, 0x3b, 0x7d, 0x43, 0xfa, 0x68, 0x86, 0x4f,
209 0x46, 0x75, 0xc6, 0x33, 0x09, 0x4f, 0x52, 0x2b, 0x79, 0x91, 0x19, 0x92,
210 0xb9, 0x23, 0xf3, 0x4d, 0x56, 0x44, 0xd6, 0xde, 0xac, 0xcf, 0xd9, 0x71,
211 0xd9, 0x2d, 0x39, 0x94, 0x9c, 0x94, 0x9c, 0xa3, 0x52, 0x0d, 0x69, 0x96,
212 0xb4, 0x2b, 0xd7, 0x30, 0xb7, 0x28, 0xb7, 0x4f, 0x66, 0x2b, 0x2b, 0x93,
213 0x0d, 0xe4, 0x79, 0xe6, 0x6d, 0xca, 0x1b, 0x93, 0x87, 0xca, 0xf7, 0xe4,
214 0x23, 0xf9, 0x73, 0xf3, 0xdb, 0x15, 0x6c, 0x85, 0x4c, 0xd1, 0xa3, 0xb4,
215 0x52, 0xae, 0x50, 0x0e, 0x16, 0x4c, 0x2f, 0xa8, 0x2b, 0x78, 0x5b, 0x18,
216 0x5b, 0x78, 0xb8, 0x48, 0xbd, 0x48, 0x5a, 0xd4, 0x33, 0xdf, 0x66, 0xfe,
217 0xea, 0xf9, 0x23, 0x0b, 0x82, 0x16, 0x7c, 0xbd, 0x90, 0xb0, 0x50, 0xb8,
218 0xb0, 0xb3, 0xd8, 0xb8, 0x78, 0x59, 0xf1, 0xe0, 0x22, 0xbf, 0x45, 0xbb,
219 0x16, 0x23, 0x8b, 0x53, 0x17, 0x77, 0x2e, 0x31, 0x5d, 0x52, 0xba, 0x64,
220 0x78, 0x69, 0xf0, 0xd2, 0x7d, 0xcb, 0x68, 0xcb, 0xb2, 0x96, 0xfd, 0x50,
221 0xe2, 0x58, 0x52, 0x55, 0xf2, 0x6a, 0x79, 0xdc, 0xf2, 0x8e, 0x52, 0x83,
222 0xd2, 0xa5, 0xa5, 0x43, 0x2b, 0x82, 0x57, 0x34, 0x95, 0xa9, 0x94, 0xc9,
223 0xcb, 0x6e, 0xae, 0xf4, 0x5a, 0xb9, 0x63, 0x15, 0x61, 0x95, 0x64, 0x55,
224 0xef, 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268 0xf7, 0x84, 0xf3, 0xfb, 0x80, 0x39, 0x25, 0x11, 0x00, 0x00, 0x00, 0x09,
269 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 0x0b, 0x13,
270 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4d,
271 0x45, 0x07, 0xdc, 0x0b, 0x0e, 0x0e, 0x25, 0x16, 0x28, 0x9e, 0x78, 0x6a,
272 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8,
273 0xff, 0xff, 0x3f, 0x00, 0x05, 0xfe, 0x02, 0xfe, 0xdc, 0xcc, 0x59, 0xe7,
274 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
277 static IWICImagingFactory *factory;
279 static HRESULT create_decoder(const void *image_data, UINT image_size, IWICBitmapDecoder **decoder)
281 HRESULT hr;
282 IStream *stream;
283 GUID format;
284 LONG refcount;
285 ULARGE_INTEGER pos;
286 LARGE_INTEGER zero;
288 *decoder = NULL;
290 stream = SHCreateMemStream (image_data, image_size);
291 ok(stream != NULL, "SHCreateMemStream error\n");
293 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, decoder);
294 if (hr == S_OK)
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));
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);
306 refcount = IStream_Release(stream);
307 ok(refcount > 0, "expected stream refcount > 0\n");
309 else
310 IStream_Release(stream);
312 return hr;
315 static WCHAR *save_profile( BYTE *buffer, UINT size )
317 static const WCHAR tstW[] = {'t','s','t',0};
318 WCHAR path[MAX_PATH], filename[MAX_PATH], *ret;
319 HANDLE handle;
320 DWORD count;
322 GetTempPathW(MAX_PATH, path);
323 GetTempFileNameW(path, tstW, 0, filename);
325 handle = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
326 if (handle == INVALID_HANDLE_VALUE) return NULL;
328 WriteFile(handle, buffer, size, &count, NULL);
329 CloseHandle( handle );
331 ret = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(filename) + 1) * sizeof(WCHAR));
332 lstrcpyW(ret, filename);
333 return ret;
336 static void test_color_contexts(void)
338 HRESULT hr;
339 IWICBitmapDecoder *decoder;
340 IWICBitmapFrameDecode *frame;
341 IWICColorContext *context;
342 WICColorContextType type;
343 UINT count, colorspace, size;
344 WCHAR *tmpfile;
345 BYTE *buffer;
346 BOOL ret;
348 hr = create_decoder(png_no_color_profile, sizeof(png_no_color_profile), &decoder);
349 ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
350 if (hr != S_OK) return;
352 /* global color context */
353 hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, NULL);
354 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts error %#x\n", hr);
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);
361 /* frame color context */
362 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
363 ok(hr == S_OK, "GetFrame error %#x\n", hr);
365 hr = IWICBitmapFrameDecode_GetColorContexts(frame, 0, NULL, NULL);
366 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
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);
373 IWICBitmapFrameDecode_Release(frame);
374 IWICBitmapDecoder_Release(decoder);
376 hr = create_decoder(png_color_profile, sizeof(png_color_profile), &decoder);
377 ok(hr == S_OK, "Failed to load PNG image data %#x\n", hr);
378 if (hr != S_OK) return;
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);
386 /* frame color context */
387 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
388 ok(hr == S_OK, "GetFrame error %#x\n", hr);
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);
395 hr = IWICImagingFactory_CreateColorContext(factory, NULL);
396 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
398 hr = IWICImagingFactory_CreateColorContext(factory, &context);
399 ok(hr == S_OK, "CreateColorContext error %#x\n", hr);
401 hr = IWICColorContext_GetType(context, NULL);
402 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
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);
409 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, NULL);
410 ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetProfileBytes error %#x\n", hr);
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);
417 hr = IWICColorContext_GetExifColorSpace(context, NULL);
418 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
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);
425 hr = IWICColorContext_InitializeFromExifColorSpace(context, 0);
426 ok(hr == S_OK, "InitializeFromExifColorSpace error %#x\n", hr);
428 hr = IWICColorContext_InitializeFromExifColorSpace(context, 1);
429 ok(hr == S_OK, "InitializeFromExifColorSpace error %#x\n", hr);
431 hr = IWICColorContext_InitializeFromExifColorSpace(context, 2);
432 ok(hr == S_OK, "InitializeFromExifColorSpace error %#x\n", hr);
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);
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);
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);
449 hr = IWICBitmapFrameDecode_GetColorContexts(frame, count, &context, &count);
450 ok(hr == WINCODEC_ERR_WRONGSTATE, "GetColorContexts error %#x\n", hr);
452 IWICColorContext_Release(context);
453 IWICBitmapFrameDecode_Release(frame);
455 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
456 ok(hr == S_OK, "GetFrame error %#x\n", hr);
458 hr = IWICImagingFactory_CreateColorContext(factory, &context);
459 ok(hr == S_OK, "CreateColorContext error %#x\n", hr);
461 count = 1;
462 hr = IWICBitmapFrameDecode_GetColorContexts(frame, count, &context, &count);
463 ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
465 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, NULL);
466 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
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);
473 buffer = HeapAlloc(GetProcessHeap(), 0, size);
474 hr = IWICColorContext_GetProfileBytes(context, size, buffer, &size);
475 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
477 tmpfile = save_profile( buffer, size );
478 HeapFree(GetProcessHeap(), 0, buffer);
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);
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);
490 hr = IWICColorContext_InitializeFromExifColorSpace(context, 1);
491 ok(hr == WINCODEC_ERR_WRONGSTATE, "InitializeFromExifColorSpace error %#x\n", hr);
493 if (tmpfile)
495 hr = IWICColorContext_InitializeFromFilename(context, NULL);
496 ok(hr == E_INVALIDARG, "InitializeFromFilename error %#x\n", hr);
498 hr = IWICColorContext_InitializeFromFilename(context, tmpfile);
499 ok(hr == S_OK, "InitializeFromFilename error %#x\n", hr);
501 ret = DeleteFileW(tmpfile);
502 ok(ret, "DeleteFileW failed %u\n", GetLastError());
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);
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);
514 hr = IWICColorContext_InitializeFromExifColorSpace(context, 1);
515 ok(hr == WINCODEC_ERR_WRONGSTATE, "InitializeFromExifColorSpace error %#x\n", hr);
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);
522 buffer = HeapAlloc(GetProcessHeap(), 0, size);
523 hr = IWICColorContext_GetProfileBytes(context, size, buffer, &size);
524 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
526 HeapFree(GetProcessHeap(), 0, buffer);
527 HeapFree(GetProcessHeap(), 0, tmpfile);
529 IWICColorContext_Release(context);
530 IWICBitmapFrameDecode_Release(frame);
531 IWICBitmapDecoder_Release(decoder);
534 /* 1 bpp 1x1 pixel PNG image with PLTE and tRNS chunks */
535 static const char png_PLTE_tRNS[] = {
536 0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,
537 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,
538 0x00,0x00,0x00,0x06,'P','L','T','E',0x01,0x02,0x03,0x04,0x05,0x06,0x95,0x53,0x6f,0x48,
539 0x00,0x00,0x00,0x02,'t','R','N','S',0xff,0x00,0xe5,0xb7,0x30,0x4a,
540 0x00,0x00,0x00,0x0a,'I','D','A','T',0x18,0xd3,0x63,0x68,0x00,0x00,0x00,0x82,0x00,0x81,0xa7,0x01,0xba,0x10,
541 0x00,0x00,0x00,0x00,'I','E','N','D',0xae,0x42,0x60,0x82
544 /* grayscale 16 bpp 1x1 pixel PNG image with tRNS chunk */
545 static const char png_gray_tRNS[] = {
546 0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,
547 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,
548 0x00,0x00,0x00,0x02,'t','R','N','S',0x00,0x00,0x76,0x93,0xcd,0x38,
549 0x00,0x00,0x00,0x0b,'I','D','A','T',0x78,0x9c,0x63,0x60,0x60,0x00,0x00,0x00,0x03,0x00,0x01,0xb8,0xad,0x3a,0x63,
550 0x00,0x00,0x00,0x00,'I','E','N','D',0xae,0x42,0x60,0x82
553 static void test_png_palette(void)
555 HRESULT hr;
556 IWICBitmapDecoder *decoder;
557 IWICBitmapFrameDecode *frame;
558 IWICPalette *palette;
559 GUID format;
560 UINT count, ret;
561 WICColor color[256];
562 char *buf;
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;
568 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
569 ok(hr == S_OK, "GetFrame error %#x\n", hr);
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));
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);
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);
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]);
591 IWICPalette_Release(palette);
592 IWICBitmapFrameDecode_Release(frame);
593 IWICBitmapDecoder_Release(decoder);
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;
599 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
600 ok(hr == S_OK, "GetFrame error %#x\n", hr);
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));
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);
612 IWICPalette_Release(palette);
613 IWICBitmapFrameDecode_Release(frame);
614 IWICBitmapDecoder_Release(decoder);
616 /* test 8 bpp grayscale PNG image with tRNS chunk */
617 buf = HeapAlloc(GetProcessHeap(), 0, sizeof(png_gray_tRNS));
618 memcpy(buf, png_gray_tRNS, sizeof(png_gray_tRNS));
619 buf[24] = 8; /* override bit depth */
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;
625 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
626 ok(hr == S_OK, "GetFrame error %#x\n", hr);
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));
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);
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);
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]);
648 HeapFree(GetProcessHeap(), 0, buf);
649 IWICPalette_Release(palette);
650 IWICBitmapFrameDecode_Release(frame);
651 IWICBitmapDecoder_Release(decoder);
654 /* RGB 24 bpp 1x1 pixel PNG image */
655 static const char png_1x1_data[] = {
656 0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,
657 0x00,0x00,0x00,0x0d,'I','H','D','R',0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,0xde,
658 0x00,0x00,0x03,0x00,'P','L','T','E',
659 0x01,0x01,0x01,0x02,0x02,0x02,0x03,0x03,0x03,0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x06,0x06,0x07,0x07,0x07,0x08,0x08,0x08,
660 0x09,0x09,0x09,0x0a,0x0a,0x0a,0x0b,0x0b,0x0b,0x0c,0x0c,0x0c,0x0d,0x0d,0x0d,0x0e,0x0e,0x0e,0x0f,0x0f,0x0f,0x10,0x10,0x10,
661 0x11,0x11,0x11,0x12,0x12,0x12,0x13,0x13,0x13,0x14,0x14,0x14,0x15,0x15,0x15,0x16,0x16,0x16,0x17,0x17,0x17,0x18,0x18,0x18,
662 0x19,0x19,0x19,0x1a,0x1a,0x1a,0x1b,0x1b,0x1b,0x1c,0x1c,0x1c,0x1d,0x1d,0x1d,0x1e,0x1e,0x1e,0x1f,0x1f,0x1f,0x20,0x20,0x20,
663 0x21,0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x23,0x24,0x24,0x24,0x25,0x25,0x25,0x26,0x26,0x26,0x27,0x27,0x27,0x28,0x28,0x28,
664 0x29,0x29,0x29,0x2a,0x2a,0x2a,0x2b,0x2b,0x2b,0x2c,0x2c,0x2c,0x2d,0x2d,0x2d,0x2e,0x2e,0x2e,0x2f,0x2f,0x2f,0x30,0x30,0x30,
665 0x31,0x31,0x31,0x32,0x32,0x32,0x33,0x33,0x33,0x34,0x34,0x34,0x35,0x35,0x35,0x36,0x36,0x36,0x37,0x37,0x37,0x38,0x38,0x38,
666 0x39,0x39,0x39,0x3a,0x3a,0x3a,0x3b,0x3b,0x3b,0x3c,0x3c,0x3c,0x3d,0x3d,0x3d,0x3e,0x3e,0x3e,0x3f,0x3f,0x3f,0x40,0x40,0x40,
667 0x41,0x41,0x41,0x42,0x42,0x42,0x43,0x43,0x43,0x44,0x44,0x44,0x45,0x45,0x45,0x46,0x46,0x46,0x47,0x47,0x47,0x48,0x48,0x48,
668 0x49,0x49,0x49,0x4a,0x4a,0x4a,0x4b,0x4b,0x4b,0x4c,0x4c,0x4c,0x4d,0x4d,0x4d,0x4e,0x4e,0x4e,0x4f,0x4f,0x4f,0x50,0x50,0x50,
669 0x51,0x51,0x51,0x52,0x52,0x52,0x53,0x53,0x53,0x54,0x54,0x54,0x55,0x55,0x55,0x56,0x56,0x56,0x57,0x57,0x57,0x58,0x58,0x58,
670 0x59,0x59,0x59,0x5a,0x5a,0x5a,0x5b,0x5b,0x5b,0x5c,0x5c,0x5c,0x5d,0x5d,0x5d,0x5e,0x5e,0x5e,0x5f,0x5f,0x5f,0x60,0x60,0x60,
671 0x61,0x61,0x61,0x62,0x62,0x62,0x63,0x63,0x63,0x64,0x64,0x64,0x65,0x65,0x65,0x66,0x66,0x66,0x67,0x67,0x67,0x68,0x68,0x68,
672 0x69,0x69,0x69,0x6a,0x6a,0x6a,0x6b,0x6b,0x6b,0x6c,0x6c,0x6c,0x6d,0x6d,0x6d,0x6e,0x6e,0x6e,0x6f,0x6f,0x6f,0x70,0x70,0x70,
673 0x71,0x71,0x71,0x72,0x72,0x72,0x73,0x73,0x73,0x74,0x74,0x74,0x75,0x75,0x75,0x76,0x76,0x76,0x77,0x77,0x77,0x78,0x78,0x78,
674 0x79,0x79,0x79,0x7a,0x7a,0x7a,0x7b,0x7b,0x7b,0x7c,0x7c,0x7c,0x7d,0x7d,0x7d,0x7e,0x7e,0x7e,0x7f,0x7f,0x7f,0x80,0x80,0x80,
675 0x01,0x01,0x01,0x02,0x02,0x02,0x03,0x03,0x03,0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x06,0x06,0x07,0x07,0x07,0x08,0x08,0x08,
676 0x09,0x09,0x09,0x0a,0x0a,0x0a,0x0b,0x0b,0x0b,0x0c,0x0c,0x0c,0x0d,0x0d,0x0d,0x0e,0x0e,0x0e,0x0f,0x0f,0x0f,0x10,0x10,0x10,
677 0x11,0x11,0x11,0x12,0x12,0x12,0x13,0x13,0x13,0x14,0x14,0x14,0x15,0x15,0x15,0x16,0x16,0x16,0x17,0x17,0x17,0x18,0x18,0x18,
678 0x19,0x19,0x19,0x1a,0x1a,0x1a,0x1b,0x1b,0x1b,0x1c,0x1c,0x1c,0x1d,0x1d,0x1d,0x1e,0x1e,0x1e,0x1f,0x1f,0x1f,0x20,0x20,0x20,
679 0x21,0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x23,0x24,0x24,0x24,0x25,0x25,0x25,0x26,0x26,0x26,0x27,0x27,0x27,0x28,0x28,0x28,
680 0x29,0x29,0x29,0x2a,0x2a,0x2a,0x2b,0x2b,0x2b,0x2c,0x2c,0x2c,0x2d,0x2d,0x2d,0x2e,0x2e,0x2e,0x2f,0x2f,0x2f,0x30,0x30,0x30,
681 0x31,0x31,0x31,0x32,0x32,0x32,0x33,0x33,0x33,0x34,0x34,0x34,0x35,0x35,0x35,0x36,0x36,0x36,0x37,0x37,0x37,0x38,0x38,0x38,
682 0x39,0x39,0x39,0x3a,0x3a,0x3a,0x3b,0x3b,0x3b,0x3c,0x3c,0x3c,0x3d,0x3d,0x3d,0x3e,0x3e,0x3e,0x3f,0x3f,0x3f,0x40,0x40,0x40,
683 0x41,0x41,0x41,0x42,0x42,0x42,0x43,0x43,0x43,0x44,0x44,0x44,0x45,0x45,0x45,0x46,0x46,0x46,0x47,0x47,0x47,0x48,0x48,0x48,
684 0x49,0x49,0x49,0x4a,0x4a,0x4a,0x4b,0x4b,0x4b,0x4c,0x4c,0x4c,0x4d,0x4d,0x4d,0x4e,0x4e,0x4e,0x4f,0x4f,0x4f,0x50,0x50,0x50,
685 0x51,0x51,0x51,0x52,0x52,0x52,0x53,0x53,0x53,0x54,0x54,0x54,0x55,0x55,0x55,0x56,0x56,0x56,0x57,0x57,0x57,0x58,0x58,0x58,
686 0x59,0x59,0x59,0x5a,0x5a,0x5a,0x5b,0x5b,0x5b,0x5c,0x5c,0x5c,0x5d,0x5d,0x5d,0x5e,0x5e,0x5e,0x5f,0x5f,0x5f,0x60,0x60,0x60,
687 0x61,0x61,0x61,0x62,0x62,0x62,0x63,0x63,0x63,0x64,0x64,0x64,0x65,0x65,0x65,0x66,0x66,0x66,0x67,0x67,0x67,0x68,0x68,0x68,
688 0x69,0x69,0x69,0x6a,0x6a,0x6a,0x6b,0x6b,0x6b,0x6c,0x6c,0x6c,0x6d,0x6d,0x6d,0x6e,0x6e,0x6e,0x6f,0x6f,0x6f,0x70,0x70,0x70,
689 0x71,0x71,0x71,0x72,0x72,0x72,0x73,0x73,0x73,0x74,0x74,0x74,0x75,0x75,0x75,0x76,0x76,0x76,0x77,0x77,0x77,0x78,0x78,0x78,
690 0x79,0x79,0x79,0x7a,0x7a,0x7a,0x7b,0x7b,0x7b,0x7c,0x7c,0x7c,0x7d,0x7d,0x7d,0x7e,0x7e,0x7e,0x7f,0x7f,0x7f,0x80,0x80,0x80,
691 0x76,0xb6,0x24,0x31,
692 0x00,0x00,0x00,0x02,'t','R','N','S',0xff,0x00,0xe5,0xb7,0x30,0x4a,
693 0x00,0x00,0x00,0x0c,'I','D','A','T',0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,0xe7,
694 0x00,0x00,0x00,0x00,'I','E','N','D',0xae,0x42,0x60,0x82
697 #define PNG_COLOR_TYPE_GRAY 0
698 #define PNG_COLOR_TYPE_RGB 2
699 #define PNG_COLOR_TYPE_PALETTE 3
700 #define PNG_COLOR_TYPE_GRAY_ALPHA 4
701 #define PNG_COLOR_TYPE_RGB_ALPHA 6
703 static BOOL is_valid_png_type_depth(int color_type, int bit_depth, BOOL plte)
705 switch (color_type)
707 case PNG_COLOR_TYPE_GRAY:
708 return bit_depth == 1 || bit_depth == 2 || bit_depth == 4 || bit_depth == 8 || bit_depth == 16;
710 case PNG_COLOR_TYPE_RGB:
711 return bit_depth == 8 || bit_depth == 16;
713 case PNG_COLOR_TYPE_PALETTE:
714 return (bit_depth == 1 || bit_depth == 2 || bit_depth == 4 || bit_depth == 8) && plte;
716 case PNG_COLOR_TYPE_GRAY_ALPHA:
717 return bit_depth == 8 || bit_depth == 16;
719 case PNG_COLOR_TYPE_RGB_ALPHA:
720 return bit_depth == 8 || bit_depth == 16;
722 default:
723 ok(0, "unknown PNG type %d, depth %d\n", color_type, bit_depth);
724 return FALSE;
728 static void test_color_formats(void)
730 static const struct
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[] =
740 /* 2 - PNG_COLOR_TYPE_RGB */
741 { 1, PNG_COLOR_TYPE_RGB, NULL, NULL, NULL },
742 { 2, PNG_COLOR_TYPE_RGB, NULL, NULL, NULL },
743 { 4, PNG_COLOR_TYPE_RGB, NULL, NULL, NULL },
744 { 8, 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.
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 */
755 { 1, PNG_COLOR_TYPE_GRAY,
756 &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormat1bppIndexed },
757 { 2, PNG_COLOR_TYPE_GRAY,
758 &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppGray, &GUID_WICPixelFormat2bppIndexed },
759 { 4, PNG_COLOR_TYPE_GRAY,
760 &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppGray, &GUID_WICPixelFormat4bppIndexed },
761 { 8, PNG_COLOR_TYPE_GRAY,
762 &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppIndexed },
763 { 16, PNG_COLOR_TYPE_GRAY,
764 &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat16bppGray, &GUID_WICPixelFormat64bppRGBA },
765 { 24, PNG_COLOR_TYPE_GRAY, NULL, NULL, NULL },
766 { 32, PNG_COLOR_TYPE_GRAY, NULL, NULL, NULL },
767 /* 3 - PNG_COLOR_TYPE_PALETTE */
768 { 1, PNG_COLOR_TYPE_PALETTE,
769 &GUID_WICPixelFormat1bppIndexed, &GUID_WICPixelFormat1bppIndexed, &GUID_WICPixelFormat1bppIndexed },
770 { 2, PNG_COLOR_TYPE_PALETTE,
771 &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat2bppIndexed },
772 { 4, PNG_COLOR_TYPE_PALETTE,
773 &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed },
774 { 8, PNG_COLOR_TYPE_PALETTE,
775 &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed },
776 { 16, PNG_COLOR_TYPE_PALETTE, NULL, NULL, NULL },
777 { 24, PNG_COLOR_TYPE_PALETTE, NULL, NULL, NULL },
778 { 32, PNG_COLOR_TYPE_PALETTE, NULL, NULL, NULL },
780 char buf[sizeof(png_1x1_data)];
781 HRESULT hr;
782 IWICBitmapDecoder *decoder;
783 IWICBitmapFrameDecode *frame;
784 GUID format;
785 int i, PLTE_off = 0, tRNS_off = 0;
787 memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
788 for (i = 0; i < sizeof(png_1x1_data) - 4; i++)
790 if (!memcmp(buf + i, "tRNS", 4))
791 tRNS_off = i;
792 else if (!memcmp(buf + i, "PLTE", 4))
793 PLTE_off = i;
796 ok(PLTE_off && tRNS_off, "PLTE offset %d, tRNS offset %d\n", PLTE_off, tRNS_off);
797 if (!PLTE_off || !tRNS_off) return;
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.
807 for (i = 0; i < ARRAY_SIZE(td); i++)
809 /* with the tRNS and PLTE chunks */
810 memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
811 buf[24] = td[i].bit_depth;
812 buf[25] = td[i].color_type;
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
818 todo_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;
822 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
823 ok(hr == S_OK, "GetFrame error %#x\n", hr);
825 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
826 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
827 todo_wine_if(td[i].todo)
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);
832 IWICBitmapFrameDecode_Release(frame);
833 IWICBitmapDecoder_Release(decoder);
835 next_1:
836 /* without the tRNS chunk */
837 memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
838 buf[24] = td[i].bit_depth;
839 buf[25] = td[i].color_type;
840 memcpy(buf + tRNS_off, "tEXt", 4);
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
846 todo_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;
850 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
851 ok(hr == S_OK, "GetFrame error %#x\n", hr);
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);
859 IWICBitmapFrameDecode_Release(frame);
860 IWICBitmapDecoder_Release(decoder);
862 next_2:
863 /* without the tRNS and PLTE chunks */
864 memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
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);
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
874 todo_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;
878 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
879 ok(hr == S_OK, "GetFrame error %#x\n", hr);
881 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
882 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
883 ok(IsEqualGUID(&format, td[i].format),
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);
887 IWICBitmapFrameDecode_Release(frame);
888 IWICBitmapDecoder_Release(decoder);
890 next_3:
891 /* without the PLTE chunk */
892 memcpy(buf, png_1x1_data, sizeof(png_1x1_data));
893 buf[24] = td[i].bit_depth;
894 buf[25] = td[i].color_type;
895 memcpy(buf + PLTE_off, "tEXt", 4);
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
901 todo_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;
905 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
906 ok(hr == S_OK, "GetFrame error %#x\n", hr);
908 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
909 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
910 todo_wine_if(td[i].todo)
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);
915 IWICBitmapFrameDecode_Release(frame);
916 IWICBitmapDecoder_Release(decoder);
919 #undef PNG_COLOR_TYPE_GRAY
920 #undef PNG_COLOR_TYPE_RGB
921 #undef PNG_COLOR_TYPE_PALETTE
922 #undef PNG_COLOR_TYPE_GRAY_ALPHA
923 #undef PNG_COLOR_TYPE_RGB_ALPHA
925 START_TEST(pngformat)
927 HRESULT hr;
929 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
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;
935 test_color_contexts();
936 test_png_palette();
937 test_color_formats();
939 IWICImagingFactory_Release(factory);
940 CoUninitialize();