84405fac1f60f1d844097386fe3a07b218672c1a
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
13 char buffer
[sizeof(BITMAPINFOHEADER
)+2*sizeof(RGBQUAD
)];
15 BITMAPINFO
* pBMI
= (BITMAPINFO
*)buffer
;
16 char bits1bpp
[] = {0x80, 0, 0, 0};
20 ZeroMemory(buffer
, sizeof(buffer
));
22 pBMI
->bmiHeader
.biSize
=sizeof(BITMAPINFOHEADER
);
23 pBMI
->bmiHeader
.biWidth
=2;
24 pBMI
->bmiHeader
.biHeight
=1;
25 pBMI
->bmiHeader
.biPlanes
=1;
26 pBMI
->bmiHeader
.biBitCount
=32;
27 pBMI
->bmiHeader
.biCompression
=BI_RGB
;
28 pBMI
->bmiHeader
.biSizeImage
=0;
29 pBMI
->bmiHeader
.biXPelsPerMeter
=0;
30 pBMI
->bmiHeader
.biYPelsPerMeter
=0;
31 pBMI
->bmiHeader
.biClrUsed
=0;
32 pBMI
->bmiHeader
.biClrImportant
=0;
34 hbmp
= CreateDIBSection(NULL
, pBMI
, DIB_RGB_COLORS
, (PVOID
*)&dibBuffer
, NULL
, 0);
35 ok(hbmp
!=NULL
, "Failed to create a DIB section\n");
37 pBMI
->bmiHeader
.biBitCount
= 1;
38 pBMI
->bmiColors
[0].rgbBlue
= 0xFF;
39 pBMI
->bmiColors
[0].rgbGreen
= 0;
40 pBMI
->bmiColors
[0].rgbRed
= 0xFF;
42 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
43 ok(ret
== 1, "Copied %i scanlines\n", ret
);
45 ok(dibBuffer
[0] == 0, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer
[0]);
46 ok(dibBuffer
[1] == 0xFF00FF, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer
[1]);
51 void Test_SetDIBits_1bpp()
53 char buffer
[sizeof(BITMAPINFOHEADER
)+2*sizeof(RGBQUAD
)];
55 BITMAPINFO
* pBMI
= (BITMAPINFO
*)buffer
;
56 char bits1bpp
[] = {0x80, 0, 0, 0};
61 hdc
= CreateCompatibleDC(0);
64 trace("No device contexr !?\n");
68 ZeroMemory(buffer
, sizeof(buffer
));
70 pBMI
->bmiHeader
.biSize
=sizeof(BITMAPINFOHEADER
);
71 pBMI
->bmiHeader
.biWidth
=2;
72 pBMI
->bmiHeader
.biHeight
=1;
73 pBMI
->bmiHeader
.biPlanes
=1;
74 pBMI
->bmiHeader
.biBitCount
=1;
75 pBMI
->bmiHeader
.biCompression
=BI_RGB
;
76 pBMI
->bmiHeader
.biSizeImage
=0;
77 pBMI
->bmiHeader
.biXPelsPerMeter
=0;
78 pBMI
->bmiHeader
.biYPelsPerMeter
=0;
79 pBMI
->bmiHeader
.biClrUsed
=2;
80 pBMI
->bmiHeader
.biClrImportant
=0;
81 pBMI
->bmiColors
[0].rgbBlue
= 0xFF;
82 pBMI
->bmiColors
[0].rgbGreen
= 0xFF;
83 pBMI
->bmiColors
[0].rgbRed
= 0xFF;
85 hbmp
= CreateBitmap(2, 1, 1, 1, NULL
);
86 ok(hbmp
!=NULL
, "Failed to create a monochrome bitmap\n");
88 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
89 ok(ret
== 1, "Copied %i scanlines\n", ret
);
91 hbmp
= SelectObject(hdc
, hbmp
);
92 ok(hbmp
!= NULL
, "Could not select the bitmap into the context.\n");
93 color
= GetPixel(hdc
, 0,0);
94 ok(color
== 0, "Wrong color at 0,0 : 0x%08x\n", (UINT
)color
);
95 color
= GetPixel(hdc
, 1,0);
96 ok(color
== 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT
)color
);
98 hbmp
= SelectObject(hdc
, hbmp
);
100 /* Try something else than 0xFFFFFF */
101 pBMI
->bmiColors
[0].rgbBlue
= 0xFF;
102 pBMI
->bmiColors
[0].rgbGreen
= 0;
103 pBMI
->bmiColors
[0].rgbRed
= 0;
105 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
106 ok(ret
== 1, "Copied %i scanlines\n", ret
);
108 hbmp
= SelectObject(hdc
, hbmp
);
109 ok(hbmp
!= NULL
, "Could not select the bitmap into the context.\n");
110 color
= GetPixel(hdc
, 0,0);
111 ok(color
== 0, "Wrong color at 0,0 : 0x%08x\n", (UINT
)color
);
112 color
= GetPixel(hdc
, 1,0);
113 ok(color
== 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT
)color
);
115 hbmp
= SelectObject(hdc
, hbmp
);
117 /* Special : try 0 */
118 pBMI
->bmiColors
[0].rgbBlue
= 0;
119 pBMI
->bmiColors
[0].rgbGreen
= 0;
120 pBMI
->bmiColors
[0].rgbRed
= 0;
122 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
123 ok(ret
== 1, "Copied %i scanlines\n", ret
);
125 hbmp
= SelectObject(hdc
, hbmp
);
126 ok(hbmp
!= NULL
, "Could not select the bitmap into the context.\n");
127 color
= GetPixel(hdc
, 0,0);
128 ok(color
== 0, "Wrong color at 0,0 : 0x%08x\n", (UINT
)color
);
129 color
= GetPixel(hdc
, 1,0);
130 ok(color
== 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT
)color
);
132 hbmp
= SelectObject(hdc
, hbmp
);
137 START_TEST(SetDIBits
)
140 Test_SetDIBits_1bpp();