2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetDIBits
5 * PROGRAMMERS: Jérôme Gardou
12 char buffer
[sizeof(BITMAPINFOHEADER
)+2*sizeof(RGBQUAD
)];
14 BITMAPINFO
* pBMI
= (BITMAPINFO
*)buffer
;
15 char bits1bpp
[] = {0x80, 0, 0, 0};
19 ZeroMemory(buffer
, sizeof(buffer
));
21 pBMI
->bmiHeader
.biSize
=sizeof(BITMAPINFOHEADER
);
22 pBMI
->bmiHeader
.biWidth
=2;
23 pBMI
->bmiHeader
.biHeight
=1;
24 pBMI
->bmiHeader
.biPlanes
=1;
25 pBMI
->bmiHeader
.biBitCount
=32;
26 pBMI
->bmiHeader
.biCompression
=BI_RGB
;
27 pBMI
->bmiHeader
.biSizeImage
=0;
28 pBMI
->bmiHeader
.biXPelsPerMeter
=0;
29 pBMI
->bmiHeader
.biYPelsPerMeter
=0;
30 pBMI
->bmiHeader
.biClrUsed
=0;
31 pBMI
->bmiHeader
.biClrImportant
=0;
33 hbmp
= CreateDIBSection(NULL
, pBMI
, DIB_RGB_COLORS
, (PVOID
*)&dibBuffer
, NULL
, 0);
34 ok(hbmp
!=NULL
, "Failed to create a DIB section\n");
36 pBMI
->bmiHeader
.biBitCount
= 1;
37 pBMI
->bmiColors
[0].rgbBlue
= 0xFF;
38 pBMI
->bmiColors
[0].rgbGreen
= 0;
39 pBMI
->bmiColors
[0].rgbRed
= 0xFF;
41 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
42 ok(ret
== 1, "Copied %i scanlines\n", ret
);
44 ok(dibBuffer
[0] == 0, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer
[0]);
45 ok(dibBuffer
[1] == 0xFF00FF, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer
[1]);
50 void Test_SetDIBits_1bpp()
52 char buffer
[sizeof(BITMAPINFOHEADER
)+2*sizeof(RGBQUAD
)];
54 BITMAPINFO
* pBMI
= (BITMAPINFO
*)buffer
;
55 char bits1bpp
[] = {0x80, 0, 0, 0};
60 hdc
= CreateCompatibleDC(0);
63 trace("No device contexr !?\n");
67 ZeroMemory(buffer
, sizeof(buffer
));
69 pBMI
->bmiHeader
.biSize
=sizeof(BITMAPINFOHEADER
);
70 pBMI
->bmiHeader
.biWidth
=2;
71 pBMI
->bmiHeader
.biHeight
=1;
72 pBMI
->bmiHeader
.biPlanes
=1;
73 pBMI
->bmiHeader
.biBitCount
=1;
74 pBMI
->bmiHeader
.biCompression
=BI_RGB
;
75 pBMI
->bmiHeader
.biSizeImage
=0;
76 pBMI
->bmiHeader
.biXPelsPerMeter
=0;
77 pBMI
->bmiHeader
.biYPelsPerMeter
=0;
78 pBMI
->bmiHeader
.biClrUsed
=2;
79 pBMI
->bmiHeader
.biClrImportant
=0;
80 pBMI
->bmiColors
[0].rgbBlue
= 0xFF;
81 pBMI
->bmiColors
[0].rgbGreen
= 0xFF;
82 pBMI
->bmiColors
[0].rgbRed
= 0xFF;
84 hbmp
= CreateBitmap(2, 1, 1, 1, NULL
);
85 ok(hbmp
!=NULL
, "Failed to create a monochrome bitmap\n");
87 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
88 ok(ret
== 1, "Copied %i scanlines\n", ret
);
90 hbmp
= SelectObject(hdc
, hbmp
);
91 ok(hbmp
!= NULL
, "Could not select the bitmap into the context.\n");
92 color
= GetPixel(hdc
, 0,0);
93 ok(color
== 0, "Wrong color at 0,0 : 0x%08x\n", (UINT
)color
);
94 color
= GetPixel(hdc
, 1,0);
95 ok(color
== 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT
)color
);
97 hbmp
= SelectObject(hdc
, hbmp
);
99 /* Try something else than 0xFFFFFF */
100 pBMI
->bmiColors
[0].rgbBlue
= 0xFF;
101 pBMI
->bmiColors
[0].rgbGreen
= 0;
102 pBMI
->bmiColors
[0].rgbRed
= 0;
104 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
105 ok(ret
== 1, "Copied %i scanlines\n", ret
);
107 hbmp
= SelectObject(hdc
, hbmp
);
108 ok(hbmp
!= NULL
, "Could not select the bitmap into the context.\n");
109 color
= GetPixel(hdc
, 0,0);
110 ok(color
== 0, "Wrong color at 0,0 : 0x%08x\n", (UINT
)color
);
111 color
= GetPixel(hdc
, 1,0);
112 ok(color
== 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT
)color
);
114 hbmp
= SelectObject(hdc
, hbmp
);
116 /* Special : try 0 */
117 pBMI
->bmiColors
[0].rgbBlue
= 0;
118 pBMI
->bmiColors
[0].rgbGreen
= 0;
119 pBMI
->bmiColors
[0].rgbRed
= 0;
121 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
122 ok(ret
== 1, "Copied %i scanlines\n", ret
);
124 hbmp
= SelectObject(hdc
, hbmp
);
125 ok(hbmp
!= NULL
, "Could not select the bitmap into the context.\n");
126 color
= GetPixel(hdc
, 0,0);
127 ok(color
== 0, "Wrong color at 0,0 : 0x%08x\n", (UINT
)color
);
128 color
= GetPixel(hdc
, 1,0);
129 ok(color
== 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT
)color
);
131 hbmp
= SelectObject(hdc
, hbmp
);
136 START_TEST(SetDIBits
)
139 Test_SetDIBits_1bpp();