Mercurial > mm7
annotate GammaControl.cpp @ 2253:aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
author | Grumpy7 |
---|---|
date | Wed, 26 Feb 2014 23:35:23 +0100 |
parents | 9bd7522cdbbb |
children | fd788d2e9585 |
rev | line source |
---|---|
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2154
diff
changeset
|
1 #define _CRT_SECURE_NO_WARNINGS |
0 | 2 #include <string> |
3 | |
4 #include "GammaControl.h" | |
5 #include "Render.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; | |
2152 | 105 //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || |
106 //pVersion->pVersionInfo.dwMajorVersion != 4) | |
0 | 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 | |
131 | |
132 | |
133 //----- (0044F215) -------------------------------------------------------- | |
134 GammaController::GammaController() | |
135 { | |
136 static float flt_4D8670_default_gamma = 1.0f; | |
137 | |
138 pGammaControl = nullptr; | |
139 fGamma = flt_4D8670_default_gamma; | |
140 } | |
141 | |
142 | |
143 | |
144 //----- (0044F24B) -------------------------------------------------------- | |
145 void GammaController::InitializeFromSurface(IDirectDrawSurface4 *a2) | |
146 { | |
147 GammaController *v2; // esi@1 | |
148 IDirectDrawGammaControl **v3; // edi@1 | |
149 IDirectDrawGammaControl *v4; // eax@1 | |
150 | |
151 v2 = this; | |
152 v3 = &this->pGammaControl; | |
153 this->pSurface = a2; | |
154 v4 = this->pGammaControl; | |
155 if ( v4 ) | |
156 { | |
157 v4->Release(); | |
158 *v3 = 0; | |
159 } | |
2154 | 160 if ( pRenderer->IsGammaSupported() ) |
0 | 161 { |
162 ErrD3D(a2->QueryInterface(IID_IDirectDrawGammaControl, (LPVOID *)v3)); | |
163 GetRamp(); | |
164 memcpy(&v2->field_60C, &v2->pDefaultRamp, 0x600u); | |
165 fGamma = _44F377(&v2->field_60C); | |
166 } | |
167 } |