2 * Copyright 2009 Vincent Povirk for CodeWeavers
3 * Copyright 2012,2016 Dmitry Timoshkov
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.
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.
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
23 #define WIN32_NO_STATUS
25 #define COM_NO_WINDOWS_H
33 #include <wine/test.h>
35 static IWICImagingFactory
*factory
;
37 static void test_custom_palette(void)
39 IWICPalette
*palette
, *palette2
;
41 WICBitmapPaletteType type
=0xffffffff;
43 const WICColor initcolors
[4]={0xff000000,0xff0000ff,0xffffff00,0xffffffff};
47 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
48 ok(SUCCEEDED(hr
), "CreatePalette failed, hr=%x\n", hr
);
51 hr
= IWICPalette_GetType(palette
, &type
);
52 ok(SUCCEEDED(hr
), "GetType failed, hr=%x\n", hr
);
53 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %x\n", type
);
55 hr
= IWICPalette_GetColorCount(palette
, &count
);
56 ok(SUCCEEDED(hr
), "GetColorCount failed, hr=%x\n", hr
);
57 ok(count
== 0, "expected 0, got %u\n", count
);
59 hr
= IWICPalette_GetColors(palette
, 0, colors
, &count
);
60 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
61 ok(count
== 0, "expected 0, got %u\n", count
);
63 hr
= IWICPalette_GetColors(palette
, 4, colors
, &count
);
64 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
65 ok(count
== 0, "expected 0, got %u\n", count
);
67 memcpy(colors
, initcolors
, sizeof(initcolors
));
68 hr
= IWICPalette_InitializeCustom(palette
, colors
, 4);
69 ok(SUCCEEDED(hr
), "InitializeCustom failed, hr=%x\n", hr
);
71 hr
= IWICPalette_GetType(palette
, &type
);
72 ok(SUCCEEDED(hr
), "GetType failed, hr=%x\n", hr
);
73 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %x\n", type
);
75 hr
= IWICPalette_GetColorCount(palette
, &count
);
76 ok(SUCCEEDED(hr
), "GetColorCount failed, hr=%x\n", hr
);
77 ok(count
== 4, "expected 4, got %u\n", count
);
79 memset(colors
, 0, sizeof(colors
));
81 hr
= IWICPalette_GetColors(palette
, 4, colors
, &count
);
82 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
83 ok(count
== 4, "expected 4, got %u\n", count
);
84 ok(!memcmp(colors
, initcolors
, sizeof(colors
)), "got unexpected palette data\n");
86 memset(colors
, 0, sizeof(colors
));
88 hr
= IWICPalette_GetColors(palette
, 2, colors
, &count
);
89 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
90 ok(count
== 2, "expected 2, got %u\n", count
);
91 ok(!memcmp(colors
, initcolors
, sizeof(WICColor
)*2), "got unexpected palette data\n");
94 hr
= IWICPalette_GetColors(palette
, 6, colors
, &count
);
95 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
96 ok(count
== 4, "expected 4, got %u\n", count
);
98 hr
= IWICPalette_HasAlpha(palette
, &boolresult
);
99 ok(SUCCEEDED(hr
), "HasAlpha failed, hr=%x\n", hr
);
100 ok(!boolresult
, "expected FALSE, got TRUE\n");
102 hr
= IWICPalette_IsBlackWhite(palette
, &boolresult
);
103 ok(SUCCEEDED(hr
), "IsBlackWhite failed, hr=%x\n", hr
);
104 ok(!boolresult
, "expected FALSE, got TRUE\n");
106 hr
= IWICPalette_IsGrayscale(palette
, &boolresult
);
107 ok(SUCCEEDED(hr
), "IsGrayscale failed, hr=%x\n", hr
);
108 ok(!boolresult
, "expected FALSE, got TRUE\n");
110 hr
= IWICImagingFactory_CreatePalette(factory
, &palette2
);
111 ok(SUCCEEDED(hr
), "CreatePalette failed, hr=%x\n", hr
);
113 hr
= IWICPalette_InitializeFromPalette(palette2
, palette
);
114 ok(SUCCEEDED(hr
), "InitializeFromPalette failed, hr=%x\n", hr
);
117 hr
= IWICPalette_GetType(palette2
, &type
);
118 ok(SUCCEEDED(hr
), "GetType failed, hr=%x\n", hr
);
119 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %x\n", type
);
122 hr
= IWICPalette_GetColorCount(palette2
, &count
);
123 ok(SUCCEEDED(hr
), "GetColorCount failed, hr=%x\n", hr
);
124 ok(count
== 4, "expected 4, got %u\n", count
);
126 memset(colors
, 0, sizeof(colors
));
128 hr
= IWICPalette_GetColors(palette2
, 4, colors
, &count
);
129 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
130 ok(count
== 4, "expected 4, got %u\n", count
);
131 ok(!memcmp(colors
, initcolors
, sizeof(colors
)), "got unexpected palette data\n");
133 /* try a palette with some alpha in it */
134 colors
[2] = 0x80ffffff;
135 hr
= IWICPalette_InitializeCustom(palette
, colors
, 4);
136 ok(SUCCEEDED(hr
), "InitializeCustom failed, hr=%x\n", hr
);
138 hr
= IWICPalette_HasAlpha(palette
, &boolresult
);
139 ok(SUCCEEDED(hr
), "HasAlpha failed, hr=%x\n", hr
);
140 ok(boolresult
, "expected TRUE, got FALSE\n");
142 /* setting to a 0-color palette is acceptable */
143 hr
= IWICPalette_InitializeCustom(palette
, NULL
, 0);
144 ok(SUCCEEDED(hr
), "InitializeCustom failed, hr=%x\n", hr
);
147 hr
= IWICPalette_GetType(palette
, &type
);
148 ok(SUCCEEDED(hr
), "GetType failed, hr=%x\n", hr
);
149 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %x\n", type
);
152 hr
= IWICPalette_GetColorCount(palette
, &count
);
153 ok(SUCCEEDED(hr
), "GetColorCount failed, hr=%x\n", hr
);
154 ok(count
== 0, "expected 0, got %u\n", count
);
157 hr
= IWICPalette_GetColors(palette
, 4, colors
, &count
);
158 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
159 ok(count
== 0, "expected 0, got %u\n", count
);
161 hr
= IWICPalette_InitializeFromPalette(palette2
, palette
);
162 ok(SUCCEEDED(hr
), "InitializeFromPalette failed, hr=%x\n", hr
);
165 hr
= IWICPalette_GetType(palette2
, &type
);
166 ok(SUCCEEDED(hr
), "GetType failed, hr=%x\n", hr
);
167 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %x\n", type
);
170 hr
= IWICPalette_GetColorCount(palette2
, &count
);
171 ok(SUCCEEDED(hr
), "GetColorCount failed, hr=%x\n", hr
);
172 ok(count
== 0, "expected 0, got %u\n", count
);
174 memset(colors
, 0, sizeof(colors
));
176 hr
= IWICPalette_GetColors(palette2
, 4, colors
, &count
);
177 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
178 ok(count
== 0, "expected 0, got %u\n", count
);
180 /* IWICPalette is paranoid about NULL pointers */
181 hr
= IWICPalette_GetType(palette
, NULL
);
182 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
184 hr
= IWICPalette_GetColorCount(palette
, NULL
);
185 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
187 hr
= IWICPalette_InitializeCustom(palette
, NULL
, 4);
188 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
190 hr
= IWICPalette_GetColors(palette
, 4, NULL
, &count
);
191 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
193 hr
= IWICPalette_GetColors(palette
, 4, colors
, NULL
);
194 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
196 hr
= IWICPalette_HasAlpha(palette
, NULL
);
197 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
199 hr
= IWICPalette_IsBlackWhite(palette
, NULL
);
200 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
202 hr
= IWICPalette_IsGrayscale(palette
, NULL
);
203 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
205 hr
= IWICPalette_InitializeFromPalette(palette
, NULL
);
206 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
208 IWICPalette_Release(palette2
);
209 IWICPalette_Release(palette
);
213 static void generate_gray16_palette(DWORD
*entries
, UINT count
)
219 for (i
= 0; i
< 16; i
++)
221 entries
[i
] = 0xff000000;
222 entries
[i
] |= (i
<< 20) | (i
<< 16) | (i
<< 12) | (i
<< 8) | (i
<< 4) | i
;
226 static void generate_gray256_palette(DWORD
*entries
, UINT count
)
230 assert(count
== 256);
232 for (i
= 0; i
< 256; i
++)
234 entries
[i
] = 0xff000000;
235 entries
[i
] |= (i
<< 16) | (i
<< 8) | i
;
239 static void generate_halftone8_palette(DWORD
*entries
, UINT count
, BOOL add_transparent
)
244 ok(count
== 17, "expected 17, got %u\n", count
);
246 ok(count
== 16, "expected 16, got %u\n", count
);
248 for (i
= 0; i
< 8; i
++)
250 entries
[i
] = 0xff000000;
251 if (i
& 1) entries
[i
] |= 0xff;
252 if (i
& 2) entries
[i
] |= 0xff00;
253 if (i
& 4) entries
[i
] |= 0xff0000;
256 for (i
= 8; i
< 16; i
++)
258 static const DWORD halftone
[8] = { 0xc0c0c0, 0x808080, 0x800000, 0x008000,
259 0x000080, 0x808000, 0x800080, 0x008080 };
260 entries
[i
] = 0xff000000;
261 entries
[i
] |= halftone
[i
-8];
268 static void generate_halftone27_palette(DWORD
*entries
, UINT count
, BOOL add_transparent
)
270 static const BYTE halftone_values
[4] = { 0x00,0x80,0xff };
274 ok(count
== 29, "expected 29, got %u\n", count
);
276 ok(count
== 28, "expected 28, got %u\n", count
);
278 for (i
= 0; i
< 27; i
++)
280 entries
[i
] = 0xff000000;
281 entries
[i
] |= halftone_values
[i
%3];
282 entries
[i
] |= halftone_values
[(i
/3)%3] << 8;
283 entries
[i
] |= halftone_values
[(i
/9)%3] << 16;
286 entries
[i
++] = 0xffc0c0c0;
291 static void generate_halftone64_palette(DWORD
*entries
, UINT count
, BOOL add_transparent
)
293 static const BYTE halftone_values
[4] = { 0x00,0x55,0xaa,0xff };
297 ok(count
== 73, "expected 73, got %u\n", count
);
299 ok(count
== 72, "expected 72, got %u\n", count
);
301 for (i
= 0; i
< 64; i
++)
303 entries
[i
] = 0xff000000;
304 entries
[i
] |= halftone_values
[i
%4];
305 entries
[i
] |= halftone_values
[(i
/4)%4] << 8;
306 entries
[i
] |= halftone_values
[(i
/16)%4] << 16;
309 for (i
= 64; i
< 72; i
++)
311 static const DWORD halftone
[8] = { 0xc0c0c0, 0x808080, 0x800000, 0x008000,
312 0x000080, 0x808000, 0x800080, 0x008080 };
313 entries
[i
] = 0xff000000;
314 entries
[i
] |= halftone
[i
-64];
321 static void generate_halftone125_palette(DWORD
*entries
, UINT count
, BOOL add_transparent
)
323 static const BYTE halftone_values
[5] = { 0x00, 0x40, 0x80, 0xbf, 0xff };
327 ok(count
== 127, "expected 127, got %u\n", count
);
329 ok(count
== 126, "expected 126, got %u\n", count
);
331 for (i
= 0; i
< 125; i
++)
333 entries
[i
] = 0xff000000;
334 entries
[i
] |= halftone_values
[i
%5];
335 entries
[i
] |= halftone_values
[(i
/5)%5] << 8;
336 entries
[i
] |= halftone_values
[(i
/25)%5] << 16;
339 entries
[i
++] = 0xffc0c0c0;
344 static void generate_halftone216_palette(DWORD
*entries
, UINT count
, BOOL add_transparent
)
346 static const BYTE halftone_values
[6] = { 0x00,0x33,0x66,0x99,0xcc,0xff };
350 ok(count
== 225, "expected 225, got %u\n", count
);
352 ok(count
== 224, "expected 224, got %u\n", count
);
354 for (i
= 0; i
< 216; i
++)
356 entries
[i
] = 0xff000000;
357 entries
[i
] |= halftone_values
[i
%6];
358 entries
[i
] |= halftone_values
[(i
/6)%6] << 8;
359 entries
[i
] |= halftone_values
[(i
/36)%6] << 16;
362 for (i
= 216; i
< 224; i
++)
364 static const DWORD halftone
[8] = { 0xc0c0c0, 0x808080, 0x800000, 0x008000,
365 0x000080, 0x808000, 0x800080, 0x008080 };
366 entries
[i
] = 0xff000000;
367 entries
[i
] |= halftone
[i
-216];
374 static void generate_halftone252_palette(DWORD
*entries
, UINT count
, BOOL add_transparent
)
376 static const BYTE halftone_values_rb
[6] = { 0x00,0x33,0x66,0x99,0xcc,0xff };
377 static const BYTE halftone_values_g
[7] = { 0x00,0x2b,0x55,0x80,0xaa,0xd5,0xff };
381 ok(count
== 253, "expected 253, got %u\n", count
);
383 ok(count
== 252, "expected 252, got %u\n", count
);
385 for (i
= 0; i
< 252; i
++)
387 entries
[i
] = 0xff000000;
388 entries
[i
] |= halftone_values_rb
[i
%6];
389 entries
[i
] |= halftone_values_g
[(i
/6)%7] << 8;
390 entries
[i
] |= halftone_values_rb
[(i
/42)%6] << 16;
397 static void generate_halftone256_palette(DWORD
*entries
, UINT count
, BOOL add_transparent
)
399 static const BYTE halftone_values_b
[4] = { 0x00,0x55,0xaa,0xff };
400 static const BYTE halftone_values_gr
[8] = { 0x00,0x24,0x49,0x6d,0x92,0xb6,0xdb,0xff };
403 assert(count
== 256);
405 for (i
= 0; i
< 256; i
++)
407 entries
[i
] = 0xff000000;
408 entries
[i
] |= halftone_values_b
[i
%4];
409 entries
[i
] |= halftone_values_gr
[(i
/4)%8] << 8;
410 entries
[i
] |= halftone_values_gr
[(i
/32)%8] << 16;
417 static void test_predefined_palette(void)
419 static struct test_data
421 WICBitmapPaletteType type
;
425 BOOL add_transparent
;
428 { WICBitmapPaletteTypeFixedBW
, 1, 1, 2, { 0xff000000, 0xffffffff } },
429 { WICBitmapPaletteTypeFixedBW
, 1, 1, 2, { 0xff000000, 0xffffffff }, 1 },
430 { WICBitmapPaletteTypeFixedGray4
, 0, 1, 4,
431 { 0xff000000, 0xff555555, 0xffaaaaaa, 0xffffffff } },
432 { WICBitmapPaletteTypeFixedGray4
, 0, 1, 4,
433 { 0xff000000, 0xff555555, 0xffaaaaaa, 0xffffffff }, 1 },
434 { WICBitmapPaletteTypeFixedGray16
, 0, 1, 16, { 0 } },
435 { WICBitmapPaletteTypeFixedGray16
, 0, 1, 16, { 0 }, 1 },
436 { WICBitmapPaletteTypeFixedGray256
, 0, 1, 256, { 0 } },
437 { WICBitmapPaletteTypeFixedGray256
, 0, 1, 256, { 0 }, 1 },
438 { WICBitmapPaletteTypeFixedHalftone8
, 0, 0, 16, { 0 } },
439 { WICBitmapPaletteTypeFixedHalftone8
, 0, 0, 17, { 0 }, 1 },
440 { WICBitmapPaletteTypeFixedHalftone27
, 0, 0, 28, { 0 } },
441 { WICBitmapPaletteTypeFixedHalftone27
, 0, 0, 29, { 0 }, 1 },
442 { WICBitmapPaletteTypeFixedHalftone64
, 0, 0, 72, { 0 } },
443 { WICBitmapPaletteTypeFixedHalftone64
, 0, 0, 73, { 0 }, 1 },
444 { WICBitmapPaletteTypeFixedHalftone125
, 0, 0, 126, { 0 } },
445 { WICBitmapPaletteTypeFixedHalftone125
, 0, 0, 127, { 0 }, 1 },
446 { WICBitmapPaletteTypeFixedHalftone216
, 0, 0, 224, { 0 } },
447 { WICBitmapPaletteTypeFixedHalftone216
, 0, 0, 225, { 0 }, 1 },
448 { WICBitmapPaletteTypeFixedHalftone252
, 0, 0, 252, { 0 } },
449 { WICBitmapPaletteTypeFixedHalftone252
, 0, 0, 253, { 0 }, 1 },
450 { WICBitmapPaletteTypeFixedHalftone256
, 0, 0, 256, { 0 } },
451 { WICBitmapPaletteTypeFixedHalftone256
, 0, 0, 256, { 0 }, 1 }
453 IWICPalette
*palette
;
455 WICBitmapPaletteType type
;
460 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
461 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
462 hr
= IWICPalette_InitializePredefined(palette
, WICBitmapPaletteTypeCustom
, FALSE
);
463 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
464 hr
= IWICPalette_InitializePredefined(palette
, WICBitmapPaletteTypeMedianCut
, FALSE
);
465 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
466 hr
= IWICPalette_InitializePredefined(palette
, 0x0f, FALSE
);
467 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
468 IWICPalette_Release(palette
);
470 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
472 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
473 ok(hr
== S_OK
, "%u: CreatePalette error %#x\n", i
, hr
);
475 hr
= IWICPalette_InitializePredefined(palette
, td
[i
].type
, td
[i
].add_transparent
);
476 ok(hr
== S_OK
, "%u: InitializePredefined error %#x\n", i
, hr
);
479 hr
= IWICPalette_IsBlackWhite(palette
, &bret
);
480 ok(hr
== S_OK
, "%u: IsBlackWhite error %#x\n", i
, hr
);
481 ok(bret
== td
[i
].is_bw
||
482 broken(td
[i
].type
== WICBitmapPaletteTypeFixedBW
&& bret
!= td
[i
].is_bw
), /* XP */
483 "%u: expected %d, got %d\n",i
, td
[i
].is_bw
, bret
);
486 hr
= IWICPalette_IsGrayscale(palette
, &bret
);
487 ok(hr
== S_OK
, "%u: IsGrayscale error %#x\n", i
, hr
);
488 ok(bret
== td
[i
].is_gray
, "%u: expected %d, got %d\n", i
, td
[i
].is_gray
, bret
);
491 hr
= IWICPalette_GetType(palette
, &type
);
492 ok(hr
== S_OK
, "%u: GetType error %#x\n", i
, hr
);
493 ok(type
== td
[i
].type
, "%u: expected %#x, got %#x\n", i
, td
[i
].type
, type
);
496 hr
= IWICPalette_GetColorCount(palette
, &count
);
497 ok(hr
== S_OK
, "%u: GetColorCount error %#x\n", i
, hr
);
498 ok(count
== td
[i
].count
, "%u: expected %u, got %u\n", i
, td
[i
].count
, count
);
500 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
501 ok(hr
== S_OK
, "%u: GetColors error %#x\n", i
, hr
);
502 ok(ret
== count
, "%u: expected %u, got %u\n", i
, count
, ret
);
503 if (ret
== td
[i
].count
)
507 if (td
[i
].type
== WICBitmapPaletteTypeFixedGray16
)
508 generate_gray16_palette(td
[i
].color
, td
[i
].count
);
509 else if (td
[i
].type
== WICBitmapPaletteTypeFixedGray256
)
510 generate_gray256_palette(td
[i
].color
, td
[i
].count
);
511 else if (td
[i
].type
== WICBitmapPaletteTypeFixedHalftone8
)
512 generate_halftone8_palette(td
[i
].color
, td
[i
].count
, td
[i
].add_transparent
);
513 else if (td
[i
].type
== WICBitmapPaletteTypeFixedHalftone27
)
514 generate_halftone27_palette(td
[i
].color
, td
[i
].count
, td
[i
].add_transparent
);
515 else if (td
[i
].type
== WICBitmapPaletteTypeFixedHalftone64
)
516 generate_halftone64_palette(td
[i
].color
, td
[i
].count
, td
[i
].add_transparent
);
517 else if (td
[i
].type
== WICBitmapPaletteTypeFixedHalftone125
)
518 generate_halftone125_palette(td
[i
].color
, td
[i
].count
, td
[i
].add_transparent
);
519 else if (td
[i
].type
== WICBitmapPaletteTypeFixedHalftone216
)
520 generate_halftone216_palette(td
[i
].color
, td
[i
].count
, td
[i
].add_transparent
);
521 else if (td
[i
].type
== WICBitmapPaletteTypeFixedHalftone252
)
522 generate_halftone252_palette(td
[i
].color
, td
[i
].count
, td
[i
].add_transparent
);
523 else if (td
[i
].type
== WICBitmapPaletteTypeFixedHalftone256
)
524 generate_halftone256_palette(td
[i
].color
, td
[i
].count
, td
[i
].add_transparent
);
526 for (j
= 0; j
< count
; j
++)
528 ok(color
[j
] == td
[i
].color
[j
], "%u:[%u]: expected %#x, got %#x\n",
529 i
, j
, td
[i
].color
[j
], color
[j
]);
533 IWICPalette_Release(palette
);
537 static BYTE
*init_bitmap(UINT
*width
, UINT
*height
, UINT
*stride
)
544 *stride
= (*width
* 3 + 3) & ~3;
545 trace("width %d, height %d, stride %d\n", *width
, *height
, *stride
);
547 src
= HeapAlloc(GetProcessHeap(), 0, *stride
* *height
);
549 scale
= 256 / *width
;
550 if (!scale
) scale
= 1;
552 for (i
= 0; i
< *height
; i
++)
554 for (j
= 0; j
< *width
; j
++)
556 src
[i
* *stride
+ j
*3 + 0] = scale
* i
;
557 src
[i
* *stride
+ j
*3 + 1] = scale
* (255 - (i
+j
)/2);
558 src
[i
* *stride
+ j
*3 + 2] = scale
* j
;
565 static void test_palette_from_bitmap(void)
570 IWICPalette
*palette
;
571 WICBitmapPaletteType type
;
572 UINT width
, height
, stride
, count
, ret
;
575 data
= init_bitmap(&width
, &height
, &stride
);
577 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, width
, height
, &GUID_WICPixelFormat24bppRGB
,
578 stride
, stride
* height
, data
, &bitmap
);
579 ok(hr
== S_OK
, "CreateBitmapFromMemory error %#x\n", hr
);
581 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
582 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
584 hr
= IWICPalette_InitializeFromBitmap(palette
, (IWICBitmapSource
*)bitmap
, 0, FALSE
);
585 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
587 hr
= IWICPalette_InitializeFromBitmap(palette
, (IWICBitmapSource
*)bitmap
, 1, FALSE
);
588 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
590 hr
= IWICPalette_InitializeFromBitmap(palette
, (IWICBitmapSource
*)bitmap
, 257, FALSE
);
591 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
593 hr
= IWICPalette_InitializeFromBitmap(palette
, NULL
, 16, FALSE
);
594 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
596 hr
= IWICPalette_InitializeFromBitmap(palette
, (IWICBitmapSource
*)bitmap
, 2, FALSE
);
597 ok(hr
== S_OK
, "InitializeFromBitmap error %#x\n", hr
);
599 hr
= IWICPalette_GetColorCount(palette
, &count
);
600 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
601 ok(count
== 2, "expected 2, got %u\n", count
);
603 hr
= IWICPalette_InitializeFromBitmap(palette
, (IWICBitmapSource
*)bitmap
, 2, TRUE
);
604 ok(hr
== S_OK
, "InitializeFromBitmap error %#x\n", hr
);
606 hr
= IWICPalette_GetColorCount(palette
, &count
);
607 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
608 ok(count
== 2, "expected 2, got %u\n", count
);
610 /* without trasparent color */
611 hr
= IWICPalette_InitializeFromBitmap(palette
, (IWICBitmapSource
*)bitmap
, 16, FALSE
);
612 ok(hr
== S_OK
, "InitializeFromBitmap error %#x\n", hr
);
614 hr
= IWICPalette_GetType(palette
, &type
);
615 ok(hr
== S_OK
, "GetType error %#x\n", hr
);
616 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %#x\n", type
);
618 hr
= IWICPalette_GetColorCount(palette
, &count
);
619 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
620 ok(count
== 16, "expected 16, got %u\n", count
);
621 memset(color
, 0, sizeof(color
));
622 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
623 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
624 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
625 ok(color
[count
- 1] != 0, "expected !0, got %08x\n", color
[count
- 1]);
627 /* with trasparent color */
628 hr
= IWICPalette_InitializeFromBitmap(palette
, (IWICBitmapSource
*)bitmap
, 16, TRUE
);
629 ok(hr
== S_OK
, "InitializeFromBitmap error %#x\n", hr
);
631 hr
= IWICPalette_GetType(palette
, &type
);
632 ok(hr
== S_OK
, "GetType error %#x\n", hr
);
633 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %#x\n", type
);
635 hr
= IWICPalette_GetColorCount(palette
, &count
);
636 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
637 ok(count
== 16, "expected 16, got %u\n", count
);
638 memset(color
, 0xff, sizeof(color
));
639 hr
= IWICPalette_GetColors(palette
, count
, color
, &ret
);
640 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
641 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
642 ok(color
[count
- 1] == 0, "expected 0, got %08x\n", color
[count
- 1]);
644 IWICPalette_Release(palette
);
645 IWICBitmap_Release(bitmap
);
647 HeapFree(GetProcessHeap(), 0, data
);
654 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
656 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
657 &IID_IWICImagingFactory
, (void **)&factory
);
658 ok(hr
== S_OK
, "CoCreateInstance error %#x\n", hr
);
660 test_custom_palette();
661 test_predefined_palette();
662 test_palette_from_bitmap();
664 IWICImagingFactory_Release(factory
);