ReactOS 0.4.16-dev-2104-gb84fa49
gditools.c File Reference
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winddi.h>
#include <prntfont.h>
#include <ndk/ntndk.h>
#include <ntgdityp.h>
#include <ntgdi.h>
#include <ntgdihdl.h>
#include "gditools.h"
Include dependency graph for gditools.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define NTOS_MODE_USER
 
#define FL_INVERT_COLORS   0x01
 
#define FL_RED_BLUE   0x02
 

Functions

PENTRY GdiQueryTable (VOID)
 
BOOL GdiIsHandleValid (_In_ HGDIOBJ hobj)
 
BOOL GdiIsHandleValidEx (_In_ HGDIOBJ hobj, _In_ GDILOOBJTYPE ObjectType)
 
PVOID GdiGetHandleUserData (_In_ HGDIOBJ hobj)
 
BOOL InitPerBitDepth (_In_ ULONG cBitsPerPixel, _In_ ULONG cx, _In_ ULONG cy, _Out_ HBITMAP *phbmp, _Out_ HDC *phdcDIB, _Out_ HBITMAP *phbmpDIB, _Out_ PVOID *ppvBits, _In_ ULONG flags)
 
BOOL GdiToolsInit (void)
 

Variables

HBITMAP ghbmp1
 
HBITMAP ghbmp1_InvCol
 
HBITMAP ghbmp1_RB
 
HBITMAP ghbmp4
 
HBITMAP ghbmp8
 
HBITMAP ghbmp16
 
HBITMAP ghbmp24
 
HBITMAP ghbmp32
 
HBITMAP ghbmpDIB1
 
HBITMAP ghbmpDIB1_InvCol
 
HBITMAP ghbmpDIB1_RB
 
HBITMAP ghbmpDIB4
 
HBITMAP ghbmpDIB8
 
HBITMAP ghbmpDIB16
 
HBITMAP ghbmpDIB24
 
HBITMAP ghbmpDIB32
 
HDC ghdcDIB1
 
HDC ghdcDIB1_InvCol
 
HDC ghdcDIB1_RB
 
HDC ghdcDIB4
 
HDC ghdcDIB8
 
HDC ghdcDIB16
 
HDC ghdcDIB24
 
HDC ghdcDIB32
 
PVOID gpvDIB1
 
PVOID gpvDIB1_InvCol
 
PVOID gpvDIB1_RB
 
PVOID gpvDIB4
 
PVOID gpvDIB8
 
PVOID gpvDIB16
 
PVOID gpvDIB24
 
PVOID gpvDIB32
 
ULONG(* gpDIB32 )[8][8]
 
HPALETTE ghpal
 
HDC ghdcInfo
 
MYPAL gpal
 

Macro Definition Documentation

◆ FL_INVERT_COLORS

#define FL_INVERT_COLORS   0x01

Definition at line 108 of file gditools.c.

◆ FL_RED_BLUE

#define FL_RED_BLUE   0x02

Definition at line 109 of file gditools.c.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 11 of file gditools.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 4 of file gditools.c.

Function Documentation

◆ GdiGetHandleUserData()

PVOID GdiGetHandleUserData ( _In_ HGDIOBJ  hobj)

Definition at line 93 of file gditools.c.

95{
96 PENTRY pentHmgr = GdiQueryTable();
97 USHORT Index = (ULONG_PTR)hobj;
98 PENTRY pentry = &pentHmgr[Index];
99
100 if (!GdiIsHandleValid(hobj))
101 {
102 return NULL;
103 }
104
105 return pentry->pUser;
106}
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
PENTRY GdiQueryTable(VOID)
Definition: gditools.c:45
BOOL GdiIsHandleValid(_In_ HGDIOBJ hobj)
Definition: gditools.c:54
unsigned short USHORT
Definition: pedump.c:61
Definition: ntgdihdl.h:218
PVOID pUser
Definition: ntgdihdl.h:238
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by CancelDC(), CreateCompatibleBitmap(), CreateCompatibleDC(), CreatePen(), GdiDeleteBrushOrPen(), GetBrushOrgEx(), GetColorSpace(), IntCreateDICW(), SetBrushOrgEx(), SetDIBitsToDevice(), START_TEST(), and StretchDIBits().

◆ GdiIsHandleValid()

BOOL GdiIsHandleValid ( _In_ HGDIOBJ  hobj)

Definition at line 54 of file gditools.c.

56{
57 PENTRY pentHmgr = GdiQueryTable();
58 USHORT Index = (ULONG_PTR)hobj & 0xFFFF;
59 PENTRY pentry = &pentHmgr[Index];
60
61 if ((pentry->einfo.pobj == NULL) ||
62 ((LONG_PTR)pentry->einfo.pobj > 0) ||
63 (pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16)))
64 {
65 return FALSE;
66 }
67
68 return TRUE;
69}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
union _ENTRY::_EINFO einfo
USHORT FullUnique
Definition: ntgdihdl.h:235
#define LONG_PTR
Definition: treelist.c:79
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:221

