ReactOS  r76032
xlate.c File Reference
#include <stdio.h>
#include <windows.h>
#include <wine/test.h>
Include dependency graph for xlate.c:

Go to the source code of this file.

Enumerations

enum  {
  BMF_1BPP = 0, BMF_4BPP = 1, BMF_8BPP = 2, BMF_16BPP_555 = 3,
  BMF_16BPP_565 = 4, BMF_24BPP_RGB = 5, BMF_24BPP_BGR = 6, BMF_32BPP_RGB = 7,
  BMF_32BPP_BGR = 8
}
 

Functions

ULONG GetRealColorDepth ()
 
static ULONG iXlateFromRGB (ULONG iFormat, COLORREF crColor)
 
static COLORREF iXlateToRGB (ULONG iFormat, ULONG ulColor)
 
static ULONG GetClosestColor (ULONG iFormat, COLORREF crColor, COLORREF crBackColor)
 
ULONG GetDIBPixel (ULONG iFormat, PVOID pvBits, ULONG x)
 
static void Initialize ()
 
void Test_SrcMono1 (ULONG iBmpFormat, HBITMAP hbmpDst, PVOID pvBits)
 
void Test_SrcMono ()
 
 START_TEST (xlate)
 

Variables

ULONG bpp [] = {1, 4, 8, 15, 16, 24, 24, 32, 32}
 
static BYTE ajBits1 [] = {0xAA, 0xAA, 0xAA, 0xAA, 0,0,0,0}
 
static BYTE ajBits8 [] = {0x00, 0xFF, 0x80, 0xCC, 0,0,0,0}
 
static WORD ajBits16 [] = {0x0000, 0xFFFF, 0x1000, 0x0C0C, 0,0,0,0}
 
static DWORD ajBits24 [] = {0x0000, 0xFFFF, 0x1000, 0x0C0C, 0,0,0,0}
 
static DWORD ajBits32 [] = {0x0000, 0xFFFF, 0x1000, 0x0C0C, 0,0,0,0}
 
static HBITMAP hbmp1bpp_a
 
static HBITMAP hbmp1bpp_b
 
static HBITMAP hbmp8bpp_a
 
static HBITMAP hbmp8bpp_b
 
static HBITMAP hbmp16bpp_a
 
static HBITMAP hbmp16bpp_b
 
static HBITMAP hbmp24bpp_a
 
static HBITMAP hbmp24bpp_b
 
static HBITMAP hbmp32bpp_a
 
static HBITMAP hbmp32bpp_b
 
static HBITMAP hbmpCompat
 
static HDC hdcSrc
 
static HDC hdcDst
 
static ULONG iDcFormat
 

Enumeration Type Documentation

anonymous enum
Enumerator
BMF_1BPP 
BMF_4BPP 
BMF_8BPP 
BMF_16BPP_555 
BMF_16BPP_565 
BMF_24BPP_RGB 
BMF_24BPP_BGR 
BMF_32BPP_RGB 
BMF_32BPP_BGR 

Definition at line 6 of file xlate.c.

7 {
8  BMF_1BPP = 0,
9  BMF_4BPP = 1,
10  BMF_8BPP = 2,
11  BMF_16BPP_555 = 3,
12  BMF_16BPP_565 = 4,
13  BMF_24BPP_RGB = 5,
14  BMF_24BPP_BGR = 6,
15  BMF_32BPP_RGB = 7,
16  BMF_32BPP_BGR = 8
17 };
Definition: xlate.c:8
Definition: xlate.c:9
Definition: xlate.c:10

Function Documentation

static ULONG GetClosestColor ( ULONG  iFormat,
COLORREF  crColor,
COLORREF  crBackColor 
)
static

Definition at line 181 of file xlate.c.

Referenced by Test_SrcMono1().

182 {
183  if (iFormat == BMF_1BPP)
184  return crBackColor;
185  return iXlateToRGB(iFormat, iXlateFromRGB(iFormat, crColor));
186 }
Definition: xlate.c:8
static ULONG iXlateFromRGB(ULONG iFormat, COLORREF crColor)
Definition: xlate.c:96
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
static COLORREF iXlateToRGB(ULONG iFormat, ULONG ulColor)
Definition: xlate.c:136
ULONG GetDIBPixel ( ULONG  iFormat,
PVOID  pvBits,
ULONG  x 
)

