ReactOS 0.4.16-dev-2207-geb15453
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 <winuser.h>
10#include <prntfont.h>
11
12#define NTOS_MODE_USER
13#include <ndk/ntndk.h>
14
15/* Public Win32K Headers */
16#include <ntgdityp.h>
17#include <ntgdi.h>
18#include <ntgdihdl.h>
19
20#include "gditools.h"
21
26ULONG (*gpDIB32)[8][8];
27HPALETTE ghpal;
29
31{
32 0x300, 8,
33 {
34 { 0x10, 0x20, 0x30, PC_NOCOLLAPSE },
35 { 0x20, 0x30, 0x40, PC_NOCOLLAPSE },
36 { 0x30, 0x40, 0x50, PC_NOCOLLAPSE },
37 { 0x40, 0x50, 0x60, PC_NOCOLLAPSE },
38 { 0x50, 0x60, 0x70, PC_NOCOLLAPSE },
39 { 0x60, 0x70, 0x80, PC_NOCOLLAPSE },
40 { 0x70, 0x80, 0x90, PC_NOCOLLAPSE },
41 { 0x80, 0x90, 0xA0, PC_NOCOLLAPSE },
42 }
43};
44
47 VOID)
48{
49 PTEB pTeb = NtCurrentTeb();
50 PPEB pPeb = pTeb->ProcessEnvironmentBlock;
51 return pPeb->GdiSharedHandleTable;
52}
53
54BOOL
56 _In_ HGDIOBJ hobj)
57{
58 PENTRY pentHmgr = GdiQueryTable();
59 USHORT Index = (ULONG_PTR)hobj & 0xFFFF;
60 PENTRY pentry = &pentHmgr[Index];
61
62 if ((pentry->einfo.pobj == NULL) ||
63 ((LONG_PTR)pentry->einfo.pobj > 0) ||
64 (pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16)))
65 {
66 return FALSE;
67 }
68
69 return TRUE;
70}
71
72BOOL
74 _In_ HGDIOBJ hobj,
76{
77 PENTRY pentHmgr = GdiQueryTable();
78 USHORT Index = (ULONG_PTR)hobj & 0xFFFF;
79 PENTRY pentry = &pentHmgr[Index];
80
81 if ((pentry->einfo.pobj == NULL) ||
82 ((LONG_PTR)pentry->einfo.pobj > 0) ||
83 (pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16)) ||
84 (pentry->Objt != (UCHAR)(ObjectType >> 16)) ||
85 (pentry->Flags != (UCHAR)(ObjectType >> 24)))
86 {
87 return FALSE;
88 }
89
90 return TRUE;
91}
92
95 _In_ HGDIOBJ hobj)
96{
97 PENTRY pentHmgr = GdiQueryTable();
98 USHORT Index = (ULONG_PTR)hobj;
99 PENTRY pentry = &pentHmgr[Index];
100
101 if (!GdiIsHandleValid(hobj))
102 {
103 return NULL;
104 }
105
106 return pentry->pUser;
107}
108
109VOID
111{
112 DEVMODEW dm = { .dmSize = sizeof(dm) };
113 ULONG iMode = 0;
114
115 printf("Available display modes:\n");
116 while (EnumDisplaySettingsW(NULL, iMode++, &dm))
117 {
118 printf(" %ux%u @ %u bpp, freq: %u Hz\n",
120 }
121}
122
123BOOL
125 _In_ ULONG cBitsPixel,
126 _Out_ PDEVMODEW pdmOld)
127{
128 DEVMODEW dm = { .dmSize = sizeof(dm) };
129
131 {
132 printf("EnumDisplaySettingsW failed\n");
133 return FALSE;
134 }
135
136 printf("ChangeScreenBpp(%lu): Old display settings: %ux%u @ %u bpp\n",
137 cBitsPixel, dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel);
138
139 *pdmOld = dm;
140
141 if (dm.dmBitsPerPel != cBitsPixel)
142 {
143 dm.dmBitsPerPel = cBitsPixel;
145 {
146 printf("Failed to change display settings.\n");
148 return FALSE;
149 }
150 }
151
153 printf("ChangeScreenBpp(%lu): New display settings: %ux%u @ %u bpp\n",
154 cBitsPixel, dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel);
155
156 return TRUE;
157}
158
159#define FL_INVERT_COLORS 0x01
160#define FL_RED_BLUE 0x02
161
162static
163BOOL
165 _In_ ULONG cBitsPerPixel,
166 _In_ ULONG cx,
167 _In_ ULONG cy,
168 _Out_opt_ HBITMAP *phbmpDDB,
169 _Out_ HDC *phdcDIB,
170 _Out_ HBITMAP *phbmpDIB,
171 _Out_ PVOID *ppvBits,
173{
174 struct
175 {
176 BITMAPINFOHEADER bmiHeader;
177 ULONG bmiColors[256];
178 } bmiBuffer;
179 LPBITMAPINFO pbmi = (LPBITMAPINFO)&bmiBuffer;
180
181 if (phbmpDDB != NULL)
182 {
183 /* Create a bitmap */
184 *phbmpDDB = CreateBitmap(cx, cy, 1, cBitsPerPixel, NULL);
185 if (*phbmpDDB == NULL)
186 {
187 printf("CreateBitmap failed %lu\n", cBitsPerPixel);
188 return FALSE;
189 }
190 }
191
192 /* Setup bitmap info */
193 memset(&bmiBuffer, 0, sizeof(bmiBuffer));
198 pbmi->bmiHeader.biBitCount = cBitsPerPixel;
205
206 if (cBitsPerPixel == 1)
207 {
208 if (flags & FL_RED_BLUE)
209 {
210 bmiBuffer.bmiColors[0] = RGB(0xFF, 0x00, 0x00);
211 bmiBuffer.bmiColors[1] = RGB(0x00, 0x00, 0xFF);
212 }
213 else if (flags & FL_INVERT_COLORS)
214 {
215 bmiBuffer.bmiColors[0] = 0xFFFFFF;
216 bmiBuffer.bmiColors[1] = 0;
217 }
218 else
219 {
220 bmiBuffer.bmiColors[0] = 0;
221 bmiBuffer.bmiColors[1] = 0xFFFFFF;
222 }
224 }
225
226 /* Create a compatible DC for the DIB */
227 *phdcDIB = CreateCompatibleDC(0);
228 if (*phdcDIB == NULL)
229 {
230 printf("CreateCompatibleDC failed %lu\n", cBitsPerPixel);
231 return FALSE;
232 }
233
234 /* Create the DIB section with the same values */
235 *phbmpDIB = CreateDIBSection(*phdcDIB, pbmi, DIB_RGB_COLORS, ppvBits, 0, 0 );
236 if (*phbmpDIB == NULL)
237 {
238 printf("CreateDIBSection failed. %lu\n", cBitsPerPixel);
239 return FALSE;
240 }
241
242 if (SelectObject(*phdcDIB, *phbmpDIB) == NULL)
243 {
244 printf("SelectObject failed for %lu bpp DIB\n", cBitsPerPixel);
245 return FALSE;
246 }
247
248 return TRUE;
249}
250
252{
253 /* Initialize a logical palette */
255 if (!ghpal)
256 {
257 printf("failed to create a palette\n");
258 return FALSE;
259 }
260
261 if (!InitPerBitDepth(1, 9, 9, &ghbmp1, &ghdcDIB1, &ghbmpDIB1, &gpvDIB1, 0) ||
264 !InitPerBitDepth(4, 5, 5, &ghbmp4, &ghdcDIB4, &ghbmpDIB4, &gpvDIB4, 0) ||
265 !InitPerBitDepth(8, 5, 5, &ghbmp8, &ghdcDIB8, &ghbmpDIB8, &gpvDIB8, 0) ||
266 !InitPerBitDepth(16, 8, 8, &ghbmp16, &ghdcDIB16, &ghbmpDIB16, &gpvDIB16, 0) ||
267 !InitPerBitDepth(24, 8, 8, &ghbmp24, &ghdcDIB24, &ghbmpDIB24, &gpvDIB24, 0) ||
269 {
270 printf("failed to create objects\n");
271 return FALSE;
272 }
273
275
276 /* Create an Info-DC */
277 ghdcInfo = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
278 if (!ghdcInfo)
279 {
280 printf("failed to create info DC\n");
281 return FALSE;
282 }
283
284 return TRUE;
285}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define BI_RGB
Definition: precomp.h:44
#define RGB(r, g, b)
Definition: precomp.h:67
#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:104
enum GDILoObjType GDILOOBJTYPE
HBITMAP ghbmp24
Definition: gditools.c:22
HBITMAP ghbmpDIB8
Definition: gditools.c:23
HBITMAP ghbmp4
Definition: gditools.c:22
HBITMAP ghbmpDIB1_InvCol
Definition: gditools.c:23
VOID PrintAvailableDisplayModes(void)
Definition: gditools.c:110
HDC ghdcDIB8
Definition: gditools.c:24
PVOID gpvDIB8
Definition: gditools.c:25
BOOL GdiIsHandleValidEx(_In_ HGDIOBJ hobj, _In_ GDILOOBJTYPE ObjectType)
Definition: gditools.c:73
HDC ghdcDIB16
Definition: gditools.c:24
HBITMAP ghbmpDIB24
Definition: gditools.c:23
ULONG(* gpDIB32)[8][8]
Definition: gditools.c:26
PENTRY GdiQueryTable(VOID)
Definition: gditools.c:46
BOOL ChangeScreenBpp(_In_ ULONG cBitsPixel, _Out_ PDEVMODEW pdmOld)
Definition: gditools.c:124
#define FL_RED_BLUE
Definition: gditools.c:160
HDC ghdcInfo
Definition: gditools.c:28
HBITMAP ghbmp1_InvCol
Definition: gditools.c:22
HBITMAP ghbmpDIB1
Definition: gditools.c:23
PVOID gpvDIB1_RB
Definition: gditools.c:25
PVOID gpvDIB1
Definition: gditools.c:25
HBITMAP ghbmpDIB1_RB
Definition: gditools.c:23
HDC ghdcDIB32
Definition: gditools.c:24
HPALETTE ghpal
Definition: gditools.c:27
HBITMAP ghbmp1_RB
Definition: gditools.c:22
PVOID gpvDIB1_InvCol
Definition: gditools.c:25
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:94
HBITMAP ghbmpDIB16
Definition: gditools.c:23
static BOOL InitPerBitDepth(_In_ ULONG cBitsPerPixel, _In_ ULONG cx, _In_ ULONG cy, _Out_opt_ HBITMAP *phbmpDDB, _Out_ HDC *phdcDIB, _Out_ HBITMAP *phbmpDIB, _Out_ PVOID *ppvBits, _In_ ULONG flags)
Definition: gditools.c:164
HBITMAP ghbmp1
Definition: gditools.c:22
PVOID gpvDIB4
Definition: gditools.c:25
PVOID gpvDIB32
Definition: gditools.c:25
PVOID gpvDIB24
Definition: gditools.c:25
HDC ghdcDIB1
Definition: gditools.c:24
HBITMAP ghbmpDIB32
Definition: gditools.c:23
HBITMAP ghbmp8
Definition: gditools.c:22
HDC ghdcDIB1_RB
Definition: gditools.c:24
MYPAL gpal
Definition: gditools.c:30
#define FL_INVERT_COLORS
Definition: gditools.c:159
HDC ghdcDIB4
Definition: gditools.c:24
PVOID gpvDIB16
Definition: gditools.c:25
BOOL GdiToolsInit(void)
Definition: gditools.c:251
BOOL GdiIsHandleValid(_In_ HGDIOBJ hobj)
Definition: gditools.c:55
HBITMAP ghbmp32
Definition: gditools.c:22
HDC ghdcDIB24
Definition: gditools.c:24
HDC ghdcDIB1_InvCol
Definition: gditools.c:24
HBITMAP ghbmp16
Definition: gditools.c:22
HBITMAP ghbmpDIB4
Definition: gditools.c:23
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_opt_
Definition: no_sal2.h:214
#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
DWORD dmBitsPerPel
Definition: wingdi.h:2093
DWORD dmPelsWidth
Definition: wingdi.h:2094
DWORD dmPelsHeight
Definition: wingdi.h:2095
DWORD dmDisplayFrequency
Definition: wingdi.h:2100
WORD dmSize
Definition: wingdi.h:2066
ULONG biClrImportant
Definition: precomp.h:40
USHORT biBitCount
Definition: precomp.h:34
LONG biYPelsPerMeter
Definition: precomp.h:38
ULONG biCompression
Definition: precomp.h:35
LONG biXPelsPerMeter
Definition: precomp.h:37
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
BOOL WINAPI EnumDisplaySettingsW(LPCWSTR lpszDeviceName, DWORD iModeNum, LPDEVMODEW lpDevMode)
Definition: display.c:408
LONG WINAPI ChangeDisplaySettingsW(LPDEVMODEW lpDevMode, DWORD dwflags)
Definition: display.c:612
_In_ ULONG iMode
Definition: winddi.h:3520
#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)
#define DISP_CHANGE_SUCCESSFUL
Definition: winuser.h:190
#define ENUM_CURRENT_SETTINGS
Definition: winuser.h:179
unsigned char UCHAR
Definition: xmlstorage.h:181