2 * Copyright 2012 Dmitry Timoshkov
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_NO_STATUS
24 #define COM_NO_WINDOWS_H
32 #include <wine/test.h>
34 static const char gif_global_palette
[] = {
35 /* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0xa1,0x02,0x00,
36 /* palette */0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
37 /* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
38 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
39 0x02,0x02,0x44,0x01,0x00,0x3b
42 /* frame 0, GCE transparent index 1
43 * frame 1, GCE transparent index 2
45 static const char gif_global_palette_2frames
[] = {
46 /* LSD */'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xa1,0x02,0x00,
47 /* palette */0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
48 /* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
49 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
50 0x02,0x02,0x44,0x01,0x00,
51 /* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x02,0x00, /* index 2 */
52 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
53 0x02,0x02,0x44,0x01,0x00,0x3b
56 static const char gif_local_palette
[] = {
57 /* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x27,0x02,0x00,
58 /* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
59 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
60 /* palette */0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
61 0x02,0x02,0x44,0x01,0x00,0x3b
64 static IWICImagingFactory
*factory
;
66 static const char *debugstr_guid(const GUID
*guid
)
70 if (!guid
) return "(null)";
71 sprintf(buf
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
72 guid
->Data1
, guid
->Data2
, guid
->Data3
, guid
->Data4
[0],
73 guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3], guid
->Data4
[4],
74 guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
78 static IWICBitmapDecoder
*create_decoder(const void *image_data
, UINT image_size
)
83 IWICBitmapDecoder
*decoder
= NULL
;
87 hmem
= GlobalAlloc(0, image_size
);
88 data
= GlobalLock(hmem
);
89 memcpy(data
, image_data
, image_size
);
92 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, &stream
);
93 ok(hr
== S_OK
, "CreateStreamOnHGlobal error %#x\n", hr
);
95 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, &decoder
);
96 ok(hr
== S_OK
, "CreateDecoderFromStream error %#x\n", hr
);
98 hr
= IWICBitmapDecoder_GetContainerFormat(decoder
, &format
);
99 ok(hr
== S_OK
, "GetContainerFormat error %#x\n", hr
);
100 ok(IsEqualGUID(&format
, &GUID_ContainerFormatGif
),
101 "wrong container format %s\n", debugstr_guid(&format
));
103 IStream_Release(stream
);
108 static void test_global_gif_palette(void)
111 IWICBitmapDecoder
*decoder
;
112 IWICBitmapFrameDecode
*frame
;
113 IWICPalette
*palette
;
118 decoder
= create_decoder(gif_global_palette
, sizeof(gif_global_palette
));
119 ok(decoder
!= 0, "Failed to load GIF image data\n");
121 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
122 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
125 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
126 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
128 hr
= IWICPalette_GetColorCount(palette
, &count
);
129 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
130 ok(count
== 4, "expected 4, got %u\n", count
);
132 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
133 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
134 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
135 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
136 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
137 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
138 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
141 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
142 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
144 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
145 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
146 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
147 "wrong pixel format %s\n", debugstr_guid(&format
));
149 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
150 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
152 hr
= IWICPalette_GetColorCount(palette
, &count
);
153 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
154 ok(count
== 4, "expected 4, got %u\n", count
);
156 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
157 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
158 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
159 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
160 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
161 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
162 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
164 IWICPalette_Release(palette
);
165 IWICBitmapFrameDecode_Release(frame
);
166 IWICBitmapDecoder_Release(decoder
);
169 static void test_global_gif_palette_2frames(void)
172 IWICBitmapDecoder
*decoder
;
173 IWICBitmapFrameDecode
*frame
;
174 IWICPalette
*palette
;
179 decoder
= create_decoder(gif_global_palette_2frames
, sizeof(gif_global_palette_2frames
));
180 ok(decoder
!= 0, "Failed to load GIF image data\n");
182 /* active frame 0, GCE transparent index 1 */
183 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
184 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
186 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
187 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
190 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
191 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
193 hr
= IWICPalette_GetColorCount(palette
, &count
);
194 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
195 ok(count
== 4, "expected 4, got %u\n", count
);
197 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
198 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
199 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
200 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
201 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
202 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
203 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
205 /* frame 0 palette */
206 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
207 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
208 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
209 "wrong pixel format %s\n", debugstr_guid(&format
));
211 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
212 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
214 hr
= IWICPalette_GetColorCount(palette
, &count
);
215 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
216 ok(count
== 4, "expected 4, got %u\n", count
);
218 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
219 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
220 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
221 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
222 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
223 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
224 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
226 IWICBitmapFrameDecode_Release(frame
);
228 /* active frame 1, GCE transparent index 2 */
229 hr
= IWICBitmapDecoder_GetFrame(decoder
, 1, &frame
);
230 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
233 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
234 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
236 hr
= IWICPalette_GetColorCount(palette
, &count
);
237 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
238 ok(count
== 4, "expected 4, got %u\n", count
);
240 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
241 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
242 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
243 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
244 ok(color
[1] == 0xff040506 || broken(color
[1] == 0x00040506) /* XP */, "expected 0xff040506, got %#x\n", color
[1]);
245 ok(color
[2] == 0x00070809 || broken(color
[2] == 0xff070809) /* XP */, "expected 0x00070809, got %#x\n", color
[2]);
246 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
248 /* frame 1 palette */
249 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
250 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
251 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
252 "wrong pixel format %s\n", debugstr_guid(&format
));
254 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
255 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
257 hr
= IWICPalette_GetColorCount(palette
, &count
);
258 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
259 ok(count
== 4, "expected 4, got %u\n", count
);
261 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
262 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
263 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
264 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
265 ok(color
[1] == 0xff040506, "expected 0xff040506, got %#x\n", color
[1]);
266 ok(color
[2] == 0x00070809, "expected 0x00070809, got %#x\n", color
[2]);
267 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
269 IWICPalette_Release(palette
);
270 IWICBitmapFrameDecode_Release(frame
);
271 IWICBitmapDecoder_Release(decoder
);
274 static void test_local_gif_palette(void)
277 IWICBitmapDecoder
*decoder
;
278 IWICBitmapFrameDecode
*frame
;
279 IWICPalette
*palette
;
280 WICBitmapPaletteType type
;
285 decoder
= create_decoder(gif_local_palette
, sizeof(gif_local_palette
));
286 ok(decoder
!= 0, "Failed to load GIF image data\n");
288 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
289 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
292 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
293 ok(hr
== S_OK
|| broken(hr
== WINCODEC_ERR_FRAMEMISSING
), "CopyPalette %#x\n", hr
);
297 hr
= IWICPalette_GetType(palette
, &type
);
298 ok(hr
== S_OK
, "GetType error %#x\n", hr
);
299 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %#x\n", type
);
301 hr
= IWICPalette_GetColorCount(palette
, &count
);
302 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
303 ok(count
== 256, "expected 256, got %u\n", count
);
305 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
306 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
307 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
308 ok(color
[0] == 0xff000000, "expected 0xff000000, got %#x\n", color
[0]);
309 ok(color
[1] == 0x00ffffff, "expected 0x00ffffff, got %#x\n", color
[1]);
311 for (i
= 2; i
< 256; i
++)
312 ok(color
[i
] == 0xff000000, "expected 0xff000000, got %#x\n", color
[i
]);
316 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
317 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
319 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
320 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
321 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
322 "wrong pixel format %s\n", debugstr_guid(&format
));
324 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
325 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
327 hr
= IWICPalette_GetColorCount(palette
, &count
);
328 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
329 ok(count
== 4, "expected 4, got %u\n", count
);
332 hr
= IWICPalette_GetType(palette
, &type
);
333 ok(hr
== S_OK
, "GetType error %#x\n", hr
);
334 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %#x\n", type
);
336 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
337 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
338 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
339 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
340 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
341 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
342 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
344 IWICPalette_Release(palette
);
345 IWICBitmapFrameDecode_Release(frame
);
346 IWICBitmapDecoder_Release(decoder
);
349 START_TEST(gifformat
)
353 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
354 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
355 &IID_IWICImagingFactory
, (void **)&factory
);
356 ok(hr
== S_OK
, "CoCreateInstance error %#x\n", hr
);
357 if (FAILED(hr
)) return;
359 test_global_gif_palette();
360 test_global_gif_palette_2frames();
361 test_local_gif_palette();
363 IWICImagingFactory_Release(factory
);