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 IWICBitmapDecoder
*create_decoder(const void *image_data
, UINT image_size
)
71 IWICBitmapDecoder
*decoder
= NULL
;
75 hmem
= GlobalAlloc(0, image_size
);
76 data
= GlobalLock(hmem
);
77 memcpy(data
, image_data
, image_size
);
80 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, &stream
);
81 ok(hr
== S_OK
, "CreateStreamOnHGlobal error %#x\n", hr
);
83 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, &decoder
);
84 ok(hr
== S_OK
, "CreateDecoderFromStream error %#x\n", hr
);
86 hr
= IWICBitmapDecoder_GetContainerFormat(decoder
, &format
);
87 ok(hr
== S_OK
, "GetContainerFormat error %#x\n", hr
);
88 ok(IsEqualGUID(&format
, &GUID_ContainerFormatGif
),
89 "wrong container format %s\n", wine_dbgstr_guid(&format
));
91 IStream_Release(stream
);
96 static void test_global_gif_palette(void)
99 IWICBitmapDecoder
*decoder
;
100 IWICBitmapFrameDecode
*frame
;
101 IWICPalette
*palette
;
106 decoder
= create_decoder(gif_global_palette
, sizeof(gif_global_palette
));
107 ok(decoder
!= 0, "Failed to load GIF image data\n");
109 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
110 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
113 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
114 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
116 hr
= IWICPalette_GetColorCount(palette
, &count
);
117 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
118 ok(count
== 4, "expected 4, got %u\n", count
);
120 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
121 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
122 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
123 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
124 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
125 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
126 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
129 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
130 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
132 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
133 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
134 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
135 "wrong pixel format %s\n", wine_dbgstr_guid(&format
));
137 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
138 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
140 hr
= IWICPalette_GetColorCount(palette
, &count
);
141 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
142 ok(count
== 4, "expected 4, got %u\n", count
);
144 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
145 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
146 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
147 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
148 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
149 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
150 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
152 IWICPalette_Release(palette
);
153 IWICBitmapFrameDecode_Release(frame
);
154 IWICBitmapDecoder_Release(decoder
);
157 static void test_global_gif_palette_2frames(void)
160 IWICBitmapDecoder
*decoder
;
161 IWICBitmapFrameDecode
*frame
;
162 IWICPalette
*palette
;
167 decoder
= create_decoder(gif_global_palette_2frames
, sizeof(gif_global_palette_2frames
));
168 ok(decoder
!= 0, "Failed to load GIF image data\n");
170 /* active frame 0, GCE transparent index 1 */
171 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
172 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
174 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
175 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
178 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
179 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
181 hr
= IWICPalette_GetColorCount(palette
, &count
);
182 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
183 ok(count
== 4, "expected 4, got %u\n", count
);
185 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
186 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
187 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
188 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
189 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
190 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
191 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
193 /* frame 0 palette */
194 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
195 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
196 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
197 "wrong pixel format %s\n", wine_dbgstr_guid(&format
));
199 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
200 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
202 hr
= IWICPalette_GetColorCount(palette
, &count
);
203 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
204 ok(count
== 4, "expected 4, got %u\n", count
);
206 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
207 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
208 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
209 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
210 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
211 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
212 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
214 IWICBitmapFrameDecode_Release(frame
);
216 /* active frame 1, GCE transparent index 2 */
217 hr
= IWICBitmapDecoder_GetFrame(decoder
, 1, &frame
);
218 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
221 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
222 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
224 hr
= IWICPalette_GetColorCount(palette
, &count
);
225 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
226 ok(count
== 4, "expected 4, got %u\n", count
);
228 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
229 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
230 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
231 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
232 ok(color
[1] == 0xff040506 || broken(color
[1] == 0x00040506) /* XP */, "expected 0xff040506, got %#x\n", color
[1]);
233 ok(color
[2] == 0x00070809 || broken(color
[2] == 0xff070809) /* XP */, "expected 0x00070809, got %#x\n", color
[2]);
234 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
236 /* frame 1 palette */
237 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
238 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
239 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
240 "wrong pixel format %s\n", wine_dbgstr_guid(&format
));
242 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
243 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
245 hr
= IWICPalette_GetColorCount(palette
, &count
);
246 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
247 ok(count
== 4, "expected 4, got %u\n", count
);
249 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
250 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
251 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
252 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
253 ok(color
[1] == 0xff040506, "expected 0xff040506, got %#x\n", color
[1]);
254 ok(color
[2] == 0x00070809, "expected 0x00070809, got %#x\n", color
[2]);
255 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
257 IWICPalette_Release(palette
);
258 IWICBitmapFrameDecode_Release(frame
);
259 IWICBitmapDecoder_Release(decoder
);
262 static void test_local_gif_palette(void)
265 IWICBitmapDecoder
*decoder
;
266 IWICBitmapFrameDecode
*frame
;
267 IWICPalette
*palette
;
268 WICBitmapPaletteType type
;
273 decoder
= create_decoder(gif_local_palette
, sizeof(gif_local_palette
));
274 ok(decoder
!= 0, "Failed to load GIF image data\n");
276 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
277 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
280 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
281 ok(hr
== S_OK
|| broken(hr
== WINCODEC_ERR_FRAMEMISSING
), "CopyPalette %#x\n", hr
);
285 hr
= IWICPalette_GetType(palette
, &type
);
286 ok(hr
== S_OK
, "GetType error %#x\n", hr
);
287 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %#x\n", type
);
289 hr
= IWICPalette_GetColorCount(palette
, &count
);
290 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
291 ok(count
== 256, "expected 256, got %u\n", count
);
293 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
294 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
295 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
296 ok(color
[0] == 0xff000000, "expected 0xff000000, got %#x\n", color
[0]);
297 ok(color
[1] == 0x00ffffff, "expected 0x00ffffff, got %#x\n", color
[1]);
299 for (i
= 2; i
< 256; i
++)
300 ok(color
[i
] == 0xff000000, "expected 0xff000000, got %#x\n", color
[i
]);
304 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
305 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
307 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
308 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
309 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
310 "wrong pixel format %s\n", wine_dbgstr_guid(&format
));
312 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
313 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
315 hr
= IWICPalette_GetColorCount(palette
, &count
);
316 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
317 ok(count
== 4, "expected 4, got %u\n", count
);
320 hr
= IWICPalette_GetType(palette
, &type
);
321 ok(hr
== S_OK
, "GetType error %#x\n", hr
);
322 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %#x\n", type
);
324 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
325 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
326 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
327 ok(color
[0] == 0xff010203, "expected 0xff010203, got %#x\n", color
[0]);
328 ok(color
[1] == 0x00040506, "expected 0x00040506, got %#x\n", color
[1]);
329 ok(color
[2] == 0xff070809, "expected 0xff070809, got %#x\n", color
[2]);
330 ok(color
[3] == 0xff0a0b0c, "expected 0xff0a0b0c, got %#x\n", color
[3]);
332 IWICPalette_Release(palette
);
333 IWICBitmapFrameDecode_Release(frame
);
334 IWICBitmapDecoder_Release(decoder
);
337 START_TEST(gifformat
)
341 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
342 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
343 &IID_IWICImagingFactory
, (void **)&factory
);
344 ok(hr
== S_OK
, "CoCreateInstance error %#x\n", hr
);
345 if (FAILED(hr
)) return;
347 test_global_gif_palette();
348 test_global_gif_palette_2frames();
349 test_local_gif_palette();
351 IWICImagingFactory_Release(factory
);