ReactOS 0.4.17-dev-116-ga4b6fe9
palette.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "mmsystem.h"
#include "wine/test.h"
Include dependency graph for palette.c:

Go to the source code of this file.

Functions

static void test_DIB_PAL_COLORS (void)
 
static void test_palette_entries (void)
 
static void test_halftone_palette (void)
 
static void check_system_palette_entries (HDC hdc)
 
static void test_system_palette_entries (void)
 
 START_TEST (palette)
 

Variables

static const PALETTEENTRY logpalettedata [8]
 

Function Documentation

◆ check_system_palette_entries()

static void check_system_palette_entries ( HDC  hdc)
static

Definition at line 203 of file palette.c.

204{
205 PALETTEENTRY entries[256];
206 PALETTEENTRY defpal[20];
207 int i, count;
208
209 memset( defpal, 0xaa, sizeof(defpal) );
211 ok( count == 20, "wrong size %u\n", count );
212
213 memset( entries, 0x55, sizeof(entries) );
214 count = GetSystemPaletteEntries( hdc, 0, 256, entries );
215 ok( count == 0, "wrong size %u\n", count);
216 for (i = 0; i < 10; i++)
217 {
218 ok( entries[i].peRed == defpal[i].peRed &&
219 entries[i].peGreen == defpal[i].peGreen &&
220 entries[i].peBlue == defpal[i].peBlue &&
221 !entries[i].peFlags,
222 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
223 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
224 defpal[i].peRed, defpal[i].peGreen, defpal[i].peBlue );
225 }
226 for (i = 10; i < 246; ++i)
227 {
228 ok( !entries[i].peRed &&
229 !entries[i].peGreen &&
230 !entries[i].peBlue &&
231 !entries[i].peFlags,
232 "%u: wrong color %02x,%02x,%02x,%02x instead of 0,0,0\n", i,
233 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags);
234 }
235 for (i = 246; i < 256; i++)
236 {
237 int idx = i - 246 + 10;
238 ok( entries[i].peRed == defpal[idx].peRed &&
239 entries[i].peGreen == defpal[idx].peGreen &&
240 entries[i].peBlue == defpal[idx].peBlue &&
241 !entries[i].peFlags,
242 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
243 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
244 defpal[idx].peRed, defpal[idx].peGreen, defpal[idx].peBlue );
245 }
246
247 memset( entries, 0x55, sizeof(entries) );
248 count = GetSystemPaletteEntries( hdc, 0, 10, entries );
249 ok( count == 0, "wrong size %u\n", count);
250 for (i = 0; i < 10; i++)
251 {
252 ok( entries[i].peRed == defpal[i].peRed &&
253 entries[i].peGreen == defpal[i].peGreen &&
254 entries[i].peBlue == defpal[i].peBlue &&
255 !entries[i].peFlags,
256 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
257 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
258 defpal[i].peRed, defpal[i].peGreen, defpal[i].peBlue );
259 }
260
261 memset( entries, 0x55, sizeof(entries) );
262 count = GetSystemPaletteEntries( hdc, 10, 246, entries );
263 ok( count == 0, "wrong size %u\n", count);
264 for (i = 0; i < 236; ++i)
265 {
266 ok( !entries[i].peRed &&
267 !entries[i].peGreen &&
268 !entries[i].peBlue &&
269 !entries[i].peFlags,
270 "%u: wrong color %02x,%02x,%02x,%02x instead of 0,0,0\n", i,
271 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags);
272 }
273 for (i = 236; i < 246; i++)
274 {
275 int idx = i - 236 + 10;
276 ok( entries[i].peRed == defpal[idx].peRed &&
277 entries[i].peGreen == defpal[idx].peGreen &&
278 entries[i].peBlue == defpal[idx].peBlue &&
279 !entries[i].peFlags,
280 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
281 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
282 defpal[idx].peRed, defpal[idx].peGreen, defpal[idx].peBlue );
283 }
284
285 memset( entries, 0x55, sizeof(entries) );
286 count = GetSystemPaletteEntries( hdc, 246, 10, entries );
287 ok( count == 0, "wrong size %u\n", count);
288 for (i = 0; i < 10; i++)
289 {
290 int idx = i + 10;
291 ok( entries[i].peRed == defpal[idx].peRed &&
292 entries[i].peGreen == defpal[idx].peGreen &&
293 entries[i].peBlue == defpal[idx].peBlue &&
294 !entries[i].peFlags,
295 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
296 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
297 defpal[idx].peRed, defpal[idx].peGreen, defpal[idx].peBlue );
298 }
299}
#define ok(value,...)
Definition: atltest.h:57
unsigned int idx
Definition: utils.c:41
GLuint GLuint GLsizei count
Definition: gl.h:1545
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
HDC hdc
Definition: main.c:9
#define memset(x, y, z)
Definition: compat.h:39
UINT WINAPI GetPaletteEntries(HPALETTE hpal, UINT iStartIndex, UINT cEntries, LPPALETTEENTRY ppe)
Definition: palette.c:64
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define DEFAULT_PALETTE
Definition: wingdi.h:913
UINT WINAPI GetSystemPaletteEntries(_In_ HDC hdc, _In_ UINT iStart, _In_ UINT cEntries, _Out_writes_opt_(cEntries) LPPALETTEENTRY pPalEntries)

