Mercurial > mm7
annotate Texture.cpp @ 1209:decc0dd6e4ba
more on arcomage
author | Gloval |
---|---|
date | Sun, 09 Jun 2013 13:20:34 +0400 |
parents | 96a81634669e |
children | 0aeac0b9ca30 |
rev | line source |
---|---|
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1119
diff
changeset
|
1 #ifdef _MSC_VER |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1119
diff
changeset
|
2 #define _CRT_SECURE_NO_WARNINGS |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1119
diff
changeset
|
3 #endif |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1119
diff
changeset
|
4 |
0 | 5 #include <stdlib.h> |
6 | |
7 #include "Texture.h" | |
8 #include "FrameTableInc.h" | |
9 #include "Allocator.h" | |
10 #include "LOD.h" | |
11 #include "PaletteManager.h" | |
12 #include "Render.h" | |
13 | |
14 #include "mm7_data.h" | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 struct TextureFrameTable *pTextureFrameTable; | |
26 | |
27 | |
28 | |
29 | |
30 | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
31 std::array<Texture *, 2> pTexture_LloydBeacons; |
0 | 32 Texture *pTexture_50635C; |
33 Texture *pTexture_506368; | |
34 Texture *pTexture_50636C; | |
35 Texture *pTexture_506370; | |
36 Texture *pTexture_506374; | |
37 Texture *pTexture_506378; | |
38 Texture *pTexture_50637C; | |
39 Texture *pTexture_506380; | |
40 Texture *pTexture_506384; | |
41 Texture *pTexture_506388; | |
42 Texture *pTexture_50638C; | |
43 Texture *pTexture_506390; | |
44 Texture *pTexture_506394; | |
45 Texture *pTex_tab_an_7a__zoot_off; | |
46 Texture *pTex_tab_an_6a__zoom_off; | |
47 Texture *pTex_tab_an_7b__zoot_on; | |
48 Texture *pTex_tab_an_6b__zoom_on; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
49 std::array<Texture *, 6> pTexture_TownPortalIcons; // [0]Harmonale, [1]Pierpont, [2]Nighon, [3]Evenmorn Island, [4]Celestia, [5]The Pit |
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
50 std::array<Texture *, 12> dword_5063D8; |
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
51 std::array<Texture *, 12> dword_506408; |
0 | 52 Texture *pTexture_50643C; // idb |
53 Texture *ptr_506440; | |
54 Texture *pTexture_506444; | |
55 Texture *pTexture_506448; // idb | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
56 std::array<std::array<Texture *, 2>, 9> pTextures_tabs; |
0 | 57 Texture *pTexture_mapbordr; // idb |
58 Texture *pTexture_pagemask; // idb | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
59 std::array<Texture *, 9> pSpellBookPagesTextr; |
688 | 60 Texture *pSpellBookPagesTextr_9; |
61 Texture *pSpellBookPagesTextr_10; | |
62 Texture *pSpellBookPagesTextr_11; | |
63 Texture *pSpellBookPagesTextr_12; | |
64 Texture *pSpellBookPagesTextr_13; | |
0 | 65 Texture *pTexture_AutonotesBook; |
66 Texture *pTexture_CurrentBook; | |
67 Texture *pTex_moon_new; | |
68 Texture *pTex_moon_4; | |
69 Texture *pTex_moon_2; | |
70 Texture *pTex_moon_2_2; | |
71 Texture *pTex_moon_ful; | |
72 | |
73 | |
74 | |
75 RGBTexture stru_506E40; // weak | |
76 RGBTexture pTexture_PCX; | |
77 | |
78 | |
79 int uTextureID_RestUI_restb4; // weak | |
80 int uTextureID_RestUI_restexit; // weak | |
81 int uTextureID_RestUI_restb3; // weak | |
82 int uTextureID_RestUI_restb1; // weak | |
83 int uTextureID_RestUI_restb2; // weak | |
84 int uTextureID_RestUI_restmain; // weak | |
85 unsigned int uTextureID_Leather; | |
86 int uTextureID_ar_dn_dn; // weak | |
87 int uTextureID_ar_dn_up; // weak | |
88 int uTextureID_ar_up_dn; // weak | |
89 int uTextureID_ar_up_up; // weak | |
90 | |
91 | |
92 int uTextureID_507698; // weak | |
93 int uTextureID_50769C; // weak | |
94 int uTextureID_5076A0; // weak | |
95 int uTextureID_5076A4; // weak | |
96 int uTextureID_5076A8; // weak | |
97 int uTextureID_5076AC; // weak | |
98 int uTextureID_5076B0; // weak | |
99 int uTextureID_5076B4; // weak | |
100 int uTextureID_Parchment; // weak | |
101 unsigned int uTextureID_mhp_yel; | |
102 unsigned int uTextureID_mhp_red; | |
103 unsigned int uTextureID_mhp_grn; | |
104 unsigned int uTextureID_mhp_capr; | |
105 unsigned int uTextureID_mhp_capl; | |
106 unsigned int uTextureID_mhp_bd; | |
107 unsigned int uTextureID_BUTTDESC2; | |
108 unsigned int uTextureID_x_x_u; | |
109 unsigned int uTextureID_BUTTMAKE2; | |
110 unsigned int uTextureID_BUTTMAKE; | |
111 unsigned int uTextureID_BUTTYES2; | |
112 unsigned int uTextureID_x_ok_u; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
113 std::array<Texture *, 22> pPlayerPortraits; |
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
114 std::array<Texture *, 9> pTexture_IC_KNIGHT; |
0 | 115 Texture *pTexture_MAKESKY; |
116 Texture *pTexture_MAKETOP; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
117 std::array<Texture *, 20> pTextures_arrowr; |
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
118 std::array<Texture *, 20> pTextures_arrowl; |
0 | 119 Texture *pTexture_presleft; |
120 Texture *pTexture_pressrigh; | |
121 Texture *pTexture_buttminu; | |
122 Texture *pTexture_buttplus; | |
362 | 123 unsigned int uTextureID_Quit1; // weak |
124 unsigned int uTextureID_Resume1; // weak | |
125 unsigned int uTextureID_Controls1; // weak | |
126 unsigned int uTextureID_Save1; // weak | |
127 unsigned int uTextureID_Load1; // weak | |
128 unsigned int uTextureID_New1; // weak | |
129 unsigned int uTextureID_Options; // weak | |
0 | 130 |
131 | |
132 unsigned int uTextureID_ib_td5_A; | |
133 unsigned int uTextureID_ib_td2_A; // weak | |
134 unsigned int uTextureID_ib_td1_A; | |
984 | 135 int uTextureID_CharacterUI_InventoryBackground; // weak |
0 | 136 int uTextureID_50795C; // weak |
137 | |
138 | |
319 | 139 unsigned int uTextureID_Btn_GameSettings; |
0 | 140 |
141 | |
319 | 142 unsigned int uTextureID_Btn_Rest; |
143 unsigned int uTextureID_Btn_CastSpell; | |
144 unsigned int uTextureID_Btn_ZoomIn; | |
145 unsigned int uTextureID_Btn_ZoomOut; | |
0 | 146 unsigned int uTextureID_FONTPAL; |
319 | 147 unsigned int uTextureID_Btn_NPCRight; |
148 unsigned int uTextureID_Btn_NPCLeft; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
149 std::array<unsigned int, 8> pTextureIDs_pMapDirs; |
0 | 150 |
151 | |
152 unsigned int uTextureID_BarRed; | |
153 unsigned int uTextureID_BarYellow; | |
154 unsigned int uTextureID_BarGreen; | |
155 unsigned int uTextureID_BarBlue; | |
156 | |
157 | |
158 unsigned int uTextureID_right_panel; // weak | |
159 | |
160 | |
161 RGBTexture *pTexture_StatusBar = new RGBTexture; | |
162 RGBTexture *pTexture_LeftFrame = new RGBTexture; | |
163 RGBTexture *pTexture_TopFrame = new RGBTexture; | |
164 RGBTexture *pTexture_BottomFrame = new RGBTexture; | |
165 RGBTexture *pTexture_RightFrame = new RGBTexture; | |
166 | |
167 | |
910 | 168 unsigned int uTextureID_right_panel_loop; |
0 | 169 |
170 | |
171 Texture *pTexture_Leather; | |
172 Texture *pTexture_RestUI_CurrentSkyFrame; // idb | |
173 Texture *pTexture_RestUI_CurrentHourglassFrame; // idb | |
174 | |
175 | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
176 std::array<unsigned int, 5> uTextureID_Optkb; |
0 | 177 |
178 unsigned int uTextureID_507C10; // weak | |
179 unsigned int uTextureID_507C14; // weak | |
180 unsigned int uTextureID_507C18; // weak | |
181 unsigned int uTextureID_507C1C; // weak | |
182 unsigned int uTextureID_507C20; // weak | |
183 unsigned int uTextureID_507C24; // weak | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
184 std::array<unsigned int, 10> pTextureIDs_GammaPositions; |
0 | 185 unsigned int uTextureID_507C50; // weak |
186 unsigned int uTextureID_507C54; // weak | |
187 unsigned int uTextureID_507C58; // weak | |
188 | |
189 | |
910 | 190 unsigned int uTextureID_detaliz_close_button; // weak |
0 | 191 unsigned int uTextureID_MAGNIF_B; // weak |
192 unsigned int uTextureID_BACKDOLL; // weak | |
193 unsigned int uTextureID_BACKHAND; // weak | |
194 | |
195 | |
196 Texture pTex_F7CE30; | |
197 | |
198 | |
199 RGBTexture stru_5773C4; // idb | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 /* 245 */ | |
212 #pragma pack(push, 1) | |
213 struct PCXHeader1 | |
214 { | |
215 char magic; | |
216 char version; | |
217 char encoding; | |
218 char bpp; | |
219 __int16 left; | |
220 __int16 up; | |
221 __int16 right; | |
222 __int16 bottom; | |
223 __int16 hres; | |
224 __int16 vres; | |
225 }; | |
226 #pragma pack(pop) | |
227 | |
228 /* 246 */ | |
229 #pragma pack(push, 1) | |
230 struct PCXHeader2 | |
231 { | |
232 char reserved; | |
233 char planes; | |
234 __int16 pitch; | |
235 __int16 palette_info; | |
236 }; | |
237 #pragma pack(pop) | |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | |
244 | |
245 | |
246 | |
247 //----- (0044E054) -------------------------------------------------------- | |
248 void TextureFrameTable::ToFile() | |
249 { | |
250 TextureFrameTable *v1; // esi@1 | |
251 FILE *v2; // eax@1 | |
252 FILE *v3; // edi@1 | |
253 | |
254 v1 = this; | |
255 v2 = fopen("data\\dtft.bin", "wb"); | |
256 v3 = v2; | |
257 if ( !v2 ) | |
258 Abortf("Unable to save dtft.bin!"); | |
259 fwrite(v1, 4u, 1u, v2); | |
711 | 260 fwrite(v1->pTextures, 0x14u, v1->sNumTextures, v3); |
0 | 261 fclose(v3); |
262 } | |
263 | |
264 //----- (0044E0A0) -------------------------------------------------------- | |
265 void TextureFrameTable::FromFile(void *pSerialized) | |
266 { | |
711 | 267 sNumTextures = *(int *)pSerialized; |
268 pTextures = (TextureFrame *)pAllocator->AllocNamedChunk(pTextures, 20 * sNumTextures, "Txt Frames"); | |
269 memcpy(pTextures, (char *)pSerialized + 4, 20 * sNumTextures); | |
0 | 270 } |
271 | |
272 //----- (0044E0ED) -------------------------------------------------------- | |
711 | 273 void TextureFrameTable::LoadAnimationSequenceAndPalettes( signed int uIconID ) |
274 { | |
0 | 275 TextureFrameTable *v3; // ebx@1 |
276 unsigned int i; // edi@3 | |
277 | |
278 v3 = this; | |
711 | 279 if ( (uIconID <= this->sNumTextures) && uIconID >= 0 ) |
0 | 280 { |
281 for ( i = uIconID; ; ++i ) | |
282 { | |
283 v3->pTextures[i].uTextureID = pBitmaps_LOD->LoadTexture(v3->pTextures[i].pTextureName, TEXTURE_DEFAULT); | |
973 | 284 |
1108
a1fd8045ffb1
probably erroneous semicolons removed, mace and staff stun chance work as they should
Grumpy7
parents:
1104
diff
changeset
|
285 if (v3->pTextures[i].uTextureID != -1) |
973 | 286 pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID].palette_id1); |
711 | 287 //result = (unsigned int)v3->pTextures; |
288 //if ( !(*(char *)(result + i * 20 + 18) & 1) ) | |
973 | 289 if( v3->pTextures[i].uFlags & 1) |
0 | 290 break; |
291 } | |
292 } | |
711 | 293 return; |
0 | 294 } |
295 | |
296 //----- (0044E163) -------------------------------------------------------- | |
297 unsigned int TextureFrameTable::FindTextureByName(const char *Str2) | |
298 { | |
299 TextureFrameTable *v2; // esi@1 | |
300 int v3; // ebx@1 | |
301 unsigned int uID; // edi@1 | |
302 unsigned int result; // eax@4 | |
303 | |
304 v2 = this; | |
305 v3 = 0; | |
306 uID = 0; | |
711 | 307 if ( (signed int)this->sNumTextures <= 0 ) |
0 | 308 { |
309 LABEL_4: | |
310 result = -1; | |
311 } | |
312 else | |
313 { | |
1104 | 314 while ( _stricmp(v2->pTextures[v3].pTextureName, Str2) ) |
0 | 315 { |
316 ++uID; | |
317 ++v3; | |
711 | 318 if ( (signed int)uID >= (signed int)v2->sNumTextures ) |
0 | 319 goto LABEL_4; |
320 } | |
321 result = uID; | |
322 } | |
323 return result; | |
324 } | |
325 | |
326 //----- (0044E19A) -------------------------------------------------------- | |
327 unsigned int TextureFrameTable::GetFrameTexture(int uFrameID, signed int a3) | |
328 { | |
329 int v3; // esi@1 | |
330 TextureFrame *v4; // edi@1 | |
331 TextureFrame *v5; // ecx@1 | |
332 __int16 v6; // dx@2 | |
333 int v7; // edx@3 | |
334 char *i; // eax@3 | |
335 int v9; // ecx@5 | |
336 unsigned int result; // eax@6 | |
337 | |
338 v3 = uFrameID; | |
339 v4 = this->pTextures; | |
340 v5 = &v4[uFrameID]; | |
341 if ( v5->uFlags & 1 && (v6 = v5->uAnimLength) != 0 ) | |
342 { | |
343 v7 = (a3 >> 3) % v6; | |
344 for ( i = (char *)&v5->uAnimTime; ; i += 20 ) | |
345 { | |
346 v9 = *(short *)i; | |
347 if ( v7 <= v9 ) | |
348 break; | |
349 v7 -= v9; | |
350 ++v3; | |
351 } | |
352 result = v4[v3].uTextureID; | |
353 } | |
354 else | |
355 { | |
356 result = v5->uTextureID; | |
357 } | |
358 return result; | |
359 } | |
360 | |
361 | |
362 | |
363 | |
364 | |
365 | |
366 //----- (0040F806) -------------------------------------------------------- | |
367 void *Texture::UnzipPalette() | |
368 { | |
369 Texture *v1; // esi@1 | |
1093 | 370 |
0 | 371 void *v2; // edi@1 |
372 Texture *pSource; // [sp+0h] [bp-4h]@1 | |
373 | |
374 pSource = this; | |
375 v1 = this; | |
376 v2 = malloc(this->uDecompressedSize); | |
710 | 377 zlib::MemUnzip(v2, (unsigned int *)&pSource, v1->pLevelOfDetail0_prolly_alpha_mask, v1->uTextureSize); |
0 | 378 return v2; |
379 } | |
380 | |
381 //----- (0040F77C) -------------------------------------------------------- | |
382 void Texture::Release() | |
383 { | |
384 if (this) | |
385 { | |
386 pName[0] = 0; | |
387 | |
388 if (pBits & 0x0400) | |
389 { | |
1093 | 390 __debugbreak(); |
391 } | |
392 | |
393 pAllocator->FreeChunk(pLevelOfDetail0_prolly_alpha_mask); | |
0 | 394 pAllocator->FreeChunk(pPalette16); |
395 pAllocator->FreeChunk(pPalette24); | |
1093 | 396 |
0 | 397 |
710 | 398 pLevelOfDetail0_prolly_alpha_mask = nullptr; |
0 | 399 pLevelOfDetail1 = nullptr; |
400 pLevelOfDetail2 = nullptr; | |
401 pLevelOfDetail3 = nullptr; | |
402 | |
403 pPalette16 = nullptr; | |
404 pPalette24 = nullptr; | |
405 | |
406 uSizeOfMaxLevelOfDetail = 0; | |
407 uTextureSize = 0; | |
408 uTextureHeight = 0; | |
409 uTextureWidth = 0; | |
410 uHeightLn2 = 0; | |
411 uWidthLn2 = 0; | |
412 palette_id1 = 0; | |
413 palette_id2 = 0; | |
414 pBits &= 0xFFFF0000; | |
415 } | |
416 } | |
417 | |
418 //----- (0040F5F5) -------------------------------------------------------- | |
419 int RGBTexture::Reload(const char *pContainer) | |
420 { | |
421 RGBTexture *v2; // esi@1 | |
422 FILE *v3; // eax@3 | |
423 FILE *v4; // edi@3 | |
424 void *v5; // ebx@7 | |
425 signed int result; // eax@11 | |
426 unsigned int v7; // ecx@12 | |
427 unsigned __int16 *v8; // ST20_4@14 | |
428 int v9; // eax@14 | |
429 char color_map[48]; // [sp+8h] [bp-98h]@9 | |
430 Texture DstBuf; // [sp+38h] [bp-68h]@1 | |
431 PCXHeader1 header1; // [sp+80h] [bp-20h]@9 | |
432 PCXHeader2 header2; // [sp+90h] [bp-10h]@9 | |
433 FILE *File; // [sp+98h] [bp-8h]@3 | |
434 size_t Count; // [sp+9Ch] [bp-4h]@6 | |
435 void *uSourceLena; // [sp+A8h] [bp+8h]@7 | |
436 | |
437 v2 = this; | |
438 if ( !v2->pPixels ) | |
439 return 2; | |
440 v3 = pIcons_LOD->FindContainer(pContainer, 0); | |
441 v4 = v3; | |
442 File = v3; | |
443 if ( !v3 ) | |
444 { | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1165
diff
changeset
|
445 sprintf(pTmpBuf.data(), "Unable to load %s", pContainer); |
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1165
diff
changeset
|
446 Abortf(pTmpBuf.data()); |
0 | 447 } |
448 fread(&DstBuf, 1u, 0x30u, v3); | |
449 Count = DstBuf.uTextureSize; | |
450 if ( DstBuf.uDecompressedSize ) | |
451 { | |
452 v5 = malloc(DstBuf.uDecompressedSize); | |
453 uSourceLena = pAllocator->AllocNamedChunk(0, DstBuf.uTextureSize, DstBuf.pName); | |
454 fread(uSourceLena, 1u, Count, File); | |
455 zlib::MemUnzip(v5, &DstBuf.uDecompressedSize, uSourceLena, DstBuf.uTextureSize); | |
456 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
457 pAllocator->FreeChunk(uSourceLena); | |
458 } | |
459 else | |
460 { | |
461 v5 = malloc(DstBuf.uTextureSize); | |
462 fread(v5, 1u, Count, v4); | |
463 } | |
464 memcpy(&header1, v5, 0x10u); | |
465 memcpy(color_map, (char *)v5 + 16, 0x30u); | |
466 memcpy(&header2, (char *)v5 + 64, 6u); | |
467 if ( header1.bpp != 8 ) | |
468 return 3; | |
469 v7 = (signed __int16)(header1.right - header1.left + 1); | |
470 if ( (signed int)(v7 * (signed __int16)(header1.bottom - header1.up + 1)) <= (signed int)v2->uNumPixels ) | |
471 { | |
472 v2->uWidth = header1.right - header1.left + 1; | |
473 v8 = v2->pPixels; | |
474 v9 = v7 * v2->uHeight; | |
475 v2->uNumPixels = v9; | |
476 v2->uHeight = v9; | |
477 v2->DecodePCX((char *)v5, v8, v7); | |
478 free(v5); | |
479 result = 0; | |
480 } | |
481 else | |
482 { | |
483 result = -1; | |
484 } | |
485 return result; | |
486 } | |
487 | |
488 //----- (0040F5BE) -------------------------------------------------------- | |
489 Texture::Texture() | |
490 { | |
491 pName[0] = 0; | |
492 uSizeOfMaxLevelOfDetail = 0; | |
493 uTextureSize = 0; | |
494 uTextureHeight = 0; | |
495 uTextureWidth = 0; | |
496 uHeightLn2 = 0; | |
497 uWidthLn2 = 0; | |
498 palette_id1 = 0; | |
499 palette_id2 = 0; | |
710 | 500 pLevelOfDetail0_prolly_alpha_mask = 0; |
0 | 501 pLevelOfDetail3 = 0; |
502 pLevelOfDetail2 = 0; | |
503 pLevelOfDetail1 = 0; | |
504 pPalette16 = 0; | |
505 pPalette24 = 0; | |
506 } | |
507 | |
508 //----- (0040F414) -------------------------------------------------------- | |
509 int RGBTexture::Load(const char *pContainer, int mode) | |
510 { | |
511 RGBTexture *v3; // esi@1 | |
512 FILE *v4; // eax@1 | |
513 FILE *v5; // ebx@1 | |
514 void *v6; // ebx@5 | |
515 unsigned __int16 v7; // ax@9 | |
516 unsigned __int16 v8; // cx@9 | |
517 int v9; // ecx@9 | |
518 void *v10; // eax@9 | |
519 void *v11; // eax@13 | |
520 unsigned __int16 *v12; // eax@17 | |
521 char color_map[48]; // [sp+Ch] [bp-98h]@7 | |
522 Texture DstBuf; // [sp+3Ch] [bp-68h]@1 | |
523 PCXHeader1 header1; // [sp+84h] [bp-20h]@7 | |
524 PCXHeader2 header2; // [sp+94h] [bp-10h]@7 | |
525 FILE *File; // [sp+9Ch] [bp-8h]@1 | |
526 size_t Count; // [sp+A0h] [bp-4h]@4 | |
527 char *Str1a; // [sp+ACh] [bp+8h]@5 | |
528 | |
529 v3 = this; | |
530 v4 = pIcons_LOD->FindContainer(pContainer, 0); | |
531 v5 = v4; | |
532 File = v4; | |
533 if ( !v4 ) | |
534 { | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1165
diff
changeset
|
535 sprintf(pTmpBuf.data(), "Unable to load %s", pContainer); |
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1165
diff
changeset
|
536 Abortf(pTmpBuf.data()); |
0 | 537 } |
538 fread(&DstBuf, 1u, 0x30u, v4); | |
539 Count = DstBuf.uTextureSize; | |
540 if ( DstBuf.uDecompressedSize ) | |
541 { | |
542 Str1a = (char *)malloc(DstBuf.uDecompressedSize); | |
543 v6 = pAllocator->AllocNamedChunk(0, DstBuf.uTextureSize, DstBuf.pName); | |
544 fread(v6, 1u, Count, File); | |
545 zlib::MemUnzip(Str1a, &DstBuf.uDecompressedSize, v6, DstBuf.uTextureSize); | |
546 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
547 pAllocator->FreeChunk(v6); | |
548 } | |
549 else | |
550 { | |
551 Str1a = (char *)malloc(DstBuf.uTextureSize); | |
552 fread(Str1a, 1u, Count, v5); | |
553 } | |
554 memcpy(&header1, Str1a, 0x10u); | |
555 memcpy(color_map, Str1a + 16, 0x30u); | |
556 memcpy(&header2, Str1a + 64, 6u); | |
557 if ( header1.bpp != 8 ) | |
558 return 3; | |
559 v7 = header1.right - header1.left + 1; | |
560 v8 = header1.bottom - header1.up + 1; | |
561 v3->uWidth = v7; | |
562 v3->uHeight = v8; | |
563 v9 = (signed __int16)v7 * (signed __int16)v8; | |
564 v10 = v3->pPixels; | |
565 v3->uNumPixels = v9; | |
566 if ( v10 ) | |
567 { | |
568 if ( mode ) | |
569 goto LABEL_14; | |
570 pAllocator->FreeChunk(v10); | |
571 } | |
572 if ( !mode ) | |
573 { | |
574 v11 = pAllocator->AllocNamedChunk(v3->pPixels, 2 * v3->uNumPixels + 4, "16bit PCX"); | |
575 goto LABEL_16; | |
576 } | |
577 LABEL_14: | |
578 if ( mode != 2 ) | |
579 goto LABEL_17; | |
580 v11 = malloc(2 * v3->uNumPixels + 4); | |
581 *(unsigned int *)&v3->field_20 |= 1u; | |
582 LABEL_16: | |
583 v3->pPixels = (unsigned __int16 *)v11; | |
584 LABEL_17: | |
585 v12 = v3->pPixels; | |
586 if ( !v12 ) | |
587 return 2; | |
588 v3->DecodePCX(Str1a, v12, v3->uWidth); | |
589 free(Str1a); | |
590 return 0; | |
591 } | |
592 | |
593 | |
594 //----- (0040F037) -------------------------------------------------------- | |
595 signed int RGBTexture::DecodePCX(char *pPcx, unsigned __int16 *pOutPixels, unsigned int uNumPixels) | |
596 { | |
597 signed int result; // eax@2 | |
598 unsigned char test_byte; // edx@3 | |
599 unsigned int read_offset; // ebx@37 | |
600 unsigned int row_position; // edi@40 | |
601 unsigned char value; // cl@63 | |
602 char count; // [sp+50h] [bp-Ch]@43 | |
603 unsigned short current_line; // [sp+54h] [bp-8h]@38 | |
604 unsigned short *dec_position; | |
605 unsigned short *temp_dec_position; | |
606 PCXHeader1 psx_head1; | |
607 PCXHeader2 psx_head2; | |
608 short int width, height; | |
609 BYTE color_map[48]; // Colormap for 16-color images | |
610 | |
611 | |
612 memcpy(&psx_head1, pPcx , 16); | |
613 memcpy(&color_map, pPcx + 16, 48); | |
614 memcpy(&psx_head2, pPcx + 64, 6); | |
615 | |
616 | |
617 if (psx_head1.bpp!=8) | |
618 return 3; | |
619 uWidth=(short int )(psx_head1.right-psx_head1.left+1); // word @ 000014 | |
620 uHeight=(short int )(psx_head1.bottom-psx_head1.up+1); // word @ 000016 | |
621 | |
622 | |
623 uNumPixels=uWidth*uHeight; // dword @ 000010 | |
624 | |
625 memset(pOutPixels, 0, uNumPixels * sizeof(__int16)); | |
626 short i=1; | |
627 while ( (1<<i) !=uWidth) | |
628 { | |
629 ++i; | |
630 if (i >= 15) | |
631 break; | |
632 } | |
633 field_18=i; | |
634 short i_=1; | |
635 while ( (1<<i_) !=uHeight) | |
636 { | |
637 ++i_; | |
638 if (i_ >= 15) | |
639 break; | |
640 } | |
641 field_1A=i_; | |
642 switch (field_18) | |
643 { | |
644 case 2: field_1C = 3; break; | |
645 case 3: field_1C = 7; break; | |
646 case 4: field_1C = 15; break; | |
647 case 5: field_1C = 31; break; | |
648 case 6: field_1C = 63; break; | |
649 case 7: field_1C = 127; break; | |
650 case 8: field_1C = 255; break; | |
651 case 9: field_1C = 511; break; | |
652 case 10: field_1C = 1023; break; | |
653 case 11: field_1C = 2047; break; | |
654 case 12: field_1C = 4095; break; | |
655 } | |
656 | |
657 switch (field_1A) | |
658 { | |
659 case 2: field_1E = 3; break; | |
660 case 3: field_1E = 7; break; | |
661 case 4: field_1E = 15; break; | |
662 case 5: field_1E = 31; break; | |
663 case 6: field_1E = 63; break; | |
664 case 7: field_1E = 127; break; | |
665 case 8: field_1E = 255; break; | |
666 case 9: field_1E = 511; break; | |
667 case 10: field_1E = 1023; break; | |
668 case 11: field_1E = 2047; break; | |
669 case 12: field_1E = 4095; break; | |
670 } | |
671 | |
672 | |
673 read_offset = 128; | |
674 if (psx_head2.planes != 3) | |
675 return 0; | |
676 current_line = 0; | |
677 if ( uHeight > 0 ) | |
678 { | |
679 dec_position = pOutPixels; | |
680 do | |
681 { | |
682 temp_dec_position = dec_position; | |
683 row_position = 0; | |
684 //decode red line | |
685 if (psx_head2.pitch) | |
686 { | |
687 do | |
688 { | |
689 test_byte = pPcx[read_offset]; | |
690 ++read_offset; | |
691 if ((test_byte & 0xC0) == 0xC0) | |
692 { | |
693 value = pPcx[read_offset]; | |
694 ++read_offset; | |
695 | |
696 if ((test_byte & 0x3F) > 0) | |
697 { | |
698 count = test_byte & 0x3F; | |
699 do | |
700 { | |
701 | |
702 ++row_position; | |
703 //*temp_dec_position =0xFF000000; | |
704 //*temp_dec_position|=(unsigned long)value<<16; | |
705 *temp_dec_position |= LOWORD(pRenderer->uTargetRMask) & ((unsigned __int8)value << (LOBYTE(pRenderer->uTargetGBits) | |
706 + LOBYTE(pRenderer->uTargetRBits) | |
707 + LOBYTE(pRenderer->uTargetBBits) | |
708 - 8)); | |
709 | |
710 temp_dec_position++; | |
711 if (row_position == psx_head2.pitch) | |
712 break; | |
713 } | |
714 while (count-- != 1); | |
715 } | |
716 } | |
717 else | |
718 { | |
719 ++row_position; | |
720 //*temp_dec_position =0xFF000000; | |
721 //*temp_dec_position|= (unsigned long)test_byte<<16; | |
722 | |
723 *temp_dec_position |= LOWORD(pRenderer->uTargetRMask) & ((unsigned __int8)test_byte << (LOBYTE(pRenderer->uTargetGBits) | |
724 + LOBYTE(pRenderer->uTargetRBits) | |
725 + LOBYTE(pRenderer->uTargetBBits) | |
726 - 8)); | |
727 | |
728 temp_dec_position++; | |
729 } | |
730 | |
731 } | |
732 while (row_position < psx_head2.pitch); | |
733 } | |
734 | |
735 temp_dec_position = dec_position; | |
736 row_position=0; | |
737 //decode green line | |
738 while (row_position < psx_head2.pitch) | |
739 { | |
740 test_byte = *(pPcx + read_offset); | |
741 ++read_offset; | |
742 if ((test_byte & 0xC0) == 0xC0) | |
743 { | |
744 value = *(pPcx + read_offset); | |
745 ++read_offset; | |
746 if ((test_byte & 0x3F) > 0) | |
747 { | |
748 count = test_byte & 0x3F; | |
749 do | |
750 { | |
751 //*temp_dec_position|= (unsigned int)value<<8; | |
752 //temp_dec_position++; | |
753 | |
754 *temp_dec_position|= pRenderer->uTargetGMask & (unsigned __int16)((unsigned __int8)value << (LOBYTE(pRenderer->uTargetGBits) | |
755 + LOBYTE(pRenderer->uTargetBBits) | |
756 - 8)); | |
757 | |
758 temp_dec_position++; | |
759 ++row_position; | |
760 if (row_position == psx_head2.pitch) | |
761 break; | |
762 | |
763 } | |
764 while (count-- != 1); | |
765 } | |
766 } | |
767 else | |
768 { | |
769 //*temp_dec_position |=(unsigned int) test_byte<<8; | |
770 //temp_dec_position++; | |
771 | |
772 *temp_dec_position|= pRenderer->uTargetGMask & (unsigned __int16)((unsigned __int8)test_byte << (LOBYTE(pRenderer->uTargetGBits) | |
773 + LOBYTE(pRenderer->uTargetBBits) | |
774 - 8)); | |
775 temp_dec_position++; | |
776 ++row_position; | |
777 } | |
778 } | |
779 | |
780 temp_dec_position = dec_position; | |
781 row_position=0; | |
782 //decode blue line | |
783 while (row_position < psx_head2.pitch) | |
784 { | |
785 test_byte = *(pPcx + read_offset); | |
786 read_offset++; | |
787 if ((test_byte & 0xC0) == 0xC0) | |
788 { | |
789 value = *(pPcx + read_offset); | |
790 ++read_offset; | |
791 if ((test_byte & 0x3F) > 0) | |
792 { | |
793 count = test_byte & 0x3F; | |
794 do | |
795 { | |
796 //*temp_dec_position|= value; | |
797 //temp_dec_position++; | |
798 | |
799 *temp_dec_position |= value >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
800 temp_dec_position++; | |
801 | |
802 ++row_position; | |
803 if (row_position == psx_head2.pitch) | |
804 break; | |
805 } | |
806 while (count-- != 1); | |
807 } | |
808 } | |
809 else | |
810 { | |
811 //*temp_dec_position|= test_byte; | |
812 //temp_dec_position++; | |
813 *temp_dec_position |= test_byte >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
814 temp_dec_position++; | |
815 | |
816 ++row_position; | |
817 } | |
818 | |
819 } | |
820 ++current_line; | |
821 dec_position += uWidth; | |
822 } | |
823 while (current_line < uHeight); | |
824 } | |
825 return 0; | |
826 /* | |
827 RGBTexture *v4; // esi@1 | |
828 signed int result; // eax@2 | |
829 unsigned __int16 v6; // ax@3 | |
830 unsigned __int16 *v7; // ecx@3 | |
831 unsigned int v8; // edx@3 | |
832 signed int v9; // ecx@3 | |
833 signed int v10; // ecx@8 | |
834 signed int v11; // ebx@37 | |
835 unsigned __int16 *v12; // eax@40 | |
836 int v13; // edi@40 | |
837 int v14; // ebx@41 | |
838 char v15; // bl@42 | |
839 unsigned __int16 *v16; // eax@50 | |
840 int v17; // ebx@51 | |
841 char v18; // bl@52 | |
842 unsigned __int16 *v19; // eax@61 | |
843 unsigned __int8 v20; // dl@62 | |
844 unsigned __int8 v21; // dl@63 | |
845 unsigned __int8 v22; // cl@63 | |
846 char color_map[48]; // [sp+8h] [bp-54h]@1 | |
847 PCXHeader1 header1; // [sp+38h] [bp-24h]@1 | |
848 PCXHeader2 header2; // [sp+48h] [bp-14h]@1 | |
849 unsigned int v26; // [sp+50h] [bp-Ch]@43 | |
850 int v27; // [sp+54h] [bp-8h]@38 | |
851 unsigned __int16 *v28; // [sp+58h] [bp-4h]@3 | |
852 int pOutPixelsa; // [sp+68h] [bp+Ch]@41 | |
853 int pOutPixelsb; // [sp+68h] [bp+Ch]@51 | |
854 | |
855 v4 = this; | |
856 memcpy(&header1, pPcx, 0x10u); | |
857 memcpy(color_map, pPcx + 16, 0x30u); | |
858 memcpy(&header2, pPcx + 64, 6u); | |
859 if ( header1.bpp == 8 ) | |
860 { | |
861 v6 = header1.right - header1.left + 1; | |
862 LOWORD(v7) = header1.bottom - header1.up + 1; | |
863 v4->uWidth = v6; | |
864 v4->uHeight = (unsigned __int16)v7; | |
865 v7 = (unsigned __int16 *)(signed __int16)v7; | |
866 v28 = v7; | |
867 v4->uNumPixels = (signed __int16)v7 * (signed __int16)v6; | |
868 HIWORD(v8) = 0; | |
869 v9 = 1; | |
870 while ( 1 << v9 != (signed __int16)v6 ) | |
871 { | |
872 ++v9; | |
873 if ( v9 >= 15 ) | |
874 goto LABEL_8; | |
875 } | |
876 v4->field_18 = v9; | |
877 LABEL_8: | |
878 v10 = 1; | |
879 while ( (unsigned __int16 *)(1 << v10) != v28 ) | |
880 { | |
881 ++v10; | |
882 if ( v10 >= 15 ) | |
883 goto LABEL_13; | |
884 } | |
885 v4->field_1A = v10; | |
886 LABEL_13: | |
887 switch ( v4->field_18 ) | |
888 { | |
889 case 2: | |
890 v4->field_1C = 3; | |
891 break; | |
892 case 3: | |
893 v4->field_1C = 7; | |
894 break; | |
895 case 4: | |
896 v4->field_1C = 15; | |
897 break; | |
898 case 5: | |
899 v4->field_1C = 31; | |
900 break; | |
901 case 6: | |
902 v4->field_1C = 63; | |
903 break; | |
904 case 7: | |
905 v4->field_1C = 127; | |
906 break; | |
907 case 8: | |
908 v4->field_1C = 255; | |
909 break; | |
910 case 9: | |
911 v4->field_1C = 511; | |
912 break; | |
913 case 10: | |
914 v4->field_1C = 1023; | |
915 break; | |
916 case 11: | |
917 v4->field_1C = 2047; | |
918 break; | |
919 case 12: | |
920 v4->field_1C = 4095; | |
921 break; | |
922 default: | |
923 break; | |
924 } | |
925 switch ( v4->field_1A ) | |
926 { | |
927 case 2: | |
928 v4->field_1E = 3; | |
929 break; | |
930 case 3: | |
931 v4->field_1E = 7; | |
932 break; | |
933 case 4: | |
934 v4->field_1E = 15; | |
935 break; | |
936 case 5: | |
937 v4->field_1E = 31; | |
938 break; | |
939 case 6: | |
940 v4->field_1E = 63; | |
941 break; | |
942 case 7: | |
943 v4->field_1E = 127; | |
944 break; | |
945 case 8: | |
946 v4->field_1E = 255; | |
947 break; | |
948 case 9: | |
949 v4->field_1E = 511; | |
950 break; | |
951 case 10: | |
952 v4->field_1E = 1023; | |
953 break; | |
954 case 11: | |
955 v4->field_1E = 2047; | |
956 break; | |
957 case 12: | |
958 v4->field_1E = 4095; | |
959 break; | |
960 default: | |
961 break; | |
962 } | |
963 v11 = 128; | |
964 if ( header2.planes == 3 ) | |
965 { | |
966 v27 = 0; | |
967 if ( (signed int)v28 > 0 ) | |
968 { | |
969 v28 = pOutPixels; | |
970 do | |
971 { | |
972 v12 = v28; | |
973 v13 = 0; | |
974 if ( header2.pitch ) | |
975 { | |
976 do | |
977 { | |
978 LOBYTE(v8) = pPcx[v11]; | |
979 v14 = v11 + 1; | |
980 pOutPixelsa = v14; | |
981 if ( (v8 & 0xC0) == -64 ) | |
982 { | |
983 pOutPixelsa = v14 + 1; | |
984 v15 = pPcx[v14]; | |
985 if ( (signed int)(v8 & 0x3F) > 0 ) | |
986 { | |
987 v26 = v8 & 0x3F; | |
988 do | |
989 { | |
990 ++v13; | |
991 *v12 = LOWORD(pRenderer->uTargetRMask) & ((unsigned __int8)v15 << (LOBYTE(pRenderer->uTargetGBits) | |
992 + LOBYTE(pRenderer->uTargetRBits) | |
993 + LOBYTE(pRenderer->uTargetBBits) | |
994 - 8)); | |
995 ++v12; | |
996 if ( v13 == (unsigned __int16)header2.pitch ) | |
997 v12 = &v12[uNumPixels - (unsigned __int16)header2.pitch - 1]; | |
998 --v26; | |
999 } | |
1000 while ( v26 ); | |
1001 } | |
1002 } | |
1003 else | |
1004 { | |
1005 LOWORD(v8) = (unsigned __int8)v8; | |
1006 v8 = pRenderer->uTargetRMask & (v8 << (LOBYTE(pRenderer->uTargetGBits) | |
1007 + LOBYTE(pRenderer->uTargetRBits) | |
1008 + LOBYTE(pRenderer->uTargetBBits) | |
1009 - 8)); | |
1010 ++v13; | |
1011 *v12 = v8; | |
1012 ++v12; | |
1013 } | |
1014 v11 = pOutPixelsa; | |
1015 } | |
1016 while ( v13 < (unsigned __int16)header2.pitch ); | |
1017 } | |
1018 v16 = v28; | |
1019 while ( v13 < 2 * (unsigned __int16)header2.pitch ) | |
1020 { | |
1021 LOBYTE(v8) = pPcx[v11]; | |
1022 v17 = v11 + 1; | |
1023 pOutPixelsb = v17; | |
1024 if ( (v8 & 0xC0) == -64 ) | |
1025 { | |
1026 pOutPixelsb = v17 + 1; | |
1027 v18 = pPcx[v17]; | |
1028 if ( (signed int)(v8 & 0x3F) > 0 ) | |
1029 { | |
1030 v26 = v8 & 0x3F; | |
1031 do | |
1032 { | |
1033 *v16 |= pRenderer->uTargetGMask & (unsigned __int16)((unsigned __int8)v18 << (LOBYTE(pRenderer->uTargetGBits) | |
1034 + LOBYTE(pRenderer->uTargetBBits) | |
1035 - 8)); | |
1036 ++v13; | |
1037 ++v16; | |
1038 if ( v13 == (unsigned __int16)header2.pitch ) | |
1039 v16 = &v16[uNumPixels - (unsigned __int16)header2.pitch - 1]; | |
1040 --v26; | |
1041 } | |
1042 while ( v26 ); | |
1043 } | |
1044 } | |
1045 else | |
1046 { | |
1047 LOWORD(v8) = (unsigned __int8)v8; | |
1048 v8 = pRenderer->uTargetGMask & (v8 << (LOBYTE(pRenderer->uTargetGBits) + LOBYTE(pRenderer->uTargetBBits) - 8)); | |
1049 *v16 |= v8; | |
1050 ++v13; | |
1051 ++v16; | |
1052 } | |
1053 v11 = pOutPixelsb; | |
1054 } | |
1055 v19 = v28; | |
1056 while ( v13 < 3 * (unsigned __int16)header2.pitch ) | |
1057 { | |
1058 v20 = pPcx[v11++]; | |
1059 if ( (v20 & 0xC0) == -64 ) | |
1060 { | |
1061 v21 = v20 & 0x3F; | |
1062 v22 = pPcx[v11++]; | |
1063 if ( (signed int)v21 > 0 ) | |
1064 { | |
1065 v26 = v21; | |
1066 do | |
1067 { | |
1068 *v19 |= v22 >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1069 ++v13; | |
1070 ++v19; | |
1071 if ( v13 == (unsigned __int16)header2.pitch ) | |
1072 { | |
1073 v8 = uNumPixels - (unsigned __int16)header2.pitch; | |
1074 v19 = &v19[uNumPixels - (unsigned __int16)header2.pitch - 1]; | |
1075 } | |
1076 --v26; | |
1077 } | |
1078 while ( v26 ); | |
1079 } | |
1080 } | |
1081 else | |
1082 { | |
1083 *v19 |= v20 >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1084 ++v13; | |
1085 ++v19; | |
1086 } | |
1087 } | |
1088 ++v27; | |
1089 v28 += uNumPixels; | |
1090 } | |
1091 while ( v27 < v4->uHeight ); | |
1092 } | |
1093 } | |
1094 result = 0; | |
1095 } | |
1096 else | |
1097 { | |
1098 result = 3; | |
1099 } | |
1100 return result; | |
1101 */ | |
1102 } | |
1103 | |
1104 //----- (0040EAD8) -------------------------------------------------------- | |
1105 unsigned int RGBTexture::LoadFromFILE(FILE *pFile, unsigned int mode, unsigned int bCloseFile) | |
1106 { | |
1107 signed int result; // eax@2 | |
1108 unsigned char test_byte; // edx@3 | |
1109 //unsigned int read_offset; // ebx@37 | |
1110 unsigned int row_position; // edi@40 | |
1111 unsigned char value; // cl@63 | |
1112 char count; // [sp+50h] [bp-Ch]@43 | |
1113 unsigned short current_line; // [sp+54h] [bp-8h]@38 | |
1114 unsigned short *dec_position; | |
1115 unsigned short *temp_dec_position; | |
1116 PCXHeader1 psx_head1; | |
1117 PCXHeader2 psx_head2; | |
1118 short int width, height; | |
1119 BYTE color_map[48]; // Colormap for 16-color images | |
1120 | |
1121 if (!pFile) | |
1122 return 1; | |
1123 | |
1124 | |
1125 fread(&psx_head1, 1, 16, pFile); | |
1126 fread(&color_map, 1, 48, pFile); | |
1127 fread(&psx_head2, 1, 6, pFile); | |
1128 | |
1129 if (psx_head1.bpp!=8) | |
1130 return 3; | |
1131 uWidth=(short int )(psx_head1.right-psx_head1.left+1); // word @ 000014 | |
1132 uHeight=(short int )(psx_head1.bottom-psx_head1.up+1); // word @ 000016 | |
1133 | |
1134 | |
1135 uNumPixels=uWidth*uHeight; // dword @ 000010 | |
1136 | |
1137 | |
1138 if ( mode == 0 ) | |
1139 { | |
1140 if ( pPixels ) | |
1141 { | |
1142 pAllocator->FreeChunk(pPixels); | |
1143 pPixels = 0; | |
1144 } | |
1145 pPixels = (unsigned __int16 *)pAllocator->AllocNamedChunk( | |
1146 pPixels, | |
1147 2 * uNumPixels + 4, | |
1148 pName); | |
1149 } | |
1150 else | |
1151 { | |
1152 if ( mode != 1 && mode == 2 ) | |
1153 { | |
1154 pPixels = (unsigned __int16 *)malloc((uNumPixels + 2) * sizeof(unsigned __int16)); | |
1155 field_20 |= 1; | |
1156 } | |
1157 } | |
1158 | |
1159 | |
1160 | |
1161 | |
1162 auto pOutPixels = pPixels; | |
1163 | |
1164 memset(pOutPixels, 0, uNumPixels * sizeof(__int16)); | |
1165 | |
1166 short i=1; | |
1167 while ( (1<<i) !=uWidth) | |
1168 { | |
1169 ++i; | |
1170 if (i >= 15) | |
1171 break; | |
1172 } | |
1173 field_18=i; | |
1174 short i_=1; | |
1175 while ( (1<<i_) !=uHeight) | |
1176 { | |
1177 ++i_; | |
1178 if (i_ >= 15) | |
1179 break; | |
1180 } | |
1181 field_1A=i_; | |
1182 switch (field_18) | |
1183 { | |
1184 case 2: field_1C = 3; break; | |
1185 case 3: field_1C = 7; break; | |
1186 case 4: field_1C = 15; break; | |
1187 case 5: field_1C = 31; break; | |
1188 case 6: field_1C = 63; break; | |
1189 case 7: field_1C = 127; break; | |
1190 case 8: field_1C = 255; break; | |
1191 case 9: field_1C = 511; break; | |
1192 case 10: field_1C = 1023; break; | |
1193 case 11: field_1C = 2047; break; | |
1194 case 12: field_1C = 4095; break; | |
1195 } | |
1196 | |
1197 switch (field_1A) | |
1198 { | |
1199 case 2: field_1E = 3; break; | |
1200 case 3: field_1E = 7; break; | |
1201 case 4: field_1E = 15; break; | |
1202 case 5: field_1E = 31; break; | |
1203 case 6: field_1E = 63; break; | |
1204 case 7: field_1E = 127; break; | |
1205 case 8: field_1E = 255; break; | |
1206 case 9: field_1E = 511; break; | |
1207 case 10: field_1E = 1023; break; | |
1208 case 11: field_1E = 2047; break; | |
1209 case 12: field_1E = 4095; break; | |
1210 } | |
1211 | |
1212 | |
1213 fseek(pFile, 128 - 70, SEEK_CUR); | |
1214 | |
1215 | |
1216 for (uint y = 0; y < uHeight; ++y) | |
1217 { | |
1218 unsigned __int16 *pDst = pPixels + y * uWidth; | |
1219 | |
1220 uint x = 0; | |
1221 do | |
1222 { | |
1223 uint ctrl = 0; | |
1224 fread(&ctrl, 1, 1, pFile); | |
1225 if ((ctrl & 0xC0) == 0xC0) | |
1226 { | |
1227 uint uNumPixels = ctrl & 0x3F; | |
1228 uint clr = 0; | |
1229 fread(&clr, 1, 1, pFile); | |
1230 for (uint i = 0; i < uNumPixels; ++i) | |
1231 pDst[x++] = pRenderer->uTargetRMask & (clr << (pRenderer->uTargetGBits + | |
1232 pRenderer->uTargetRBits + | |
1233 pRenderer->uTargetBBits - 8)); | |
1234 } | |
1235 else | |
1236 { | |
1237 pDst[x++] = pRenderer->uTargetRMask & (ctrl << (pRenderer->uTargetGBits + | |
1238 pRenderer->uTargetRBits + | |
1239 pRenderer->uTargetBBits - 8)); | |
1240 } | |
1241 } while (x < psx_head2.pitch); | |
1242 | |
1243 | |
1244 | |
1245 | |
1246 | |
1247 x = 0; | |
1248 do | |
1249 { | |
1250 uint ctrl = 0; | |
1251 fread(&ctrl, 1, 1, pFile); | |
1252 if ((ctrl & 0xC0) == 0xC0) | |
1253 { | |
1254 uint uNumPixels = ctrl & 0x3F; | |
1255 uint clr = 0; | |
1256 fread(&clr, 1, 1, pFile); | |
1257 for (uint i = 0; i < uNumPixels; ++i) | |
1258 pDst[x++] |= pRenderer->uTargetGMask & (clr << (pRenderer->uTargetGBits + | |
1259 pRenderer->uTargetBBits - 8)); | |
1260 } | |
1261 else | |
1262 { | |
1263 pDst[x++] |= pRenderer->uTargetGMask & (ctrl << (pRenderer->uTargetGBits + | |
1264 pRenderer->uTargetBBits - 8)); | |
1265 } | |
1266 } while (x < psx_head2.pitch); | |
1267 | |
1268 | |
1269 | |
1270 | |
1271 | |
1272 x = 0; | |
1273 do | |
1274 { | |
1275 uint ctrl = 0; | |
1276 fread(&ctrl, 1, 1, pFile); | |
1277 if ((ctrl & 0xC0) == 0xC0) | |
1278 { | |
1279 uint uNumPixels = ctrl & 0x3F; | |
1280 uint clr = 0; | |
1281 fread(&clr, 1, 1, pFile); | |
1282 for (uint i = 0; i < uNumPixels; ++i) | |
1283 pDst[x++] |= pRenderer->uTargetBMask & (clr >> (8 - pRenderer->uTargetBBits)); | |
1284 } | |
1285 else | |
1286 { | |
1287 pDst[x++] |= pRenderer->uTargetBMask & (ctrl >> (8 - pRenderer->uTargetRBits)); | |
1288 } | |
1289 } while (x < psx_head2.pitch); | |
1290 } | |
1291 | |
1292 if (bCloseFile) | |
1293 fclose(pFile); | |
1294 return 0; | |
1295 } | |
1296 | |
1297 //----- (0040E51F) -------------------------------------------------------- | |
1298 void RGBTexture::Release() | |
1299 { | |
1300 RGBTexture *v1; // esi@1 | |
1301 char v2; // zf@1 | |
1302 void *v3; // [sp-4h] [bp-Ch]@1 | |
1303 | |
1304 v1 = this; | |
1305 v2 = (this->field_20 & 1) == 0; | |
1306 v3 = this->pPixels; | |
1307 this->pName[0] = 0; | |
1308 if ( v2 ) | |
1309 pAllocator->FreeChunk(v3); | |
1310 else | |
1311 free(v3); | |
1312 *(unsigned int *)&v1->field_20 = 0; | |
1313 v1->pPixels = 0; | |
1314 v1->uNumPixels = 0; | |
1315 v1->uHeight = 0; | |
1316 v1->uWidth = 0; | |
1317 v1->field_1A = 0; | |
1318 v1->field_18 = 0; | |
1319 } | |
1320 | |
1321 //----- (0040E55E) -------------------------------------------------------- | |
1322 int RGBTexture::_40E55E(const char *Filename, unsigned int a3) | |
1323 { | |
1324 RGBTexture *v3; // esi@1 | |
1325 signed int result; // eax@2 | |
1326 char *v6; // eax@3 | |
1327 int v7; // edx@3 | |
1328 char v8; // cl@4 | |
1329 unsigned __int16 v9; // cx@9 | |
1330 unsigned __int16 v10; // ax@9 | |
1331 int v11; // eax@9 | |
1332 char v12; // zf@9 | |
1333 void *v13; // eax@12 | |
1334 signed int v14; // ecx@19 | |
1335 signed int v15; // ecx@24 | |
1336 int v16; // eax@57 | |
1337 unsigned __int16 *v17; // ecx@57 | |
1338 unsigned __int16 *v18; // edi@57 | |
1339 signed int v19; // eax@59 | |
1340 unsigned __int16 *v20; // edi@64 | |
1341 signed int v21; // eax@66 | |
1342 unsigned __int16 *v22; // edi@71 | |
1343 signed int v23; // eax@73 | |
1344 int v24; // eax@78 | |
71 | 1345 char v25[48]; // [sp+Ch] [bp-54h]@3 |
1346 PCXHeader1 pcx_header1; | |
1347 PCXHeader2 pcx_header2; | |
0 | 1348 int v37; // [sp+54h] [bp-Ch]@3 |
1349 int v38; // [sp+58h] [bp-8h]@57 | |
1350 FILE *File; // [sp+5Ch] [bp-4h]@1 | |
1351 | |
1352 v3 = this; | |
1353 File = fopen(Filename, "rb"); | |
1354 if ( !File ) | |
1355 return 1; | |
71 | 1356 |
1357 fread(&pcx_header1, sizeof(pcx_header1), 1, File); | |
1358 fread(&v25,48,1,File); | |
1359 fread(&pcx_header2, 4, 1, File); | |
1360 | |
0 | 1361 v6 = (char *)Filename; |
1362 v37 = 0; | |
1363 v7 = (char *)v3 - Filename; | |
1364 do | |
1365 { | |
1366 v8 = *v6; | |
1367 if ( !*v6 ) | |
1368 break; | |
1369 if ( v8 == 46 ) | |
1370 break; | |
1371 ++v37; | |
1372 (v6++)[v7] = v8; | |
1373 } | |
1374 while ( v37 < 15 ); | |
1375 v3->pName[v37] = 0; | |
71 | 1376 if ( pcx_header1.bpp != 8 ) |
0 | 1377 return 3; |
71 | 1378 v9 = pcx_header1.right - pcx_header1.left + 1; |
1379 v10 = pcx_header1.bottom - pcx_header1.up; | |
0 | 1380 v3->uWidth = v9; |
1381 ++v10; | |
1382 v3->uHeight = v10; | |
1383 v11 = (signed __int16)v9 * (signed __int16)v10; | |
1384 v12 = a3 == 0; | |
1385 v3->uNumPixels = v11; | |
1386 if ( v12 ) | |
1387 { | |
1388 if ( v3->pPixels ) | |
1389 pAllocator->FreeChunk(v3->pPixels); | |
1390 v13 = pAllocator->AllocNamedChunk(v3->pPixels, 2 * v3->uNumPixels + 4, v3->pName); | |
1391 goto LABEL_16; | |
1392 } | |
1393 if ( a3 != 1 && a3 == 2 ) | |
1394 { | |
1395 v13 = operator new(4 * v11 + 8); | |
1396 *(unsigned int *)&v3->field_20 |= 1u; | |
1397 LABEL_16: | |
1398 v3->pPixels = (unsigned __int16 *)v13; | |
1399 } | |
1400 if ( v3->pPixels ) | |
1401 { | |
1402 v14 = 1; | |
1403 while ( 1 << v14 != v3->uWidth ) | |
1404 { | |
1405 ++v14; | |
1406 if ( v14 >= 15 ) | |
1407 goto LABEL_24; | |
1408 } | |
1409 v3->field_18 = v14; | |
1410 LABEL_24: | |
1411 v15 = 1; | |
1412 while ( 1 << v15 != v3->uHeight ) | |
1413 { | |
1414 ++v15; | |
1415 if ( v15 >= 15 ) | |
1416 goto LABEL_29; | |
1417 } | |
1418 v3->field_1A = v15; | |
1419 LABEL_29: | |
1420 switch ( v3->field_18 ) | |
1421 { | |
1422 case 2: | |
1423 v3->field_1C = 3; | |
1424 break; | |
1425 case 3: | |
1426 v3->field_1C = 7; | |
1427 break; | |
1428 case 4: | |
1429 v3->field_1C = 15; | |
1430 break; | |
1431 case 5: | |
1432 v3->field_1C = 31; | |
1433 break; | |
1434 case 6: | |
1435 v3->field_1C = 63; | |
1436 break; | |
1437 case 7: | |
1438 v3->field_1C = 127; | |
1439 break; | |
1440 case 8: | |
1441 v3->field_1C = 255; | |
1442 break; | |
1443 case 9: | |
1444 v3->field_1C = 511; | |
1445 break; | |
1446 case 10: | |
1447 v3->field_1C = 1023; | |
1448 break; | |
1449 case 11: | |
1450 v3->field_1C = 2047; | |
1451 break; | |
1452 case 12: | |
1453 v3->field_1C = 4095; | |
1454 break; | |
1455 default: | |
1456 break; | |
1457 } | |
1458 switch ( v3->field_1A ) | |
1459 { | |
1460 case 2: | |
1461 v3->field_1E = 3; | |
1462 break; | |
1463 case 3: | |
1464 v3->field_1E = 7; | |
1465 break; | |
1466 case 4: | |
1467 v3->field_1E = 15; | |
1468 break; | |
1469 case 5: | |
1470 v3->field_1E = 31; | |
1471 break; | |
1472 case 6: | |
1473 v3->field_1E = 63; | |
1474 break; | |
1475 case 7: | |
1476 v3->field_1E = 127; | |
1477 break; | |
1478 case 8: | |
1479 v3->field_1E = 255; | |
1480 break; | |
1481 case 9: | |
1482 v3->field_1E = 511; | |
1483 break; | |
1484 case 10: | |
1485 v3->field_1E = 1023; | |
1486 break; | |
1487 case 11: | |
1488 v3->field_1E = 2047; | |
1489 break; | |
1490 case 12: | |
1491 v3->field_1E = 4095; | |
1492 break; | |
1493 default: | |
1494 break; | |
1495 } | |
1496 fseek(File, 128, 0); | |
1497 ftell(File); | |
71 | 1498 if ( pcx_header2.planes == 1 ) |
0 | 1499 Abortf("24bit PCX Only!"); |
71 | 1500 if ( pcx_header2.planes == 3 ) |
0 | 1501 { |
1502 v37 = 0; | |
1503 if ( v3->uHeight > 0 ) | |
1504 { | |
1505 do | |
1506 { | |
1507 v16 = v37 * v3->uWidth; | |
1508 v17 = v3->pPixels; | |
1509 v38 = 0; | |
1510 v18 = &v17[v16]; | |
71 | 1511 if ( pcx_header2.pitch ) |
0 | 1512 { |
1513 do | |
1514 { | |
1515 fread((char *)&Filename + 3, 1u, 1u, File); | |
1516 if ( (BYTE3(Filename) & 0xC0) == -64 ) | |
1517 { | |
1518 BYTE3(Filename) &= 0x3Fu; | |
1519 fread((char *)&a3 + 3, 1u, 1u, File); | |
1520 v19 = 0; | |
1521 if ( BYTE3(Filename) ) | |
1522 { | |
1523 do | |
1524 { | |
1525 ++v38; | |
1526 *v18 = LOWORD(pRenderer->uTargetRMask) & (BYTE3(a3) << (LOBYTE(pRenderer->uTargetGBits) | |
1527 + LOBYTE(pRenderer->uTargetRBits) | |
1528 + LOBYTE(pRenderer->uTargetBBits) | |
1529 - 8)); | |
1530 ++v18; | |
1531 ++v19; | |
1532 } | |
1533 while ( v19 < BYTE3(Filename) ); | |
1534 } | |
1535 } | |
1536 else | |
1537 { | |
1538 ++v38; | |
1539 *v18 = LOWORD(pRenderer->uTargetRMask) & (BYTE3(Filename) << (LOBYTE(pRenderer->uTargetGBits) | |
1540 + LOBYTE(pRenderer->uTargetRBits) | |
1541 + LOBYTE(pRenderer->uTargetBBits) | |
1542 - 8)); | |
1543 ++v18; | |
1544 } | |
1545 } | |
71 | 1546 while ( v38 < (unsigned __int16)pcx_header2.pitch); |
0 | 1547 } |
1548 v20 = &v3->pPixels[v37 * v3->uWidth]; | |
71 | 1549 while ( v38 < 2 * (unsigned __int16)pcx_header2.pitch ) |
0 | 1550 { |
1551 fread((char *)&Filename + 3, 1u, 1u, File); | |
1552 if ( (BYTE3(Filename) & 0xC0) == -64 ) | |
1553 { | |
1554 BYTE3(Filename) &= 0x3Fu; | |
1555 fread((char *)&a3 + 3, 1u, 1u, File); | |
1556 v21 = 0; | |
1557 if ( BYTE3(Filename) ) | |
1558 { | |
1559 do | |
1560 { | |
1561 *v20 |= pRenderer->uTargetGMask & (unsigned __int16)(BYTE3(a3) << (LOBYTE(pRenderer->uTargetGBits) | |
1562 + LOBYTE(pRenderer->uTargetBBits) | |
1563 - 8)); | |
1564 ++v38; | |
1565 ++v20; | |
1566 ++v21; | |
1567 } | |
1568 while ( v21 < BYTE3(Filename) ); | |
1569 } | |
1570 } | |
1571 else | |
1572 { | |
1573 *v20 |= pRenderer->uTargetGMask & (unsigned __int16)(BYTE3(Filename) << (LOBYTE(pRenderer->uTargetGBits) | |
1574 + LOBYTE(pRenderer->uTargetBBits) | |
1575 - 8)); | |
1576 ++v38; | |
1577 ++v20; | |
1578 } | |
1579 } | |
1580 v22 = &v3->pPixels[v37 * v3->uWidth]; | |
71 | 1581 while ( v38 < 3 * (unsigned __int16)pcx_header2.pitch ) |
0 | 1582 { |
1583 fread((char *)&Filename + 3, 1u, 1u, File); | |
1584 if ( (BYTE3(Filename) & 0xC0) == -64 ) | |
1585 { | |
1586 BYTE3(Filename) &= 0x3Fu; | |
1587 fread((char *)&a3 + 3, 1u, 1u, File); | |
1588 v23 = 0; | |
1589 if ( BYTE3(Filename) ) | |
1590 { | |
1591 do | |
1592 { | |
1593 *v22 |= BYTE3(a3) >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1594 ++v38; | |
1595 ++v22; | |
1596 ++v23; | |
1597 } | |
1598 while ( v23 < BYTE3(Filename) ); | |
1599 } | |
1600 } | |
1601 else | |
1602 { | |
1603 *v22 |= BYTE3(Filename) >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1604 ++v38; | |
1605 ++v22; | |
1606 } | |
1607 } | |
1608 v24 = v3->uHeight; | |
1609 ++v37; | |
1610 } | |
1611 while ( v37 < v24 ); | |
1612 } | |
1613 } | |
1614 fclose(File); | |
1615 result = 0; | |
1616 } | |
1617 else | |
1618 { | |
1619 result = 2; | |
1620 } | |
1621 return result; | |
1622 } | |
1623 | |
1624 | |
1625 //----- (0040D73D) -------------------------------------------------------- | |
1626 RGBTexture::RGBTexture() | |
1627 { | |
1628 pName[0] = 0; | |
1629 pPixels = 0; | |
1630 uNumPixels = 0; | |
1631 uHeight = 0; | |
1632 uWidth = 0; | |
1633 field_1A = 0; | |
1634 field_18 = 0; | |
1635 field_20 = 0; | |
1636 field_22 = 0; | |
1637 } |