ReactOS 0.4.15-dev-7788-g1ad9096
palette.c
Go to the documentation of this file.
1/*
2 * Unit test suite for palettes
3 *
4 * Copyright 2005 Glenn Wurster
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdarg.h>
22
23#include "windef.h"
24#include "winbase.h"
25#include "wingdi.h"
26#include "winuser.h"
27#include "mmsystem.h"
28
29#include "wine/test.h"
30
31static const PALETTEENTRY logpalettedata[8] = {
32 { 0x10, 0x20, 0x30, PC_NOCOLLAPSE },
33 { 0x20, 0x30, 0x40, PC_NOCOLLAPSE },
34 { 0x30, 0x40, 0x50, PC_NOCOLLAPSE },
35 { 0x40, 0x50, 0x60, PC_NOCOLLAPSE },
36 { 0x50, 0x60, 0x70, PC_NOCOLLAPSE },
37 { 0x60, 0x70, 0x80, PC_NOCOLLAPSE },
38 { 0x70, 0x80, 0x90, PC_NOCOLLAPSE },
39 { 0x80, 0x90, 0xA0, PC_NOCOLLAPSE },
40};
41
42static void test_DIB_PAL_COLORS(void) {
43 HDC hdc = GetDC( NULL );
44 HDC memhdc = CreateCompatibleDC( hdc );
46 char bmpbuf[sizeof(BITMAPINFO) + 10 * sizeof(WORD)];
47 PBITMAPINFO bmp = (PBITMAPINFO)bmpbuf;
48 WORD * bmpPalPtr;
49 char logpalettebuf[sizeof(LOGPALETTE) + sizeof(logpalettedata)];
50 PLOGPALETTE logpalette = (PLOGPALETTE)logpalettebuf;
51 HPALETTE hpal, hpalOld;
52 COLORREF setColor, chkColor, getColor;
53 int i;
54
55 /* Initialize the logical palette with a few colours */
56 logpalette->palVersion = 0x300;
58 memcpy( logpalette->palPalEntry, logpalettedata, sizeof(logpalettedata) );
59 hpal = CreatePalette( logpalette );
60 hpalOld = SelectPalette( memhdc, hpal, FALSE );
61 ok( hpalOld != NULL, "error=%d\n", GetLastError() );
62
63 /* Create a DIB BMP which references colours in the logical palette */
64 memset( bmp, 0x00, sizeof(BITMAPINFO) );
65 bmp->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
66 bmp->bmiHeader.biWidth = 1;
67 bmp->bmiHeader.biHeight = 1;
68 bmp->bmiHeader.biPlanes = 1;
69 bmp->bmiHeader.biBitCount = 8;
70 bmp->bmiHeader.biCompression = BI_RGB;
71 bmp->bmiHeader.biClrUsed = 10;
72 bmp->bmiHeader.biClrImportant = 0;
73 bmpPalPtr = (WORD *)&bmp->bmiColors;
74 for( i = 0; i < 8; i++ ) {
75 *bmpPalPtr++ = i;
76 }
77 *bmpPalPtr++ = 8; /* Pointer to logical palette index just outside range */
78 *bmpPalPtr++ = 19; /* Pointer to bad logical palette index */
79
80 hbmp = CreateDIBSection( memhdc, bmp, DIB_PAL_COLORS, 0, 0, 0 );
81 ok( hbmp != NULL, "error=%d\n", GetLastError() );
82 hbmpOld = SelectObject( memhdc, hbmp );
83 ok( hbmpOld != NULL, "error=%d\n", GetLastError() );
84
85 /* Test with a RGB to DIB_PAL_COLORS */
86 setColor = RGB( logpalettedata[1].peRed, logpalettedata[1].peGreen, logpalettedata[1].peBlue );
87 SetPixel( memhdc, 0, 0, setColor );
88 chkColor = RGB( logpalettedata[1].peRed, logpalettedata[1].peGreen, logpalettedata[1].peBlue );
89 getColor = GetPixel( memhdc, 0, 0 );
90 ok( getColor == chkColor, "getColor=%08X\n", (UINT)getColor );
91
92 /* Test with a valid DIBINDEX to DIB_PAL_COLORS */
93 setColor = DIBINDEX( 2 );
94 SetPixel( memhdc, 0, 0, setColor );
95 chkColor = RGB( logpalettedata[2].peRed, logpalettedata[2].peGreen, logpalettedata[2].peBlue );
96 getColor = GetPixel( memhdc, 0, 0 );
97 ok( getColor == chkColor, "getColor=%08X\n", (UINT)getColor );
98
99 /* Test with an invalid DIBINDEX to DIB_PAL_COLORS */
100 setColor = DIBINDEX( 12 );
101 SetPixel( memhdc, 0, 0, setColor );
102 chkColor = RGB( 0, 0, 0 );
103 getColor = GetPixel( memhdc, 0, 0 );
104 ok( getColor == chkColor, "getColor=%08X\n", (UINT)getColor );
105
106 /* Test for double wraparound on logical palette references from */
107 /* DIBINDEX by DIB_PAL_COLORS. */
108 setColor = DIBINDEX( 9 );
109 SetPixel( memhdc, 0, 0, setColor );
110 chkColor = RGB( logpalettedata[3].peRed, logpalettedata[3].peGreen, logpalettedata[3].peBlue );
111 getColor = GetPixel( memhdc, 0, 0 );
112 ok( getColor == chkColor, "getColor=%08X\n", (UINT)getColor );
113
114 SelectPalette( memhdc, hpalOld, FALSE );
115 DeleteObject( hpal );
116 SelectObject( memhdc, hbmpOld );
118 DeleteDC( memhdc );
119 ReleaseDC( NULL, hdc );
120}
121
122static void test_palette_entries(void)
123{
124 char logpalettebuf[sizeof(LOGPALETTE) + sizeof(logpalettedata)];
125 PLOGPALETTE logpalette = (PLOGPALETTE)logpalettebuf;
126 HPALETTE hpal;
127 UINT res=0;
128 PALETTEENTRY palEntry = { 0x1, 0x2, 0x3, 0xff };
129 PALETTEENTRY getEntryResult;
130
131 /* Initialize the logical palette with a few colours */
132 logpalette->palVersion = 0x300;
134 memcpy( logpalette->palPalEntry, logpalettedata, sizeof(logpalettedata) );
135 hpal = CreatePalette( logpalette );
136
137 /* Set a new entry with peFlags to 0xff */
138 SetPaletteEntries(hpal, 0, 1, &palEntry);
139
140 /* Retrieve the entry to see if GDI32 performs any filtering on peFlags */
141 res = GetPaletteEntries(hpal, 0, 1, &getEntryResult);
142 ok(res == 1, "GetPaletteEntries should have returned 1 but returned %d\n", res);
143
144 ok( palEntry.peFlags == getEntryResult.peFlags, "palEntry.peFlags (%#x) != getEntryResult.peFlags (%#x)\n", palEntry.peFlags, getEntryResult.peFlags );
145}
146
147static void test_halftone_palette(void)
148{
149 HDC hdc;
150 HPALETTE pal;
151 PALETTEENTRY entries[256];
152 PALETTEENTRY defpal[20];
153 int i, count;
154
155 hdc = GetDC(0);
156
158 ok( count == 20, "wrong size %u\n", count );
159
160 pal = CreateHalftonePalette( hdc );
161 count = GetPaletteEntries( pal, 0, 256, entries );
162 ok( count == 256 || broken(count <= 20), /* nt 4 */
163 "wrong size %u\n", count );
164
165 /* first and last 8 match the default palette */
166 if (count >= 20)
167 {
168 for (i = 0; i < 8; i++)
169 {
170 ok( entries[i].peRed == defpal[i].peRed &&
171 entries[i].peGreen == defpal[i].peGreen &&
172 entries[i].peBlue == defpal[i].peBlue &&
173 !entries[i].peFlags,
174 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
175 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
176 defpal[i].peRed, defpal[i].peGreen, defpal[i].peBlue );
177 }
178 for (i = count - 8; i < count; i++)
179 {
180 int idx = i - count + 20;
181 ok( entries[i].peRed == defpal[idx].peRed &&
182 entries[i].peGreen == defpal[idx].peGreen &&
183 entries[i].peBlue == defpal[idx].peBlue &&
184 !entries[i].peFlags,
185 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
186 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
187 defpal[idx].peRed, defpal[idx].peGreen, defpal[idx].peBlue );
188 }
189 }
190 DeleteObject( pal );
191 ReleaseDC( 0, hdc );
192}
193
195{
196 PALETTEENTRY entries[256];
197 PALETTEENTRY defpal[20];
198 int i, count;
199
200 memset( defpal, 0xaa, sizeof(defpal) );
202 ok( count == 20, "wrong size %u\n", count );
203
204 memset( entries, 0x55, sizeof(entries) );
205 count = GetSystemPaletteEntries( hdc, 0, 256, entries );
206 ok( count == 0, "wrong size %u\n", count);
207 for (i = 0; i < 10; i++)
208 {
209 ok( entries[i].peRed == defpal[i].peRed &&
210 entries[i].peGreen == defpal[i].peGreen &&
211 entries[i].peBlue == defpal[i].peBlue &&
212 !entries[i].peFlags,
213 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
214 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
215 defpal[i].peRed, defpal[i].peGreen, defpal[i].peBlue );
216 }
217 for (i = 10; i < 246; ++i)
218 {
219 ok( !entries[i].peRed &&
220 !entries[i].peGreen &&
221 !entries[i].peBlue &&
222 !entries[i].peFlags,
223 "%u: wrong color %02x,%02x,%02x,%02x instead of 0,0,0\n", i,
224 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags);
225 }
226 for (i = 246; i < 256; i++)
227 {
228 int idx = i - 246 + 10;
229 ok( entries[i].peRed == defpal[idx].peRed &&
230 entries[i].peGreen == defpal[idx].peGreen &&
231 entries[i].peBlue == defpal[idx].peBlue &&
232 !entries[i].peFlags,
233 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
234 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
235 defpal[idx].peRed, defpal[idx].peGreen, defpal[idx].peBlue );
236 }
237
238 memset( entries, 0x55, sizeof(entries) );
239 count = GetSystemPaletteEntries( hdc, 0, 10, entries );
240 ok( count == 0, "wrong size %u\n", count);
241 for (i = 0; i < 10; i++)
242 {
243 ok( entries[i].peRed == defpal[i].peRed &&
244 entries[i].peGreen == defpal[i].peGreen &&
245 entries[i].peBlue == defpal[i].peBlue &&
246 !entries[i].peFlags,
247 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
248 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
249 defpal[i].peRed, defpal[i].peGreen, defpal[i].peBlue );
250 }
251
252 memset( entries, 0x55, sizeof(entries) );
253 count = GetSystemPaletteEntries( hdc, 10, 246, entries );
254 ok( count == 0, "wrong size %u\n", count);
255 for (i = 0; i < 236; ++i)
256 {
257 ok( !entries[i].peRed &&
258 !entries[i].peGreen &&
259 !entries[i].peBlue &&
260 !entries[i].peFlags,
261 "%u: wrong color %02x,%02x,%02x,%02x instead of 0,0,0\n", i,
262 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags);
263 }
264 for (i = 236; i < 246; i++)
265 {
266 int idx = i - 236 + 10;
267 ok( entries[i].peRed == defpal[idx].peRed &&
268 entries[i].peGreen == defpal[idx].peGreen &&
269 entries[i].peBlue == defpal[idx].peBlue &&
270 !entries[i].peFlags,
271 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
272 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
273 defpal[idx].peRed, defpal[idx].peGreen, defpal[idx].peBlue );
274 }
275
276 memset( entries, 0x55, sizeof(entries) );
277 count = GetSystemPaletteEntries( hdc, 246, 10, entries );
278 ok( count == 0, "wrong size %u\n", count);
279 for (i = 0; i < 10; i++)
280 {
281 int idx = i + 10;
282 ok( entries[i].peRed == defpal[idx].peRed &&
283 entries[i].peGreen == defpal[idx].peGreen &&
284 entries[i].peBlue == defpal[idx].peBlue &&
285 !entries[i].peFlags,
286 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
287 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
288 defpal[idx].peRed, defpal[idx].peGreen, defpal[idx].peBlue );
289 }
290}
291
293{
294 HDC hdc;
295 HDC metafile_dc;
296 HMETAFILE metafile;
297
298 hdc = GetDC(0);
299
301 {
303 }
304 else
305 {
306 skip( "device is palette-based, skipping test\n" );
307 }
308
309 ReleaseDC( 0, hdc );
310
311 metafile_dc = CreateMetaFileA(NULL);
312
313 check_system_palette_entries(metafile_dc);
314
315 metafile = CloseMetaFile(metafile_dc);
317}
318
320{
325}
#define broken(x)
Definition: _sntprintf.h:21
FORCEINLINE VOID SetPixel(_In_ ULONG Left, _In_ ULONG Top, _In_ UCHAR Color)
Definition: arm.h:50
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
#define BI_RGB
Definition: precomp.h:47
#define RGB(r, g, b)
Definition: precomp.h:62
unsigned short WORD
Definition: ntddk_ex.h:93
pKey DeleteObject()
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
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
HANDLE hbmpOld
Definition: magnifier.c:54
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define DIBINDEX(n)
Definition: mmsystem.h:932
BITMAP bmp
Definition: alphablend.c:62
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
static void test_halftone_palette(void)
Definition: palette.c:147
static void test_palette_entries(void)
Definition: palette.c:122
static void test_DIB_PAL_COLORS(void)
Definition: palette.c:42
static void check_system_palette_entries(HDC hdc)
Definition: palette.c:194
static const PALETTEENTRY logpalettedata[8]
Definition: palette.c:31
static void test_system_palette_entries(void)
Definition: palette.c:292
static const unsigned char metafile[]
Definition: olepicture.c:138
static HPALETTE palette
Definition: clipboard.c:1345
static const LOGPALETTE logpalette
Definition: clipboard.c:1346
unsigned int UINT
Definition: ndis.h:50
#define memset(x, y, z)
Definition: compat.h:39
WORD palNumEntries
Definition: wingdi.h:1834
WORD palVersion
Definition: wingdi.h:1833
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
UINT WINAPI GetPaletteEntries(HPALETTE hpal, UINT iStartIndex, UINT cEntries, LPPALETTEENTRY ppe)
Definition: palette.c:64
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD COLORREF
Definition: windef.h:300
BOOL WINAPI DeleteMetaFile(_In_ HMETAFILE)
#define RASTERCAPS
Definition: wingdi.h:745
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define DEFAULT_PALETTE
Definition: wingdi.h:913
HDC WINAPI CreateMetaFileA(_In_opt_ LPCSTR)
struct tagLOGPALETTE * PLOGPALETTE
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
struct tagLOGPALETTE LOGPALETTE
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HMETAFILE WINAPI CloseMetaFile(_In_ HDC hdc)
#define DIB_PAL_COLORS
Definition: wingdi.h:366
UINT WINAPI GetSystemPaletteEntries(_In_ HDC hdc, _In_ UINT iStart, _In_ UINT cEntries, _Out_writes_opt_(cEntries) LPPALETTEENTRY pPalEntries)
struct tagBITMAPINFO BITMAPINFO
struct tagBITMAPINFO * PBITMAPINFO
#define PC_NOCOLLAPSE
Definition: wingdi.h:881
UINT WINAPI SetPaletteEntries(_In_ HPALETTE hpal, _In_ UINT iStart, _In_ UINT cEntries, _In_reads_(cEntries) CONST PALETTEENTRY *pPalEntries)
BOOL WINAPI DeleteDC(_In_ HDC)
HPALETTE WINAPI CreateHalftonePalette(_In_opt_ HDC)
#define RC_PALETTE
Definition: wingdi.h:790
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)