84405fac1f60f1d844097386fe3a07b218672c1a
[reactos.git] / rostests / apitests / gdi32 / SetDIBits.c
1 /*
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
6 */
7
8 #include <wine/test.h>
9 #include <wingdi.h>
10
11 void Test_SetDIBits()
12 {
13 char buffer[sizeof(BITMAPINFOHEADER)+2*sizeof(RGBQUAD)];
14 ULONG* dibBuffer;
15 BITMAPINFO* pBMI = (BITMAPINFO*)buffer;
16 char bits1bpp[] = {0x80, 0, 0, 0};
17 HBITMAP hbmp;
18 int ret;
19
20 ZeroMemory(buffer, sizeof(buffer));
21
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;
33
34 hbmp = CreateDIBSection(NULL, pBMI, DIB_RGB_COLORS, (PVOID*)&dibBuffer, NULL, 0);
35 ok(hbmp!=NULL, "Failed to create a DIB section\n");
36
37 pBMI->bmiHeader.biBitCount = 1;
38 pBMI->bmiColors[0].rgbBlue = 0xFF;
39 pBMI->bmiColors[0].rgbGreen = 0;
40 pBMI->bmiColors[0].rgbRed = 0xFF;
41
42 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
43 ok(ret == 1, "Copied %i scanlines\n", ret);
44
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]);
47
48 DeleteObject(hbmp);
49 }
50
51 void Test_SetDIBits_1bpp()
52 {
53 char buffer[sizeof(BITMAPINFOHEADER)+2*sizeof(RGBQUAD)];
54 HDC hdc;
55 BITMAPINFO* pBMI = (BITMAPINFO*)buffer;
56 char bits1bpp[] = {0x80, 0, 0, 0};
57 HBITMAP hbmp;
58 int ret;
59 COLORREF color;
60
61 hdc = CreateCompatibleDC(0);
62 if(!hdc)
63 {
64 trace("No device contexr !?\n");
65 return;
66 }
67
68 ZeroMemory(buffer, sizeof(buffer));
69
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;
84
85 hbmp = CreateBitmap(2, 1, 1, 1, NULL);
86 ok(hbmp!=NULL, "Failed to create a monochrome bitmap\n");
87
88 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
89 ok(ret == 1, "Copied %i scanlines\n", ret);
90
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);
97
98 hbmp = SelectObject(hdc, hbmp);
99
100 /* Try something else than 0xFFFFFF */
101 pBMI->bmiColors[0].rgbBlue = 0xFF;
102 pBMI->bmiColors[0].rgbGreen = 0;
103 pBMI->bmiColors[0].rgbRed = 0;
104
105 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
106 ok(ret == 1, "Copied %i scanlines\n", ret);
107
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);
114
115 hbmp = SelectObject(hdc, hbmp);
116
117 /* Special : try 0 */
118 pBMI->bmiColors[0].rgbBlue = 0;
119 pBMI->bmiColors[0].rgbGreen = 0;
120 pBMI->bmiColors[0].rgbRed = 0;
121
122 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
123 ok(ret == 1, "Copied %i scanlines\n", ret);
124
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);
131
132 hbmp = SelectObject(hdc, hbmp);
133 DeleteObject(hbmp);
134 DeleteDC(hdc);
135 }
136
137 START_TEST(SetDIBits)
138 {
139 Test_SetDIBits();
140 Test_SetDIBits_1bpp();
141 }