Referenced by GdiGetHandleUserData(), and START_TEST().

◆ GdiIsHandleValidEx()

BOOL GdiIsHandleValidEx ( _In_ HGDIOBJ  hobj,
_In_ GDILOOBJTYPE  ObjectType 
)

Definition at line 72 of file gditools.c.

75{
76 PENTRY pentHmgr = GdiQueryTable();
77 USHORT Index = (ULONG_PTR)hobj & 0xFFFF;
78 PENTRY pentry = &pentHmgr[Index];
79
80 if ((pentry->einfo.pobj == NULL) ||
81 ((LONG_PTR)pentry->einfo.pobj > 0) ||
82 (pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16)) ||
83 (pentry->Objt != (UCHAR)(ObjectType >> 16)) ||
84 (pentry->Flags != (UCHAR)(ObjectType >> 24)))
85 {
86 return FALSE;
87 }
88
89 return TRUE;
90}
ObjectType
Definition: metafile.c:81
UCHAR Objt
Definition: ntgdihdl.h:236
UCHAR Flags
Definition: ntgdihdl.h:237
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ GdiQueryTable()

PENTRY GdiQueryTable ( VOID  )

Definition at line 45 of file gditools.c.

47{
48 PTEB pTeb = NtCurrentTeb();
49 PPEB pPeb = pTeb->ProcessEnvironmentBlock;
50 return pPeb->GdiSharedHandleTable;
51}
#define NtCurrentTeb
PVOID GdiSharedHandleTable
Definition: ntddk_ex.h:292
Definition: compat.h:836
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337

Referenced by GdiGetHandleUserData(), GdiIsHandleValid(), and GdiIsHandleValidEx().

◆ GdiToolsInit()

BOOL GdiToolsInit ( void  )

Definition at line 192 of file gditools.c.