Referenced by test_system_palette_entries().

◆ START_TEST()

START_TEST ( palette  )

Definition at line 330 of file palette.c.

331{
336}
static void test_halftone_palette(void)
Definition: palette.c:156
static void test_palette_entries(void)
Definition: palette.c:122
static void test_DIB_PAL_COLORS(void)
Definition: palette.c:42
static void test_system_palette_entries(void)
Definition: palette.c:301

◆ test_DIB_PAL_COLORS()

static void test_DIB_PAL_COLORS ( void  )
static

Definition at line 42 of file palette.c.

42 {
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=%ld\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=%ld\n", GetLastError() );
82 hbmpOld = SelectObject( memhdc, hbmp );
83 ok( hbmpOld != NULL, "error=%ld\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}
#define DIBINDEX(n)
Definition: NtGdiLineTo.c:11
VOID SetPixel(_In_ ULONG Left, _In_ ULONG Top, _In_ UCHAR Color)
Definition: bootvid.c:52
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
#define RGB(r, g, b)
Definition: precomp.h:67
unsigned short WORD
Definition: ntddk_ex.h:93
pKey DeleteObject()
HANDLE hbmpOld
Definition: magnifier.c:54
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BITMAP bmp
Definition: alphablend.c:62
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
static const PALETTEENTRY logpalettedata[8]
Definition: palette.c:31
static const LOGPALETTE logpalette
Definition: clipboard.c:1458
unsigned int UINT
Definition: ndis.h:50
WORD palNumEntries
Definition: wingdi.h:2280
WORD palVersion
Definition: wingdi.h:2279
#define BI_RGB
Definition: uefivid.c:46
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD COLORREF
Definition: windef.h:100
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:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define DIB_PAL_COLORS
Definition: wingdi.h:366
struct tagBITMAPINFO BITMAPINFO
struct tagBITMAPINFO * PBITMAPINFO
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)

Referenced by START_TEST().

◆ test_halftone_palette()

static void test_halftone_palette ( void  )
static

Definition at line 156 of file palette.c.

157{
158 HDC hdc;
159 HPALETTE pal;
160 PALETTEENTRY entries[256];
161 PALETTEENTRY defpal[20];
162 int i, count;
163
164 hdc = GetDC(0);
165
167 ok( count == 20, "wrong size %u\n", count );
168
169 pal = CreateHalftonePalette( hdc );
170 count = GetPaletteEntries( pal, 0, 256, entries );
171 ok( count == 256 || broken(count <= 20), /* nt 4 */
172 "wrong size %u\n", count );
173
174 /* first and last 8 match the default palette */
175 if (count >= 20)
176 {
177 for (i = 0; i < 8; i++)
178 {
179 ok( entries[i].peRed == defpal[i].peRed &&
180 entries[i].peGreen == defpal[i].peGreen &&
181 entries[i].peBlue == defpal[i].peBlue &&
182 !entries[i].peFlags,
183 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
184 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
185 defpal[i].peRed, defpal[i].peGreen, defpal[i].peBlue );
186 }
187 for (i = count - 8; i < count; i++)
188 {
189 int idx = i - count + 20;
190 ok( entries[i].peRed == defpal[idx].peRed &&
191 entries[i].peGreen == defpal[idx].peGreen &&
192 entries[i].peBlue == defpal[idx].peBlue &&
193 !entries[i].peFlags,
194 "%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
195 entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
196 defpal[idx].peRed, defpal[idx].peGreen, defpal[idx].peBlue );
197 }
198 }
199 DeleteObject( pal );
200 ReleaseDC( 0, hdc );
201}
#define broken(x)
Definition: atltest.h:178
HPALETTE WINAPI CreateHalftonePalette(_In_opt_ HDC)

Referenced by START_TEST().

◆ test_palette_entries()

static void test_palette_entries ( void  )
static

Definition at line 122 of file palette.c.

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 /* Try setting the system palette */
148 res = SetPaletteEntries(hpal, 0, 1, &palEntry);
149 ok(!res, "SetPaletteEntries() should have failed\n");
150
151 res = GetPaletteEntries(hpal, 0, 1, &getEntryResult);
152 ok(res == 1, "GetPaletteEntries should have returned 1 but returned %d\n", res);
153 ok(memcmp(&palEntry, &getEntryResult, sizeof(PALETTEENTRY)), "entries should not match\n");
154}
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
GLuint res
Definition: glext.h:9613
UINT WINAPI SetPaletteEntries(_In_ HPALETTE hpal, _In_ UINT iStart, _In_ UINT cEntries, _In_reads_(cEntries) CONST PALETTEENTRY *pPalEntries)

