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