193{
194
195 /* Initialize a logical palette */
197 if (!ghpal)
198 {
199 printf("failed to create a palette\n");
200 return FALSE;
201 }
202
203 if (!InitPerBitDepth(1, 9, 9, &ghbmp1, &ghdcDIB1, &ghbmpDIB1, &gpvDIB1, 0) ||
206 !InitPerBitDepth(4, 5, 5, &ghbmp4, &ghdcDIB4, &ghbmpDIB4, &gpvDIB4, 0) ||
207 !InitPerBitDepth(8, 5, 5, &ghbmp8, &ghdcDIB8, &ghbmpDIB8, &gpvDIB8, 0) ||
208 !InitPerBitDepth(16, 8, 8, &ghbmp16, &ghdcDIB16, &ghbmpDIB16, &gpvDIB16, 0) ||
209 !InitPerBitDepth(24, 8, 8, &ghbmp24, &ghdcDIB24, &ghbmpDIB24, &gpvDIB24, 0) ||
211 {
212 printf("failed to create objects\n");
213 return FALSE;
214 }
215
217
218 /* Create an Info-DC */
219 ghdcInfo = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
220 if (!ghdcInfo)
221 {
222 printf("failed to create info DC\n");
223 return FALSE;
224 }
225
226 return TRUE;
227}
#define L(x)
Definition: resources.c:13
#define printf
Definition: freeldr.h:97
HBITMAP ghbmp24
Definition: gditools.c:21
HBITMAP ghbmpDIB8
Definition: gditools.c:22
HBITMAP ghbmp4
Definition: gditools.c:21
HBITMAP ghbmpDIB1_InvCol
Definition: gditools.c:22
HDC ghdcDIB8
Definition: gditools.c:23
PVOID gpvDIB8
Definition: gditools.c:24
HDC ghdcDIB16
Definition: gditools.c:23
HBITMAP ghbmpDIB24
Definition: gditools.c:22
ULONG(* gpDIB32)[8][8]
Definition: gditools.c:25
#define FL_RED_BLUE
Definition: gditools.c:109
HDC ghdcInfo
Definition: gditools.c:27
HBITMAP ghbmp1_InvCol
Definition: gditools.c:21
BOOL InitPerBitDepth(_In_ ULONG cBitsPerPixel, _In_ ULONG cx, _In_ ULONG cy, _Out_ HBITMAP *phbmp, _Out_ HDC *phdcDIB, _Out_ HBITMAP *phbmpDIB, _Out_ PVOID *ppvBits, _In_ ULONG flags)
Definition: gditools.c:112
HBITMAP ghbmpDIB1
Definition: gditools.c:22
PVOID gpvDIB1_RB
Definition: gditools.c:24
PVOID gpvDIB1
Definition: gditools.c:24
HBITMAP ghbmpDIB1_RB
Definition: gditools.c:22
HDC ghdcDIB32
Definition: gditools.c:23
HPALETTE ghpal
Definition: gditools.c:26
HBITMAP ghbmp1_RB
Definition: gditools.c:21
PVOID gpvDIB1_InvCol
Definition: gditools.c:24
HBITMAP ghbmpDIB16
Definition: gditools.c:22
HBITMAP ghbmp1
Definition: gditools.c:21
PVOID gpvDIB4
Definition: gditools.c:24
PVOID gpvDIB32
Definition: gditools.c:24
PVOID gpvDIB24
Definition: gditools.c:24
HDC ghdcDIB1
Definition: gditools.c:23
HBITMAP ghbmpDIB32
Definition: gditools.c:22
HBITMAP ghbmp8
Definition: gditools.c:21
HDC ghdcDIB1_RB
Definition: gditools.c:23
MYPAL gpal
Definition: gditools.c:29
#define FL_INVERT_COLORS
Definition: gditools.c:108
HDC ghdcDIB4
Definition: gditools.c:23
PVOID gpvDIB16
Definition: gditools.c:24
HBITMAP ghbmp32
Definition: gditools.c:21
HDC ghdcDIB24
Definition: gditools.c:23
HDC ghdcDIB1_InvCol
Definition: gditools.c:23
HBITMAP ghbmp16
Definition: gditools.c:21
HBITMAP ghbmpDIB4
Definition: gditools.c:22
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
HDC WINAPI CreateDCW(_In_opt_ LPCWSTR pszDriver, _In_opt_ LPCWSTR pszDevice, _In_opt_ LPCWSTR psz, _In_opt_ const DEVMODEW *pdmInit)

Referenced by START_TEST().

◆ InitPerBitDepth()

BOOL InitPerBitDepth ( _In_ ULONG  cBitsPerPixel,
_In_ ULONG  cx,
_In_ ULONG  cy,
_Out_ HBITMAP phbmp,
_Out_ HDC phdcDIB,
_Out_ HBITMAP phbmpDIB,
_Out_ PVOID ppvBits,
_In_ ULONG  flags 
)

Definition at line 112 of file gditools.c.

121{
122 struct
123 {
124 BITMAPINFOHEADER bmiHeader;
125 ULONG bmiColors[256];
126 } bmiBuffer;
127 LPBITMAPINFO pbmi = (LPBITMAPINFO)&bmiBuffer;
128
129 /* Create a bitmap */
130 *phbmp = CreateBitmap(cx, cy, 1, cBitsPerPixel, NULL);
131 if (*phbmp == NULL)
132 {
133 printf("CreateBitmap failed %lu\n", cBitsPerPixel);
134 return FALSE;
135 }
136
137 /* Setup bitmap info */
138 memset(&bmiBuffer, 0, sizeof(bmiBuffer));
143 pbmi->bmiHeader.biBitCount = cBitsPerPixel;
150
151 if (cBitsPerPixel == 1)
152 {
153 if (flags & FL_RED_BLUE)
154 {
155 bmiBuffer.bmiColors[0] = RGB(0xFF, 0x00, 0x00);
156 bmiBuffer.bmiColors[1] = RGB(0x00, 0x00, 0xFF);
157 }
158 else if (flags & FL_INVERT_COLORS)
159 {
160 bmiBuffer.bmiColors[0] = 0xFFFFFF;
161 bmiBuffer.bmiColors[1] = 0;
162 }
163 else
164 {
165 bmiBuffer.bmiColors[0] = 0;
166 bmiBuffer.bmiColors[1] = 0xFFFFFF;
167 }
169 }
170
171 /* Create a compatible DC for the DIB */
172 *phdcDIB = CreateCompatibleDC(0);
173 if (*phdcDIB == NULL)
174 {
175 printf("CreateCompatibleDC failed %lu\n", cBitsPerPixel);
176 return FALSE;
177 }
178
179 /* Create the DIB section with the same values */
180 *phbmpDIB = CreateDIBSection(*phdcDIB, pbmi, DIB_RGB_COLORS, ppvBits, 0, 0 );
181 if (*phbmpDIB == NULL)
182 {
183 printf("CreateDIBSection failed. %lu\n", cBitsPerPixel);
184 return FALSE;
185 }
186
187 SelectObject(*phdcDIB, *phbmpDIB);
188
189 return TRUE;
190}
#define BI_RGB
Definition: precomp.h:55
#define RGB(r, g, b)
Definition: precomp.h:78
GLbitfield flags
Definition: glext.h:7161
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
long LONG
Definition: pedump.c:60
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
#define memset(x, y, z)
Definition: compat.h:39
ULONG biClrImportant
Definition: precomp.h:51
USHORT biBitCount
Definition: precomp.h:45
LONG biYPelsPerMeter
Definition: precomp.h:49
ULONG biCompression
Definition: precomp.h:46
LONG biXPelsPerMeter
Definition: precomp.h:48
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1922
uint32_t ULONG
Definition: typedefs.h:59
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
#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)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
struct tagBITMAPINFO * LPBITMAPINFO

Referenced by GdiToolsInit().

Variable Documentation

◆ ghbmp1

HBITMAP ghbmp1

Definition at line 21 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmp16

HBITMAP ghbmp16

Definition at line 21 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmp1_InvCol

HBITMAP ghbmp1_InvCol

Definition at line 21 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmp1_RB

HBITMAP ghbmp1_RB

Definition at line 21 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmp24

HBITMAP ghbmp24

Definition at line 21 of file gditools.c.

Referenced by GdiToolsInit(), and Test_MaskBlt_1bpp().

◆ ghbmp32

HBITMAP ghbmp32

Definition at line 21 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmp4

HBITMAP ghbmp4

Definition at line 21 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmp8

HBITMAP ghbmp8

Definition at line 21 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmpDIB1

HBITMAP ghbmpDIB1

Definition at line 22 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmpDIB16

HBITMAP ghbmpDIB16

Definition at line 22 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmpDIB1_InvCol

HBITMAP ghbmpDIB1_InvCol

Definition at line 22 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmpDIB1_RB

HBITMAP ghbmpDIB1_RB

Definition at line 22 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmpDIB24

HBITMAP ghbmpDIB24

Definition at line 22 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghbmpDIB32

HBITMAP ghbmpDIB32

Definition at line 22 of file gditools.c.

Referenced by GdiToolsInit(), and Test_NtGdiSetPixel_generic().

◆ ghbmpDIB4

HBITMAP ghbmpDIB4

Definition at line 22 of file gditools.c.

Referenced by GdiToolsInit(), and Test_GetDIBits().

◆ ghbmpDIB8

HBITMAP ghbmpDIB8

Definition at line 22 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghdcDIB1

HDC ghdcDIB1

Definition at line 23 of file gditools.c.

Referenced by GdiToolsInit(), Test_NtGdiSetPixel_1Bpp(), and Test_PaintRgn().

◆ ghdcDIB16

HDC ghdcDIB16

Definition at line 23 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghdcDIB1_InvCol

HDC ghdcDIB1_InvCol

Definition at line 23 of file gditools.c.

Referenced by GdiToolsInit(), and Test_NtGdiSetPixel_1Bpp().

◆ ghdcDIB1_RB

HDC ghdcDIB1_RB

Definition at line 23 of file gditools.c.

Referenced by GdiToolsInit(), and Test_NtGdiSetPixel_1Bpp().

◆ ghdcDIB24

HDC ghdcDIB24

Definition at line 23 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghdcDIB32

◆ ghdcDIB4

HDC ghdcDIB4

Definition at line 23 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghdcDIB8

HDC ghdcDIB8

Definition at line 23 of file gditools.c.

Referenced by GdiToolsInit().

◆ ghdcInfo

HDC ghdcInfo

Definition at line 27 of file gditools.c.

Referenced by GdiToolsInit(), and Test_NtGdiSetPixel_generic().

◆ ghpal

◆ gpal

MYPAL 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:881

Definition at line 29 of file gditools.c.

Referenced by GdiToolsInit().

◆ gpDIB32

◆ gpvDIB1

PVOID gpvDIB1

Definition at line 24 of file gditools.c.

Referenced by GdiToolsInit(), Test_NtGdiSetPixel_1Bpp(), and Test_PaintRgn().

◆ gpvDIB16

PVOID gpvDIB16

Definition at line 24 of file gditools.c.

Referenced by GdiToolsInit().

◆ gpvDIB1_InvCol

PVOID gpvDIB1_InvCol

Definition at line 24 of file gditools.c.

Referenced by GdiToolsInit(), and Test_NtGdiSetPixel_1Bpp().

◆ gpvDIB1_RB

PVOID gpvDIB1_RB

Definition at line 24 of file gditools.c.

Referenced by GdiToolsInit(), and Test_NtGdiSetPixel_1Bpp().

◆ gpvDIB24

PVOID gpvDIB24

Definition at line 24 of file gditools.c.

Referenced by GdiToolsInit().

◆ gpvDIB32

PVOID gpvDIB32

Definition at line 24 of file gditools.c.

Referenced by GdiToolsInit(), Test_NtGdiSetPixel_32Bpp(), and Test_NtGdiSetPixel_generic().

◆ gpvDIB4

PVOID gpvDIB4

Definition at line 24 of file gditools.c.

Referenced by GdiToolsInit().

◆ gpvDIB8

PVOID gpvDIB8

Definition at line 24 of file gditools.c.

Referenced by GdiToolsInit().