Definition at line 189 of file xlate.c.

Referenced by Test_SrcMono1().

190 {
191  switch (iFormat)
192  {
193  case BMF_1BPP:
194  //
195  case BMF_16BPP_555:
196  case BMF_16BPP_565:
197  return *(WORD*)((PCHAR)pvBits + x * sizeof(WORD));
198 
199  case BMF_24BPP_RGB:
200  case BMF_24BPP_BGR:
201  return (*(DWORD*)((PCHAR)pvBits + x * 3)) & 0xffffff;
202 
203  case BMF_32BPP_RGB:
204  case BMF_32BPP_BGR:
205  return *(DWORD*)((PCHAR)pvBits + x * sizeof(DWORD));
206  }
207  return 0;
208 }
signed char * PCHAR
Definition: retypes.h:7
unsigned short WORD
Definition: ntddk_ex.h:93
#define DWORD
Definition: msvc.h:34
DWORD DWORD
Definition: winlogon.h:75
Definition: xlate.c:8
#define PCHAR
Definition: match.c:90
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
INT x
Definition: msvc.h:62
ULONG GetRealColorDepth ( )

Definition at line 36 of file xlate.c.

Referenced by Initialize().

37 {
38  HBITMAP hbmp;
39  HDC hdc;
40  struct
41  {
42  BITMAPINFOHEADER bmiHeader;
43  ULONG aulMasks[3];
44  } bmi;
46  ULONG ulColorDepth;
47 
48  /* Get the screen DC */
49  hdc = GetDC(NULL);
50 
51  /* Create a compatible bitmap */
52  hbmp = CreateCompatibleBitmap(hdc, 1, 1);
53 
54  /* Fill BITMAPINFOHEADER */
55  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
56  GetDIBits(hdc, hbmp, 0, 1, NULL, pbmi, DIB_RGB_COLORS);
57 
58  /* Call again to fill in the bitfields */
59  GetDIBits(hdc, hbmp, 0, 1, NULL, pbmi, DIB_RGB_COLORS);
60 
61  /* Get the basic color depth */
62  ulColorDepth = bmi.bmiHeader.biBitCount;
63 
64  DeleteObject(hbmp);
65 
66  switch (ulColorDepth)
67  {
68  case 1:
69  return BMF_1BPP;
70  case 4:
71  return BMF_4BPP;
72  case 8:
73  return BMF_8BPP;
74  case 16:
75  /* Check the red mask */
76  if (bmi.aulMasks[0] == 0x7c00)
77  return BMF_16BPP_555;
78  else
79  return BMF_16BPP_565;
80  case 24:
81  return BMF_4BPP;
82  case 32:
83  if (bmi.bmiHeader.biCompression == BI_BITFIELDS &&
84  bmi.aulMasks[0] == 0xff)
85  return BMF_32BPP_RGB;
86  else
87  return BMF_32BPP_BGR;
88  }
89 
90  /* Cleanup and return */
91  return BMF_32BPP_RGB;
92 }
#define HDC
Definition: msvc.h:22
#define HBITMAP
Definition: msvc.h:28
HDC WINAPI GetDC(_In_opt_ HWND)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define BI_BITFIELDS
Definition: mmreg.h:505
Definition: xlate.c:8
HDC hdc
Definition: msvc.h:53
smooth NULL
Definition: ftsmooth.c:557
Definition: xlate.c:9
Definition: xlate.c:10
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
unsigned int ULONG
Definition: retypes.h:1
struct tagBITMAPINFO * PBITMAPINFO
#define DIB_RGB_COLORS
Definition: wingdi.h:365
HBITMAP hbmp
Definition: msvc.h:60
static void Initialize ( )
static

Definition at line 212 of file xlate.c.

Referenced by START_TEST().

