comparison Engine/Graphics/GammaControl.cpp @ 2496:5abd8fc8f1c6

for ITEM_ARTIFACT_LADYS_ESCORT
author Ritor1
date Thu, 18 Sep 2014 17:38:54 +0600
parents
children 68cdef6879a0
comparison
equal deleted inserted replaced
2495:7b076fe64f23 2496:5abd8fc8f1c6
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
11 #include "mm7_data.h"
12
13
14
15 //----- (0044F324) --------------------------------------------------------
16 void GammaController::GetRamp()
17 {
18 if (pGammaControl)
19 ErrD3D(pGammaControl->GetGammaRamp(0, &pDefaultRamp));
20 else
21 MessageBoxW(nullptr, L"Gamma control not active", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\GammaControl.cpp:83", 0);
22 }
23
24 //----- (0044F377) --------------------------------------------------------
25 double GammaController::_44F377(DDGAMMARAMP *a1)
26 {
27 double v2; // st7@1
28 unsigned __int16 *v3; // ecx@1
29 double v4; // st6@2
30 signed int v6; // [sp+0h] [bp-8h]@1
31 signed int v7; // [sp+4h] [bp-4h]@1
32
33 v2 = 0.0;
34 v6 = 256;
35 v3 = a1->green;
36 for ( v7 = 0; v7 < 256; ++v7 )
37 {
38 v4 = ((double)*(v3 - 256) + (double)v3[256] + (double)*v3) * 0.000015259022 * 0.33333334;
39 if ( v4 == 0.0 )
40 --v6;
41 else
42 v2 = v2 + (double)v7 * 0.0039215689 / v4;
43 ++v3;
44 }
45 if ( v6 )
46 return v2 / (double)v6;
47 else
48 return 1.0;
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 v2 = pRamp->green;
69 for ( v6 = 0; v6 < 256; ++v6 )
70 {
71 v3 = (double)v6 * 0.0039215689 * this->fGamma;
72 if ( v3 >= 1.0 || (v4 = (signed __int64)(v3 * 65535.0), (signed int)v4 > 65535) )
73 LODWORD(v4) = 65535;
74 else if ( (signed int)v4 < 0 )
75 LODWORD(v4) = 0;
76 else
77 {
78 if ( (signed int)v4 > 65535 )
79 LODWORD(v4) = 65535;
80 }
81 v2[256] = v4;
82 *v2 = v4;
83 *(v2 - 256) = v4;
84 ++v2;
85 }
86 return v4;
87 }
88
89 //----- (0044F4D9) --------------------------------------------------------
90 void GammaController::Initialize(float gamma)
91 {
92 double v3; // st7@3
93 double v4; // st6@4
94
95 //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
96 //pVersion->pVersionInfo.dwMajorVersion != 4)
97 {
98 InitializeFromSurface(pRenderer->pFrontBuffer4);
99 v3 = 2.8;
100 if ( gamma <= 2.8f )
101 v4 = gamma;
102 else
103 v4 = 2.8;
104 if ( v4 >= 0.1f )
105 {
106 if ( gamma <= 2.8f )
107 v3 = gamma;
108 }
109 else
110 v3 = 0.1;
111 this->fGamma = v3;
112 InitGammaRamp(&this->field_60C);
113 SetGammaRamp(&this->field_60C);
114 }
115 }
116
117 //----- (0044F215) --------------------------------------------------------
118 GammaController::GammaController()
119 {
120 static float flt_4D8670_default_gamma = 1.0f;
121
122 pGammaControl = nullptr;
123 fGamma = flt_4D8670_default_gamma;
124 }
125
126 //----- (0044F24B) --------------------------------------------------------
127 void GammaController::InitializeFromSurface(IDirectDrawSurface4 *a2)
128 {
129 this->pSurface = a2;
130 if ( this->pGammaControl )
131 {
132 this->pGammaControl->Release();
133 this->pGammaControl = 0;
134 }
135 if ( pRenderer->IsGammaSupported() )
136 {
137 ErrD3D(a2->QueryInterface(IID_IDirectDrawGammaControl, (LPVOID *)&this->pGammaControl));
138 GetRamp();
139 memcpy(&this->field_60C, &this->pDefaultRamp, 0x600u);
140 fGamma = _44F377(&this->field_60C);
141 }
142 }