ReactOS  0.4.14-dev-293-g2b39b42
SetPixel.c File Reference
#include "precomp.h"
#include <mmsystem.h>
Include dependency graph for SetPixel.c:

Go to the source code of this file.

Functions

void Test_SetPixel_Params ()
 
void Test_SetPixel_PAL ()
 
 START_TEST (SetPixel)
 

Variables

struct {
   WORD   palVersion
 
   WORD   palNumEntries
 
   PALETTEENTRY   logpalettedata [8]
 
gpal
 

Function Documentation

◆ START_TEST()

START_TEST ( SetPixel  )

Definition at line 182 of file SetPixel.c.

183 {
186 }
void Test_SetPixel_Params()
Definition: SetPixel.c:32
void Test_SetPixel_PAL()
Definition: SetPixel.c:62

◆ Test_SetPixel_PAL()

void Test_SetPixel_PAL ( )

Definition at line 62 of file SetPixel.c.

63 {
64  struct
65  {
66  BITMAPINFOHEADER bmiHeader;
67  WORD bmiColors[8];
68  } bmibuffer;
69  BITMAPINFO *pbmi = (PVOID)&bmibuffer;
70  HBITMAP hbmp;
71  HDC hdc;
72  HPALETTE hpal, hpalOld;
73  PULONG pulBits;
74  USHORT i;
75 
76  /* Initialize the BITMAPINFO */
78  pbmi->bmiHeader.biWidth = 1;
79  pbmi->bmiHeader.biHeight = 1;
80  pbmi->bmiHeader.biPlanes = 1;
88  for( i = 0; i < 8; i++ )
89  {
90  bmibuffer.bmiColors[i] = i + 1;
91  }
92 
93  /* Create a memory DC */
95  ok(hdc != 0, "failed\n");
96 
97  /* Create a DIB section and select it */
98  hbmp = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (PVOID*)&pulBits, 0, 0 );
99  ok(hbmp != NULL, "CreateDIBSection failed with error %ld\n", GetLastError());
100  ok(SelectObject(hdc, hbmp) != 0, "SelectObject failed\n");
101 
102  ok_long(SetPixel(hdc, 0, 0, 0), 0);
103  ok_long(pulBits[0], 8);
104  ok_long(SetPixel(hdc, 0, 0, 1), 0);
105  ok_long(pulBits[0], 8);
106  ok_long(SetPixel(hdc, 0, 0, RGB(255,255,255)), 0xc0dcc0);
107  ok_long(pulBits[0], 7);
108 
109  ok_long(SetPixel(hdc, 0, 0, RGB(255,0,0)), 0x80);
110  ok_long(pulBits[0], 0);
111 
112  /* Test DIBINDEX */
113  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0)), 0x80);
114  ok_long(pulBits[0], 0);
115  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(1)), 0x8000);
116  ok_long(pulBits[0], 1);
117  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(7)), 0xc0dcc0);
118  ok_long(pulBits[0], 7);
119  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(8)), 0);
120  ok_long(pulBits[0], 8);
121  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(126)), 0);
122  ok_long(pulBits[0], 126);
123  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0x123456)), 0);
124  ok_long(pulBits[0], 0x56);
125 
126  /* Test PALETTEINDEX */
127  ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(0)), 0);
128  ok_long(pulBits[0], 8);
129  ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(1)), 0x80);
130  ok_long(pulBits[0], 0);
131  ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(2)), 0x8000);
132  ok_long(pulBits[0], 1);
133 
134  /* Delete the DIB section */
136 
137 
138  /* Initialize the logical palette and select it */
139  hpal = CreatePalette((LOGPALETTE*)&gpal);
140  hpalOld = SelectPalette(hdc, hpal, FALSE);
141  ok(hpalOld != NULL, "error=%ld\n", GetLastError());
142 
143 
144  /* Create a DIB section and select it */
145  hbmp = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (PVOID*)&pulBits, 0, 0 );
146  ok(hbmp != NULL, "CreateDIBSection failed with error %ld\n", GetLastError());
147  ok(SelectObject(hdc, hbmp) != 0, "SelectObject failed\n");
148 
149  ok_long(SetPixel(hdc, 0, 0, 0), 0);
150  ok_long(pulBits[0], 8);
151 
152  ok_long(SetPixel(hdc, 0, 0, RGB(255,0,0)), 0x605040);
153  ok_long(pulBits[0], 2);
154 
155  /* Test DIBINDEX */
156  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0)), 0x403020);
157  ok_long(pulBits[0], 0);
158  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(1)), 0x504030);
159  ok_long(pulBits[0], 1);
160  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(7)), 0x302010);
161  ok_long(pulBits[0], 7);
162  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(8)), 0);
163  ok_long(pulBits[0], 8);
164  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(126)), 0);
165  ok_long(pulBits[0], 126);
166  ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0x123456)), 0);
167  ok_long(pulBits[0], 0x56);
168 
169  /* Test PALETTEINDEX */
170  ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(0)), 0x302010);
171  ok_long(pulBits[0], 7);
172  ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(1)), 0x403020);
173  ok_long(pulBits[0], 0);
174  ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(253)), 0x302010);
175  ok_long(pulBits[0], 7);
176  ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(254)), 0x302010);
177  ok_long(pulBits[0], 7);
178 
179 
180 }
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1471
static struct @1567 gpal
DWORD biClrImportant
Definition: amvideo.idl:40
#define DIB_PAL_COLORS
Definition: wingdi.h:365
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
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
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define ok_long(expression, result)
Definition: atltest.h:133
LONG biYPelsPerMeter
Definition: amvideo.idl:38
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DIBINDEX(n)
Definition: mmsystem.h:932
DWORD biCompression
Definition: amvideo.idl:35
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
HBITMAP hbmp
FORCEINLINE VOID SetPixel(IN ULONG Left, IN ULONG Top, IN UCHAR Color)
Definition: vga.c:93
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
#define RGB(r, g, b)
Definition: wingdi.h:2935
unsigned short WORD
Definition: ntddk_ex.h:93
DWORD biSizeImage
Definition: amvideo.idl:36
HDC hdc
Definition: main.c:9
unsigned short USHORT
Definition: pedump.c:61
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 * PULONG
Definition: retypes.h:1
static HBITMAP
Definition: button.c:44
#define BI_RGB
Definition: precomp.h:34
#define PALETTEINDEX(i)
Definition: wingdi.h:2938