213 {
216 
218  ok(hbmpCompat != 0, "CreateCompatibleBitmap failed\n");
219 
221  printf("got iDcFormat = %ld\n", iDcFormat);
222 
223  hbmp1bpp_a = CreateBitmap(4, 2, 1, 1, ajBits1);
224  ok(hbmp1bpp_a != 0, "CreateBitmap failed\n");
225 
226  hbmp1bpp_b = CreateBitmap(4, 2, 1, 1, ajBits1);
227  ok(hbmp1bpp_b != 0, "CreateBitmap failed\n");
228 
229  hbmp8bpp_a = CreateBitmap(4, 2, 1, 8, ajBits8);
230  ok(hbmp8bpp_a != 0, "CreateBitmap failed\n");
231 
232  hbmp8bpp_b = CreateBitmap(4, 2, 1, 8, ajBits8);
233  ok(hbmp8bpp_b != 0, "CreateBitmap failed\n");
234 
235  hbmp16bpp_a = CreateBitmap(4, 2, 1, 16, ajBits16);
236  ok(hbmp16bpp_a != 0, "CreateBitmap failed\n");
237 
238  hbmp16bpp_b = CreateBitmap(4, 2, 1, 16, ajBits16);
239  ok(hbmp16bpp_b != 0, "CreateBitmap failed\n");
240 
241  hbmp24bpp_a = CreateBitmap(4, 2, 1, 24, ajBits24);
242  ok(hbmp24bpp_a != 0, "CreateBitmap failed\n");
243 
244  hbmp24bpp_b = CreateBitmap(4, 2, 1, 24, ajBits24);
245  ok(hbmp24bpp_b != 0, "CreateBitmap failed\n");
246 
247  hbmp32bpp_a = CreateBitmap(4, 2, 1, 32, ajBits32);
248  ok(hbmp32bpp_a != 0, "CreateBitmap failed\n");
249 
250  hbmp32bpp_b = CreateBitmap(4, 2, 1, 32, ajBits32);
251  ok(hbmp32bpp_b != 0, "CreateBitmap failed\n");
252 
253 }
static WORD ajBits16[]
Definition: xlate.c:23
HDC WINAPI GetDC(_In_opt_ HWND)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
static HBITMAP hbmp16bpp_b
Definition: xlate.c:28
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
static HBITMAP hbmp24bpp_a
Definition: xlate.c:29
static HDC hdcSrc
Definition: xlate.c:32
static ULONG iDcFormat
Definition: xlate.c:33
static HBITMAP hbmp1bpp_a
Definition: xlate.c:26
static HBITMAP hbmp32bpp_b
Definition: xlate.c:30
static HBITMAP hbmp16bpp_a
Definition: xlate.c:28
static HBITMAP hbmp8bpp_a
Definition: xlate.c:27
static HBITMAP hbmp24bpp_b
Definition: xlate.c:29
static HBITMAP hbmp32bpp_a
Definition: xlate.c:30
ULONG GetRealColorDepth()
Definition: xlate.c:36
static HBITMAP hbmp1bpp_b
Definition: xlate.c:26
static BYTE ajBits8[]
Definition: xlate.c:22
static HBITMAP hbmp8bpp_b
Definition: xlate.c:27
static HDC hdcDst
Definition: xlate.c:32
static BYTE ajBits1[]
Definition: xlate.c:21
static DWORD ajBits24[]
Definition: xlate.c:24
static DWORD ajBits32[]
Definition: xlate.c:25
static HBITMAP hbmpCompat
Definition: xlate.c:31
#define ok(value,...)
Definition: CImage.cpp:33
#define printf
Definition: config.h:203
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
static ULONG iXlateFromRGB ( ULONG  iFormat,
COLORREF  crColor 
)
static

Definition at line 96 of file xlate.c.

Referenced by GetClosestColor(), Test_SrcMono(), and Test_SrcMono1().

