annotate GammaControl.cpp @ 110:430786d916d6

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