2496
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
2499
|
6 #include "../ErrorHandling.h"
|
2496
|
7 #include "PaletteManager.h"
|
2499
|
8 #include "../Game.h"
|
|
9 #include "../LOD.h"
|
|
10 #include "../Log.h"
|
|
11 #include "../OurMath.h"
|
2496
|
12
|
2499
|
13 #include "../mm7_data.h"
|
2496
|
14
|
|
15
|
|
16
|
|
17
|
|
18 PaletteManager *pPaletteManager = new PaletteManager;
|
|
19
|
|
20
|
|
21
|
|
22 //----- (00452AE2) --------------------------------------------------------
|
|
23 int __fastcall MakeColorMaskFromBitDepth(int a1)
|
|
24 {
|
|
25 signed __int64 v1; // qax@1
|
|
26
|
|
27 v1 = 4294967296i64;
|
|
28 if ( a1 > 0 )
|
|
29 {
|
|
30 do
|
|
31 {
|
|
32 LODWORD(v1) = HIDWORD(v1) + v1;
|
|
33 HIDWORD(v1) *= 2;
|
|
34 --a1;
|
|
35 }
|
|
36 while ( a1 );
|
|
37 }
|
|
38 return v1;
|
|
39 }
|
|
40
|
|
41 //----- (0048A643) --------------------------------------------------------
|
|
42 bool __fastcall HSV2RGB(float *a1, float *a2, float *a3, float a4, float a5, float a6)
|
|
43 {
|
|
44 float *v6; // ebx@1
|
|
45 float *v7; // edi@1
|
|
46 float *v8; // esi@1
|
|
47 double v9; // st7@5
|
|
48 signed __int64 v10; // qax@5
|
|
49 double v11; // st7@5
|
|
50 double v12; // st5@5
|
|
51 int v13; // eax@6
|
|
52 int v14; // eax@7
|
|
53 int v15; // eax@8
|
|
54 int v16; // eax@9
|
|
55 float v17; // eax@11
|
|
56 float a3a; // [sp+1Ch] [bp+8h]@14
|
|
57 float a4b; // [sp+20h] [bp+Ch]@5
|
|
58 float a4c; // [sp+20h] [bp+Ch]@5
|
|
59 float a4a; // [sp+20h] [bp+Ch]@5
|
|
60
|
|
61 v6 = a3;
|
|
62 v7 = a2;
|
|
63 v8 = a1;
|
|
64 if ( a5 == 0.0 )
|
|
65 {
|
|
66 *a3 = a6;
|
|
67 *a2 = a6;
|
|
68 *a1 = a6;
|
|
69 goto LABEL_20;
|
|
70 }
|
|
71 if ( a4 == 360.0 )
|
|
72 a4 = 0.0;
|
|
73 v9 = a4 * 0.01666666666666667;
|
|
74 a4b = v9;
|
|
75 floor(v9);
|
|
76 v10 = (signed __int64)v9;
|
|
77 a4c = a4b - (double)(signed int)(signed __int64)v9;
|
|
78 v11 = (1.0 - a5) * a6;
|
|
79 v12 = (1.0 - a4c * a5) * a6;
|
|
80 a4a = (1.0 - (1.0 - a4c) * a5) * a6;
|
|
81 if ( (int)v10 )
|
|
82 {
|
|
83 v13 = v10 - 1;
|
|
84 if ( v13 )
|
|
85 {
|
|
86 v14 = v13 - 1;
|
|
87 if ( v14 )
|
|
88 {
|
|
89 v15 = v14 - 1;
|
|
90 if ( v15 )
|
|
91 {
|
|
92 v16 = v15 - 1;
|
|
93 if ( v16 )
|
|
94 {
|
|
95 if ( v16 != 1 )
|
|
96 goto LABEL_20;
|
|
97 *v8 = a6;
|
|
98 v17 = v12;
|
|
99 *v7 = v11;
|
|
100 goto LABEL_12;
|
|
101 }
|
|
102 *(int *)v8 = LODWORD(a4a);
|
|
103 *v7 = v11;
|
|
104 }
|
|
105 else
|
|
106 {
|
|
107 *v8 = v11;
|
|
108 a3a = v12;
|
|
109 *(int *)v7 = LODWORD(a3a);
|
|
110 }
|
|
111 v17 = a6;
|
|
112 }
|
|
113 else
|
|
114 {
|
|
115 *v8 = v11;
|
|
116 *(int *)v7 = LODWORD(a6);
|
|
117 v17 = a4a;
|
|
118 }
|
|
119 LABEL_12:
|
|
120 *(int *)v6 = LODWORD(v17);
|
|
121 goto LABEL_20;
|
|
122 }
|
|
123 *v8 = v12;
|
|
124 *v7 = a6;
|
|
125 }
|
|
126 else
|
|
127 {
|
|
128 *v8 = a6;
|
|
129 *(int *)v7 = LODWORD(a4a);
|
|
130 }
|
|
131 *a3 = v11;
|
|
132 LABEL_20:
|
|
133 if ( *v8 > 1.0 )
|
|
134 *v8 = 1.0;
|
|
135 if ( *v7 > 1.0 )
|
|
136 *v7 = 1.0;
|
|
137 if ( *v6 > 1.0 )
|
|
138 *v6 = 1.0;
|
|
139 if ( *v8 < 0.0 )
|
|
140 *v8 = 0.0;
|
|
141 if ( *v7 < 0.0 )
|
|
142 *v7 = 0.0;
|
|
143 if ( *v6 < 0.0 )
|
|
144 *v6 = 0.0;
|
|
145 return 1;
|
|
146 }
|
|
147
|
|
148 //----- (0048A7AA) --------------------------------------------------------
|
|
149 void __fastcall RGB2HSV(float *a1, float *a2, float a3, float a4, float a5, float *a6)
|
|
150 {
|
|
151 double v6; // st7@2
|
|
152 double v7; // st6@7
|
|
153 double v8; // st5@12
|
|
154 double v9; // st7@15
|
|
155 double v10; // st7@17
|
|
156 // double v11; // st7@21
|
|
157 // __int16 v12; // fps@21
|
|
158 // unsigned __int8 v13; // c0@21
|
|
159 // unsigned __int8 v14; // c2@21
|
|
160 float a6a; // [sp+14h] [bp+14h]@16
|
|
161
|
|
162 if ( a3 <= (double)a4 )
|
|
163 v6 = a4;
|
|
164 else
|
|
165 v6 = a3;
|
|
166 if ( v6 < a5 )
|
|
167 v6 = a5;
|
|
168 if ( a3 <= (double)a4 )
|
|
169 v7 = a3;
|
|
170 else
|
|
171 v7 = a4;
|
|
172 if ( v7 > a5 )
|
|
173 v7 = a5;
|
|
174 *a6 = v6;
|
|
175 if ( v6 == 0.0 )
|
|
176 v8 = 0.0;
|
|
177 else
|
|
178 v8 = (v6 - v7) / v6;
|
|
179 *a2 = v8;
|
|
180 if ( v8 == 0.0 )
|
|
181 {
|
|
182 v9 = 0.0;
|
|
183 //LABEL_23:
|
|
184 *a1 = v9;
|
|
185 return;
|
|
186 }
|
|
187 a6a = v6 - v7;
|
|
188 if ( a3 == v6 )
|
|
189 {
|
|
190 v10 = (a4 - a5) / a6a;
|
|
191 }
|
|
192 else
|
|
193 {
|
|
194 if ( a4 == v6 )
|
|
195 v10 = (a5 - a3) / a6a + 2.0;
|
|
196 else
|
|
197 v10 = (a3 - a4) / a6a + 4.0;
|
|
198 }
|
|
199 //*a1 = v10;
|
|
200 //v11 = *a1 * 60.0;
|
|
201 //UNDEF(v12);
|
|
202 *a1 = v10 * 60.0;
|
|
203 if (*a1 < 0)
|
|
204 {
|
|
205 *a1 += 360.0;
|
|
206 }
|
|
207 }
|
|
208
|
|
209
|
|
210
|
|
211 //----- (0048A8A3) --------------------------------------------------------
|
|
212 int PaletteManager::LockAll()
|
|
213 {
|
|
214 int *v1; // edx@1
|
|
215 signed int v2; // eax@1
|
|
216
|
|
217 v1 = &this->pPaletteIDs[1];
|
|
218 v2 = 1;
|
|
219 do
|
|
220 {
|
|
221 if ( *v1 )
|
|
222 this->_num_locked = v2 + 1;
|
|
223 ++v2;
|
|
224 ++v1;
|
|
225 }
|
|
226 while ( v2 < 50 );
|
|
227 return this->_num_locked;
|
|
228 }
|
|
229
|
|
230 //----- (0048A8CC) --------------------------------------------------------
|
|
231 int PaletteManager::LockTestAll()
|
|
232 {
|
|
233 char *v1; // edx@1
|
|
234 signed int v2; // eax@1
|
|
235
|
|
236 v1 = (char *)&this->pPaletteIDs[1];
|
|
237 v2 = 1;
|
|
238 do
|
|
239 {
|
|
240 if ( *(int *)v1 )
|
|
241 this->_pal_lock_test = v2 + 1;
|
|
242 ++v2;
|
|
243 v1 += 4;
|
|
244 }
|
|
245 while ( v2 < 50 );
|
|
246 return this->_pal_lock_test;
|
|
247 }
|
|
248
|
|
249
|
|
250 //----- (0048A8F5) --------------------------------------------------------
|
|
251 void PaletteManager::SetColorChannelInfo(int uNumRBits, int uNumGBits, int uNumBBits)
|
|
252 {
|
|
253 PaletteManager *v4; // esi@1
|
|
254 int v5; // edi@1
|
|
255 int v6; // eax@1
|
|
256 int v7; // ebx@1
|
|
257
|
|
258 v4 = this;
|
|
259 this->uNumTargetRBits = uNumRBits;
|
|
260 this->uNumTargetGBits = uNumGBits;
|
|
261 v5 = this->uNumTargetGBits;
|
|
262 this->uNumTargetBBits = uNumBBits;
|
|
263 v6 = MakeColorMaskFromBitDepth(uNumRBits);
|
|
264 v7 = v4->uNumTargetBBits;
|
|
265 v4->uTargetRMask = v6 << (v5 + v4->uNumTargetBBits);
|
|
266 v4->uTargetGMask = MakeColorMaskFromBitDepth(v5) << v7;
|
|
267 v4->uTargetBMask = MakeColorMaskFromBitDepth(v7);
|
|
268 }
|
|
269
|
|
270
|
|
271 //----- (00489BE0) --------------------------------------------------------
|
|
272 void PaletteManager::CalcPalettes_LUT(int a2)
|
|
273 {
|
|
274 PaletteManager *v2; // esi@1
|
|
275 //char *v3; // edi@1
|
|
276 //signed int v4; // ebx@4
|
|
277 //float v5; // ST08_4@5
|
|
278 //float v6; // ST04_4@5
|
|
279 //float v7; // ST00_4@5
|
|
280 //int v8; // eax@7
|
|
281 //float *v9; // edx@8
|
|
282 //float *v10; // ST0C_4@8
|
|
283 //float *v11; // ecx@8
|
|
284 //int v12; // ebx@8
|
|
285 //int v13; // eax@8
|
|
286 //float v14; // ebx@8
|
|
287 // float v15; // ST08_4@8
|
|
288 // float v16; // ST04_4@8
|
|
289 // float v17; // ST00_4@8
|
|
290 //unsigned __int8 v18; // sf@8
|
|
291 //unsigned __int8 v19; // of@8
|
|
292 //int v20; // eax@10
|
|
293 double v21; // st5@11
|
|
294 //float v22; // ST0C_4@13
|
|
295 unsigned int v23; // eax@13
|
|
296 //__int16 v24; // bx@16
|
|
297 //int v25; // eax@16
|
|
298 double v26; // st7@20
|
|
299 //float v27; // ST0C_4@22
|
|
300 unsigned int v28; // eax@22
|
|
301 //__int16 v29; // bx@25
|
|
302 //__int16 *v30; // eax@25
|
|
303 //int v31; // eax@27
|
|
304 double v32; // st5@28
|
|
305 //float v33; // ST0C_4@30
|
|
306 //float v34; // ST08_4@30
|
|
307 unsigned int v35; // ebx@30
|
|
308 signed __int64 v36; // qax@33
|
|
309 signed int v37; // edx@33
|
|
310 char v38; // cl@33
|
|
311 unsigned int v39; // ebx@33
|
|
312 signed int v40; // edi@33
|
|
313 unsigned int v41; // ecx@33
|
|
314 unsigned int v42; // ecx@35
|
|
315 //int v43; // eax@39
|
|
316 signed int v44; // edx@39
|
|
317 //unsigned __int8 v45; // al@40
|
|
318 //double v46; // st6@43
|
|
319 //signed int v47; // eax@43
|
|
320 //int v48; // eax@45
|
|
321 double v49; // st6@47
|
|
322 //float v50; // ST08_4@49
|
|
323 //unsigned int v51; // ebx@49
|
|
324 int v52; // edi@55
|
|
325 int v53; // ebx@55
|
|
326 signed __int64 v54; // qax@55
|
|
327 double v55; // st7@56
|
|
328 unsigned int v56; // ecx@57
|
|
329 unsigned int v57; // ecx@59
|
|
330 //int v58; // edx@61
|
|
331 unsigned int v59; // ecx@61
|
|
332 unsigned int v60; // eax@63
|
|
333 char v61; // cl@63
|
|
334 //int result; // eax@63
|
|
335 float v63[256]; // [sp+1Ch] [bp-C38h]@5
|
|
336 float v64[256]; // [sp+41Ch] [bp-838h]@5
|
|
337 float a6[256]; // [sp+81Ch] [bp-438h]@5
|
|
338 // int v66; // [sp+C1Ch] [bp-38h]@43
|
|
339 float v67; // [sp+C20h] [bp-34h]@43
|
|
340 float v68; // [sp+C24h] [bp-30h]@43
|
|
341 //PaletteManager *v69; // [sp+C28h] [bp-2Ch]@9
|
|
342 //float v70; // [sp+C2Ch] [bp-28h]@43
|
|
343 //double v71; // [sp+C30h] [bp-24h]@10
|
|
344 //int v72; // [sp+C38h] [bp-1Ch]@9
|
|
345 //int v73; // [sp+C3Ch] [bp-18h]@9
|
|
346 //int i; // [sp+C40h] [bp-14h]@7
|
|
347 //float v75; // [sp+C44h] [bp-10h]@5
|
|
348 float a2a; // [sp+C48h] [bp-Ch]@13
|
|
349 float a1; // [sp+C4Ch] [bp-8h]@13
|
|
350 float a3; // [sp+C50h] [bp-4h]@13
|
|
351 signed int v79; // [sp+C5Ch] [bp+8h]@33
|
|
352 //signed int v80; // [sp+C5Ch] [bp+8h]@43
|
|
353 int v81; // [sp+C5Ch] [bp+8h]@57
|
|
354
|
|
355 v2 = this;
|
|
356 //v3 = (char *)pBaseColors[a2];
|
|
357 if (pPalette_tintColor[0] || pPalette_tintColor[1] || pPalette_tintColor[2])
|
|
358 {
|
|
359 //v8 = 0;
|
|
360 //i = 0;
|
|
361
|
|
362 for (uint i = 0; i < 256; ++i)
|
|
363 RGB2HSV(&v64[i], &v63[i], (pBaseColors[a2][i][0] + pPalette_tintColor[0]) / (255.0f + 255.0f), //Uninitialized memory access
|
|
364 (pBaseColors[a2][i][1] + pPalette_tintColor[1]) / (255.0f + 255.0f),
|
|
365 (pBaseColors[a2][i][2] + pPalette_tintColor[2]) / (255.0f + 255.0f), &a6[i]);
|
|
366 //do
|
|
367 //{
|
|
368 //v9 = (float *)((char *)v63 + v8);
|
|
369 //v10 = (float *)((char *)a6 + v8);
|
|
370 //v11 = (float *)((char *)v64 + v8);
|
|
371 //v12 = pPalette_tintColor[1];
|
|
372 //LODWORD(v75) = pPalette_tintColor[2] + (unsigned __int8)v3[2];
|
|
373 //v13 = pPalette_tintColor[1] + (unsigned __int8)v3[1];
|
|
374 //LODWORD(v14) = (unsigned __int8)*v3;
|
|
375 //v15 = (double)((unsigned __int8)v3[2] + pPalette_tintColor[2]) / (2.0f * 255.0f);
|
|
376 //LODWORD(v75) = v13;
|
|
377 //LODWORD(v75) = (unsigned __int8)*v3 + pPalette_tintColor[0];
|
|
378 //v16 = (double)((unsigned __int8)v3[1] + pPalette_tintColor[1]) / 510.0f;
|
|
379 //v17 = (double)((unsigned __int8)*v3 + pPalette_tintColor[0]) / 510.0f;
|
|
380 //RGB2HSV(&v64[i], &v63[i], v17, v16, v15, &a6[i]);
|
|
381 //v3 += 3;
|
|
382 //v8 = i + 4;
|
|
383 //v19 = __OFSUB__(i + 4, 1024);
|
|
384 //v18 = i - 1020 < 0;
|
|
385 //i += 4;
|
|
386 //}
|
|
387 //while ( i < );
|
|
388 }
|
|
389 else
|
|
390 {
|
|
391 for (uint i = 0; i < 256; ++i)
|
|
392 RGB2HSV(&v64[i], &v63[i], pBaseColors[a2][i][0] / 255.0f,
|
|
393 pBaseColors[a2][i][1] / 255.0f,
|
|
394 pBaseColors[a2][i][2] / 255.0f, &a6[i]);
|
|
395 /*v4 = 0;
|
|
396 do
|
|
397 {
|
|
398 LODWORD(v75) = (unsigned __int8)v3[2];
|
|
399 v5 = (double)SLODWORD(v75) * 0.00392156862745098;
|
|
400 LODWORD(v75) = (unsigned __int8)v3[1];
|
|
401 v6 = (double)SLODWORD(v75) * 0.00392156862745098;
|
|
402 LODWORD(v75) = (unsigned __int8)*v3;
|
|
403 v7 = (double)SLODWORD(v75) * 0.00392156862745098;
|
|
404 RGB2HSV(&v64[v4], &v63[v4], v7, v6, v5, &a6[v4]);
|
|
405 ++v4;
|
|
406 v3 += 3;
|
|
407 }
|
|
408 while ( v4 < 256 );*/
|
|
409 }
|
|
410
|
|
411 //v69 = (PaletteManager *)((char *)v2 + 16384 * a2);
|
|
412 //v72 = 0;
|
|
413 //v73 = (int)pPalette1[a2];
|
|
414 for (uint i = 0; i < 32; ++i)
|
|
415 //do
|
|
416 {
|
|
417 //v20 = 0;
|
|
418 //i = 0;
|
|
419 //v71 = 1.0 - (double)v72 / 31.0f;
|
|
420 //do
|
|
421 for (uint j = 0; j < 256; ++j)
|
|
422 {
|
|
423 v21 = a6[j] * (1.0f - i / 32.0f);
|
|
424 if ( v21 < 0.0 )
|
|
425 v21 = 0.0;
|
|
426
|
|
427 //v22 = v21;
|
|
428 HSV2RGB(&a1, &a2a, &a3, v64[j], v63[j], v21);
|
|
429 v23 = v2->uNumTargetGBits;
|
|
430 if ( v23 == 6 ) // r5g6b5
|
|
431 {
|
|
432 a1 = a1 * 31.0;
|
|
433 a2a = a2a * 62.0;
|
|
434 a3 = a3 * 31.0;
|
|
435 }
|
|
436 else if (v23 == 5) // r5g5b5
|
|
437 {
|
|
438 a1 = a1 * 31.0;
|
|
439 a2a = a2a * 31.0;
|
|
440 a3 = a3 * 31.0;
|
|
441 }
|
|
442 else if (v23 == 0)
|
|
443 Log::Warning(L"Calling palette manager with num_target_bits == 0");
|
|
444 else Error("(%u)", v23);
|
|
445 //v24 = (unsigned __int32)a3 | ((unsigned __int32)a2a << v2->uNumTargetBBits) | ((unsigned __int32)a1 << (v2->uNumTargetBBits + v2->uNumTargetGBits));
|
|
446 //v25 = v73;
|
|
447 //v73 += 2;
|
|
448 //*(short *)v25 = v24;
|
|
449 pPalette1[a2][i][j] = (unsigned __int32)a3 |
|
|
450 ((unsigned __int32)a2a << v2->uNumTargetBBits) |
|
|
451 ((unsigned __int32)a1 << (v2->uNumTargetBBits + v2->uNumTargetGBits));
|
|
452 //v20 = i + 4;
|
|
453 //v19 = __OFSUB__(i + 4, 1024);
|
|
454 //v18 = i - 1020 < 0;
|
|
455 //i += 4;
|
|
456 }
|
|
457 //while ( v18 ^ v19 );
|
|
458 //++v72;
|
|
459 }
|
|
460 //while ( v72 < 32 );
|
|
461
|
|
462 //v72 = 0;
|
|
463 //v73 = (int)v69->field_199600_palettes;
|
|
464 //do
|
|
465 for (uint i = 0; i < 32; ++i)
|
|
466 {
|
|
467 //i = 0;
|
|
468 //v71 = 1.0 - (double)v72 / 31.0f;
|
|
469 //do
|
|
470 for (uint j = 0; j < 256; ++j)
|
|
471 {
|
|
472 v26 = a6[j] * (1.0 - i / 31.0f);
|
|
473 if ( v26 < 0.0 )
|
|
474 v26 = 0.0;
|
|
475
|
|
476 //v27 = v26;
|
|
477 HSV2RGB(&a1, &a2a, &a3, 1.0, 1.0, v26);
|
|
478 v28 = v2->uNumTargetGBits;
|
|
479 if ( v28 == 6 )
|
|
480 {
|
|
481 a1 = a1 * 31.0;
|
|
482 a2a = a2a * 62.0;
|
|
483 a3 = a3 * 31.0;
|
|
484 }
|
|
485 else if (v28 == 5)
|
|
486 {
|
|
487 a1 = a1 * 31.0;
|
|
488 a2a = a2a * 31.0;
|
|
489 a3 = a3 * 31.0;
|
|
490 }
|
|
491 else if (v23 == 0)
|
|
492 Log::Warning(L"Calling palette manager with num_target_bits == 0");
|
|
493 else Error("(%u)", v23);
|
|
494
|
|
495 //v29 = (unsigned __int64)(signed __int64)a3 | ((unsigned __int16)(signed __int64)a2a << v2->uNumTargetBBits) | (unsigned __int16)((unsigned __int16)(signed __int64)a1 << (v2->uNumTargetBBits + v28));
|
|
496 //v30 = (__int16 *)v73;
|
|
497 //++i;
|
|
498 //v73 += 2;
|
|
499 //v19 = __OFSUB__(i, 256);
|
|
500 //v18 = i - 256 < 0;
|
|
501 //*v30 = v29;
|
|
502 field_199600_palettes[a2][i][j] = (unsigned __int64)(signed __int64)a3 | ((unsigned __int16)(signed __int64)a2a << v2->uNumTargetBBits) | (unsigned __int16)((unsigned __int16)(signed __int64)a1 << (v2->uNumTargetBBits + v28));
|
|
503 }
|
|
504 //while ( v18 ^ v19 );
|
|
505 //++v72;
|
|
506 }
|
|
507 //while ( v72 < 32 );
|
|
508
|
|
509 //v73 = (int)((char *)v2 + 512 * (a2 + 4875)); // field_261600[a2]
|
|
510 //v31 = 0;
|
|
511 //i = 0;
|
|
512 for (uint i = 0; i < 256; ++i)
|
|
513 //do
|
|
514 {
|
|
515 //v32 = (*(float *)((char *)a6 + v31) - 0.8) * 0.8387096774193549 + 0.8;
|
|
516 v32 = (a6[i] - 0.8f) * 0.8387096774193549 + 0.8;
|
|
517 if ( v32 < 0.0 )
|
|
518 v32 = 0.0;
|
|
519
|
|
520 //v33 = v32;
|
|
521 //v34 = v63[i] * 0.7034339229968783;
|
|
522 HSV2RGB(&a1, &a2a, &a3, v64[i], v63[i] * 0.7034339229968783, v32);
|
|
523 v35 = v2->uNumTargetGBits;
|
|
524 if ( v35 == 6 )
|
|
525 {
|
|
526 a1 = a1 * 31.0;
|
|
527 a2a = a2a * 62.0;
|
|
528 a3 = a3 * 31.0;
|
|
529 }
|
|
530 else if (v35 == 5)
|
|
531 {
|
|
532 a1 = a1 * 31.0;
|
|
533 a2a = a2a * 31.0;
|
|
534 a3 = a3 * 31.0;
|
|
535 }
|
|
536 else if (v23 == 0)
|
|
537 Log::Warning(L"Calling palette manager with num_target_bits == 0");
|
|
538 else Error("(%u)", v23);
|
|
539
|
|
540 v36 = (signed __int64)((a1 + a2a + a3) * 0.3333333333333333 * 8.0);
|
|
541 v37 = (signed int)v36 >> (8 - v2->uNumTargetRBits);
|
|
542 v38 = 8 - v35;
|
|
543 v39 = v2->uNumTargetBBits;
|
|
544 v40 = (signed int)v36 >> v38;
|
|
545 v41 = v2->uNumTargetRBits;
|
|
546 v79 = (signed int)v36 >> (8 - v39);
|
|
547 if ( v37 > (1 << v41) - 1 )
|
|
548 v37 = (1 << v41) - 1;
|
|
549 v42 = v2->uNumTargetGBits;
|
|
550 if ( v40 > (1 << v42) - 1 )
|
|
551 v40 = (1 << v42) - 1;
|
|
552 if ( v79 > (1 << v39) - 1 )
|
|
553 v79 = (1 << v39) - 1;
|
|
554 //v43 = v73;
|
|
555 v44 = v37 << (v39 + v2->uNumTargetGBits);
|
|
556 //v73 += 2;
|
|
557 //*(short *)v43 = v79 | ((short)v40 << v39) | (unsigned __int16)v44;
|
|
558 field_261600[a2][i] = v79 | ((unsigned short)v40 << v39) | (unsigned __int16)v44;
|
|
559 //v31 = i + 4;
|
|
560 //v19 = __OFSUB__(i + 4, 1024);
|
|
561 //v18 = i - 1020 < 0;
|
|
562 //i += 4;
|
|
563 }
|
|
564 //while ( v18 ^ v19 );
|
|
565
|
|
566 //v45 = pPalette_mistColor[0];
|
|
567 float mist_a, mist_b, mist_c;
|
|
568 if (pPalette_mistColor[0] || pPalette_mistColor[1] || pPalette_mistColor[2])
|
|
569 {
|
|
570 //v46 = (double)v45;
|
|
571 //v80 = pPalette_mistColor[1];
|
|
572 //v47 = pPalette_mistColor[2];
|
|
573 //v70 = v46 * 0.00392156862745098;
|
|
574 //*((float *)&v71 + 1) = (double)v80 * 0.00392156862745098;
|
|
575 //v75 = (double)v47 * 0.00392156862745098;
|
|
576 mist_a = pPalette_mistColor[0] / 255.0f;
|
|
577 mist_b = pPalette_mistColor[1] / 255.0f;
|
|
578 mist_c = pPalette_mistColor[2] / 255.0f;
|
|
579
|
|
580 float unused;
|
|
581 RGB2HSV(&v68, &v67, mist_a, mist_b, mist_c, &unused);
|
|
582 }
|
|
583
|
|
584 //v72 = 0;
|
|
585 //v73 = (int)v69->field_D1600;
|
|
586 //do
|
|
587 for (uint i = 0; i < 32; ++i)
|
|
588 {
|
|
589 //v48 = 0;
|
|
590 //for ( i = 0; ; v48 = i )
|
|
591 for (uint j = 0; j < 256; ++j)
|
|
592 {
|
|
593 v49 = v63[j];
|
|
594 if ( v49 < 0.0 )
|
|
595 v49 = 0.0;
|
|
596
|
|
597 //v50 = v49;
|
|
598 HSV2RGB(&a1, &a2a, &a3, v64[j], v49, a6[j]);
|
|
599 //v51 = v2->uNumTargetGBits;
|
|
600 if ( v2->uNumTargetGBits == 6 )
|
|
601 {
|
|
602 a1 = a1 * 31.0;
|
|
603 a2a = a2a * 62.0;
|
|
604 a3 = a3 * 31.0;
|
|
605 }
|
|
606 else if (v2->uNumTargetGBits == 5)
|
|
607 {
|
|
608 a1 = a1 * 31.0;
|
|
609 a2a = a2a * 31.0;
|
|
610 a3 = a3 * 31.0;
|
|
611 }
|
|
612 else if (v23 == 0)
|
|
613 Log::Warning(L"Calling palette manager with num_target_bits == 0");
|
|
614 else Error("(%u)", v23);
|
|
615
|
|
616 if (pPalette_mistColor[0] || pPalette_mistColor[1] || pPalette_mistColor[2])
|
|
617 {
|
|
618 v55 = (double)i / 31.0f;
|
|
619 v52 = (signed __int64)((double)(1 << v2->uNumTargetRBits) * mist_a * v55 + a1 * (1.0 - v55));
|
|
620 v53 = (signed __int64)((double)(1 << v2->uNumTargetGBits) * mist_b * v55 + a2a * (1.0 - v55));
|
|
621 v54 = (signed __int64)((double)(1 << v2->uNumTargetBBits) * mist_c * v55 + a3 * (1.0 - v55));
|
|
622 }
|
|
623 else
|
|
624 {
|
|
625 v52 = (signed __int64)a1;
|
|
626 v53 = (signed __int64)a2a;
|
|
627 v54 = (signed __int64)a3;
|
|
628 }
|
|
629
|
|
630 v56 = v2->uNumTargetRBits;
|
|
631 v81 = v54;
|
|
632 if ( v52 > (1 << v56) - 1 )
|
|
633 v52 = (1 << v56) - 1;
|
|
634 v57 = v2->uNumTargetGBits;
|
|
635 if ( v53 > (1 << v57) - 1 )
|
|
636 v53 = (1 << v57) - 1;
|
|
637 HIDWORD(v54) = v2->uNumTargetBBits;
|
|
638 v59 = v2->uNumTargetBBits;
|
|
639 if ( (signed int)v54 > (1 << v59) - 1 )
|
|
640 v81 = (1 << v59) - 1;
|
|
641 v60 = v2->uNumTargetGBits;
|
|
642 //i += 4;
|
|
643 v61 = uNumTargetBBits + v60;
|
|
644 //result = v73;
|
|
645 //v73 += 2;
|
|
646 //v19 = __OFSUB__(i, 1024);
|
|
647 //v18 = i - 1024 < 0;
|
|
648 //*(short *)result = v81 | ((short)v53 << uNumTargetBBits) | (v52 << v61);
|
|
649 field_D1600[a2][i][j] = v81 | ((short)v53 << uNumTargetBBits) | (v52 << v61);
|
|
650 //if ( !(v18 ^ v19) )
|
|
651 // break;
|
|
652 }
|
|
653 //++v72;
|
|
654 }
|
|
655 //while ( v72 < 32 );
|
|
656 }
|
|
657
|
|
658
|
|
659 //----- (0048A300) --------------------------------------------------------
|
|
660 PaletteManager::PaletteManager():
|
|
661 uNumTargetRBits(0), uNumTargetGBits(0),uNumTargetBBits(0),_num_locked(0)
|
|
662 {
|
|
663 for (uint i = 0; i < 256; ++i)
|
|
664 {
|
|
665 pBaseColors[0][i][0] = i;
|
|
666 pBaseColors[0][i][1] = i;
|
|
667 pBaseColors[0][i][2] = i;
|
|
668 }
|
|
669
|
|
670 memset(pPaletteIDs, 0, sizeof(pPaletteIDs));
|
|
671 memset(pPalette_tintColor, 0, sizeof(pPalette_tintColor));
|
|
672 memset(pPalette_mistColor, 0, sizeof(pPalette_mistColor));
|
|
673 CalcPalettes_LUT(0);
|
|
674 }
|
|
675
|
|
676 //----- (0048A336) --------------------------------------------------------
|
|
677 // make grayscale palette at 0, clear all palettes ids that aren't locked
|
|
678 int PaletteManager::ResetNonLocked()
|
|
679 {
|
|
680 PaletteManager *v1; // esi@1
|
|
681 signed int v2; // ecx@1
|
|
682 int v3; // eax@1
|
|
683 signed int result; // eax@3
|
|
684 void *v5; // edi@4
|
|
685 int v6; // ecx@4
|
|
686
|
|
687 v1 = this;
|
|
688 v2 = 0;
|
|
689 v3 = (int)&v1->pBaseColors[0][0][1];
|
|
690 do
|
|
691 {
|
|
692 *(char *)(v3 + 1) = v2;
|
|
693 *(char *)v3 = v2;
|
|
694 *(char *)(v3 - 1) = v2++;
|
|
695 v3 += 3;
|
|
696 }
|
|
697 while ( v2 < 256 );
|
|
698 CalcPalettes_LUT(0);
|
|
699 result = v1->_num_locked;
|
|
700 if ( result < 50 )
|
|
701 {
|
|
702 v5 = &v1->pPaletteIDs[result];
|
|
703 v6 = 50 - result;
|
|
704 result = 0;
|
|
705 memset(v5, 0, 4 * v6);
|
|
706 }
|
|
707 return result;
|
|
708 }
|
|
709
|
|
710 //----- (0048A379) --------------------------------------------------------
|
|
711 // make grayscale palette at 0, clear all palettes ids that aren't in "lock_test"
|
|
712 int PaletteManager::ResetNonTestLocked()
|
|
713 {
|
|
714 PaletteManager *v1; // esi@1
|
|
715 signed int v2; // ecx@1
|
|
716 int v3; // eax@1
|
|
717 signed int result; // eax@3
|
|
718 void *v5; // edi@4
|
|
719 int v6; // ecx@4
|
|
720
|
|
721 v1 = this;
|
|
722 v2 = 0;
|
|
723 v3 = (int)&v1->pBaseColors[0][0][1];
|
|
724 do
|
|
725 {
|
|
726 *(char *)(v3 + 1) = v2;
|
|
727 *(char *)v3 = v2;
|
|
728 *(char *)(v3 - 1) = v2++;
|
|
729 v3 += 3;
|
|
730 }
|
|
731 while ( v2 < 256 );
|
|
732 CalcPalettes_LUT(0);
|
|
733 result = v1->_pal_lock_test;
|
|
734 if ( result < 50 )
|
|
735 {
|
|
736 v5 = &v1->pPaletteIDs[result];
|
|
737 v6 = 50 - result;
|
|
738 result = 0;
|
|
739 memset(v5, 0, 4 * v6);
|
|
740 }
|
|
741 return result;
|
|
742 }
|
|
743
|
|
744 //----- (0048A3BC) --------------------------------------------------------
|
|
745 int PaletteManager::LoadPalette(unsigned int uPaletteID)
|
|
746 {
|
|
747 unsigned int *v2; // ecx@1
|
|
748 signed int result; // eax@1
|
|
749 signed int v4; // esi@6
|
|
750 double v5; // st7@7
|
|
751 double v6; // st7@12
|
|
752 double v7; // st6@17
|
|
753 signed __int64 v8; // qax@17
|
|
754 double v9; // st6@17
|
|
755 char v10[768]; // [sp+18h] [bp-388h]@6
|
|
756 //char v11; // [sp+19h] [bp-387h]@17
|
|
757 //char v12[766]; // [sp+1Ah] [bp-386h]@17
|
|
758 char Source[32]; // [sp+360h] [bp-40h]@4
|
|
759 //PaletteManager *v15; // [sp+380h] [bp-20h]@1
|
|
760 float v16; // [sp+384h] [bp-1Ch]@7
|
|
761 int v17; // [sp+388h] [bp-18h]@6
|
|
762 float v18; // [sp+38Ch] [bp-14h]@7
|
|
763 float a2a; // [sp+390h] [bp-10h]@7
|
|
764 float a1; // [sp+394h] [bp-Ch]@7
|
|
765 float a6; // [sp+398h] [bp-8h]@7
|
|
766 float a3; // [sp+39Ch] [bp-4h]@7
|
|
767
|
|
768 //v15 = this;
|
|
769 v2 = (unsigned int *)&this->pPaletteIDs[1];
|
|
770 result = 1;
|
|
771 while ( *v2 != uPaletteID )
|
|
772 {
|
|
773 ++result;
|
|
774 ++v2;
|
|
775 if ( result >= 50 )
|
|
776 {
|
|
777 sprintf(Source, "pal%03i", uPaletteID);
|
|
778
|
|
779 Texture tex; // [sp+318h] [bp-88h]@4
|
|
780 //Texture::Texture(&tex);
|
|
781
|
|
782 if ( pBitmaps_LOD->LoadTextureFromLOD(&tex, Source, TEXTURE_24BIT_PALETTE) == 1 )
|
|
783 {
|
|
784 v4 = 0;
|
|
785 v17 = 1 - (int)&v10;
|
|
786 do
|
|
787 {
|
|
788 //LODWORD(a1) = tex.pPalette24[v4];
|
|
789 a1 = (double)tex.pPalette24[v4] / 255.0f;
|
|
790 LODWORD(a2a) = (unsigned __int8)*(&v10 + v4 + v17 + (unsigned int)tex.pPalette24);
|
|
791 a2a = (double)tex.pPalette24[v4 + 1] / 255.0f;
|
|
792 //a3 = tex.pPalette24[v4 + 2];
|
|
793 a3 = (double)tex.pPalette24[v4 + 2] / 255.0f;
|
|
794 RGB2HSV(&v16, &v18, a1, a2a, a3, &a6);
|
|
795 v5 = a6 * 1.1;
|
|
796 if ( v5 >= 0.0 && v5 >= 1.0 )
|
|
797 v5 = 1.0;
|
|
798 else
|
|
799 {
|
|
800 if ( v5 < 0.0 )
|
|
801 v5 = 0.0;
|
|
802 }
|
|
803 a6 = v5;
|
|
804 v6 = v18 * 0.64999998;
|
|
805 if ( v6 >= 0.0 && v6 >= 1.0 )
|
|
806 v6 = 1.0;
|
|
807 else
|
|
808 {
|
|
809 if ( v6 < 0.0 )
|
|
810 v6 = 0.0;
|
|
811 }
|
|
812 v18 = v6;
|
|
813 HSV2RGB(&a1, &a2a, &a3, v16, v18, a6);
|
|
814 v7 = a2a * 255.0;
|
|
815 v10[v4] = (signed __int64)(a1 * 255.0);
|
|
816 v8 = (signed __int64)v7;
|
|
817 v9 = a3 * 255.0;
|
|
818 v10[v4 + 1] = v8;
|
|
819 v10[v4 + 2] = (signed __int64)v9;
|
|
820 v4 += 3;
|
|
821 }
|
|
822 while ( v4 < 768 );
|
|
823 tex.Release();
|
|
824 result = this->MakeBasePaletteLut(uPaletteID, v10);
|
|
825 }
|
|
826 else
|
|
827 result = 0;
|
|
828 return result;
|
|
829 }
|
|
830 }
|
|
831 return result;
|
|
832 }
|
|
833 // 48A3BC: using guessed type char var_386[766];
|
|
834
|
|
835 //----- (0048A5A4) --------------------------------------------------------
|
|
836 int PaletteManager::MakeBasePaletteLut(int idx, char *entries)
|
|
837 {
|
|
838 //PaletteManager *v3; // edi@1
|
|
839 //signed int result; // eax@1
|
|
840 //int *v5; // ecx@1
|
|
841 int v6; // eax@4
|
|
842 int v7; // esi@4
|
|
843 //int v8; // eax@9
|
|
844 //signed int v9; // ecx@9
|
|
845 //int v10; // edx@9
|
|
846
|
|
847 //v3 = this;
|
|
848 //result = 0;
|
|
849 //v5 = this->pPaletteIDs;
|
|
850
|
|
851 for (uint i = 0; i < 50; ++i)
|
|
852 if (pPaletteIDs[i] == idx)
|
|
853 return i;
|
|
854
|
|
855 v6 = (int)&pPaletteIDs[1];
|
|
856 v7 = 1;
|
|
857 while ( *(int *)v6 )
|
|
858 {
|
|
859 ++v7;
|
|
860 v6 += 4;
|
|
861 if ( v7 >= 50 )
|
|
862 return 0;
|
|
863 }
|
|
864 /*v8 = (int)pBaseColors[v7];//(int)((char *)v3 + 768 * v7);
|
|
865 v9 = 768;
|
|
866 v10 = (int)(entries - v8);
|
|
867 do
|
|
868 {
|
|
869 *(char *)v8 = *(char *)(v10 + v8);
|
|
870 ++v8;
|
|
871 --v9;
|
|
872 }
|
|
873 while ( v9 );*/
|
|
874 unsigned __int8 *dst = (unsigned __int8 *)pBaseColors[v7];
|
|
875 for (uint i = 0; i < 768; ++i)
|
|
876 dst[i] = entries[i];
|
|
877
|
|
878 pPaletteIDs[v7] = idx;
|
|
879 CalcPalettes_LUT(v7);
|
|
880 return v7;
|
|
881
|
|
882 }
|
|
883
|
|
884 // inlined
|
|
885 //----- (mm6c::0045C610) ---------------------------------------------------
|
|
886 void PaletteManager::SetMistColor(unsigned char r, unsigned char g, unsigned char b)
|
|
887 {
|
|
888 pPalette_mistColor[0] = r;
|
|
889 pPalette_mistColor[1] = g;
|
|
890 pPalette_mistColor[2] = b;
|
|
891 }
|
|
892
|
|
893 //----- (0048A614) --------------------------------------------------------
|
|
894 void PaletteManager::RecalculateAll()
|
|
895 {
|
|
896 CalcPalettes_LUT(0);
|
|
897
|
|
898 for (uint i = 1; i < 50; ++i)
|
|
899 if (pPaletteIDs[i])
|
|
900 CalcPalettes_LUT(i);
|
|
901 }
|
|
902
|
|
903
|
|
904 //----- (0047BE67) --------------------------------------------------------
|
|
905 unsigned __int16 *PaletteManager::Get(int a1)
|
|
906 {
|
|
907 return (unsigned __int16 *)pPaletteManager->field_199600_palettes[a1];
|
|
908 }
|
|
909
|
|
910 //----- (0047BE72) --------------------------------------------------------
|
|
911 unsigned __int16 *PaletteManager::Get_Mist_or_Red_LUT(int a1, int a2, char a3)
|
|
912 {
|
|
913 int v3; // eax@4
|
|
914
|
|
915 if ( a3 & 2 || byte_4D864C && BYTE2(pGame->uFlags) & 4 )
|
|
916 v3 = 32 * a1 + a2 + 3275;
|
|
917 else
|
|
918 v3 = 32 * a1 + a2 + 1675;
|
|
919 return (unsigned __int16 *)((char *)&pPaletteManager + 512 * v3);
|
|
920 }
|
|
921 // 4D864C: using guessed type char byte_4D864C;
|
|
922
|
|
923
|
|
924 //----- (0041F50D) --------------------------------------------------------
|
|
925 unsigned __int16 *PaletteManager::Get_Dark_or_Red_LUT(int a1, int a2, char a3)
|
|
926 {
|
|
927 int v3; // eax@4
|
|
928
|
|
929 if ( a3 & 2 || byte_4D864C && BYTE2(pGame->uFlags) & 4 )
|
|
930 v3 = 32 * a1 + a2 + 3275;
|
|
931 else
|
|
932 v3 = 32 * a1 + a2 + 75;
|
|
933 return (unsigned __int16 *)((char *)&pPaletteManager + 512 * v3);
|
|
934 }
|
|
935 // 4D864C: using guessed type char byte_4D864C;
|
|
936
|
|
937
|
|
938 //----- (0047C30E) --------------------------------------------------------
|
|
939 unsigned __int16 *PaletteManager::_47C30E_get_palette(int a1, char a2)
|
|
940 {
|
|
941 char *result; // eax@4
|
|
942
|
|
943 if ( a2 & 2 || byte_4D864C && BYTE2(pGame->uFlags) & 4 )
|
|
944 result = (char *)pPaletteManager->field_199600_palettes[a1];
|
|
945 else
|
|
946 result = (char *)pPaletteManager->field_D1600[a1];
|
|
947 return (unsigned __int16 *)result;
|
|
948 }
|
|
949
|
|
950
|
|
951 //----- (0047C33F) --------------------------------------------------------
|
|
952 unsigned __int16 *PaletteManager::_47C33F_get_palette(int a1, char a2)
|
|
953 {
|
|
954 unsigned __int16 *result; // eax@4
|
|
955
|
|
956 if ( a2 & 2 || byte_4D864C && BYTE2(pGame->uFlags) & 4 )
|
|
957 result = (unsigned __int16 *)pPaletteManager->field_199600_palettes[a1];
|
|
958 else
|
|
959 result = (unsigned __int16 *)pPaletteManager->pPalette1[a1];
|
|
960 return result;
|
|
961 }
|
|
962 // 4D864C: using guessed type char byte_4D864C;
|
|
963
|
|
964
|
|
965 //----- (0048A959) --------------------------------------------------------
|
|
966 signed int ReplaceHSV(unsigned int uColor, float h_replace, float s_replace, float v_replace)
|
|
967 {
|
|
968 float r = ((uColor & 0x00FF0000) >> 16) / 255.0f,
|
|
969 g = ((uColor & 0x0000FF00) >> 8) / 255.0f,
|
|
970 b = (uColor & 0x000000FF) / 255.0f;
|
|
971
|
|
972 float h, s, v;
|
|
973 RGB2HSV(&h, &s, r, g, b, &v);
|
|
974
|
|
975 if ( h_replace != -1.0 )
|
|
976 h = h_replace;
|
|
977 if ( s_replace != -1.0 )
|
|
978 s = s_replace;
|
|
979 if ( v_replace != -1.0 )
|
|
980 v = v_replace;
|
|
981 HSV2RGB(&r, &g, &b, h, s, v);
|
|
982
|
|
983 return (((uint)round_to_int(r * 255.0f) & 0xFF) << 16) |
|
|
984 (((uint)round_to_int(g * 255.0f) & 0xFF) << 8) |
|
|
985 (((uint)round_to_int(b * 255.0f) & 0xFF));
|
|
986 } |