97 {
98  ULONG ulRed, ulGreen, ulBlue;
99 
100  ulRed = GetRValue(crColor);
101  ulGreen = GetGValue(crColor);
102  ulBlue = GetBValue(crColor);
103 
104  switch (iFormat)
105  {
106  case BMF_1BPP:
107  return crColor ? 0xffffff : 0;
108 
109  case BMF_4BPP:
110  case BMF_8BPP:
111  case BMF_16BPP_555:
112  ulRed = (ulRed & 0xF8) >> 3;
113  ulGreen = (ulGreen & 0xF8) >> 3;
114  ulBlue = (ulBlue & 0xF8) >> 3;
115  return ulRed << 10 | ulGreen << 5 | ulBlue;
116 
117  case BMF_16BPP_565:
118  ulRed = (ulRed & 0xF8) >> 3;
119  ulGreen = (ulGreen & 0xFC) >> 2;
120  ulBlue = (ulBlue & 0xF8) >> 3;
121  return ulRed << 11 | ulGreen << 5 | ulBlue;
122 
123  case BMF_24BPP_RGB:
124  case BMF_32BPP_RGB:
125  return crColor;
126 
127  case BMF_24BPP_BGR:
128  case BMF_32BPP_BGR:
129  return RGB(ulBlue, ulGreen, ulRed);
130  }
131  return 0;
132 }
#define GetRValue(rgb)
Definition: wingdi.h:2912
Definition: xlate.c:8
#define GetGValue(rgb)
Definition: wingdi.h:2913
#define RGB(r, g, b)
Definition: wingdi.h:2917
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
Definition: xlate.c:9
Definition: xlate.c:10
unsigned int ULONG
Definition: retypes.h:1
#define GetBValue(rgb)
Definition: wingdi.h:2914
static COLORREF iXlateToRGB ( ULONG  iFormat,
ULONG  ulColor 
)
static

Definition at line 136 of file xlate.c.

Referenced by GetClosestColor(), and Test_SrcMono().

137 {
138  ULONG ulRed, ulGreen, ulBlue;
139 
140  switch (iFormat)
141  {
142  case BMF_1BPP:
143  return ulColor ? 0xffffff : 0;
144 
145  case BMF_4BPP:
146  case BMF_8BPP:
147  case BMF_16BPP_555:
148  ulRed = (ulColor & 0x7C00) >> 7;
149  ulRed |= ulRed >> 5;
150  ulGreen = (ulColor & 0x3E0) >> 2;
151  ulGreen |= ulGreen >> 5;
152  ulBlue = (ulColor & 0x1F) << 3;
153  ulBlue |= ulBlue >> 5;
154  return RGB(ulRed, ulGreen, ulBlue);
155 
156  case BMF_16BPP_565:
157  ulRed = (ulColor & 0xF800) >> 8;
158  ulRed |= ulRed >> 5;
159  ulGreen = (ulColor & 0x7E0) >> 3;
160  ulGreen |= ulGreen >> 6;
161  ulBlue = (ulColor & 0x1F) << 3;
162  ulBlue |= ulBlue >> 5;
163  return RGB(ulRed, ulGreen, ulBlue);
164 
165  case BMF_24BPP_RGB:
166  case BMF_32BPP_RGB:
167  return ulColor;
168 
169  case BMF_24BPP_BGR:
170  case BMF_32BPP_BGR:
171  ulRed = GetRValue(ulColor);
172  ulGreen = GetGValue(ulColor);
173  ulBlue = GetBValue(ulColor);
174  return RGB(ulBlue, ulGreen, ulRed);
175  }
176  return 0;
177 }
#define GetRValue(rgb)
Definition: wingdi.h:2912
Definition: xlate.c:8
#define GetGValue(rgb)
Definition: wingdi.h:2913
#define RGB(r, g, b)
Definition: wingdi.h:2917
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
Definition: xlate.c:9
Definition: xlate.c:10
unsigned int ULONG
Definition: retypes.h:1
#define GetBValue(rgb)
Definition: wingdi.h:2914
START_TEST ( xlate  )

Definition at line 536 of file xlate.c.

537 {
538  Initialize();
539 
540  Test_SrcMono();
541 }
void Test_SrcMono()
Definition: xlate.c:458
static void Initialize()
Definition: xlate.c:212
void Test_SrcMono ( )

Definition at line 458 of file xlate.c.

Referenced by START_TEST().

