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
14 char buffer
[sizeof(BITMAPINFOHEADER
)+2*sizeof(RGBQUAD
)];
16 BITMAPINFO
* pBMI
= (BITMAPINFO
*)buffer
;
17 char bits1bpp
[] = {0x80, 0, 0, 0};
21 ZeroMemory(buffer
, sizeof(buffer
));
23 pBMI
->bmiHeader
.biSize
=sizeof(BITMAPINFOHEADER
);
24 pBMI
->bmiHeader
.biWidth
=2;
25 pBMI
->bmiHeader
.biHeight
=1;
26 pBMI
->bmiHeader
.biPlanes
=1;
27 pBMI
->bmiHeader
.biBitCount
=32;
28 pBMI
->bmiHeader
.biCompression
=BI_RGB
;
29 pBMI
->bmiHeader
.biSizeImage
=0;
30 pBMI
->bmiHeader
.biXPelsPerMeter
=0;
31 pBMI
->bmiHeader
.biYPelsPerMeter
=0;
32 pBMI
->bmiHeader
.biClrUsed
=0;
33 pBMI
->bmiHeader
.biClrImportant
=0;
35 hbmp
= CreateDIBSection(NULL
, pBMI
, DIB_RGB_COLORS
, (PVOID
*)&dibBuffer
, NULL
, 0);
36 ok(hbmp
!=NULL
, "Failed to create a DIB section\n");
38 pBMI
->bmiHeader
.biBitCount
= 1;
39 pBMI
->bmiColors
[0].rgbBlue
= 0xFF;
40 pBMI
->bmiColors
[0].rgbGreen
= 0;
41 pBMI
->bmiColors
[0].rgbRed
= 0xFF;
43 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
44 ok(ret
== 1, "Copied %i scanlines\n", ret
);
46 ok(dibBuffer
[0] == 0, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer
[0]);
47 ok(dibBuffer
[1] == 0xFF00FF, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer
[1]);
52 void Test_SetDIBits_1bpp()
54 char buffer
[sizeof(BITMAPINFOHEADER
)+2*sizeof(RGBQUAD
)];
56 BITMAPINFO
* pBMI
= (BITMAPINFO
*)buffer
;
57 char bits1bpp
[] = {0x80, 0, 0, 0};
62 hdc
= CreateCompatibleDC(0);
65 trace("No device contexr !?\n");
69 ZeroMemory(buffer
, sizeof(buffer
));
71 pBMI
->bmiHeader
.biSize
=sizeof(BITMAPINFOHEADER
);
72 pBMI
->bmiHeader
.biWidth
=2;
73 pBMI
->bmiHeader
.biHeight
=1;
74 pBMI
->bmiHeader
.biPlanes
=1;
75 pBMI
->bmiHeader
.biBitCount
=1;
76 pBMI
->bmiHeader
.biCompression
=BI_RGB
;
77 pBMI
->bmiHeader
.biSizeImage
=0;
78 pBMI
->bmiHeader
.biXPelsPerMeter
=0;
79 pBMI
->bmiHeader
.biYPelsPerMeter
=0;
80 pBMI
->bmiHeader
.biClrUsed
=2;
81 pBMI
->bmiHeader
.biClrImportant
=0;
82 pBMI
->bmiColors
[0].rgbBlue
= 0xFF;
83 pBMI
->bmiColors
[0].rgbGreen
= 0xFF;
84 pBMI
->bmiColors
[0].rgbRed
= 0xFF;
86 hbmp
= CreateBitmap(2, 1, 1, 1, NULL
);
87 ok(hbmp
!=NULL
, "Failed to create a monochrome bitmap\n");
89 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
90 ok(ret
== 1, "Copied %i scanlines\n", ret
);
92 hbmp
= SelectObject(hdc
, hbmp
);
93 ok(hbmp
!= NULL
, "Could not select the bitmap into the context.\n");
94 color
= GetPixel(hdc
, 0,0);
95 ok(color
== 0, "Wrong color at 0,0 : 0x%08x\n", (UINT
)color
);
96 color
= GetPixel(hdc
, 1,0);
97 ok(color
== 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT
)color
);
99 hbmp
= SelectObject(hdc
, hbmp
);
101 /* Try something else than 0xFFFFFF */
102 pBMI
->bmiColors
[0].rgbBlue
= 0xFF;
103 pBMI
->bmiColors
[0].rgbGreen
= 0;
104 pBMI
->bmiColors
[0].rgbRed
= 0;
106 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
107 ok(ret
== 1, "Copied %i scanlines\n", ret
);
109 hbmp
= SelectObject(hdc
, hbmp
);
110 ok(hbmp
!= NULL
, "Could not select the bitmap into the context.\n");
111 color
= GetPixel(hdc
, 0,0);
112 ok(color
== 0, "Wrong color at 0,0 : 0x%08x\n", (UINT
)color
);
113 color
= GetPixel(hdc
, 1,0);
114 ok(color
== 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT
)color
);
116 hbmp
= SelectObject(hdc
, hbmp
);
118 /* Special : try 0 */
119 pBMI
->bmiColors
[0].rgbBlue
= 0;
120 pBMI
->bmiColors
[0].rgbGreen
= 0;
121 pBMI
->bmiColors
[0].rgbRed
= 0;
123 ret
= SetDIBits(NULL
, hbmp
, 0, 1, bits1bpp
, pBMI
, DIB_RGB_COLORS
);
124 ok(ret
== 1, "Copied %i scanlines\n", ret
);
126 hbmp
= SelectObject(hdc
, hbmp
);
127 ok(hbmp
!= NULL
, "Could not select the bitmap into the context.\n");
128 color
= GetPixel(hdc
, 0,0);
129 ok(color
== 0, "Wrong color at 0,0 : 0x%08x\n", (UINT
)color
);
130 color
= GetPixel(hdc
, 1,0);
131 ok(color
== 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT
)color
);
133 hbmp
= SelectObject(hdc
, hbmp
);
138 START_TEST(SetDIBits
)
141 Test_SetDIBits_1bpp();