ReactOS 0.4.16-dev-2104-gb84fa49
gditools.c
Go to the documentation of this file.
1
2
3/* SDK/DDK/NDK Headers. */
4#define WIN32_NO_STATUS
5#include <windef.h>
6#include <winbase.h>
7#include <wingdi.h>
8#include <winddi.h>
9#include <prntfont.h>
10
11#define NTOS_MODE_USER
12#include <ndk/ntndk.h>
13
14/* Public Win32K Headers */
15#include <ntgdityp.h>
16#include <ntgdi.h>
17#include <ntgdihdl.h>
18
19#include "gditools.h"
20
25ULONG (*gpDIB32)[8][8];
26HPALETTE ghpal;
28
30{
31 0x300, 8,
32 {
33 { 0x10, 0x20, 0x30, PC_NOCOLLAPSE },
34 { 0x20, 0x30, 0x40, PC_NOCOLLAPSE },
35 { 0x30, 0x40, 0x50, PC_NOCOLLAPSE },
36 { 0x40, 0x50, 0x60, PC_NOCOLLAPSE },
37 { 0x50, 0x60, 0x70, PC_NOCOLLAPSE },
38 { 0x60, 0x70, 0x80, PC_NOCOLLAPSE },
39 { 0x70, 0x80, 0x90, PC_NOCOLLAPSE },
40 { 0x80, 0x90, 0xA0, PC_NOCOLLAPSE },
41 }
42};
43
46 VOID)
47{
48 PTEB pTeb = NtCurrentTeb();
49 PPEB pPeb = pTeb->ProcessEnvironmentBlock;
50 return pPeb->GdiSharedHandleTable;
51}
52
53BOOL
55 _In_ HGDIOBJ hobj)
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}
70
71BOOL
73 _In_ HGDIOBJ hobj,
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}
91
94 _In_ HGDIOBJ hobj)
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}
107
108#define FL_INVERT_COLORS 0x01
109#define FL_RED_BLUE 0x02
110
111BOOL
113 _In_ ULONG cBitsPerPixel,
114 _In_ ULONG cx,
115 _In_ ULONG cy,
116 _Out_ HBITMAP *phbmp,
117 _Out_ HDC *phdcDIB,
118 _Out_ HBITMAP *phbmpDIB,
119 _Out_ PVOID *ppvBits,
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}
191
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 NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define BI_RGB
Definition: precomp.h:55
#define RGB(r, g, b)
Definition: precomp.h:78
#define L(x)
Definition: resources.c:13
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
#define printf
Definition: freeldr.h:97
enum GDILoObjType GDILOOBJTYPE
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
BOOL GdiIsHandleValidEx(_In_ HGDIOBJ hobj, _In_ GDILOOBJTYPE ObjectType)
Definition: gditools.c:72
HDC ghdcDIB16
Definition: gditools.c:23
HBITMAP ghbmpDIB24
Definition: gditools.c:22
ULONG(* gpDIB32)[8][8]
Definition: gditools.c:25
PENTRY GdiQueryTable(VOID)
Definition: gditools.c:45
#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
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:93
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
BOOL GdiToolsInit(void)
Definition: gditools.c:192
BOOL GdiIsHandleValid(_In_ HGDIOBJ hobj)
Definition: gditools.c:54
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
GLbitfield flags
Definition: glext.h:7161
#define NtCurrentTeb
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
ObjectType
Definition: metafile.c:81
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
_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
Definition: gditools.h:15
Definition: ntgdihdl.h:218
UCHAR Objt
Definition: ntgdihdl.h:236
PVOID pUser
Definition: ntgdihdl.h:238
UCHAR Flags
Definition: ntgdihdl.h:237
union _ENTRY::_EINFO einfo
USHORT FullUnique
Definition: ntgdihdl.h:235
PVOID GdiSharedHandleTable
Definition: ntddk_ex.h:292
Definition: compat.h:836
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337
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
#define LONG_PTR
Definition: treelist.c:79
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:221
_In_ WDFCOLLECTION _In_ ULONG Index
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)
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
struct tagBITMAPINFO * LPBITMAPINFO
#define PC_NOCOLLAPSE
Definition: wingdi.h:881
HDC WINAPI CreateDCW(_In_opt_ LPCWSTR pszDriver, _In_opt_ LPCWSTR pszDevice, _In_opt_ LPCWSTR psz, _In_opt_ const DEVMODEW *pdmInit)
unsigned char UCHAR
Definition: xmlstorage.h:181