2005-08-22 11:18:02 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for palettes
|
|
|
|
*
|
|
|
|
* Copyright 2005 Glenn Wurster
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-08-22 11:18:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "mmsystem.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2006-05-24 15:58:57 +02:00
|
|
|
static const PALETTEENTRY logpalettedata[8] = {
|
2005-08-22 11:18:02 +02:00
|
|
|
{ 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 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_DIB_PAL_COLORS(void) {
|
|
|
|
HDC hdc = GetDC( NULL );
|
|
|
|
HDC memhdc = CreateCompatibleDC( hdc );
|
|
|
|
HBITMAP hbmp, hbmpOld;
|
|
|
|
char bmpbuf[sizeof(BITMAPINFO) + 10 * sizeof(WORD)];
|
|
|
|
PBITMAPINFO bmp = (PBITMAPINFO)bmpbuf;
|
|
|
|
WORD * bmpPalPtr;
|
|
|
|
char logpalettebuf[sizeof(LOGPALETTE) + sizeof(logpalettedata)];
|
|
|
|
PLOGPALETTE logpalette = (PLOGPALETTE)logpalettebuf;
|
|
|
|
HPALETTE hpal, hpalOld;
|
|
|
|
COLORREF setColor, chkColor, getColor;
|
|
|
|
int i;
|
|
|
|
|
2011-08-24 15:28:14 +02:00
|
|
|
/* Initialize the logical palette with a few colours */
|
2005-08-22 11:18:02 +02:00
|
|
|
logpalette->palVersion = 0x300;
|
|
|
|
logpalette->palNumEntries = 8;
|
|
|
|
memcpy( logpalette->palPalEntry, logpalettedata, sizeof(logpalettedata) );
|
|
|
|
hpal = CreatePalette( logpalette );
|
|
|
|
hpalOld = SelectPalette( memhdc, hpal, FALSE );
|
2006-10-12 22:56:45 +02:00
|
|
|
ok( hpalOld != NULL, "error=%d\n", GetLastError() );
|
2005-08-22 11:18:02 +02:00
|
|
|
|
|
|
|
/* Create a DIB BMP which references colours in the logical palette */
|
|
|
|
memset( bmp, 0x00, sizeof(BITMAPINFO) );
|
|
|
|
bmp->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
bmp->bmiHeader.biWidth = 1;
|
|
|
|
bmp->bmiHeader.biHeight = 1;
|
|
|
|
bmp->bmiHeader.biPlanes = 1;
|
|
|
|
bmp->bmiHeader.biBitCount = 8;
|
|
|
|
bmp->bmiHeader.biCompression = BI_RGB;
|
|
|
|
bmp->bmiHeader.biClrUsed = 10;
|
|
|
|
bmp->bmiHeader.biClrImportant = 0;
|
|
|
|
bmpPalPtr = (WORD *)&bmp->bmiColors;
|
|
|
|
for( i = 0; i < 8; i++ ) {
|
|
|
|
*bmpPalPtr++ = i;
|
|
|
|
}
|
|
|
|
*bmpPalPtr++ = 8; /* Pointer to logical palette index just outside range */
|
|
|
|
*bmpPalPtr++ = 19; /* Pointer to bad logical palette index */
|
|
|
|
|
|
|
|
hbmp = CreateDIBSection( memhdc, bmp, DIB_PAL_COLORS, 0, 0, 0 );
|
2006-10-12 22:56:45 +02:00
|
|
|
ok( hbmp != NULL, "error=%d\n", GetLastError() );
|
2005-08-22 11:18:02 +02:00
|
|
|
hbmpOld = SelectObject( memhdc, hbmp );
|
2006-10-12 22:56:45 +02:00
|
|
|
ok( hbmpOld != NULL, "error=%d\n", GetLastError() );
|
2005-08-22 11:18:02 +02:00
|
|
|
|
|
|
|
/* Test with a RGB to DIB_PAL_COLORS */
|
|
|
|
setColor = RGB( logpalettedata[1].peRed, logpalettedata[1].peGreen, logpalettedata[1].peBlue );
|
|
|
|
SetPixel( memhdc, 0, 0, setColor );
|
|
|
|
chkColor = RGB( logpalettedata[1].peRed, logpalettedata[1].peGreen, logpalettedata[1].peBlue );
|
|
|
|
getColor = GetPixel( memhdc, 0, 0 );
|
|
|
|
ok( getColor == chkColor, "getColor=%08X\n", (UINT)getColor );
|
|
|
|
|
|
|
|
/* Test with a valid DIBINDEX to DIB_PAL_COLORS */
|
|
|
|
setColor = DIBINDEX( 2 );
|
|
|
|
SetPixel( memhdc, 0, 0, setColor );
|
|
|
|
chkColor = RGB( logpalettedata[2].peRed, logpalettedata[2].peGreen, logpalettedata[2].peBlue );
|
|
|
|
getColor = GetPixel( memhdc, 0, 0 );
|
|
|
|
ok( getColor == chkColor, "getColor=%08X\n", (UINT)getColor );
|
|
|
|
|
2013-12-03 14:25:04 +01:00
|
|
|
/* Test with an invalid DIBINDEX to DIB_PAL_COLORS */
|
2005-08-22 11:18:02 +02:00
|
|
|
setColor = DIBINDEX( 12 );
|
|
|
|
SetPixel( memhdc, 0, 0, setColor );
|
|
|
|
chkColor = RGB( 0, 0, 0 );
|
|
|
|
getColor = GetPixel( memhdc, 0, 0 );
|
|
|
|
ok( getColor == chkColor, "getColor=%08X\n", (UINT)getColor );
|
|
|
|
|
|
|
|
/* Test for double wraparound on logical palette references from */
|
|
|
|
/* DIBINDEX by DIB_PAL_COLORS. */
|
|
|
|
setColor = DIBINDEX( 9 );
|
|
|
|
SetPixel( memhdc, 0, 0, setColor );
|
|
|
|
chkColor = RGB( logpalettedata[3].peRed, logpalettedata[3].peGreen, logpalettedata[3].peBlue );
|
|
|
|
getColor = GetPixel( memhdc, 0, 0 );
|
2011-07-27 03:01:07 +02:00
|
|
|
ok( getColor == chkColor, "getColor=%08X\n", (UINT)getColor );
|
2005-08-22 11:18:02 +02:00
|
|
|
|
|
|
|
SelectPalette( memhdc, hpalOld, FALSE );
|
|
|
|
DeleteObject( hpal );
|
|
|
|
SelectObject( memhdc, hbmpOld );
|
|
|
|
DeleteObject( hbmp );
|
|
|
|
DeleteDC( memhdc );
|
|
|
|
ReleaseDC( NULL, hdc );
|
|
|
|
}
|
|
|
|
|
2008-02-17 14:57:16 +01:00
|
|
|
static void test_palette_entries(void)
|
|
|
|
{
|
|
|
|
char logpalettebuf[sizeof(LOGPALETTE) + sizeof(logpalettedata)];
|
|
|
|
PLOGPALETTE logpalette = (PLOGPALETTE)logpalettebuf;
|
|
|
|
HPALETTE hpal;
|
|
|
|
UINT res=0;
|
|
|
|
PALETTEENTRY palEntry = { 0x1, 0x2, 0x3, 0xff };
|
|
|
|
PALETTEENTRY getEntryResult;
|
|
|
|
|
2011-08-24 15:28:14 +02:00
|
|
|
/* Initialize the logical palette with a few colours */
|
2008-02-17 14:57:16 +01:00
|
|
|
logpalette->palVersion = 0x300;
|
|
|
|
logpalette->palNumEntries = 8;
|
|
|
|
memcpy( logpalette->palPalEntry, logpalettedata, sizeof(logpalettedata) );
|
|
|
|
hpal = CreatePalette( logpalette );
|
|
|
|
|
|
|
|
/* Set a new entry with peFlags to 0xff */
|
|
|
|
SetPaletteEntries(hpal, 0, 1, &palEntry);
|
|
|
|
|
|
|
|
/* Retrieve the entry to see if GDI32 performs any filtering on peFlags */
|
|
|
|
res = GetPaletteEntries(hpal, 0, 1, &getEntryResult);
|
|
|
|
ok(res == 1, "GetPaletteEntries should have returned 1 but returned %d\n", res);
|
|
|
|
|
|
|
|
ok( palEntry.peFlags == getEntryResult.peFlags, "palEntry.peFlags (%#x) != getEntryResult.peFlags (%#x)\n", palEntry.peFlags, getEntryResult.peFlags );
|
|
|
|
}
|
|
|
|
|
2011-12-12 11:16:59 +01:00
|
|
|
static void test_halftone_palette(void)
|
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
HPALETTE pal;
|
|
|
|
PALETTEENTRY entries[256];
|
|
|
|
PALETTEENTRY defpal[20];
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
hdc = GetDC(0);
|
|
|
|
|
|
|
|
count = GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, 20, defpal );
|
|
|
|
ok( count == 20, "wrong size %u\n", count );
|
|
|
|
|
|
|
|
pal = CreateHalftonePalette( hdc );
|
|
|
|
count = GetPaletteEntries( pal, 0, 256, entries );
|
2011-12-13 12:24:33 +01:00
|
|
|
ok( count == 256 || broken(count <= 20), /* nt 4 */
|
2011-12-12 11:16:59 +01:00
|
|
|
"wrong size %u\n", count );
|
|
|
|
|
2014-01-09 16:02:14 +01:00
|
|
|
/* first and last 8 match the default palette */
|
2011-12-13 12:24:33 +01:00
|
|
|
if (count >= 20)
|
|
|
|
{
|
2014-01-09 16:02:14 +01:00
|
|
|
for (i = 0; i < 8; i++)
|
2011-12-13 12:24:33 +01:00
|
|
|
{
|
|
|
|
ok( entries[i].peRed == defpal[i].peRed &&
|
|
|
|
entries[i].peGreen == defpal[i].peGreen &&
|
|
|
|
entries[i].peBlue == defpal[i].peBlue &&
|
|
|
|
!entries[i].peFlags,
|
|
|
|
"%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
|
|
|
|
entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
|
|
|
|
defpal[i].peRed, defpal[i].peGreen, defpal[i].peBlue );
|
|
|
|
}
|
2014-01-09 16:02:14 +01:00
|
|
|
for (i = count - 8; i < count; i++)
|
2011-12-13 12:24:33 +01:00
|
|
|
{
|
|
|
|
int idx = i - count + 20;
|
|
|
|
ok( entries[i].peRed == defpal[idx].peRed &&
|
|
|
|
entries[i].peGreen == defpal[idx].peGreen &&
|
|
|
|
entries[i].peBlue == defpal[idx].peBlue &&
|
|
|
|
!entries[i].peFlags,
|
|
|
|
"%u: wrong color %02x,%02x,%02x,%02x instead of %02x,%02x,%02x\n", i,
|
|
|
|
entries[i].peRed, entries[i].peGreen, entries[i].peBlue, entries[i].peFlags,
|
|
|
|
defpal[idx].peRed, defpal[idx].peGreen, defpal[idx].peBlue );
|
|
|
|
}
|
|
|
|
}
|
2011-12-12 11:16:59 +01:00
|
|
|
DeleteObject( pal );
|
|
|
|
ReleaseDC( 0, hdc );
|
|
|
|
}
|
|
|
|
|
2005-08-22 11:18:02 +02:00
|
|
|
START_TEST(palette)
|
|
|
|
{
|
|
|
|
test_DIB_PAL_COLORS();
|
2008-02-17 14:57:16 +01:00
|
|
|
test_palette_entries();
|
2011-12-12 11:16:59 +01:00
|
|
|
test_halftone_palette();
|
2005-08-22 11:18:02 +02:00
|
|
|
}
|