Referenced by START_TEST().

◆ test_system_palette_entries()

static void test_system_palette_entries ( void  )
static

Definition at line 301 of file palette.c.

302{
303 HDC hdc;
304 HDC metafile_dc;
305 HMETAFILE metafile;
306
307 hdc = GetDC(0);
308
310 {
312 }
313 else
314 {
315 skip( "device is palette-based, skipping test\n" );
316 }
317
318 ReleaseDC( 0, hdc );
319
320 metafile_dc = CreateMetaFileA(NULL);
321
322 check_system_palette_entries(metafile_dc);
323
324 metafile = CloseMetaFile(metafile_dc);
326
328}
#define skip(...)
Definition: atltest.h:64
#define ULongToHandle(h)
Definition: basetsd.h:75
static void check_system_palette_entries(HDC hdc)
Definition: palette.c:203
static const unsigned char metafile[]
Definition: olepicture.c:138
BOOL WINAPI DeleteMetaFile(_In_ HMETAFILE)
#define RASTERCAPS
Definition: wingdi.h:745
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
HDC WINAPI CreateMetaFileA(_In_opt_ LPCSTR)
HMETAFILE WINAPI CloseMetaFile(_In_ HDC hdc)
#define RC_PALETTE
Definition: wingdi.h:790

Referenced by START_TEST().

Variable Documentation

◆ logpalettedata

const PALETTEENTRY logpalettedata[8]
static
Initial value:
= {
{ 0x10, 0x20, 0x30, PC_NOCOLLAPSE },
{ 0x20, 0x30, 0x40, PC_NOCOLLAPSE },
{ 0x30, 0x40, 0x50, PC_NOCOLLAPSE },
{ 0x40, 0x50, 0x60, PC_NOCOLLAPSE },
{ 0x50, 0x60, 0x70, PC_NOCOLLAPSE },
{ 0x60, 0x70, 0x80, PC_NOCOLLAPSE },
{ 0x70, 0x80, 0x90, PC_NOCOLLAPSE },
{ 0x80, 0x90, 0xA0, PC_NOCOLLAPSE },
}
#define PC_NOCOLLAPSE
Definition: wingdi.h:881

Definition at line 31 of file palette.c.

Referenced by test_DIB_PAL_COLORS(), and test_palette_entries().