ReactOS 0.4.16-dev-1007-g2e85425
gifformat.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 Dmitry Timoshkov
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include <stdarg.h>
20#include <stdio.h>
21
22#define COBJMACROS
23
24#include "windef.h"
25#include "wincodec.h"
26#include "wine/test.h"
27
29
30static const char gif_global_palette[] = {
31/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0xa1,0x02,0x00,
32/* palette */0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
33/* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
34/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
350x02,0x02,0x44,0x01,0x00,0x3b
36};
37
38/* frame 0, GCE transparent index 1
39 * frame 1, GCE transparent index 2
40 */
41static const char gif_global_palette_2frames[] = {
42/* LSD */'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xa1,0x02,0x00,
43/* palette */0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
44/* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
45/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
460x02,0x02,0x44,0x01,0x00,
47/* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x02,0x00, /* index 2 */
48/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
490x02,0x02,0x44,0x01,0x00,0x3b
50};
51
52static const char gif_local_palette[] = {
53/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x27,0x02,0x00,
54/* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
55/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
56/* palette */0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
570x02,0x02,0x44,0x01,0x00,0x3b
58};
59
60static const char gif_no_palette[] = {
61/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x21,0x02,0x00,
62/* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
63/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
640x02,0x02,0x44,0x01,0x00,0x3b
65};
66
67/* Generated with ImageMagick:
68 * convert -delay 100 -size 2x2 xc:red \
69 * -dispose none -page +0+0 -size 2x1 xc:white \
70 * test.gif
71 */
72static const char gif_frame_sizes[] = {
73 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x02, 0x00,
74 0x02, 0x00, 0xf1, 0x00, 0x00, 0xff, 0x00, 0x00,
75 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
76 0x00, 0x21, 0xf9, 0x04, 0x00, 0x64, 0x00, 0x00,
77 0x00, 0x21, 0xff, 0x0b, 0x4e, 0x45, 0x54, 0x53,
78 0x43, 0x41, 0x50, 0x45, 0x32, 0x2e, 0x30, 0x03,
79 0x01, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00,
80 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x02, 0x03,
81 0x44, 0x34, 0x05, 0x00, 0x21, 0xf9, 0x04, 0x04,
82 0x64, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00,
83 0x00, 0x02, 0x00, 0x01, 0x00, 0x80, 0xff, 0xff,
84 0xff, 0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x0a,
85 0x00, 0x3b
86};
87
89
90static IStream *create_stream(const void *image_data, UINT image_size)
91{
92 HGLOBAL hmem;
93 BYTE *data;
94 HRESULT hr;
96
97 hmem = GlobalAlloc(0, image_size);
98 data = GlobalLock(hmem);
99 memcpy(data, image_data, image_size);
100 GlobalUnlock(hmem);
101
103 ok(hr == S_OK, "CreateStreamOnHGlobal error %#lx\n", hr);
104
105 return stream;
106}
107
108static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size)
109{
110 HRESULT hr;
113 GUID format;
114 LONG refcount;
115
116 stream = create_stream(image_data, image_size);
117 if (!stream) return NULL;
118
119 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
120 ok(hr == S_OK, "CreateDecoderFromStream error %#lx\n", hr);
121
122 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
123 ok(hr == S_OK, "GetContainerFormat error %#lx\n", hr);
124 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
125 "wrong container format %s\n", wine_dbgstr_guid(&format));
126
127 refcount = IStream_Release(stream);
128 ok(refcount > 0, "expected stream refcount > 0\n");
129
130 return decoder;
131}
132
133static void test_global_gif_palette(void)
134{
135 HRESULT hr;
139 GUID format;
140 UINT count, ret;
141 WICColor color[256];
142
144 ok(decoder != 0, "Failed to load GIF image data\n");
145
146 hr = IWICImagingFactory_CreatePalette(factory, &palette);
147 ok(hr == S_OK, "CreatePalette error %#lx\n", hr);
148
149 /* global palette */
150 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
151 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
152
153 hr = IWICPalette_GetColorCount(palette, &count);
154 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
155 ok(count == 4, "expected 4, got %u\n", count);
156
157 hr = IWICPalette_GetColors(palette, count, color, &ret);
158 ok(hr == S_OK, "GetColors error %#lx\n", hr);
159 ok(ret == count, "expected %u, got %u\n", count, ret);
160 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
161 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
162 ok(color[2] == 0xff070809, "expected 0xff070809, got %#x\n", color[2]);
163 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
164
165 /* frame palette */
166 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
167 ok(hr == S_OK, "GetFrame error %#lx\n", hr);
168
169 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
170 ok(hr == S_OK, "GetPixelFormat error %#lx\n", hr);
171 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
172 "wrong pixel format %s\n", wine_dbgstr_guid(&format));
173
174 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
175 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
176
177 hr = IWICPalette_GetColorCount(palette, &count);
178 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
179 ok(count == 4, "expected 4, got %u\n", count);
180
181 hr = IWICPalette_GetColors(palette, count, color, &ret);
182 ok(hr == S_OK, "GetColors error %#lx\n", hr);
183 ok(ret == count, "expected %u, got %u\n", count, ret);
184 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
185 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
186 ok(color[2] == 0xff070809, "expected 0xff070809, got %#x\n", color[2]);
187 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
188
189 IWICPalette_Release(palette);
190 IWICBitmapFrameDecode_Release(frame);
191 IWICBitmapDecoder_Release(decoder);
192}
193
195{
196 HRESULT hr;
200 GUID format;
201 UINT count, ret;
202 WICColor color[256];
203
205 ok(decoder != 0, "Failed to load GIF image data\n");
206
207 /* active frame 0, GCE transparent index 1 */
208 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
209 ok(hr == S_OK, "GetFrame error %#lx\n", hr);
210
211 hr = IWICImagingFactory_CreatePalette(factory, &palette);
212 ok(hr == S_OK, "CreatePalette error %#lx\n", hr);
213
214 /* global palette */
215 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
216 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
217
218 hr = IWICPalette_GetColorCount(palette, &count);
219 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
220 ok(count == 4, "expected 4, got %u\n", count);
221
222 hr = IWICPalette_GetColors(palette, count, color, &ret);
223 ok(hr == S_OK, "GetColors error %#lx\n", hr);
224 ok(ret == count, "expected %u, got %u\n", count, ret);
225 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
226 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
227 ok(color[2] == 0xff070809, "expected 0xff070809, got %#x\n", color[2]);
228 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
229
230 /* frame 0 palette */
231 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
232 ok(hr == S_OK, "GetPixelFormat error %#lx\n", hr);
233 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
234 "wrong pixel format %s\n", wine_dbgstr_guid(&format));
235
236 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
237 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
238
239 hr = IWICPalette_GetColorCount(palette, &count);
240 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
241 ok(count == 4, "expected 4, got %u\n", count);
242
243 hr = IWICPalette_GetColors(palette, count, color, &ret);
244 ok(hr == S_OK, "GetColors error %#lx\n", hr);
245 ok(ret == count, "expected %u, got %u\n", count, ret);
246 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
247 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
248 ok(color[2] == 0xff070809, "expected 0xff070809, got %#x\n", color[2]);
249 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
250
251 IWICBitmapFrameDecode_Release(frame);
252
253 /* active frame 1, GCE transparent index 2 */
254 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &frame);
255 ok(hr == S_OK, "GetFrame error %#lx\n", hr);
256
257 /* global palette */
258 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
259 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
260
261 hr = IWICPalette_GetColorCount(palette, &count);
262 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
263 ok(count == 4, "expected 4, got %u\n", count);
264
265 hr = IWICPalette_GetColors(palette, count, color, &ret);
266 ok(hr == S_OK, "GetColors error %#lx\n", hr);
267 ok(ret == count, "expected %u, got %u\n", count, ret);
268 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
269 ok(color[1] == 0xff040506 || broken(color[1] == 0x00040506) /* XP */, "expected 0xff040506, got %#x\n", color[1]);
270 ok(color[2] == 0x00070809 || broken(color[2] == 0xff070809) /* XP */, "expected 0x00070809, got %#x\n", color[2]);
271 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
272
273 /* frame 1 palette */
274 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
275 ok(hr == S_OK, "GetPixelFormat error %#lx\n", hr);
276 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
277 "wrong pixel format %s\n", wine_dbgstr_guid(&format));
278
279 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
280 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
281
282 hr = IWICPalette_GetColorCount(palette, &count);
283 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
284 ok(count == 4, "expected 4, got %u\n", count);
285
286 hr = IWICPalette_GetColors(palette, count, color, &ret);
287 ok(hr == S_OK, "GetColors error %#lx\n", hr);
288 ok(ret == count, "expected %u, got %u\n", count, ret);
289 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
290 ok(color[1] == 0xff040506, "expected 0xff040506, got %#x\n", color[1]);
291 ok(color[2] == 0x00070809, "expected 0x00070809, got %#x\n", color[2]);
292 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
293
294 IWICPalette_Release(palette);
295 IWICBitmapFrameDecode_Release(frame);
296 IWICBitmapDecoder_Release(decoder);
297}
298
299static void test_local_gif_palette(void)
300{
301 HRESULT hr;
306 GUID format;
307 UINT count, ret, i;
308 WICColor color[256];
309
311 ok(decoder != 0, "Failed to load GIF image data\n");
312
313 hr = IWICImagingFactory_CreatePalette(factory, &palette);
314 ok(hr == S_OK, "CreatePalette error %#lx\n", hr);
315
316 /* global palette */
317 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
318 ok(hr == S_OK || broken(hr == WINCODEC_ERR_FRAMEMISSING), "CopyPalette %#lx\n", hr);
319 if (hr == S_OK)
320 {
321 type = -1;
322 hr = IWICPalette_GetType(palette, &type);
323 ok(hr == S_OK, "GetType error %#lx\n", hr);
324 ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %#x\n", type);
325
326 hr = IWICPalette_GetColorCount(palette, &count);
327 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
328 ok(count == 256, "expected 256, got %u\n", count);
329
330 hr = IWICPalette_GetColors(palette, count, color, &ret);
331 ok(hr == S_OK, "GetColors error %#lx\n", hr);
332 ok(ret == count, "expected %u, got %u\n", count, ret);
333 ok(color[0] == 0xff000000, "expected 0xff000000, got %#x\n", color[0]);
334 ok(color[1] == 0x00ffffff, "expected 0x00ffffff, got %#x\n", color[1]);
335
336 for (i = 2; i < 256; i++)
337 ok(color[i] == 0xff000000, "expected 0xff000000, got %#x\n", color[i]);
338 }
339
340 /* frame palette */
341 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
342 ok(hr == S_OK, "GetFrame error %#lx\n", hr);
343
344 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
345 ok(hr == S_OK, "GetPixelFormat error %#lx\n", hr);
346 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
347 "wrong pixel format %s\n", wine_dbgstr_guid(&format));
348
349 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
350 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
351
352 hr = IWICPalette_GetColorCount(palette, &count);
353 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
354 ok(count == 4, "expected 4, got %u\n", count);
355
356 type = -1;
357 hr = IWICPalette_GetType(palette, &type);
358 ok(hr == S_OK, "GetType error %#lx\n", hr);
359 ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %#x\n", type);
360
361 hr = IWICPalette_GetColors(palette, count, color, &ret);
362 ok(hr == S_OK, "GetColors error %#lx\n", hr);
363 ok(ret == count, "expected %u, got %u\n", count, ret);
364 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
365 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
366 ok(color[2] == 0xff070809, "expected 0xff070809, got %#x\n", color[2]);
367 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
368
369 IWICPalette_Release(palette);
370 IWICBitmapFrameDecode_Release(frame);
371 IWICBitmapDecoder_Release(decoder);
372}
373
374static void test_no_gif_palette(void)
375{
376 HRESULT hr;
380 GUID format;
381 UINT count, ret;
382 WICColor color[256];
383
385 ok(decoder != 0, "Failed to load GIF image data\n");
386
387 hr = IWICImagingFactory_CreatePalette(factory, &palette);
388 ok(hr == S_OK, "CreatePalette error %#lx\n", hr);
389
390 /* global palette */
391 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
392 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
393
394 hr = IWICPalette_GetColorCount(palette, &count);
395 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
396 ok(count == 4, "expected 4, got %u\n", count);
397
398 hr = IWICPalette_GetColors(palette, count, color, &ret);
399 ok(hr == S_OK, "GetColors error %#lx\n", hr);
400 ok(ret == count, "expected %u, got %u\n", count, ret);
401 ok(color[0] == 0xff000000, "expected 0xff000000, got %#x\n", color[0]);
402 ok(color[1] == 0x00ffffff, "expected 0x00ffffff, got %#x\n", color[1]);
403 ok(color[2] == 0xff000000, "expected 0xff000000, got %#x\n", color[2]);
404 ok(color[3] == 0xff000000, "expected 0xff000000, got %#x\n", color[3]);
405
406 /* frame palette */
407 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
408 ok(hr == S_OK, "GetFrame error %#lx\n", hr);
409
410 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
411 ok(hr == S_OK, "GetPixelFormat error %#lx\n", hr);
412 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
413 "wrong pixel format %s\n", wine_dbgstr_guid(&format));
414
415 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
416 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
417
418 hr = IWICPalette_GetColorCount(palette, &count);
419 ok(hr == S_OK, "GetColorCount error %#lx\n", hr);
420 ok(count == 4, "expected 4, got %u\n", count);
421
422 hr = IWICPalette_GetColors(palette, count, color, &ret);
423 ok(hr == S_OK, "GetColors error %#lx\n", hr);
424 ok(ret == count, "expected %u, got %u\n", count, ret);
425 ok(color[0] == 0xff000000, "expected 0xff000000, got %#x\n", color[0]);
426 ok(color[1] == 0x00ffffff, "expected 0x00ffffff, got %#x\n", color[1]);
427 ok(color[2] == 0xff000000, "expected 0xff000000, got %#x\n", color[2]);
428 ok(color[3] == 0xff000000, "expected 0xff000000, got %#x\n", color[3]);
429
430 IWICPalette_Release(palette);
431 IWICBitmapFrameDecode_Release(frame);
432 IWICBitmapDecoder_Release(decoder);
433}
434
435static void test_gif_frame_sizes(void)
436{
437 static const BYTE frame0[] = {0, 1, 0xfe, 0xfe, 2, 3, 0xfe, 0xfe};
438 static const BYTE frame1[] = {0, 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
439
443 BYTE buf[8];
444 HRESULT hr;
445
447 ok(decoder != 0, "Failed to load GIF image data\n");
448
449 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
450 ok(hr == S_OK, "GetFrame error %#lx\n", hr);
451
452 hr = IWICBitmapFrameDecode_GetSize(frame, &width, &height);
453 ok(hr == S_OK, "GetSize error %lx\n", hr);
454 ok(width == 2, "width = %d\n", width);
455 ok(height == 2, "height = %d\n", height);
456
457 memset(buf, 0xfe, sizeof(buf));
458 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, 4, sizeof(buf), buf);
459 ok(hr == S_OK, "CopyPixels error %lx\n", hr);
460 ok(!memcmp(buf, frame0, sizeof(buf)), "buf = %x %x %x %x %x %x %x %x\n",
461 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
462
463 IWICBitmapFrameDecode_Release(frame);
464
465 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &frame);
466 ok(hr == S_OK, "GetFrame error %#lx\n", hr);
467
468 hr = IWICBitmapFrameDecode_GetSize(frame, &width, &height);
469 ok(hr == S_OK, "GetSize error %lx\n", hr);
470 ok(width == 2, "width = %d\n", width);
471 ok(height == 1, "height = %d\n", height);
472
473 memset(buf, 0xfe, sizeof(buf));
474 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, 4, sizeof(buf), buf);
475 ok(hr == S_OK, "CopyPixels error %lx\n", hr);
476 ok(!memcmp(buf, frame1, sizeof(buf)), "buf = %x %x %x %x %x %x %x %x\n",
477 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
478
479 IWICBitmapFrameDecode_Release(frame);
480
481 IWICBitmapDecoder_Release(decoder);
482}
483
484static const char gif_with_trailer_1[] = {
485/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x80,0x00,0x00,
486/* palette */0xff,0xff,0xff,0xff,0xff,0xff,
487/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
488/* image data */0x02,0x02,0x44,0x01,0x00,0x3b
489};
490static const char gif_with_trailer_2[] = {
491/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x00,0x00,0x00,
492/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
493/* image data */0x02,0x02,0x44,0x3b
494};
495static const char gif_without_trailer_1[] = {
496/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x80,0x00,0x00,
497/* palette */0xff,0xff,0xff,0xff,0xff,0xff,
498/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
499/* image data */0x02,0x02,0x44,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef
500};
501
502static const char gif_without_trailer_2[] = {
503/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x00,0x00,0x00,
504/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
505/* image data */0x02,0x02,0x44,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef
506};
507
508static void test_truncated_gif(void)
509{
510 HRESULT hr;
513 GUID format;
514
516 if (!stream) return;
517
518 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
519 ok(hr == S_OK, "CreateDecoderFromStream error %#lx\n", hr);
520 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
521 ok(hr == S_OK, "GetContainerFormat error %#lx\n", hr);
522 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
523 "wrong container format %s\n", wine_dbgstr_guid(&format));
524 IWICBitmapDecoder_Release(decoder);
525 IStream_Release(stream);
526
528 if (!stream) return;
529 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
530 ok(hr == S_OK, "CreateDecoderFromStream error %#lx\n", hr);
531 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
532 ok(hr == S_OK, "GetContainerFormat error %#lx\n", hr);
533 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
534 "wrong container format %s\n", wine_dbgstr_guid(&format));
535 IWICBitmapDecoder_Release(decoder);
536 IStream_Release(stream);
537
539 if (!stream) return;
540 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
541 ok(hr == S_OK, "CreateDecoderFromStream error %#lx\n", hr);
542 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
543 ok(hr == S_OK, "GetContainerFormat error %#lx\n", hr);
544 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
545 "wrong container format %s\n", wine_dbgstr_guid(&format));
546 IWICBitmapDecoder_Release(decoder);
547 IStream_Release(stream);
548
550 if (!stream) return;
551 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
552 ok(hr == S_OK, "CreateDecoderFromStream error %#lx\n", hr);
553 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
554 ok(hr == S_OK, "GetContainerFormat error %#lx\n", hr);
555 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
556 "wrong container format %s\n", wine_dbgstr_guid(&format));
557 IWICBitmapDecoder_Release(decoder);
558 IStream_Release(stream);
559}
560
561/* 1x1 pixel gif, missing trailer */
562static unsigned char gifimage_notrailer[] = {
5630x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x71,0xff,0xff,0xff,
5640xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
5650x01,0x00
566};
567
568static void test_gif_notrailer(void)
569{
572 HRESULT hr;
573 IWICStream *gifstream;
574 IWICBitmapFrameDecode *framedecode;
575 double dpiX = 0.0, dpiY = 0.0;
576 UINT framecount;
577
578 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
579 &IID_IWICImagingFactory, (void**)&factory);
580 ok(hr == S_OK, "CoCreateInstance failed, hr=%lx\n", hr);
581 if (FAILED(hr)) return;
582
583 hr = IWICImagingFactory_CreateStream(factory, &gifstream);
584 ok(hr == S_OK, "CreateStream failed, hr=%lx\n", hr);
585 if (SUCCEEDED(hr))
586 {
587 hr = IWICStream_InitializeFromMemory(gifstream, gifimage_notrailer,
588 sizeof(gifimage_notrailer));
589 ok(hr == S_OK, "InitializeFromMemory failed, hr=%lx\n", hr);
590
591 if (SUCCEEDED(hr))
592 {
593 hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER,
594 &IID_IWICBitmapDecoder, (void**)&decoder);
595 ok(hr == S_OK, "CoCreateInstance failed, hr=%lx\n", hr);
596 }
597
598 if (SUCCEEDED(hr))
599 {
600 hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)gifstream,
602 ok(hr == S_OK, "Initialize failed, hr=%lx\n", hr);
603
604 if (SUCCEEDED(hr))
605 {
606 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
607 ok(hr == S_OK, "GetFrame failed, hr=%lx\n", hr);
608 if (SUCCEEDED(hr))
609 {
610 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
611 ok(SUCCEEDED(hr), "GetResolution failed, hr=%lx\n", hr);
612 ok(dpiX == 48.0, "expected dpiX=48.0, got %f\n", dpiX);
613 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
614
615 IWICBitmapFrameDecode_Release(framedecode);
616 }
617 }
618
619 if (SUCCEEDED(hr))
620 {
621 hr = IWICBitmapDecoder_GetFrameCount(decoder, &framecount);
622 ok(hr == S_OK, "GetFrameCount failed, hr=%lx\n", hr);
623 ok(framecount == 1, "framecount=%u\n", framecount);
624 }
625
626 IWICBitmapDecoder_Release(decoder);
627 }
628
629 IWICStream_Release(gifstream);
630 }
631
632 IWICImagingFactory_Release(factory);
633}
634
635START_TEST(gifformat)
636{
637 HRESULT hr;
638
640 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
641 &IID_IWICImagingFactory, (void **)&factory);
642 ok(hr == S_OK, "CoCreateInstance error %#lx\n", hr);
643 if (FAILED(hr)) return;
644
651
652 IWICImagingFactory_Release(factory);
654
655 /* run the same tests with no COM initialization */
656 hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
657 ok(hr == S_OK, "WICCreateImagingFactory_Proxy error %#lx\n", hr);
658
665
666 IWICImagingFactory_Release(factory);
667}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ok(value,...)
Definition: atltest.h:57
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
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
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM *ppstm)
static IStream * create_stream(const void *data, int data_size)
Definition: gifformat.c:521
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLuint color
Definition: glext.h:6243
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
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
static GLint image_size(GLint width, GLint height, GLenum format, GLenum type)
Definition: mipmap.c:4858
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static HPALETTE palette
Definition: clipboard.c:1345
static IWICBitmapDecoder * create_decoder(void)
Definition: ddsformat.c:485
static void test_gif_frame_sizes(void)
Definition: gifformat.c:435
static const char gif_without_trailer_2[]
Definition: gifformat.c:502
static const char gif_no_palette[]
Definition: gifformat.c:60
static void test_no_gif_palette(void)
Definition: gifformat.c:374
static const char gif_with_trailer_2[]
Definition: gifformat.c:490
static IWICImagingFactory * factory
Definition: gifformat.c:88
static const char gif_with_trailer_1[]
Definition: gifformat.c:484
static void test_global_gif_palette_2frames(void)
Definition: gifformat.c:194
static const char gif_global_palette[]
Definition: gifformat.c:30
static void test_gif_notrailer(void)
Definition: gifformat.c:568
static const char gif_without_trailer_1[]
Definition: gifformat.c:495
static const char gif_global_palette_2frames[]
Definition: gifformat.c:41
static const char gif_local_palette[]
Definition: gifformat.c:52
static void test_global_gif_palette(void)
Definition: gifformat.c:133
HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT, IWICImagingFactory **)
Definition: proxy.c:649
static void test_local_gif_palette(void)
Definition: gifformat.c:299
static unsigned char gifimage_notrailer[]
Definition: gifformat.c:562
static const char gif_frame_sizes[]
Definition: gifformat.c:72
static void test_truncated_gif(void)
Definition: gifformat.c:508
unsigned int UINT
Definition: ndis.h:50
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:278
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:197
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
Definition: main.c:439
Definition: format.c:58
Definition: parse.h:23
int ret
@ WICDecodeMetadataCacheOnDemand
Definition: wincodec.idl:29
WICBitmapPaletteType
Definition: wincodec.idl:91
@ WICBitmapPaletteTypeCustom
Definition: wincodec.idl:92
UINT32 WICColor
Definition: wincodec.idl:364
#define WINAPI
Definition: msvc.h:6
#define WINCODEC_ERR_FRAMEMISSING
Definition: winerror.h:3301
unsigned char BYTE
Definition: xxhash.c:193