Mercurial > mm7
annotate GammaControl.cpp @ 2444:c59a8fddb5e8
Слияние
author | Ritor1 |
---|---|
date | Wed, 23 Jul 2014 17:36:56 +0600 |
parents | f4af3b203f65 |
children |
rev | line source |
---|---|
2415 | 1 #define _CRTDBG_MAP_ALLOC |
2 #include <stdlib.h> | |
3 #include <crtdbg.h> | |
4 | |
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
|
5 #define _CRT_SECURE_NO_WARNINGS |
0 | 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; | |
2268 | 36 for ( v7 = 0; v7 < 256; ++v7 ) |
0 | 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 ) | |
2268 | 46 return v2 / (double)v6; |
0 | 47 else |
2268 | 48 return 1.0; |
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; | |
2268 | 69 for ( v6 = 0; v6 < 256; ++v6 ) |
0 | 70 { |
71 v3 = (double)v6 * 0.0039215689 * this->fGamma; | |
72 if ( v3 >= 1.0 || (v4 = (signed __int64)(v3 * 65535.0), (signed int)v4 > 65535) ) | |
2268 | 73 LODWORD(v4) = 65535; |
1421 | 74 else if ( (signed int)v4 < 0 ) |
0 | 75 LODWORD(v4) = 0; |
1421 | 76 else |
77 { | |
0 | 78 if ( (signed int)v4 > 65535 ) |
79 LODWORD(v4) = 65535; | |
1421 | 80 } |
0 | 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 | |
2152 | 95 //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || |
96 //pVersion->pVersionInfo.dwMajorVersion != 4) | |
0 | 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; | |
2268 | 111 this->fGamma = v3; |
112 InitGammaRamp(&this->field_60C); | |
113 SetGammaRamp(&this->field_60C); | |
0 | 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; | |
2268 | 130 if ( this->pGammaControl ) |
0 | 131 { |
2268 | 132 this->pGammaControl->Release(); |
133 this->pGammaControl = 0; | |
0 | 134 } |
2154 | 135 if ( pRenderer->IsGammaSupported() ) |
0 | 136 { |
2268 | 137 ErrD3D(a2->QueryInterface(IID_IDirectDrawGammaControl, (LPVOID *)&this->pGammaControl)); |
0 | 138 GetRamp(); |
2268 | 139 memcpy(&this->field_60C, &this->pDefaultRamp, 0x600u); |
140 fGamma = _44F377(&this->field_60C); | |
0 | 141 } |
142 } |