2 * Copyright 2009 Vincent Povirk for CodeWeavers
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
26 #include "wine/test.h"
28 static void test_custom_palette(void)
30 IWICImagingFactory
*factory
;
33 WICBitmapPaletteType type
=0xffffffff;
35 const WICColor initcolors
[4]={0xff000000,0xff0000ff,0xffffff00,0xffffffff};
39 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
40 &IID_IWICImagingFactory
, (void**)&factory
);
41 ok(SUCCEEDED(hr
), "CoCreateInstance failed, hr=%x\n", hr
);
42 if (FAILED(hr
)) return;
44 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
45 ok(SUCCEEDED(hr
), "CreatePalette failed, hr=%x\n", hr
);
48 hr
= IWICPalette_GetType(palette
, &type
);
49 ok(SUCCEEDED(hr
), "GetType failed, hr=%x\n", hr
);
50 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %x\n", type
);
52 hr
= IWICPalette_GetColorCount(palette
, &count
);
53 ok(SUCCEEDED(hr
), "GetColorCount failed, hr=%x\n", hr
);
54 ok(count
== 0, "expected 0, got %u\n", count
);
56 hr
= IWICPalette_GetColors(palette
, 0, colors
, &count
);
57 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
58 ok(count
== 0, "expected 0, got %u\n", count
);
60 hr
= IWICPalette_GetColors(palette
, 4, colors
, &count
);
61 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
62 ok(count
== 0, "expected 0, got %u\n", count
);
64 memcpy(colors
, initcolors
, sizeof(initcolors
));
65 hr
= IWICPalette_InitializeCustom(palette
, colors
, 4);
66 ok(SUCCEEDED(hr
), "InitializeCustom failed, hr=%x\n", hr
);
68 hr
= IWICPalette_GetType(palette
, &type
);
69 ok(SUCCEEDED(hr
), "GetType failed, hr=%x\n", hr
);
70 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %x\n", type
);
72 hr
= IWICPalette_GetColorCount(palette
, &count
);
73 ok(SUCCEEDED(hr
), "GetColorCount failed, hr=%x\n", hr
);
74 ok(count
== 4, "expected 4, got %u\n", count
);
76 memset(colors
, 0, sizeof(colors
));
78 hr
= IWICPalette_GetColors(palette
, 4, colors
, &count
);
79 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
80 ok(count
== 4, "expected 4, got %u\n", count
);
81 ok(!memcmp(colors
, initcolors
, sizeof(colors
)), "got unexpected palette data\n");
83 memset(colors
, 0, sizeof(colors
));
85 hr
= IWICPalette_GetColors(palette
, 2, colors
, &count
);
86 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
87 ok(count
== 2, "expected 2, got %u\n", count
);
88 ok(!memcmp(colors
, initcolors
, sizeof(WICColor
)*2), "got unexpected palette data\n");
91 hr
= IWICPalette_GetColors(palette
, 6, colors
, &count
);
92 ok(SUCCEEDED(hr
), "GetColors failed, hr=%x\n", hr
);
93 ok(count
== 4, "expected 4, got %u\n", count
);
95 hr
= IWICPalette_HasAlpha(palette
, &boolresult
);
96 ok(SUCCEEDED(hr
), "HasAlpha failed, hr=%x\n", hr
);
97 ok(!boolresult
, "expected FALSE, got TRUE\n");
99 hr
= IWICPalette_IsBlackWhite(palette
, &boolresult
);
100 ok(SUCCEEDED(hr
), "IsBlackWhite failed, hr=%x\n", hr
);
101 ok(!boolresult
, "expected FALSE, got TRUE\n");
103 hr
= IWICPalette_IsGrayscale(palette
, &boolresult
);
104 ok(SUCCEEDED(hr
), "IsGrayscale failed, hr=%x\n", hr
);
105 ok(!boolresult
, "expected FALSE, got TRUE\n");
107 /* try a palette with some alpha in it */
108 colors
[2] = 0x80ffffff;
109 hr
= IWICPalette_InitializeCustom(palette
, colors
, 4);
110 ok(SUCCEEDED(hr
), "InitializeCustom failed, hr=%x\n", hr
);
112 hr
= IWICPalette_HasAlpha(palette
, &boolresult
);
113 ok(SUCCEEDED(hr
), "HasAlpha failed, hr=%x\n", hr
);
114 ok(boolresult
, "expected TRUE, got FALSE\n");
116 /* setting to a 0-color palette is acceptable */
117 hr
= IWICPalette_InitializeCustom(palette
, NULL
, 0);
118 ok(SUCCEEDED(hr
), "InitializeCustom failed, hr=%x\n", hr
);
120 /* IWICPalette is paranoid about NULL pointers */
121 hr
= IWICPalette_GetType(palette
, NULL
);
122 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
124 hr
= IWICPalette_GetColorCount(palette
, NULL
);
125 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
127 hr
= IWICPalette_InitializeCustom(palette
, NULL
, 4);
128 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
130 hr
= IWICPalette_GetColors(palette
, 4, NULL
, &count
);
131 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
133 hr
= IWICPalette_GetColors(palette
, 4, colors
, NULL
);
134 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
136 hr
= IWICPalette_HasAlpha(palette
, NULL
);
137 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
139 hr
= IWICPalette_IsBlackWhite(palette
, NULL
);
140 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
142 hr
= IWICPalette_IsGrayscale(palette
, NULL
);
143 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %x\n", hr
);
145 IWICPalette_Release(palette
);
148 IWICImagingFactory_Release(factory
);
153 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
155 test_custom_palette();