Referenced by START_TEST().

◆ Test_SetPixel_Params()

void Test_SetPixel_Params ( )

Definition at line 32 of file SetPixel.c.

33 {
34  HDC hdc;
35 
36  SetLastError(0);
37  ok_long(SetPixel(0, 0, 0, RGB(255,255,255)), -1);
39 
40  /* Test an info DC */
41  hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
42  ok(hdc != 0, "\n");
43  SetLastError(0);
44  ok_long(SetPixel(hdc, 0, 0, 0), -1);
45  ok_long(SetPixel(hdc, 0, 0, RGB(255,255,255)), -1);
46  ok_err(0);
47  DeleteDC(hdc);
48 
49  /* Test a mem DC without selecting a bitmap */
51  ok(hdc != 0, "\n");
52  SetLastError(0);
53  ok_long(SetPixel(hdc, 0, 0, 0), -1);
54  ok_err(0);
55  DeleteDC(hdc);
56 
57  /* Test deleted DC */
58  ok_long(SetPixel(hdc, 0, 0, 0), -1);
59 
60 }
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
static HDC
Definition: imagelist.c:92
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define ok_long(expression, result)
Definition: atltest.h:133
HDC WINAPI CreateICA(_In_opt_ LPCSTR, _In_opt_ LPCSTR, _In_opt_ LPCSTR, _In_opt_ const DEVMODEA *)
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID SetPixel(IN ULONG Left, IN ULONG Top, IN UCHAR Color)
Definition: vga.c:93
#define RGB(r, g, b)
Definition: wingdi.h:2935
#define SetLastError(x)
Definition: compat.h:409
HDC hdc
Definition: main.c:9
#define ok_err(error)
Definition: atltest.h:124
BOOL WINAPI DeleteDC(_In_ HDC)
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

Variable Documentation

◆ gpal

struct { ... } gpal
Initial value:
=
{
0x300, 8,
{
{ 0x10, 0x20, 0x30, PC_NOCOLLAPSE },
{ 0x20, 0x30, 0x40, PC_NOCOLLAPSE },
{ 0x30, 0x40, 0x50, PC_NOCOLLAPSE },
{ 0x40, 0x50, 0x60, PC_NOCOLLAPSE },
{ 0x50, 0x60, 0x70, PC_NOCOLLAPSE },
{ 0x60, 0x70, 0x80, PC_NOCOLLAPSE },
{ 0x70, 0x80, 0x90, PC_NOCOLLAPSE },
{ 0x80, 0x90, 0xA0, PC_NOCOLLAPSE },
}
}
#define PC_NOCOLLAPSE
Definition: wingdi.h:880

Referenced by Test_SetPixel_PAL().

◆ logpalettedata

PALETTEENTRY logpalettedata[8]

Definition at line 16 of file SetPixel.c.

◆ palNumEntries

WORD palNumEntries

Definition at line 15 of file SetPixel.c.

◆ palVersion

WORD palVersion

Definition at line 14 of file SetPixel.c.