Mercurial > mm7
comparison GammaControl.cpp @ 0:9c0607679772
init
author | Ritor1 |
---|---|
date | Sat, 12 Jan 2013 09:45:18 +0600 |
parents | |
children | 4fff79f04dbd |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9c0607679772 |
---|---|
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) ) | |
75 goto LABEL_12; | |
76 if ( (signed int)v4 < 0 ) | |
77 { | |
78 LODWORD(v4) = 0; | |
79 goto LABEL_8; | |
80 } | |
81 if ( (signed int)v4 > 65535 ) | |
82 LABEL_12: | |
83 LODWORD(v4) = 65535; | |
84 LABEL_8: | |
85 ++v6; | |
86 v2[256] = v4; | |
87 *v2 = v4; | |
88 *(v2 - 256) = v4; | |
89 ++v2; | |
90 } | |
91 while ( v6 < 256 ); | |
92 return v4; | |
93 } | |
94 | |
95 //----- (0044F4D9) -------------------------------------------------------- | |
96 void GammaController::Initialize(float gamma) | |
97 { | |
98 GammaController *v2; // esi@1 | |
99 double v3; // st7@3 | |
100 double v4; // st6@4 | |
101 | |
102 v2 = this; | |
103 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || | |
104 pVersion->pVersionInfo.dwMajorVersion != 4) | |
105 { | |
106 InitializeFromSurface(pRenderer->pFrontBuffer4); | |
107 v3 = 2.8; | |
108 if ( gamma <= 2.8f ) | |
109 v4 = gamma; | |
110 else | |
111 v4 = 2.8; | |
112 if ( v4 >= 0.1f ) | |
113 { | |
114 if ( gamma <= 2.8f ) | |
115 v3 = gamma; | |
116 } | |
117 else | |
118 { | |
119 v3 = 0.1; | |
120 } | |
121 v2->fGamma = v3; | |
122 InitGammaRamp(&v2->field_60C); | |
123 SetGammaRamp(&v2->field_60C); | |
124 } | |
125 } | |
126 | |
127 | |
128 //----- (0044F2B2) -------------------------------------------------------- | |
129 bool GammaController::IsGammaSupported() | |
130 { | |
131 bool result; // eax@3 | |
132 HRESULT v1; // eax@4 | |
133 | |
134 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) | |
135 { | |
136 DDCAPS halCaps; // [sp+0h] [bp-180h]@4 | |
137 memset(&halCaps, 0, sizeof(DDCAPS)); | |
138 halCaps.dwSize = sizeof(DDCAPS); | |
139 | |
140 ErrD3D(pRenderer->pDirectDraw4->GetCaps(&halCaps, 0)); | |
141 return (halCaps.dwCaps2 >> 17) & 1; | |
142 } | |
143 else | |
144 return false; | |
145 } | |
146 | |
147 | |
148 | |
149 //----- (0044F215) -------------------------------------------------------- | |
150 GammaController::GammaController() | |
151 { | |
152 static float flt_4D8670_default_gamma = 1.0f; | |
153 | |
154 pGammaControl = nullptr; | |
155 fGamma = flt_4D8670_default_gamma; | |
156 } | |
157 | |
158 | |
159 | |
160 //----- (0044F24B) -------------------------------------------------------- | |
161 void GammaController::InitializeFromSurface(IDirectDrawSurface4 *a2) | |
162 { | |
163 GammaController *v2; // esi@1 | |
164 IDirectDrawGammaControl **v3; // edi@1 | |
165 IDirectDrawGammaControl *v4; // eax@1 | |
166 | |
167 v2 = this; | |
168 v3 = &this->pGammaControl; | |
169 this->pSurface = a2; | |
170 v4 = this->pGammaControl; | |
171 if ( v4 ) | |
172 { | |
173 v4->Release(); | |
174 *v3 = 0; | |
175 } | |
176 if ( IsGammaSupported() ) | |
177 { | |
178 ErrD3D(a2->QueryInterface(IID_IDirectDrawGammaControl, (LPVOID *)v3)); | |
179 GetRamp(); | |
180 memcpy(&v2->field_60C, &v2->pDefaultRamp, 0x600u); | |
181 fGamma = _44F377(&v2->field_60C); | |
182 } | |
183 } |