459 {
460  HBITMAP hbmp;
461  struct
462  {
463  BITMAPINFOHEADER bmiHeader;
464  ULONG bmiColors[3];
465  } bmi;
466  PVOID pvBits;
467  ULONG c, expected;
468 
470 
473 
474  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
475  bmi.bmiHeader.biWidth = 2;
476  bmi.bmiHeader.biHeight = -2;
477  bmi.bmiHeader.biPlanes = 1;
478  bmi.bmiHeader.biBitCount = 16;
479  bmi.bmiHeader.biCompression = BI_RGB;
480  bmi.bmiHeader.biSizeImage = 0;
481  bmi.bmiHeader.biXPelsPerMeter = 1;
482  bmi.bmiHeader.biYPelsPerMeter = 1;
483  bmi.bmiHeader.biClrUsed = 0;
484  bmi.bmiHeader.biClrImportant = 0;
485  hbmp = CreateDIBSection(hdcDst, (LPBITMAPINFO)&bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
486  ok(hbmp != 0, "CreateDIBSection failed\n");
487  memset(pvBits, 0x55555555, 8 * 8 * 2);
488 
489  SelectObject(hdcDst, hbmp);
490 
491  c = GetPixel(hdcDst, 0, 0);
492  expected = iXlateToRGB(BMF_16BPP_555, 0x5555);
493  ok(c == expected, "expected %lx, got %lx\n", expected, c);
494 
495  expected = 0x123456;
496  SetPixel(hdcDst, 0, 0, expected);
497  expected = iXlateFromRGB(BMF_16BPP_555, expected);
498  c = *(volatile WORD*)pvBits;
499  ok(c == expected, "expected %lx, got %lx\n", expected, c);
500 
501  Test_SrcMono1(BMF_16BPP_555, hbmp, pvBits);
502 
503  DeleteObject(hbmp);
504 
505  /* Create a 565 DIB section */
506  bmi.bmiHeader.biCompression = BI_BITFIELDS;
507  bmi.bmiHeader.biClrUsed = 3;
508  bmi.bmiHeader.biClrImportant = 3;
509  bmi.bmiColors[0] = 0xF800;
510  bmi.bmiColors[1] = 0x7E0;
511  bmi.bmiColors[2] = 0x1F;
512  hbmp = CreateDIBSection(hdcDst, (LPBITMAPINFO)&bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
513  ok(hbmp != 0, "CreateDIBSection failed\n");
514  SelectObject(hdcDst, hbmp);
515 
516  Test_SrcMono1(BMF_16BPP_565, hbmp, pvBits);
517 
518  DeleteObject(hbmp);
519 
520  /* Create a 32 bpp DIB section */
521  bmi.bmiHeader.biBitCount = 32;
522  bmi.bmiHeader.biCompression = BI_RGB;
523  bmi.bmiHeader.biClrUsed = 0;
524  bmi.bmiHeader.biClrImportant = 0;
525  hbmp = CreateDIBSection(hdcDst, (LPBITMAPINFO)&bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
526  ok(hbmp != 0, "CreateDIBSection failed\n");
527  SelectObject(hdcDst, hbmp);
528 
529  Test_SrcMono1(BMF_32BPP_BGR, hbmp, pvBits);
530 
531  DeleteObject(hbmp);
532 
533 }
DWORD *typedef PVOID
Definition: winlogon.h:52
unsigned short WORD
Definition: ntddk_ex.h:93
#define HBITMAP
Definition: msvc.h:28
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
static HDC hdcSrc
Definition: xlate.c:32
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
#define BI_BITFIELDS
Definition: mmreg.h:505
static ULONG iDcFormat
Definition: xlate.c:33
Definition: xlate.c:8
static HBITMAP hbmp1bpp_a
Definition: xlate.c:26
smooth NULL
Definition: ftsmooth.c:557
static ULONG iXlateFromRGB(ULONG iFormat, COLORREF crColor)
Definition: xlate.c:96
FORCEINLINE VOID SetPixel(IN ULONG Left, IN ULONG Top, IN UCHAR Color)
Definition: vga.c:99
static HBITMAP hbmp1bpp_b
Definition: xlate.c:26
void Test_SrcMono1(ULONG iBmpFormat, HBITMAP hbmpDst, PVOID pvBits)
Definition: xlate.c:256
static HDC hdcDst
Definition: xlate.c:32
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
#define c
Definition: ke_i.h:80
static HBITMAP hbmpCompat
Definition: xlate.c:31
unsigned int ULONG
Definition: retypes.h:1
#define ok(value,...)
Definition: CImage.cpp:33
static COLORREF iXlateToRGB(ULONG iFormat, ULONG ulColor)
Definition: xlate.c:136
#define DIB_RGB_COLORS
Definition: wingdi.h:365
HBITMAP hbmp
Definition: msvc.h:60
#define memset(x, y, z)
Definition: compat.h:39
#define BI_RGB
Definition: precomp.h:35
BOOL expected
Definition: store.c:2140
void Test_SrcMono1 ( ULONG  iBmpFormat,
HBITMAP  hbmpDst,
PVOID  pvBits 
)

Definition at line 256 of file xlate.c.

Referenced by Test_SrcMono().

257 {
259  HBRUSH hbr;
260  RECT rect;
261  struct
262  {
263  BITMAPINFOHEADER bmiHeader;
264  ULONG bmiColors[2];
265  BYTE aj[32];
266  } bmi;
267 
269  SelectObject(hdcDst, hbmpDst);
270 
271  /* Set default dc fore and back colors */
272  SetTextColor(hdcSrc, 0x000000);
273  SetBkColor(hdcSrc, 0xffffff);
274  SetTextColor(hdcDst, 0x000000);
275  SetBkColor(hdcDst, 0xffffff);
276 
277  /* Do a bitblt operation */
278  ok(BitBlt(hdcDst, 0, 0, 2, 2, hdcSrc, 0, 0, SRCCOPY), "(%ld): BitBlt failed", iBmpFormat);
279 
280  /* Test background color */
281  c = GetPixel(hdcDst, 0, 0);
282  expected = 0xffffff;
283  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
284 
285  /* Test foreground color */
286  c = GetPixel(hdcDst, 1, 0);
287  expected = 0x000000;
288  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
289 
290  if (pvBits)
291  {
292  c = GetDIBPixel(iBmpFormat, pvBits, 0);
293  expected = iXlateFromRGB(iBmpFormat, GetBkColor(hdcSrc));
294  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
295 
296  c = GetDIBPixel(iBmpFormat, pvBits, 1);
297  expected = iXlateFromRGB(iBmpFormat, GetTextColor(hdcSrc));
298  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
299  }
300 
301  /* Set different dc fore and back colors */
302  SetTextColor(hdcSrc, 0xf00f0f);
303  SetBkColor(hdcSrc, 0xf0ff0f);
304  SetTextColor(hdcDst, 0xefFee5);
305  SetBkColor(hdcDst, 0x100121);
306 
307  /* Make sure this alone didn't affect the resulting colors */
308  c = GetPixel(hdcDst, 0, 0);
309  expected = 0xffffff;
310  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
311  c = GetPixel(hdcDst, 1, 0);
312  expected = 0x000000;
313  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
314 
315  /* Repeat the bitblt operation */
316  ok(BitBlt(hdcDst, 0, 0, 2, 2, hdcSrc, 0, 0, SRCCOPY), "(%ld): BitBlt failed", iBmpFormat);
317 
318  /* Test background color */
319  c = GetPixel(hdcDst, 0, 0);
320  expected = GetClosestColor(iBmpFormat, GetBkColor(hdcDst), 0xffffff);
321  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
322 
323  /* Test foreground color */
324  c = GetPixel(hdcDst, 1, 0);
325  expected = GetClosestColor(iBmpFormat, GetTextColor(hdcDst), 0);
326  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
327 
328  if (pvBits)
329  {
330  c = GetDIBPixel(iBmpFormat, pvBits, 0);
331  expected = iXlateFromRGB(iBmpFormat, GetBkColor(hdcDst));
332  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
333 
334  c = GetDIBPixel(iBmpFormat, pvBits, 1);
335  expected = iXlateFromRGB(iBmpFormat, GetTextColor(hdcDst));
336  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
337  }
338 
339  /* Set inverted fore and back colors */
340  SetTextColor(hdcSrc, 0);
341  SetBkColor(hdcSrc, 0xffffff);
342  SetTextColor(hdcDst, 0xffffff);
343  SetBkColor(hdcDst, 0x000000);
344 
345  /* Repeat the bitblt operation */
346  ok(BitBlt(hdcDst, 0, 0, 2, 2, hdcSrc, 0, 0, SRCCOPY), "(%ld): BitBlt failed", iBmpFormat);
347 
348  /* Test background color */
349  c = GetPixel(hdcDst, 0, 0);
350  expected = GetClosestColor(iBmpFormat, GetBkColor(hdcDst), 0xffffff);
351  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
352 
353  /* Test foreground color */
354  c = GetPixel(hdcDst, 1, 0);
355  expected = GetClosestColor(iBmpFormat, GetTextColor(hdcDst), 0);
356  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
357 
358  if (pvBits)
359  {
360  c = GetDIBPixel(iBmpFormat, pvBits, 0);
361  expected = iXlateFromRGB(iBmpFormat, GetBkColor(hdcDst));
362  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
363 
364  c = GetDIBPixel(iBmpFormat, pvBits, 1);
365  expected = iXlateFromRGB(iBmpFormat, GetTextColor(hdcDst));
366  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
367  }
368 
369 
370 /* Hatch brush ****************************************************************/
371 
372  /* Set dc fore and back colors */
373  SetTextColor(hdcDst, 0x102030);
374  SetBkColor(hdcDst, 0xeeccdd);
376 
377  /* Create a hatch brush */
378  hbr = CreateHatchBrush(HS_DIAGCROSS, 0x123456);
379 
380  /* Fill the destination bitmap */
381  rect.left = rect.top = 0;
382  rect.bottom = rect.right = 4;
383  ok(FillRect(hdcDst, &rect, hbr), "FillRect failed\n");
384 
385  /* Test the fore color of the hatch brush */
386  c = GetPixel(hdcDst, 0, 0);
387  expected = GetClosestColor(iBmpFormat, 0x123456, 0);
388  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
389 
390  /* Test the back color of the hatch brush */
391  c = GetPixel(hdcDst, 1, 0);
392  expected = GetClosestColor(iBmpFormat, GetBkColor(hdcDst), 0xffffff);
393  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
394 
395  if (pvBits)
396  {
397  c = GetDIBPixel(iBmpFormat, pvBits, 0);
398  expected = iXlateFromRGB(iBmpFormat, 0x123456);
399  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
400 
401  c = GetDIBPixel(iBmpFormat, pvBits, 1);
402  expected = iXlateFromRGB(iBmpFormat, GetBkColor(hdcDst));
403  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
404  }
405 
406  DeleteObject(hbr);
407 
408 /* DIB brush ******************************************************************/
409 
410  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
411  bmi.bmiHeader.biWidth = 8;
412  bmi.bmiHeader.biHeight = 8;
413  bmi.bmiHeader.biPlanes = 1;
414  bmi.bmiHeader.biBitCount = 1;
415  bmi.bmiHeader.biCompression = BI_RGB;
416  bmi.bmiHeader.biSizeImage = 0;
417  bmi.bmiHeader.biXPelsPerMeter = 1;
418  bmi.bmiHeader.biYPelsPerMeter = 1;
419  bmi.bmiHeader.biClrUsed = 2;
420  bmi.bmiHeader.biClrImportant = 2;
421  bmi.bmiColors[0] = 0xeeeeee;
422  bmi.bmiColors[1] = 0x111111;
423  memset(bmi.aj, 0xaaaa, sizeof(bmi.aj));
425  ok(hbr != 0, "CreateDIBPatternBrushPt failed\n");
426 
427  rect.left = rect.top = 0;
428  rect.bottom = rect.right = 4;
429  ok(FillRect(hdcDst, &rect, hbr),"FillRect failed\n");
430 
431  /* Test color 1 of the dib brush */
432  c = GetPixel(hdcDst, 0, 0);
433  expected = GetClosestColor(iBmpFormat, bmi.bmiColors[1], 0);
434  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
435 
436  /* Test color 0 of the dib brush */
437  c = GetPixel(hdcDst, 1, 0);
438  expected = GetClosestColor(iBmpFormat, bmi.bmiColors[0], 0xffffff);
439  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
440 
441  if (pvBits)
442  {
443  c = GetDIBPixel(iBmpFormat, pvBits, 0);
444  expected = iXlateFromRGB(iBmpFormat, bmi.bmiColors[1]);
445  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
446 
447  c = GetDIBPixel(iBmpFormat, pvBits, 1);
448  expected = iXlateFromRGB(iBmpFormat, bmi.bmiColors[0]);
449  ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
450  }
451 
452  DeleteObject(hbr);
453 
454 
455 }
COLORREF WINAPI GetBkColor(_In_ HDC)
Definition: dc.c:954
static ULONG GetClosestColor(ULONG iFormat, COLORREF crColor, COLORREF crBackColor)
Definition: xlate.c:181
HBRUSH WINAPI CreateHatchBrush(_In_ int, _In_ COLORREF)
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
LONG top
Definition: windef.h:320
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
ULONG GetDIBPixel(ULONG iFormat, PVOID pvBits, ULONG x)
Definition: xlate.c:189
LONG left
Definition: windef.h:319
static HDC hdcSrc
Definition: xlate.c:32
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
LONG right
Definition: windef.h:321
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:416
& rect
Definition: startmenu.cpp:1413
static HBITMAP hbmp1bpp_a
Definition: xlate.c:26
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:975
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1032
COLORREF WINAPI GetTextColor(_In_ HDC)
Definition: text.c:699
static ULONG iXlateFromRGB(ULONG iFormat, COLORREF crColor)
Definition: xlate.c:96
#define OPAQUE
Definition: wingdi.h:947
unsigned char BYTE
Definition: ntddk_ex.h:96
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:756
static HDC hdcDst
Definition: xlate.c:32
#define HS_DIAGCROSS
Definition: wingdi.h:576
#define c
Definition: ke_i.h:80
unsigned int ULONG
Definition: retypes.h:1
LONG bottom
Definition: windef.h:322
#define ok(value,...)
Definition: CImage.cpp:33
#define DIB_RGB_COLORS
Definition: wingdi.h:365
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
DWORD COLORREF
Definition: windef.h:313
#define memset(x, y, z)
Definition: compat.h:39
HBRUSH WINAPI CreateDIBPatternBrushPt(_In_ const VOID *pvPackedDIB, _In_ UINT uUsage)
#define BI_RGB
Definition: precomp.h:35
#define SRCCOPY
Definition: wingdi.h:331
BOOL expected
Definition: store.c:2140

Variable Documentation

BYTE ajBits1[] = {0xAA, 0xAA, 0xAA, 0xAA, 0,0,0,0}
static

Definition at line 21 of file xlate.c.

Referenced by Initialize().

WORD ajBits16[] = {0x0000, 0xFFFF, 0x1000, 0x0C0C, 0,0,0,0}
static

Definition at line 23 of file xlate.c.

Referenced by Initialize().

DWORD ajBits24[] = {0x0000, 0xFFFF, 0x1000, 0x0C0C, 0,0,0,0}
static

Definition at line 24 of file xlate.c.

Referenced by Initialize().

DWORD ajBits32[] = {0x0000, 0xFFFF, 0x1000, 0x0C0C, 0,0,0,0}
static

Definition at line 25 of file xlate.c.

Referenced by Initialize().

BYTE ajBits8[] = {0x00, 0xFF, 0x80, 0xCC, 0,0,0,0}
static

Definition at line 22 of file xlate.c.

Referenced by Initialize().

ULONG bpp[] = {1, 4, 8, 15, 16, 24, 24, 32, 32}

Definition at line 19 of file xlate.c.

HBITMAP hbmp16bpp_a
static

Definition at line 28 of file xlate.c.

Referenced by Initialize().

HBITMAP hbmp16bpp_b
static

Definition at line 28 of file xlate.c.

Referenced by Initialize().

HBITMAP hbmp1bpp_a
static

Definition at line 26 of file xlate.c.

Referenced by Initialize(), Test_SrcMono(), and Test_SrcMono1().

HBITMAP hbmp1bpp_b
static

Definition at line 26 of file xlate.c.

Referenced by Initialize(), and Test_SrcMono().

HBITMAP hbmp24bpp_a
static

Definition at line 29 of file xlate.c.

Referenced by Initialize().

HBITMAP hbmp24bpp_b
static

Definition at line 29 of file xlate.c.

Referenced by Initialize().

HBITMAP hbmp32bpp_a
static

Definition at line 30 of file xlate.c.

Referenced by Initialize().

HBITMAP hbmp32bpp_b
static

Definition at line 30 of file xlate.c.

Referenced by Initialize().

HBITMAP hbmp8bpp_a
static

Definition at line 27 of file xlate.c.

Referenced by Initialize().

HBITMAP hbmp8bpp_b
static

Definition at line 27 of file xlate.c.

Referenced by Initialize().

HBITMAP hbmpCompat
static

Definition at line 31 of file xlate.c.

Referenced by Initialize(), and Test_SrcMono().

ULONG iDcFormat
static

Definition at line 33 of file xlate.c.

Referenced by Initialize(), and Test_SrcMono().