-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutoHDR_input.cpp
134 lines (110 loc) · 3.33 KB
/
AutoHDR_input.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "Windows.h"
#include <iostream>
void HDR()
{
uint32_t pathCount, modeCount;
uint8_t set[] = { 0x0A, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x14, 0x81, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
uint8_t request[] = { 0x09, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x7C, 0x6F, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0xDB, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00 };
if (ERROR_SUCCESS == GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount))
{
DISPLAYCONFIG_PATH_INFO* pathsArray = nullptr;
DISPLAYCONFIG_MODE_INFO* modesArray = nullptr;
const size_t sizePathsArray = pathCount * sizeof(DISPLAYCONFIG_PATH_INFO);
const size_t sizeModesArray = modeCount * sizeof(DISPLAYCONFIG_MODE_INFO);
pathsArray = static_cast<DISPLAYCONFIG_PATH_INFO*>(std::malloc(sizePathsArray));
modesArray = static_cast<DISPLAYCONFIG_MODE_INFO*>(std::malloc(sizeModesArray));
if (pathsArray != nullptr && modesArray != nullptr)
{
std::memset(pathsArray, 0, sizePathsArray);
std::memset(modesArray, 0, sizeModesArray);
if (ERROR_SUCCESS == QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, pathsArray,
&modeCount, modesArray, 0))
{
DISPLAYCONFIG_DEVICE_INFO_HEADER* setPacket =
reinterpret_cast<DISPLAYCONFIG_DEVICE_INFO_HEADER*>(set);
DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket =
reinterpret_cast<DISPLAYCONFIG_DEVICE_INFO_HEADER*>(request);
for (int i = 0; i < modeCount; i++)
{
if (modesArray[i].infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET)
{
setPacket->adapterId.HighPart = modesArray[i].adapterId.HighPart;
setPacket->adapterId.LowPart = modesArray[i].adapterId.LowPart;
setPacket->id = modesArray[i].id;
requestPacket->adapterId.HighPart = modesArray[i].adapterId.HighPart;
requestPacket->adapterId.LowPart = modesArray[i].adapterId.LowPart;
requestPacket->id = modesArray[i].id;
}
}
if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(requestPacket))
{
if (request[20] == 0xD1) // HDR is OFF
{
set[20] = 1;
DisplayConfigSetDeviceInfo(setPacket);
}
else if (request[20] == 0xD3) // HDR is ON
{
set[20] = 0;
DisplayConfigSetDeviceInfo(setPacket);
}
}
}
std::free(pathsArray);
std::free(modesArray);
}
}
}
void exec()
{
char * pCmd = ::GetCommandLine();
// skip the executable
if (*pCmd++ == L'"')
{
while (*pCmd++ != L'"');
}
else
{
while (*pCmd != NULL && *pCmd != L' ')
++pCmd;
}
while (*pCmd == L' ')
pCmd++;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// Start the child process.
if (!CreateProcess(NULL,
pCmd,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si, // Pointer to STARTUPINFO structure.
&pi)) // Pointer to PROCESS_INFORMATION
{
puts("Error");
return;
}
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
int main()
{
//Start HDR
HDR();
//call user executable
exec();
//Turn HDR off
HDR();
return 0;
}