2496
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6 #include <string>
|
|
7
|
|
8 #include "GammaControl.h"
|
|
9 #include "Render.h"
|
|
10
|
2499
|
11 #include "../mm7_data.h"
|
2496
|
12
|
|
13
|
|
14
|
|
15 //----- (0044F324) --------------------------------------------------------
|
|
16 void GammaController::GetRamp()
|
|
17 {
|
|
18 if (pGammaControl)
|
|
19 ErrD3D(pGammaControl->GetGammaRamp(0, &pDefaultRamp));
|
|
20 }
|
|
21
|
|
22 //----- (0044F377) --------------------------------------------------------
|
|
23 double GammaController::_44F377(DDGAMMARAMP *a1)
|
|
24 {
|
|
25 double v2; // st7@1
|
|
26 unsigned __int16 *v3; // ecx@1
|
|
27 double v4; // st6@2
|
|
28 signed int v6; // [sp+0h] [bp-8h]@1
|
|
29 signed int v7; // [sp+4h] [bp-4h]@1
|
|
30
|
|
31 v2 = 0.0;
|
|
32 v6 = 256;
|
|
33 v3 = a1->green;
|
|
34 for ( v7 = 0; v7 < 256; ++v7 )
|
|
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 ++v3;
|
|
42 }
|
|
43 if ( v6 )
|
|
44 return v2 / (double)v6;
|
|
45 else
|
|
46 return 1.0;
|
|
47 }
|
|
48
|
|
49 //----- (0044F408) --------------------------------------------------------
|
|
50 void GammaController::SetGammaRamp(DDGAMMARAMP *pRamp)
|
|
51 {
|
|
52 if (pGammaControl)
|
|
53 ErrD3D(pGammaControl->SetGammaRamp(0, pRamp));
|
|
54 }
|
|
55
|
|
56 //----- (0044F45B) --------------------------------------------------------
|
|
57 int GammaController::InitGammaRamp(DDGAMMARAMP *pRamp)
|
|
58 {
|
|
59 unsigned __int16 *v2; // esi@1
|
|
60 double v3; // st7@2
|
|
61 signed __int64 v4; // qax@3
|
|
62 signed int v6; // [sp+Ch] [bp-4h]@1
|
|
63
|
|
64 v2 = pRamp->green;
|
|
65 for ( v6 = 0; v6 < 256; ++v6 )
|
|
66 {
|
|
67 v3 = (double)v6 * 0.0039215689 * this->fGamma;
|
|
68 if ( v3 >= 1.0 || (v4 = (signed __int64)(v3 * 65535.0), (signed int)v4 > 65535) )
|
|
69 LODWORD(v4) = 65535;
|
|
70 else if ( (signed int)v4 < 0 )
|
|
71 LODWORD(v4) = 0;
|
|
72 else
|
|
73 {
|
|
74 if ( (signed int)v4 > 65535 )
|
|
75 LODWORD(v4) = 65535;
|
|
76 }
|
|
77 v2[256] = v4;
|
|
78 *v2 = v4;
|
|
79 *(v2 - 256) = v4;
|
|
80 ++v2;
|
|
81 }
|
|
82 return v4;
|
|
83 }
|
|
84
|
|
85 //----- (0044F4D9) --------------------------------------------------------
|
|
86 void GammaController::Initialize(float gamma)
|
|
87 {
|
|
88 double v3; // st7@3
|
|
89 double v4; // st6@4
|
|
90
|
|
91 //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
|
|
92 //pVersion->pVersionInfo.dwMajorVersion != 4)
|
|
93 {
|
|
94 InitializeFromSurface(pRenderer->pFrontBuffer4);
|
|
95 v3 = 2.8;
|
|
96 if ( gamma <= 2.8f )
|
|
97 v4 = gamma;
|
|
98 else
|
|
99 v4 = 2.8;
|
|
100 if ( v4 >= 0.1f )
|
|
101 {
|
|
102 if ( gamma <= 2.8f )
|
|
103 v3 = gamma;
|
|
104 }
|
|
105 else
|
|
106 v3 = 0.1;
|
|
107 this->fGamma = v3;
|
|
108 InitGammaRamp(&this->field_60C);
|
|
109 SetGammaRamp(&this->field_60C);
|
|
110 }
|
|
111 }
|
|
112
|
|
113 //----- (0044F215) --------------------------------------------------------
|
|
114 GammaController::GammaController()
|
|
115 {
|
|
116 static float flt_4D8670_default_gamma = 1.0f;
|
|
117
|
|
118 pGammaControl = nullptr;
|
|
119 fGamma = flt_4D8670_default_gamma;
|
|
120 }
|
|
121
|
|
122 //----- (0044F24B) --------------------------------------------------------
|
|
123 void GammaController::InitializeFromSurface(IDirectDrawSurface4 *a2)
|
|
124 {
|
|
125 this->pSurface = a2;
|
|
126 if ( this->pGammaControl )
|
|
127 {
|
|
128 this->pGammaControl->Release();
|
|
129 this->pGammaControl = 0;
|
|
130 }
|
|
131 if ( pRenderer->IsGammaSupported() )
|
|
132 {
|
|
133 ErrD3D(a2->QueryInterface(IID_IDirectDrawGammaControl, (LPVOID *)&this->pGammaControl));
|
|
134 GetRamp();
|
|
135 memcpy(&this->field_60C, &this->pDefaultRamp, 0x600u);
|
|
136 fGamma = _44F377(&this->field_60C);
|
|
137 }
|
|
138 } |