[WINDOWSCODECS_WINETEST] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / rostests / winetests / windowscodecs / gifformat.c
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 WIN32_NO_STATUS
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 #define COBJMACROS
27
28 #include <windef.h>
29 #include <winbase.h>
30 #include <ole2.h>
31 #include <wincodec.h>
32 #include <wine/test.h>
33
34 HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT, IWICImagingFactory**);
35
36 static const char gif_global_palette[] = {
37 /* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0xa1,0x02,0x00,
38 /* palette */0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
39 /* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
40 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
41 0x02,0x02,0x44,0x01,0x00,0x3b
42 };
43
44 /* frame 0, GCE transparent index 1
45 * frame 1, GCE transparent index 2
46 */
47 static const char gif_global_palette_2frames[] = {
48 /* LSD */'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xa1,0x02,0x00,
49 /* palette */0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
50 /* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
51 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
52 0x02,0x02,0x44,0x01,0x00,
53 /* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x02,0x00, /* index 2 */
54 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
55 0x02,0x02,0x44,0x01,0x00,0x3b
56 };
57
58 static const char gif_local_palette[] = {
59 /* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x27,0x02,0x00,
60 /* GCE */0x21,0xf9,0x04,0x01,0x05,0x00,0x01,0x00, /* index 1 */
61 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
62 /* palette */0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
63 0x02,0x02,0x44,0x01,0x00,0x3b
64 };
65
66 /* Generated with ImageMagick:
67 * convert -delay 100 -size 2x2 xc:red \
68 * -dispose none -page +0+0 -size 2x1 xc:white \
69 * test.gif
70 */
71 static const char gif_frame_sizes[] = {
72 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x02, 0x00,
73 0x02, 0x00, 0xf1, 0x00, 0x00, 0xff, 0x00, 0x00,
74 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
75 0x00, 0x21, 0xf9, 0x04, 0x00, 0x64, 0x00, 0x00,
76 0x00, 0x21, 0xff, 0x0b, 0x4e, 0x45, 0x54, 0x53,
77 0x43, 0x41, 0x50, 0x45, 0x32, 0x2e, 0x30, 0x03,
78 0x01, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00,
79 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x02, 0x03,
80 0x44, 0x34, 0x05, 0x00, 0x21, 0xf9, 0x04, 0x04,
81 0x64, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00,
82 0x00, 0x02, 0x00, 0x01, 0x00, 0x80, 0xff, 0xff,
83 0xff, 0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x0a,
84 0x00, 0x3b
85 };
86
87 static IWICImagingFactory *factory;
88
89 static IStream *create_stream(const void *image_data, UINT image_size)
90 {
91 HGLOBAL hmem;
92 BYTE *data;
93 HRESULT hr;
94 IStream *stream;
95
96 hmem = GlobalAlloc(0, image_size);
97 data = GlobalLock(hmem);
98 memcpy(data, image_data, image_size);
99 GlobalUnlock(hmem);
100
101 hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
102 ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
103
104 return stream;
105 }
106
107 static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size)
108 {
109 HRESULT hr;
110 IWICBitmapDecoder *decoder;
111 IStream *stream;
112 GUID format;
113 LONG refcount;
114
115 stream = create_stream(image_data, image_size);
116 if (!stream) return NULL;
117
118 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
119 ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
120
121 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
122 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
123 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
124 "wrong container format %s\n", wine_dbgstr_guid(&format));
125
126 refcount = IStream_Release(stream);
127 ok(refcount > 0, "expected stream refcount > 0\n");
128
129 return decoder;
130 }
131
132 static void test_global_gif_palette(void)
133 {
134 HRESULT hr;
135 IWICBitmapDecoder *decoder;
136 IWICBitmapFrameDecode *frame;
137 IWICPalette *palette;
138 GUID format;
139 UINT count, ret;
140 WICColor color[256];
141
142 decoder = create_decoder(gif_global_palette, sizeof(gif_global_palette));
143 ok(decoder != 0, "Failed to load GIF image data\n");
144
145 hr = IWICImagingFactory_CreatePalette(factory, &palette);
146 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
147
148 /* global palette */
149 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
150 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
151
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);
155
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]);
163
164 /* frame palette */
165 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
166 ok(hr == S_OK, "GetFrame error %#x\n", hr);
167
168 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
169 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
170 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
171 "wrong pixel format %s\n", wine_dbgstr_guid(&format));
172
173 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
174 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
175
176 hr = IWICPalette_GetColorCount(palette, &count);
177 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
178 ok(count == 4, "expected 4, got %u\n", count);
179
180 hr = IWICPalette_GetColors(palette, count, color, &ret);
181 ok(hr == S_OK, "GetColors error %#x\n", hr);
182 ok(ret == count, "expected %u, got %u\n", count, ret);
183 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
184 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
185 ok(color[2] == 0xff070809, "expected 0xff070809, got %#x\n", color[2]);
186 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
187
188 IWICPalette_Release(palette);
189 IWICBitmapFrameDecode_Release(frame);
190 IWICBitmapDecoder_Release(decoder);
191 }
192
193 static void test_global_gif_palette_2frames(void)
194 {
195 HRESULT hr;
196 IWICBitmapDecoder *decoder;
197 IWICBitmapFrameDecode *frame;
198 IWICPalette *palette;
199 GUID format;
200 UINT count, ret;
201 WICColor color[256];
202
203 decoder = create_decoder(gif_global_palette_2frames, sizeof(gif_global_palette_2frames));
204 ok(decoder != 0, "Failed to load GIF image data\n");
205
206 /* active frame 0, GCE transparent index 1 */
207 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
208 ok(hr == S_OK, "GetFrame error %#x\n", hr);
209
210 hr = IWICImagingFactory_CreatePalette(factory, &palette);
211 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
212
213 /* global palette */
214 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
215 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
216
217 hr = IWICPalette_GetColorCount(palette, &count);
218 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
219 ok(count == 4, "expected 4, got %u\n", count);
220
221 hr = IWICPalette_GetColors(palette, count, color, &ret);
222 ok(hr == S_OK, "GetColors error %#x\n", hr);
223 ok(ret == count, "expected %u, got %u\n", count, ret);
224 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
225 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
226 ok(color[2] == 0xff070809, "expected 0xff070809, got %#x\n", color[2]);
227 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
228
229 /* frame 0 palette */
230 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
231 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
232 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
233 "wrong pixel format %s\n", wine_dbgstr_guid(&format));
234
235 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
236 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
237
238 hr = IWICPalette_GetColorCount(palette, &count);
239 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
240 ok(count == 4, "expected 4, got %u\n", count);
241
242 hr = IWICPalette_GetColors(palette, count, color, &ret);
243 ok(hr == S_OK, "GetColors error %#x\n", hr);
244 ok(ret == count, "expected %u, got %u\n", count, ret);
245 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
246 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
247 ok(color[2] == 0xff070809, "expected 0xff070809, got %#x\n", color[2]);
248 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
249
250 IWICBitmapFrameDecode_Release(frame);
251
252 /* active frame 1, GCE transparent index 2 */
253 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &frame);
254 ok(hr == S_OK, "GetFrame error %#x\n", hr);
255
256 /* global palette */
257 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
258 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
259
260 hr = IWICPalette_GetColorCount(palette, &count);
261 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
262 ok(count == 4, "expected 4, got %u\n", count);
263
264 hr = IWICPalette_GetColors(palette, count, color, &ret);
265 ok(hr == S_OK, "GetColors error %#x\n", hr);
266 ok(ret == count, "expected %u, got %u\n", count, ret);
267 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
268 ok(color[1] == 0xff040506 || broken(color[1] == 0x00040506) /* XP */, "expected 0xff040506, got %#x\n", color[1]);
269 ok(color[2] == 0x00070809 || broken(color[2] == 0xff070809) /* XP */, "expected 0x00070809, got %#x\n", color[2]);
270 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
271
272 /* frame 1 palette */
273 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
274 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
275 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
276 "wrong pixel format %s\n", wine_dbgstr_guid(&format));
277
278 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
279 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
280
281 hr = IWICPalette_GetColorCount(palette, &count);
282 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
283 ok(count == 4, "expected 4, got %u\n", count);
284
285 hr = IWICPalette_GetColors(palette, count, color, &ret);
286 ok(hr == S_OK, "GetColors error %#x\n", hr);
287 ok(ret == count, "expected %u, got %u\n", count, ret);
288 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
289 ok(color[1] == 0xff040506, "expected 0xff040506, got %#x\n", color[1]);
290 ok(color[2] == 0x00070809, "expected 0x00070809, got %#x\n", color[2]);
291 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
292
293 IWICPalette_Release(palette);
294 IWICBitmapFrameDecode_Release(frame);
295 IWICBitmapDecoder_Release(decoder);
296 }
297
298 static void test_local_gif_palette(void)
299 {
300 HRESULT hr;
301 IWICBitmapDecoder *decoder;
302 IWICBitmapFrameDecode *frame;
303 IWICPalette *palette;
304 WICBitmapPaletteType type;
305 GUID format;
306 UINT count, ret, i;
307 WICColor color[256];
308
309 decoder = create_decoder(gif_local_palette, sizeof(gif_local_palette));
310 ok(decoder != 0, "Failed to load GIF image data\n");
311
312 hr = IWICImagingFactory_CreatePalette(factory, &palette);
313 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
314
315 /* global palette */
316 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
317 ok(hr == S_OK || broken(hr == WINCODEC_ERR_FRAMEMISSING), "CopyPalette %#x\n", hr);
318 if (hr == S_OK)
319 {
320 type = -1;
321 hr = IWICPalette_GetType(palette, &type);
322 ok(hr == S_OK, "GetType error %#x\n", hr);
323 ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %#x\n", type);
324
325 hr = IWICPalette_GetColorCount(palette, &count);
326 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
327 ok(count == 256, "expected 256, got %u\n", count);
328
329 hr = IWICPalette_GetColors(palette, count, color, &ret);
330 ok(hr == S_OK, "GetColors error %#x\n", hr);
331 ok(ret == count, "expected %u, got %u\n", count, ret);
332 ok(color[0] == 0xff000000, "expected 0xff000000, got %#x\n", color[0]);
333 ok(color[1] == 0x00ffffff, "expected 0x00ffffff, got %#x\n", color[1]);
334
335 for (i = 2; i < 256; i++)
336 ok(color[i] == 0xff000000, "expected 0xff000000, got %#x\n", color[i]);
337 }
338
339 /* frame palette */
340 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
341 ok(hr == S_OK, "GetFrame error %#x\n", hr);
342
343 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
344 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
345 ok(IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed),
346 "wrong pixel format %s\n", wine_dbgstr_guid(&format));
347
348 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
349 ok(hr == S_OK, "CopyPalette error %#x\n", hr);
350
351 hr = IWICPalette_GetColorCount(palette, &count);
352 ok(hr == S_OK, "GetColorCount error %#x\n", hr);
353 ok(count == 4, "expected 4, got %u\n", count);
354
355 type = -1;
356 hr = IWICPalette_GetType(palette, &type);
357 ok(hr == S_OK, "GetType error %#x\n", hr);
358 ok(type == WICBitmapPaletteTypeCustom, "expected WICBitmapPaletteTypeCustom, got %#x\n", type);
359
360 hr = IWICPalette_GetColors(palette, count, color, &ret);
361 ok(hr == S_OK, "GetColors error %#x\n", hr);
362 ok(ret == count, "expected %u, got %u\n", count, ret);
363 ok(color[0] == 0xff010203, "expected 0xff010203, got %#x\n", color[0]);
364 ok(color[1] == 0x00040506, "expected 0x00040506, got %#x\n", color[1]);
365 ok(color[2] == 0xff070809, "expected 0xff070809, got %#x\n", color[2]);
366 ok(color[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color[3]);
367
368 IWICPalette_Release(palette);
369 IWICBitmapFrameDecode_Release(frame);
370 IWICBitmapDecoder_Release(decoder);
371 }
372
373 static void test_gif_frame_sizes(void)
374 {
375 static const BYTE frame0[] = {0, 1, 0xfe, 0xfe, 2, 3, 0xfe, 0xfe};
376 static const BYTE frame1[] = {0, 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
377
378 IWICBitmapDecoder *decoder;
379 IWICBitmapFrameDecode *frame;
380 UINT width, height;
381 BYTE buf[8];
382 HRESULT hr;
383
384 decoder = create_decoder(gif_frame_sizes, sizeof(gif_frame_sizes));
385 ok(decoder != 0, "Failed to load GIF image data\n");
386
387 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
388 ok(hr == S_OK, "GetFrame error %#x\n", hr);
389
390 hr = IWICBitmapFrameDecode_GetSize(frame, &width, &height);
391 ok(hr == S_OK, "GetSize error %x\n", hr);
392 ok(width == 2, "width = %d\n", width);
393 ok(height == 2, "height = %d\n", height);
394
395 memset(buf, 0xfe, sizeof(buf));
396 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, 4, sizeof(buf), buf);
397 ok(hr == S_OK, "CopyPixels error %x\n", hr);
398 ok(!memcmp(buf, frame0, sizeof(buf)), "buf = %x %x %x %x %x %x %x %x\n",
399 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
400
401 IWICBitmapFrameDecode_Release(frame);
402
403 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &frame);
404 ok(hr == S_OK, "GetFrame error %#x\n", hr);
405
406 hr = IWICBitmapFrameDecode_GetSize(frame, &width, &height);
407 ok(hr == S_OK, "GetSize error %x\n", hr);
408 ok(width == 2, "width = %d\n", width);
409 ok(height == 1, "height = %d\n", height);
410
411 memset(buf, 0xfe, sizeof(buf));
412 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, 4, sizeof(buf), buf);
413 ok(hr == S_OK, "CopyPixels error %x\n", hr);
414 ok(!memcmp(buf, frame1, sizeof(buf)), "buf = %x %x %x %x %x %x %x %x\n",
415 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
416
417 IWICBitmapFrameDecode_Release(frame);
418
419 IWICBitmapDecoder_Release(decoder);
420 }
421
422 static const char gif_with_trailer_1[] = {
423 /* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x80,0x00,0x00,
424 /* palette */0xff,0xff,0xff,0xff,0xff,0xff,
425 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
426 /* image data */0x02,0x02,0x44,0x01,0x00,0x3b
427 };
428 static const char gif_with_trailer_2[] = {
429 /* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x00,0x00,0x00,
430 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
431 /* image data */0x02,0x02,0x44,0x3b
432 };
433 static const char gif_without_trailer_1[] = {
434 /* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x80,0x00,0x00,
435 /* palette */0xff,0xff,0xff,0xff,0xff,0xff,
436 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
437 /* image data */0x02,0x02,0x44,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef
438 };
439
440 static const char gif_without_trailer_2[] = {
441 /* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x00,0x00,0x00,
442 /* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
443 /* image data */0x02,0x02,0x44,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef
444 };
445
446 static void test_truncated_gif(void)
447 {
448 HRESULT hr;
449 IStream *stream;
450 IWICBitmapDecoder *decoder;
451 GUID format;
452
453 stream = create_stream(gif_with_trailer_1, sizeof(gif_with_trailer_1));
454 if (!stream) return;
455
456 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
457 ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
458 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
459 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
460 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
461 "wrong container format %s\n", wine_dbgstr_guid(&format));
462 IWICBitmapDecoder_Release(decoder);
463 IStream_Release(stream);
464
465 stream = create_stream(gif_with_trailer_2, sizeof(gif_with_trailer_2));
466 if (!stream) return;
467 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
468 ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
469 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
470 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
471 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
472 "wrong container format %s\n", wine_dbgstr_guid(&format));
473 IWICBitmapDecoder_Release(decoder);
474 IStream_Release(stream);
475
476 stream = create_stream(gif_without_trailer_1, sizeof(gif_without_trailer_1));
477 if (!stream) return;
478 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
479 ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
480 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
481 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
482 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
483 "wrong container format %s\n", wine_dbgstr_guid(&format));
484 IWICBitmapDecoder_Release(decoder);
485 IStream_Release(stream);
486
487 stream = create_stream(gif_without_trailer_2, sizeof(gif_without_trailer_2));
488 if (!stream) return;
489 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
490 ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
491 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
492 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
493 ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
494 "wrong container format %s\n", wine_dbgstr_guid(&format));
495 IWICBitmapDecoder_Release(decoder);
496 IStream_Release(stream);
497 }
498
499 START_TEST(gifformat)
500 {
501 HRESULT hr;
502
503 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
504 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
505 &IID_IWICImagingFactory, (void **)&factory);
506 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
507 if (FAILED(hr)) return;
508
509 test_global_gif_palette();
510 test_global_gif_palette_2frames();
511 test_local_gif_palette();
512 test_gif_frame_sizes();
513
514 IWICImagingFactory_Release(factory);
515 CoUninitialize();
516
517 /* run the same tests with no COM initialization */
518 hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
519 ok(hr == S_OK, "WICCreateImagingFactory_Proxy error %#x\n", hr);
520
521 test_global_gif_palette();
522 test_global_gif_palette_2frames();
523 test_local_gif_palette();
524 test_gif_frame_sizes();
525 test_truncated_gif();
526
527 IWICImagingFactory_Release(factory);
528 }