[WINDOWSCODECS_WINETEST] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / rostests / winetests / windowscodecs / pngformat.c
1 /*
2 * Copyright 2012 Dmitry Timoshkov
3 * Copyright 2012 Hans Leidekker for CodeWeavers
4 *
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.
9 *
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.
14 *
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
18 */
19
20 //#include <stdarg.h>
21 #include <stdio.h>
22
23 #define WIN32_NO_STATUS
24 #define _INC_WINDOWS
25 #define COM_NO_WINDOWS_H
26
27 #define COBJMACROS
28
29 #include <windef.h>
30 #include <winbase.h>
31 #include <ole2.h>
32 #include <wincodec.h>
33 #include <wine/test.h>
34
35 /* 1x1 pixel PNG image */
36 static const char png_no_color_profile[] = {
37 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
38 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
39 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xde, 0x00, 0x00, 0x00,
40 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 0x0b,
41 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49,
42 0x4d, 0x45, 0x07, 0xdc, 0x0b, 0x0e, 0x0e, 0x22, 0x17, 0x10, 0xd8, 0xde,
43 0x3b, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63,
44 0xf8, 0xff, 0xff, 0x3f, 0x00, 0x05, 0xfe, 0x02, 0xfe, 0xdc, 0xcc, 0x59,
45 0xe7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
46 0x82
47 };
48
49 /* 1x1 pixel PNG image with embedded sRGB profile */
50 static const char png_color_profile[] = {
51 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
52 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
53 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xde, 0x00, 0x00, 0x0a,
54 0x43, 0x69, 0x43, 0x43, 0x50, 0x49, 0x43, 0x43, 0x20, 0x70, 0x72, 0x6f,
55 0x66, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x78, 0xda, 0x9d, 0x53, 0x77, 0x58,
56 0x93, 0xf7, 0x16, 0x3e, 0xdf, 0xf7, 0x65, 0x0f, 0x56, 0x42, 0xd8, 0xf0,
57 0xb1, 0x97, 0x6c, 0x81, 0x00, 0x22, 0x23, 0xac, 0x08, 0xc8, 0x10, 0x59,
58 0xa2, 0x10, 0x92, 0x00, 0x61, 0x84, 0x10, 0x12, 0x40, 0xc5, 0x85, 0x88,
59 0x0a, 0x56, 0x14, 0x15, 0x11, 0x9c, 0x48, 0x55, 0xc4, 0x82, 0xd5, 0x0a,
60 0x48, 0x9d, 0x88, 0xe2, 0xa0, 0x28, 0xb8, 0x67, 0x41, 0x8a, 0x88, 0x5a,
61 0x8b, 0x55, 0x5c, 0x38, 0xee, 0x1f, 0xdc, 0xa7, 0xb5, 0x7d, 0x7a, 0xef,
62 0xed, 0xed, 0xfb, 0xd7, 0xfb, 0xbc, 0xe7, 0x9c, 0xe7, 0xfc, 0xce, 0x79,
63 0xcf, 0x0f, 0x80, 0x11, 0x12, 0x26, 0x91, 0xe6, 0xa2, 0x6a, 0x00, 0x39,
64 0x52, 0x85, 0x3c, 0x3a, 0xd8, 0x1f, 0x8f, 0x4f, 0x48, 0xc4, 0xc9, 0xbd,
65 0x80, 0x02, 0x15, 0x48, 0xe0, 0x04, 0x20, 0x10, 0xe6, 0xcb, 0xc2, 0x67,
66 0x05, 0xc5, 0x00, 0x00, 0xf0, 0x03, 0x79, 0x78, 0x7e, 0x74, 0xb0, 0x3f,
67 0xfc, 0x01, 0xaf, 0x6f, 0x00, 0x02, 0x00, 0x70, 0xd5, 0x2e, 0x24, 0x12,
68 0xc7, 0xe1, 0xff, 0x83, 0xba, 0x50, 0x26, 0x57, 0x00, 0x20, 0x91, 0x00,
69 0xe0, 0x22, 0x12, 0xe7, 0x0b, 0x01, 0x90, 0x52, 0x00, 0xc8, 0x2e, 0x54,
70 0xc8, 0x14, 0x00, 0xc8, 0x18, 0x00, 0xb0, 0x53, 0xb3, 0x64, 0x0a, 0x00,
71 0x94, 0x00, 0x00, 0x6c, 0x79, 0x7c, 0x42, 0x22, 0x00, 0xaa, 0x0d, 0x00,
72 0xec, 0xf4, 0x49, 0x3e, 0x05, 0x00, 0xd8, 0xa9, 0x93, 0xdc, 0x17, 0x00,
73 0xd8, 0xa2, 0x1c, 0xa9, 0x08, 0x00, 0x8d, 0x01, 0x00, 0x99, 0x28, 0x47,
74 0x24, 0x02, 0x40, 0xbb, 0x00, 0x60, 0x55, 0x81, 0x52, 0x2c, 0x02, 0xc0,
75 0xc2, 0x00, 0xa0, 0xac, 0x40, 0x22, 0x2e, 0x04, 0xc0, 0xae, 0x01, 0x80,
76 0x59, 0xb6, 0x32, 0x47, 0x02, 0x80, 0xbd, 0x05, 0x00, 0x76, 0x8e, 0x58,
77 0x90, 0x0f, 0x40, 0x60, 0x00, 0x80, 0x99, 0x42, 0x2c, 0xcc, 0x00, 0x20,
78 0x38, 0x02, 0x00, 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0x00, 0x71, 0x9a, 0x40, 0x99, 0xad, 0xc0, 0xa3, 0x83, 0xfd, 0x71, 0x61,
94 0x6e, 0x76, 0xae, 0x52, 0x8e, 0xe7, 0xcb, 0x04, 0x42, 0x31, 0x6e, 0xf7,
95 0xe7, 0x23, 0xfe, 0xc7, 0x85, 0x7f, 0xfd, 0x8e, 0x29, 0xd1, 0xe2, 0x34,
96 0xb1, 0x5c, 0x2c, 0x15, 0x8a, 0xf1, 0x58, 0x89, 0xb8, 0x50, 0x22, 0x4d,
97 0xc7, 0x79, 0xb9, 0x52, 0x91, 0x44, 0x21, 0xc9, 0x95, 0xe2, 0x12, 0xe9,
98 0x7f, 0x32, 0xf1, 0x1f, 0x96, 0xfd, 0x09, 0x93, 0x77, 0x0d, 0x00, 0xac,
99 0x86, 0x4f, 0xc0, 0x4e, 0xb6, 0x07, 0xb5, 0xcb, 0x6c, 0xc0, 0x7e, 0xee,
100 0x01, 0x02, 0x8b, 0x0e, 0x58, 0xd2, 0x76, 0x00, 0x40, 0x7e, 0xf3, 0x2d,
101 0x8c, 0x1a, 0x0b, 0x91, 0x00, 0x10, 0x67, 0x34, 0x32, 0x79, 0xf7, 0x00,
102 0x00, 0x93, 0xbf, 0xf9, 0x8f, 0x40, 0x2b, 0x01, 0x00, 0xcd, 0x97, 0xa4,
103 0xe3, 0x00, 0x00, 0xbc, 0xe8, 0x18, 0x5c, 0xa8, 0x94, 0x17, 0x4c, 0xc6,
104 0x08, 0x00, 0x00, 0x44, 0xa0, 0x81, 0x2a, 0xb0, 0x41, 0x07, 0x0c, 0xc1,
105 0x14, 0xac, 0xc0, 0x0e, 0x9c, 0xc1, 0x1d, 0xbc, 0xc0, 0x17, 0x02, 0x61,
106 0x06, 0x44, 0x40, 0x0c, 0x24, 0xc0, 0x3c, 0x10, 0x42, 0x06, 0xe4, 0x80,
107 0x1c, 0x0a, 0xa1, 0x18, 0x96, 0x41, 0x19, 0x54, 0xc0, 0x3a, 0xd8, 0x04,
108 0xb5, 0xb0, 0x03, 0x1a, 0xa0, 0x11, 0x9a, 0xe1, 0x10, 0xb4, 0xc1, 0x31,
109 0x38, 0x0d, 0xe7, 0xe0, 0x12, 0x5c, 0x81, 0xeb, 0x70, 0x17, 0x06, 0x60,
110 0x18, 0x9e, 0xc2, 0x18, 0xbc, 0x86, 0x09, 0x04, 0x41, 0xc8, 0x08, 0x13,
111 0x61, 0x21, 0x3a, 0x88, 0x11, 0x62, 0x8e, 0xd8, 0x22, 0xce, 0x08, 0x17,
112 0x99, 0x8e, 0x04, 0x22, 0x61, 0x48, 0x34, 0x92, 0x80, 0xa4, 0x20, 0xe9,
113 0x88, 0x14, 0x51, 0x22, 0xc5, 0xc8, 0x72, 0xa4, 0x02, 0xa9, 0x42, 0x6a,
114 0x91, 0x5d, 0x48, 0x23, 0xf2, 0x2d, 0x72, 0x14, 0x39, 0x8d, 0x5c, 0x40,
115 0xfa, 0x90, 0xdb, 0xc8, 0x20, 0x32, 0x8a, 0xfc, 0x8a, 0xbc, 0x47, 0x31,
116 0x94, 0x81, 0xb2, 0x51, 0x03, 0xd4, 0x02, 0x75, 0x40, 0xb9, 0xa8, 0x1f,
117 0x1a, 0x8a, 0xc6, 0xa0, 0x73, 0xd1, 0x74, 0x34, 0x0f, 0x5d, 0x80, 0x96,
118 0xa2, 0x6b, 0xd1, 0x1a, 0xb4, 0x1e, 0x3d, 0x80, 0xb6, 0xa2, 0xa7, 0xd1,
119 0x4b, 0xe8, 0x75, 0x74, 0x00, 0x7d, 0x8a, 0x8e, 0x63, 0x80, 0xd1, 0x31,
120 0x0e, 0x66, 0x8c, 0xd9, 0x61, 0x5c, 0x8c, 0x87, 0x45, 0x60, 0x89, 0x58,
121 0x1a, 0x26, 0xc7, 0x16, 0x63, 0xe5, 0x58, 0x35, 0x56, 0x8f, 0x35, 0x63,
122 0x1d, 0x58, 0x37, 0x76, 0x15, 0x1b, 0xc0, 0x9e, 0x61, 0xef, 0x08, 0x24,
123 0x02, 0x8b, 0x80, 0x13, 0xec, 0x08, 0x5e, 0x84, 0x10, 0xc2, 0x6c, 0x82,
124 0x90, 0x90, 0x47, 0x58, 0x4c, 0x58, 0x43, 0xa8, 0x25, 0xec, 0x23, 0xb4,
125 0x12, 0xba, 0x08, 0x57, 0x09, 0x83, 0x84, 0x31, 0xc2, 0x27, 0x22, 0x93,
126 0xa8, 0x4f, 0xb4, 0x25, 0x7a, 0x12, 0xf9, 0xc4, 0x78, 0x62, 0x3a, 0xb1,
127 0x90, 0x58, 0x46, 0xac, 0x26, 0xee, 0x21, 0x1e, 0x21, 0x9e, 0x25, 0x5e,
128 0x27, 0x0e, 0x13, 0x5f, 0x93, 0x48, 0x24, 0x0e, 0xc9, 0x92, 0xe4, 0x4e,
129 0x0a, 0x21, 0x25, 0x90, 0x32, 0x49, 0x0b, 0x49, 0x6b, 0x48, 0xdb, 0x48,
130 0x2d, 0xa4, 0x53, 0xa4, 0x3e, 0xd2, 0x10, 0x69, 0x9c, 0x4c, 0x26, 0xeb,
131 0x90, 0x6d, 0xc9, 0xde, 0xe4, 0x08, 0xb2, 0x80, 0xac, 0x20, 0x97, 0x91,
132 0xb7, 0x90, 0x0f, 0x90, 0x4f, 0x92, 0xfb, 0xc9, 0xc3, 0xe4, 0xb7, 0x14,
133 0x3a, 0xc5, 0x88, 0xe2, 0x4c, 0x09, 0xa2, 0x24, 0x52, 0xa4, 0x94, 0x12,
134 0x4a, 0x35, 0x65, 0x3f, 0xe5, 0x04, 0xa5, 0x9f, 0x32, 0x42, 0x99, 0xa0,
135 0xaa, 0x51, 0xcd, 0xa9, 0x9e, 0xd4, 0x08, 0xaa, 0x88, 0x3a, 0x9f, 0x5a,
136 0x49, 0x6d, 0xa0, 0x76, 0x50, 0x2f, 0x53, 0x87, 0xa9, 0x13, 0x34, 0x75,
137 0x9a, 0x25, 0xcd, 0x9b, 0x16, 0x43, 0xcb, 0xa4, 0x2d, 0xa3, 0xd5, 0xd0,
138 0x9a, 0x69, 0x67, 0x69, 0xf7, 0x68, 0x2f, 0xe9, 0x74, 0xba, 0x09, 0xdd,
139 0x83, 0x1e, 0x45, 0x97, 0xd0, 0x97, 0xd2, 0x6b, 0xe8, 0x07, 0xe9, 0xe7,
140 0xe9, 0x83, 0xf4, 0x77, 0x0c, 0x0d, 0x86, 0x0d, 0x83, 0xc7, 0x48, 0x62,
141 0x28, 0x19, 0x6b, 0x19, 0x7b, 0x19, 0xa7, 0x18, 0xb7, 0x19, 0x2f, 0x99,
142 0x4c, 0xa6, 0x05, 0xd3, 0x97, 0x99, 0xc8, 0x54, 0x30, 0xd7, 0x32, 0x1b,
143 0x99, 0x67, 0x98, 0x0f, 0x98, 0x6f, 0x55, 0x58, 0x2a, 0xf6, 0x2a, 0x7c,
144 0x15, 0x91, 0xca, 0x12, 0x95, 0x3a, 0x95, 0x56, 0x95, 0x7e, 0x95, 0xe7,
145 0xaa, 0x54, 0x55, 0x73, 0x55, 0x3f, 0xd5, 0x79, 0xaa, 0x0b, 0x54, 0xab,
146 0x55, 0x0f, 0xab, 0x5e, 0x56, 0x7d, 0xa6, 0x46, 0x55, 0xb3, 0x50, 0xe3,
147 0xa9, 0x09, 0xd4, 0x16, 0xab, 0xd5, 0xa9, 0x1d, 0x55, 0xbb, 0xa9, 0x36,
148 0xae, 0xce, 0x52, 0x77, 0x52, 0x8f, 0x50, 0xcf, 0x51, 0x5f, 0xa3, 0xbe,
149 0x5f, 0xfd, 0x82, 0xfa, 0x63, 0x0d, 0xb2, 0x86, 0x85, 0x46, 0xa0, 0x86,
150 0x48, 0xa3, 0x54, 0x63, 0xb7, 0xc6, 0x19, 0x8d, 0x21, 0x16, 0xc6, 0x32,
151 0x65, 0xf1, 0x58, 0x42, 0xd6, 0x72, 0x56, 0x03, 0xeb, 0x2c, 0x6b, 0x98,
152 0x4d, 0x62, 0x5b, 0xb2, 0xf9, 0xec, 0x4c, 0x76, 0x05, 0xfb, 0x1b, 0x76,
153 0x2f, 0x7b, 0x4c, 0x53, 0x43, 0x73, 0xaa, 0x66, 0xac, 0x66, 0x91, 0x66,
154 0x9d, 0xe6, 0x71, 0xcd, 0x01, 0x0e, 0xc6, 0xb1, 0xe0, 0xf0, 0x39, 0xd9,
155 0x9c, 0x4a, 0xce, 0x21, 0xce, 0x0d, 0xce, 0x7b, 0x2d, 0x03, 0x2d, 0x3f,
156 0x2d, 0xb1, 0xd6, 0x6a, 0xad, 0x66, 0xad, 0x7e, 0xad, 0x37, 0xda, 0x7a,
157 0xda, 0xbe, 0xda, 0x62, 0xed, 0x72, 0xed, 0x16, 0xed, 0xeb, 0xda, 0xef,
158 0x75, 0x70, 0x9d, 0x40, 0x9d, 0x2c, 0x9d, 0xf5, 0x3a, 0x6d, 0x3a, 0xf7,
159 0x75, 0x09, 0xba, 0x36, 0xba, 0x51, 0xba, 0x85, 0xba, 0xdb, 0x75, 0xcf,
160 0xea, 0x3e, 0xd3, 0x63, 0xeb, 0x79, 0xe9, 0x09, 0xf5, 0xca, 0xf5, 0x0e,
161 0xe9, 0xdd, 0xd1, 0x47, 0xf5, 0x6d, 0xf4, 0xa3, 0xf5, 0x17, 0xea, 0xef,
162 0xd6, 0xef, 0xd1, 0x1f, 0x37, 0x30, 0x34, 0x08, 0x36, 0x90, 0x19, 0x6c,
163 0x31, 0x38, 0x63, 0xf0, 0xcc, 0x90, 0x63, 0xe8, 0x6b, 0x98, 0x69, 0xb8,
164 0xd1, 0xf0, 0x84, 0xe1, 0xa8, 0x11, 0xcb, 0x68, 0xba, 0x91, 0xc4, 0x68,
165 0xa3, 0xd1, 0x49, 0xa3, 0x27, 0xb8, 0x26, 0xee, 0x87, 0x67, 0xe3, 0x35,
166 0x78, 0x17, 0x3e, 0x66, 0xac, 0x6f, 0x1c, 0x62, 0xac, 0x34, 0xde, 0x65,
167 0xdc, 0x6b, 0x3c, 0x61, 0x62, 0x69, 0x32, 0xdb, 0xa4, 0xc4, 0xa4, 0xc5,
168 0xe4, 0xbe, 0x29, 0xcd, 0x94, 0x6b, 0x9a, 0x66, 0x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9d, 0x15, 0x5a, 0x1b, 0xfa, 0x30, 0xcc, 0x26, 0x4c, 0x1e, 0xd6, 0x11,
199 0x8e, 0x86, 0xcf, 0x08, 0xdf, 0x10, 0x7e, 0x6f, 0xa6, 0xf9, 0x4c, 0xe9,
200 0xcc, 0xb6, 0x08, 0x88, 0xe0, 0x47, 0x6c, 0x88, 0xb8, 0x1f, 0x69, 0x19,
201 0x99, 0x17, 0xf9, 0x7d, 0x14, 0x29, 0x2a, 0x32, 0xaa, 0x2e, 0xea, 0x51,
202 0xb4, 0x53, 0x74, 0x71, 0x74, 0xf7, 0x2c, 0xd6, 0xac, 0xe4, 0x59, 0xfb,
203 0x67, 0xbd, 0x8e, 0xf1, 0x8f, 0xa9, 0x8c, 0xb9, 0x3b, 0xdb, 0x6a, 0xb6,
204 0x72, 0x76, 0x67, 0xac, 0x6a, 0x6c, 0x52, 0x6c, 0x63, 0xec, 0x9b, 0xb8,
205 0x80, 0xb8, 0xaa, 0xb8, 0x81, 0x78, 0x87, 0xf8, 0x45, 0xf1, 0x97, 0x12,
206 0x74, 0x13, 0x24, 0x09, 0xed, 0x89, 0xe4, 0xc4, 0xd8, 0xc4, 0x3d, 0x89,
207 0xe3, 0x73, 0x02, 0xe7, 0x6c, 0x9a, 0x33, 0x9c, 0xe4, 0x9a, 0x54, 0x96,
208 0x74, 0x63, 0xae, 0xe5, 0xdc, 0xa2, 0xb9, 0x17, 0xe6, 0xe9, 0xce, 0xcb,
209 0x9e, 0x77, 0x3c, 0x59, 0x35, 0x59, 0x90, 0x7c, 0x38, 0x85, 0x98, 0x12,
210 0x97, 0xb2, 0x3f, 0xe5, 0x83, 0x20, 0x42, 0x50, 0x2f, 0x18, 0x4f, 0xe5,
211 0xa7, 0x6e, 0x4d, 0x1d, 0x13, 0xf2, 0x84, 0x9b, 0x85, 0x4f, 0x45, 0xbe,
212 0xa2, 0x8d, 0xa2, 0x51, 0xb1, 0xb7, 0xb8, 0x4a, 0x3c, 0x92, 0xe6, 0x9d,
213 0x56, 0x95, 0xf6, 0x38, 0xdd, 0x3b, 0x7d, 0x43, 0xfa, 0x68, 0x86, 0x4f,
214 0x46, 0x75, 0xc6, 0x33, 0x09, 0x4f, 0x52, 0x2b, 0x79, 0x91, 0x19, 0x92,
215 0xb9, 0x23, 0xf3, 0x4d, 0x56, 0x44, 0xd6, 0xde, 0xac, 0xcf, 0xd9, 0x71,
216 0xd9, 0x2d, 0x39, 0x94, 0x9c, 0x94, 0x9c, 0xa3, 0x52, 0x0d, 0x69, 0x96,
217 0xb4, 0x2b, 0xd7, 0x30, 0xb7, 0x28, 0xb7, 0x4f, 0x66, 0x2b, 0x2b, 0x93,
218 0x0d, 0xe4, 0x79, 0xe6, 0x6d, 0xca, 0x1b, 0x93, 0x87, 0xca, 0xf7, 0xe4,
219 0x23, 0xf9, 0x73, 0xf3, 0xdb, 0x15, 0x6c, 0x85, 0x4c, 0xd1, 0xa3, 0xb4,
220 0x52, 0xae, 0x50, 0x0e, 0x16, 0x4c, 0x2f, 0xa8, 0x2b, 0x78, 0x5b, 0x18,
221 0x5b, 0x78, 0xb8, 0x48, 0xbd, 0x48, 0x5a, 0xd4, 0x33, 0xdf, 0x66, 0xfe,
222 0xea, 0xf9, 0x23, 0x0b, 0x82, 0x16, 0x7c, 0xbd, 0x90, 0xb0, 0x50, 0xb8,
223 0xb0, 0xb3, 0xd8, 0xb8, 0x78, 0x59, 0xf1, 0xe0, 0x22, 0xbf, 0x45, 0xbb,
224 0x16, 0x23, 0x8b, 0x53, 0x17, 0x77, 0x2e, 0x31, 0x5d, 0x52, 0xba, 0x64,
225 0x78, 0x69, 0xf0, 0xd2, 0x7d, 0xcb, 0x68, 0xcb, 0xb2, 0x96, 0xfd, 0x50,
226 0xe2, 0x58, 0x52, 0x55, 0xf2, 0x6a, 0x79, 0xdc, 0xf2, 0x8e, 0x52, 0x83,
227 0xd2, 0xa5, 0xa5, 0x43, 0x2b, 0x82, 0x57, 0x34, 0x95, 0xa9, 0x94, 0xc9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a,
272 0x63, 0xc7, 0xa7, 0xd0, 0x4f, 0xf7, 0x3e, 0xe7, 0x7c, 0xfe, 0xfc, 0x2f,
273 0xf7, 0x84, 0xf3, 0xfb, 0x80, 0x39, 0x25, 0x11, 0x00, 0x00, 0x00, 0x09,
274 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 0x0b, 0x13,
275 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4d,
276 0x45, 0x07, 0xdc, 0x0b, 0x0e, 0x0e, 0x25, 0x16, 0x28, 0x9e, 0x78, 0x6a,
277 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8,
278 0xff, 0xff, 0x3f, 0x00, 0x05, 0xfe, 0x02, 0xfe, 0xdc, 0xcc, 0x59, 0xe7,
279 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
280 };
281
282 static IWICImagingFactory *factory;
283
284 static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size)
285 {
286 HGLOBAL hmem;
287 BYTE *data;
288 HRESULT hr;
289 IWICBitmapDecoder *decoder = NULL;
290 IStream *stream;
291 GUID format;
292 LONG refcount;
293
294 hmem = GlobalAlloc(0, image_size);
295 data = GlobalLock(hmem);
296 memcpy(data, image_data, image_size);
297 GlobalUnlock(hmem);
298
299 hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
300 ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
301
302 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
303 ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
304 if (FAILED(hr)) return NULL;
305
306 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
307 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
308 ok(IsEqualGUID(&format, &GUID_ContainerFormatPng),
309 "wrong container format %s\n", wine_dbgstr_guid(&format));
310
311 refcount = IStream_Release(stream);
312 ok(refcount > 0, "expected stream refcount > 0\n");
313
314 return decoder;
315 }
316
317 static WCHAR *save_profile( BYTE *buffer, UINT size )
318 {
319 static const WCHAR tstW[] = {'t','s','t',0};
320 WCHAR path[MAX_PATH], filename[MAX_PATH], *ret;
321 HANDLE handle;
322 DWORD count;
323
324 GetTempPathW(MAX_PATH, path);
325 GetTempFileNameW(path, tstW, 0, filename);
326
327 handle = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
328 if (handle == INVALID_HANDLE_VALUE) return NULL;
329
330 WriteFile(handle, buffer, size, &count, NULL);
331 CloseHandle( handle );
332
333 ret = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(filename) + 1) * sizeof(WCHAR));
334 lstrcpyW(ret, filename);
335 return ret;
336 }
337
338 static void test_color_contexts(void)
339 {
340 HRESULT hr;
341 IWICBitmapDecoder *decoder;
342 IWICBitmapFrameDecode *frame;
343 IWICColorContext *context;
344 WICColorContextType type;
345 UINT count, colorspace, size;
346 WCHAR *tmpfile;
347 BYTE *buffer;
348 BOOL ret;
349
350 decoder = create_decoder(png_no_color_profile, sizeof(png_no_color_profile));
351 ok(decoder != 0, "Failed to load PNG image data\n");
352 if (!decoder) return;
353
354 /* global color context */
355 hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, NULL);
356 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts error %#x\n", hr);
357
358 count = 0xdeadbeef;
359 hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, &count);
360 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts error %#x\n", hr);
361 ok(count == 0xdeadbeef, "unexpected count %u\n", count);
362
363 /* frame color context */
364 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
365 ok(hr == S_OK, "GetFrame error %#x\n", hr);
366
367 hr = IWICBitmapFrameDecode_GetColorContexts(frame, 0, NULL, NULL);
368 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
369
370 count = 0xdeadbeef;
371 hr = IWICBitmapFrameDecode_GetColorContexts(frame, 0, NULL, &count);
372 ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
373 ok(!count, "unexpected count %u\n", count);
374
375 IWICBitmapFrameDecode_Release(frame);
376 IWICBitmapDecoder_Release(decoder);
377
378 decoder = create_decoder(png_color_profile, sizeof(png_color_profile));
379 ok(decoder != 0, "Failed to load PNG image data\n");
380 if (!decoder) return;
381
382 /* global color context */
383 count = 0xdeadbeef;
384 hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, &count);
385 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts error %#x\n", hr);
386 ok(count == 0xdeadbeef, "unexpected count %u\n", count);
387
388 /* frame color context */
389 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
390 ok(hr == S_OK, "GetFrame error %#x\n", hr);
391
392 count = 0xdeadbeef;
393 hr = IWICBitmapFrameDecode_GetColorContexts(frame, 0, NULL, &count);
394 ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
395 ok(count == 1, "unexpected count %u\n", count);
396
397 hr = IWICImagingFactory_CreateColorContext(factory, NULL);
398 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
399
400 hr = IWICImagingFactory_CreateColorContext(factory, &context);
401 ok(hr == S_OK, "CreateColorContext error %#x\n", hr);
402
403 hr = IWICColorContext_GetType(context, NULL);
404 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
405
406 type = 0xdeadbeef;
407 hr = IWICColorContext_GetType(context, &type);
408 ok(hr == S_OK, "GetType error %#x\n", hr);
409 ok(type == WICColorContextUninitialized, "unexpected type %u\n", type);
410
411 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, NULL);
412 ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetProfileBytes error %#x\n", hr);
413
414 size = 0;
415 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
416 ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetProfileBytes error %#x\n", hr);
417 ok(!size, "unexpected size %u\n", size);
418
419 hr = IWICColorContext_GetExifColorSpace(context, NULL);
420 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
421
422 colorspace = 0xdeadbeef;
423 hr = IWICColorContext_GetExifColorSpace(context, &colorspace);
424 ok(hr == S_OK, "GetExifColorSpace error %#x\n", hr);
425 ok(colorspace == 0xffffffff, "unexpected color space %u\n", colorspace);
426
427 hr = IWICColorContext_InitializeFromExifColorSpace(context, 0);
428 ok(hr == S_OK, "InitializeFromExifColorSpace error %#x\n", hr);
429
430 hr = IWICColorContext_InitializeFromExifColorSpace(context, 1);
431 ok(hr == S_OK, "InitializeFromExifColorSpace error %#x\n", hr);
432
433 hr = IWICColorContext_InitializeFromExifColorSpace(context, 2);
434 ok(hr == S_OK, "InitializeFromExifColorSpace error %#x\n", hr);
435
436 colorspace = 0xdeadbeef;
437 hr = IWICColorContext_GetExifColorSpace(context, &colorspace);
438 ok(hr == S_OK, "GetExifColorSpace error %#x\n", hr);
439 ok(colorspace == 2, "unexpected color space %u\n", colorspace);
440
441 size = 0;
442 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
443 ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetProfileBytes error %#x\n", hr);
444 ok(!size, "unexpected size %u\n", size);
445
446 type = 0xdeadbeef;
447 hr = IWICColorContext_GetType(context, &type);
448 ok(hr == S_OK, "GetType error %#x\n", hr);
449 ok(type == WICColorContextExifColorSpace, "unexpected type %u\n", type);
450
451 hr = IWICBitmapFrameDecode_GetColorContexts(frame, count, &context, &count);
452 ok(hr == WINCODEC_ERR_WRONGSTATE, "GetColorContexts error %#x\n", hr);
453
454 IWICColorContext_Release(context);
455 IWICBitmapFrameDecode_Release(frame);
456
457 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
458 ok(hr == S_OK, "GetFrame error %#x\n", hr);
459
460 hr = IWICImagingFactory_CreateColorContext(factory, &context);
461 ok(hr == S_OK, "CreateColorContext error %#x\n", hr);
462
463 count = 1;
464 hr = IWICBitmapFrameDecode_GetColorContexts(frame, count, &context, &count);
465 ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
466
467 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, NULL);
468 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
469
470 size = 0;
471 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
472 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
473 ok(size, "unexpected size %u\n", size);
474
475 buffer = HeapAlloc(GetProcessHeap(), 0, size);
476 hr = IWICColorContext_GetProfileBytes(context, size, buffer, &size);
477 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
478
479 tmpfile = save_profile( buffer, size );
480 HeapFree(GetProcessHeap(), 0, buffer);
481
482 type = 0xdeadbeef;
483 hr = IWICColorContext_GetType(context, &type);
484 ok(hr == S_OK, "GetType error %#x\n", hr);
485 ok(type == WICColorContextProfile, "unexpected type %u\n", type);
486
487 colorspace = 0xdeadbeef;
488 hr = IWICColorContext_GetExifColorSpace(context, &colorspace);
489 ok(hr == S_OK, "GetExifColorSpace error %#x\n", hr);
490 ok(colorspace == 0xffffffff, "unexpected color space %u\n", colorspace);
491
492 hr = IWICColorContext_InitializeFromExifColorSpace(context, 1);
493 ok(hr == WINCODEC_ERR_WRONGSTATE, "InitializeFromExifColorSpace error %#x\n", hr);
494
495 if (tmpfile)
496 {
497 hr = IWICColorContext_InitializeFromFilename(context, NULL);
498 ok(hr == E_INVALIDARG, "InitializeFromFilename error %#x\n", hr);
499
500 hr = IWICColorContext_InitializeFromFilename(context, tmpfile);
501 ok(hr == S_OK, "InitializeFromFilename error %#x\n", hr);
502
503 ret = DeleteFileW(tmpfile);
504 ok(ret, "DeleteFileW failed %u\n", GetLastError());
505
506 type = 0xdeadbeef;
507 hr = IWICColorContext_GetType(context, &type);
508 ok(hr == S_OK, "GetType error %#x\n", hr);
509 ok(type == WICColorContextProfile, "unexpected type %u\n", type);
510
511 colorspace = 0xdeadbeef;
512 hr = IWICColorContext_GetExifColorSpace(context, &colorspace);
513 ok(hr == S_OK, "GetExifColorSpace error %#x\n", hr);
514 ok(colorspace == 0xffffffff, "unexpected color space %u\n", colorspace);
515
516 hr = IWICColorContext_InitializeFromExifColorSpace(context, 1);
517 ok(hr == WINCODEC_ERR_WRONGSTATE, "InitializeFromExifColorSpace error %#x\n", hr);
518
519 size = 0;
520 hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
521 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
522 ok(size, "unexpected size %u\n", size);
523
524 buffer = HeapAlloc(GetProcessHeap(), 0, size);
525 hr = IWICColorContext_GetProfileBytes(context, size, buffer, &size);
526 ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
527
528 HeapFree(GetProcessHeap(), 0, buffer);
529 HeapFree(GetProcessHeap(), 0, tmpfile);
530 }
531 IWICColorContext_Release(context);
532 IWICBitmapFrameDecode_Release(frame);
533 IWICBitmapDecoder_Release(decoder);
534 }
535
536 /* 1 bpp 1x1 pixel PNG image with PLTE and tRNS chunks */
537 static const char png_PLTE_tRNS[] = {
538 0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,
539 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,
540 0x00,0x00,0x00,0x06,'P','L','T','E',0x01,0x02,0x03,0x04,0x05,0x06,0x95,0x53,0x6f,0x48,
541 0x00,0x00,0x00,0x02,'t','R','N','S',0xff,0x00,0xe5,0xb7,0x30,0x4a,
542 0x00,0x00,0x00,0x0a,'I','D','A','T',0x18,0xd3,0x63,0x68,0x00,0x00,0x00,0x82,0x00,0x81,0xa7,0x01,0xba,0x10,
543 0x00,0x00,0x00,0x00,'I','E','N','D',0xae,0x42,0x60,0x82
544 };
545
546 static void test_png_palette(void)
547 {
548 HRESULT hr;
549 IWICBitmapDecoder *decoder;
550 IWICBitmapFrameDecode *frame;
551 IWICPalette *palette;
552 GUID format;
553 UINT count, ret;
554 WICColor color[256];
555
556 decoder = create_decoder(png_PLTE_tRNS, sizeof(png_PLTE_tRNS));
557 ok(decoder != 0, "Failed to load PNG image data\n");
558 if (!decoder) return;
559
560 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
561 ok(hr == S_OK, "GetFrame error %#x\n", hr);
562
563 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
564 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
565 ok(IsEqualGUID(&format, &GUID_WICPixelFormat1bppIndexed),
566 "got wrong format %s\n", wine_dbgstr_guid(&format));
567
568 hr = IWICImagingFactory_CreatePalette(factory, &palette);
569 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
570 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
571 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
572
573 hr = IWICPalette_GetColorCount(palette, &count);
574 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
575 ok(count == 2, "expected 2, got %u\n", count);
576
577 hr = IWICPalette_GetColors(palette, 256, color, &ret);
578 ok(hr == S_OK, "GetColors error %#x\n", hr);
579 ok(ret == count, "expected %u, got %u\n", count, ret);
580 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
581 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
582
583 IWICPalette_Release(palette);
584 IWICBitmapFrameDecode_Release(frame);
585 IWICBitmapDecoder_Release(decoder);
586 }
587
588 START_TEST(pngformat)
589 {
590 HRESULT hr;
591
592 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
593 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
594 &IID_IWICImagingFactory, (void **)&factory);
595 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
596 if (FAILED(hr)) return;
597
598 test_color_contexts();
599 test_png_palette();
600
601 IWICImagingFactory_Release(factory);
602 CoUninitialize();
603 }