0
|
1 #include <string>
|
|
2
|
|
3 #include "GammaControl.h"
|
|
4 #include "Render.h"
|
|
5 #include "OSInfo.h"
|
|
6
|
|
7 #include "mm7_data.h"
|
|
8
|
|
9
|
|
10
|
|
11 //----- (0044F324) --------------------------------------------------------
|
|
12 void GammaController::GetRamp()
|
|
13 {
|
|
14 if (pGammaControl)
|
|
15 ErrD3D(pGammaControl->GetGammaRamp(0, &pDefaultRamp));
|
|
16 else
|
|
17 MessageBoxW(nullptr, L"Gamma control not active", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\GammaControl.cpp:83", 0);
|
|
18 }
|
|
19
|
|
20 //----- (0044F377) --------------------------------------------------------
|
|
21 double GammaController::_44F377(DDGAMMARAMP *a1)
|
|
22 {
|
|
23 double v2; // st7@1
|
|
24 unsigned __int16 *v3; // ecx@1
|
|
25 double v4; // st6@2
|
|
26 double result; // st7@7
|
|
27 signed int v6; // [sp+0h] [bp-8h]@1
|
|
28 signed int v7; // [sp+4h] [bp-4h]@1
|
|
29
|
|
30 v7 = 0;
|
|
31 v2 = 0.0;
|
|
32 v6 = 256;
|
|
33 v3 = a1->green;
|
|
34 do
|
|
35 {
|
|
36 v4 = ((double)*(v3 - 256) + (double)v3[256] + (double)*v3) * 0.000015259022 * 0.33333334;
|
|
37 if ( v4 == 0.0 )
|
|
38 --v6;
|
|
39 else
|
|
40 v2 = v2 + (double)v7 * 0.0039215689 / v4;
|
|
41 ++v7;
|
|
42 ++v3;
|
|
43 }
|
|
44 while ( v7 < 256 );
|
|
45 if ( v6 )
|
|
46 result = v2 / (double)v6;
|
|
47 else
|
|
48 result = 1.0;
|
|
49 return result;
|
|
50 }
|
|
51
|
|
52 //----- (0044F408) --------------------------------------------------------
|
|
53 void GammaController::SetGammaRamp(DDGAMMARAMP *pRamp)
|
|
54 {
|
|
55 if (pGammaControl)
|
|
56 ErrD3D(pGammaControl->SetGammaRamp(0, pRamp));
|
|
57 else
|
|
58 MessageBoxW(nullptr, L"Gamma control not active", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\GammaControl.cpp:120", 0);
|
|
59 }
|
|
60
|
|
61 //----- (0044F45B) --------------------------------------------------------
|
|
62 int GammaController::InitGammaRamp(DDGAMMARAMP *pRamp)
|
|
63 {
|
|
64 unsigned __int16 *v2; // esi@1
|
|
65 double v3; // st7@2
|
|
66 signed __int64 v4; // qax@3
|
|
67 signed int v6; // [sp+Ch] [bp-4h]@1
|
|
68
|
|
69 v6 = 0;
|
|
70 v2 = pRamp->green;
|
|
71 do
|
|
72 {
|
|
73 v3 = (double)v6 * 0.0039215689 * this->fGamma;
|
|
74 if ( v3 >= 1.0 || (v4 = (signed __int64)(v3 * 65535.0), (signed int)v4 > 65535) )
|
1421
|
75 {
|
|
76 LODWORD(v4) = 65535;
|
|
77 }
|
|
78 else if ( (signed int)v4 < 0 )
|
0
|
79 {
|
|
80 LODWORD(v4) = 0;
|
|
81 }
|
1421
|
82 else
|
|
83 {
|
0
|
84 if ( (signed int)v4 > 65535 )
|
|
85 LODWORD(v4) = 65535;
|
1421
|
86 }
|
0
|
87 ++v6;
|
|
88 v2[256] = v4;
|
|
89 *v2 = v4;
|
|
90 *(v2 - 256) = v4;
|
|
91 ++v2;
|
|
92 }
|
|
93 while ( v6 < 256 );
|
|
94 return v4;
|
|
95 }
|
|
96
|
|
97 //----- (0044F4D9) --------------------------------------------------------
|
|
98 void GammaController::Initialize(float gamma)
|
|
99 {
|
|
100 GammaController *v2; // esi@1
|
|
101 double v3; // st7@3
|
|
102 double v4; // st6@4
|
|
103
|
|
104 v2 = this;
|
|
105 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
|
|
106 pVersion->pVersionInfo.dwMajorVersion != 4)
|
|
107 {
|
|
108 InitializeFromSurface(pRenderer->pFrontBuffer4);
|
|
109 v3 = 2.8;
|
|
110 if ( gamma <= 2.8f )
|
|
111 v4 = gamma;
|
|
112 else
|
|
113 v4 = 2.8;
|
|
114 if ( v4 >= 0.1f )
|
|
115 {
|
|
116 if ( gamma <= 2.8f )
|
|
117 v3 = gamma;
|
|
118 }
|
|
119 else
|
|
120 {
|
|
121 v3 = 0.1;
|
|
122 }
|
|
123 v2->fGamma = v3;
|
|
124 InitGammaRamp(&v2->field_60C);
|
|
125 SetGammaRamp(&v2->field_60C);
|
|
126 }
|
|
127 }
|
|
128
|
|
129
|
|
130 //----- (0044F2B2) --------------------------------------------------------
|
|
131 bool GammaController::IsGammaSupported()
|
|
132 {
|
|
133 bool result; // eax@3
|
|
134 HRESULT v1; // eax@4
|
|
135
|
|
136 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
|
|
137 {
|
|
138 DDCAPS halCaps; // [sp+0h] [bp-180h]@4
|
|
139 memset(&halCaps, 0, sizeof(DDCAPS));
|
|
140 halCaps.dwSize = sizeof(DDCAPS);
|
|
141
|
|
142 ErrD3D(pRenderer->pDirectDraw4->GetCaps(&halCaps, 0));
|
|
143 return (halCaps.dwCaps2 >> 17) & 1;
|
|
144 }
|
|
145 else
|
|
146 return false;
|
|
147 }
|
|
148
|
|
149
|
|
150
|
|
151 //----- (0044F215) --------------------------------------------------------
|
|
152 GammaController::GammaController()
|
|
153 {
|
|
154 static float flt_4D8670_default_gamma = 1.0f;
|
|
155
|
|
156 pGammaControl = nullptr;
|
|
157 fGamma = flt_4D8670_default_gamma;
|
|
158 }
|
|
159
|
|
160
|
|
161
|
|
162 //----- (0044F24B) --------------------------------------------------------
|
|
163 void GammaController::InitializeFromSurface(IDirectDrawSurface4 *a2)
|
|
164 {
|
|
165 GammaController *v2; // esi@1
|
|
166 IDirectDrawGammaControl **v3; // edi@1
|
|
167 IDirectDrawGammaControl *v4; // eax@1
|
|
168
|
|
169 v2 = this;
|
|
170 v3 = &this->pGammaControl;
|
|
171 this->pSurface = a2;
|
|
172 v4 = this->pGammaControl;
|
|
173 if ( v4 )
|
|
174 {
|
|
175 v4->Release();
|
|
176 *v3 = 0;
|
|
177 }
|
|
178 if ( IsGammaSupported() )
|
|
179 {
|
|
180 ErrD3D(a2->QueryInterface(IID_IDirectDrawGammaControl, (LPVOID *)v3));
|
|
181 GetRamp();
|
|
182 memcpy(&v2->field_60C, &v2->pDefaultRamp, 0x600u);
|
|
183 fGamma = _44F377(&v2->field_60C);
|
|
184 }
|
|
185 } |