ReactOS  0.4.13-dev-1148-g9b75b67
SetDIBits.c
Go to the documentation of this file.
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 "precomp.h"
9 
11 {
12  char buffer[sizeof(BITMAPINFOHEADER)+2*sizeof(RGBQUAD)];
13  ULONG* dibBuffer;
14  BITMAPINFO* pBMI = (BITMAPINFO*)buffer;
15  char bits1bpp[] = {0x80, 0, 0, 0};
16  HBITMAP hbmp;
17  int ret;
18 
19  ZeroMemory(buffer, sizeof(buffer));
20 
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;
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;
32 
33  hbmp = CreateDIBSection(NULL, pBMI, DIB_RGB_COLORS, (PVOID*)&dibBuffer, NULL, 0);
34  ok(hbmp!=NULL, "Failed to create a DIB section\n");
35 
36  pBMI->bmiHeader.biBitCount = 1;
37  pBMI->bmiColors[0].rgbBlue = 0xFF;
38  pBMI->bmiColors[0].rgbGreen = 0;
39  pBMI->bmiColors[0].rgbRed = 0xFF;
40 
41  ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
42  ok(ret == 1, "Copied %i scanlines\n", ret);
43 
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]);
46 
48 }
49 
51 {
52  char buffer[sizeof(BITMAPINFOHEADER)+2*sizeof(RGBQUAD)];
53  HDC hdc;
54  BITMAPINFO* pBMI = (BITMAPINFO*)buffer;
55  char bits1bpp[] = {0x80, 0, 0, 0};
56  HBITMAP hbmp;
57  int ret;
59 
61  if(!hdc)
62  {
63  trace("No device contexr !?\n");
64  return;
65  }
66 
67  ZeroMemory(buffer, sizeof(buffer));
68 
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;
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;
83 
84  hbmp = CreateBitmap(2, 1, 1, 1, NULL);
85  ok(hbmp!=NULL, "Failed to create a monochrome bitmap\n");
86 
87  ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
88  ok(ret == 1, "Copied %i scanlines\n", ret);
89 
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);
96 
98 
99  /* Try something else than 0xFFFFFF */
100  pBMI->bmiColors[0].rgbBlue = 0xFF;
101  pBMI->bmiColors[0].rgbGreen = 0;
102  pBMI->bmiColors[0].rgbRed = 0;
103 
104  ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
105  ok(ret == 1, "Copied %i scanlines\n", ret);
106 
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);
113 
115 
116  /* Special : try 0 */
117  pBMI->bmiColors[0].rgbBlue = 0;
118  pBMI->bmiColors[0].rgbGreen = 0;
119  pBMI->bmiColors[0].rgbRed = 0;
120 
121  ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
122  ok(ret == 1, "Copied %i scanlines\n", ret);
123 
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);
130 
133  DeleteDC(hdc);
134 }
135 
137 {
138  Test_SetDIBits();
140 }
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1471
DWORD biClrImportant
Definition: amvideo.idl:40
START_TEST(SetDIBits)
Definition: SetDIBits.c:136
void Test_SetDIBits()
Definition: SetDIBits.c:10
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
GLuint buffer
Definition: glext.h:5915
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
LONG biYPelsPerMeter
Definition: amvideo.idl:38
UCHAR rgbBlue
Definition: inbv.c:170
UCHAR rgbGreen
Definition: inbv.c:171
UCHAR rgbRed
Definition: inbv.c:172
GLuint color
Definition: glext.h:6243
DWORD biCompression
Definition: amvideo.idl:35
smooth NULL
Definition: ftsmooth.c:416
HBITMAP hbmp
void Test_SetDIBits_1bpp()
Definition: SetDIBits.c:50
#define trace
Definition: atltest.h:70
RGBQUAD bmiColors[1]
Definition: wingdi.h:1472
DWORD COLORREF
Definition: windef.h:285
DWORD biSizeImage
Definition: amvideo.idl:36
int ret
HDC hdc
Definition: main.c:9
BOOL WINAPI DeleteDC(_In_ HDC)
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1
static HBITMAP
Definition: button.c:44
#define DIB_RGB_COLORS
Definition: wingdi.h:366
int WINAPI SetDIBits(_In_opt_ HDC, _In_ HBITMAP, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
#define BI_RGB
Definition: precomp.h:34
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)