ReactOS 0.4.16-dev-251-ga17b6e9
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;
15 char bits1bpp[] = {0x80, 0, 0, 0};
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;
30 pBMI->bmiHeader.biClrUsed=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;
55 char bits1bpp[] = {0x80, 0, 0, 0};
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;
78 pBMI->bmiHeader.biClrUsed=2;
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{
140}
void Test_SetDIBits()
Definition: SetDIBits.c:10
void Test_SetDIBits_1bpp()
Definition: SetDIBits.c:50
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define BI_RGB
Definition: precomp.h:56
ULONG RGBQUAD
Definition: precomp.h:59
pKey DeleteObject()
GLuint buffer
Definition: glext.h:5915
GLuint color
Definition: glext.h:6243
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
unsigned int UINT
Definition: ndis.h:50
ULONG biClrImportant
Definition: precomp.h:52
USHORT biBitCount
Definition: precomp.h:46
LONG biYPelsPerMeter
Definition: precomp.h:50
ULONG biCompression
Definition: precomp.h:47
LONG biXPelsPerMeter
Definition: precomp.h:49
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
RGBQUAD bmiColors[1]
Definition: wingdi.h:1477
UCHAR rgbBlue
Definition: bootanim.c:103
UCHAR rgbRed
Definition: bootanim.c:105
UCHAR rgbGreen
Definition: bootanim.c:104
uint32_t ULONG
Definition: typedefs.h:59
int ret
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
#define ZeroMemory
Definition: winbase.h:1737
DWORD COLORREF
Definition: windef.h:300
#define DIB_RGB_COLORS
Definition: wingdi.h:367
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
int WINAPI SetDIBits(_In_opt_ HDC, _In_ HBITMAP, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI DeleteDC(_In_ HDC)