Mercurial > mm7
annotate Texture.cpp @ 1308:ad903bb5b702
Слияние
author | Ritor1 |
---|---|
date | Mon, 24 Jun 2013 18:59:39 +0600 |
parents | 13b7be8b06a0 |
children | a519a6a412d0 |
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 | |
1262 | 195 stru355 stru_4E82A4 = {0x20, 0x41, 0, 0x20, 0xFF0000, 0xFF00, 0xFF, 0xFF000000}; |
196 stru355 stru_4EFCBC = {0x20, 0x41, 0, 0x10, 0x7C00, 0x3E0, 0x1F, 0x8000}; | |
0 | 197 |
198 Texture pTex_F7CE30; | |
199 | |
200 | |
201 RGBTexture stru_5773C4; // idb | |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 /* 245 */ | |
214 #pragma pack(push, 1) | |
215 struct PCXHeader1 | |
216 { | |
217 char magic; | |
218 char version; | |
219 char encoding; | |
220 char bpp; | |
221 __int16 left; | |
222 __int16 up; | |
223 __int16 right; | |
224 __int16 bottom; | |
225 __int16 hres; | |
226 __int16 vres; | |
227 }; | |
228 #pragma pack(pop) | |
229 | |
230 /* 246 */ | |
231 #pragma pack(push, 1) | |
232 struct PCXHeader2 | |
233 { | |
234 char reserved; | |
235 char planes; | |
236 __int16 pitch; | |
237 __int16 palette_info; | |
238 }; | |
239 #pragma pack(pop) | |
240 | |
241 | |
242 | |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | |
249 //----- (0044E054) -------------------------------------------------------- | |
250 void TextureFrameTable::ToFile() | |
251 { | |
252 TextureFrameTable *v1; // esi@1 | |
253 FILE *v2; // eax@1 | |
254 FILE *v3; // edi@1 | |
255 | |
256 v1 = this; | |
257 v2 = fopen("data\\dtft.bin", "wb"); | |
258 v3 = v2; | |
259 if ( !v2 ) | |
260 Abortf("Unable to save dtft.bin!"); | |
261 fwrite(v1, 4u, 1u, v2); | |
711 | 262 fwrite(v1->pTextures, 0x14u, v1->sNumTextures, v3); |
0 | 263 fclose(v3); |
264 } | |
265 | |
266 //----- (0044E0A0) -------------------------------------------------------- | |
267 void TextureFrameTable::FromFile(void *pSerialized) | |
268 { | |
711 | 269 sNumTextures = *(int *)pSerialized; |
270 pTextures = (TextureFrame *)pAllocator->AllocNamedChunk(pTextures, 20 * sNumTextures, "Txt Frames"); | |
271 memcpy(pTextures, (char *)pSerialized + 4, 20 * sNumTextures); | |
0 | 272 } |
273 | |
274 //----- (0044E0ED) -------------------------------------------------------- | |
711 | 275 void TextureFrameTable::LoadAnimationSequenceAndPalettes( signed int uIconID ) |
276 { | |
0 | 277 TextureFrameTable *v3; // ebx@1 |
278 unsigned int i; // edi@3 | |
279 | |
280 v3 = this; | |
711 | 281 if ( (uIconID <= this->sNumTextures) && uIconID >= 0 ) |
0 | 282 { |
283 for ( i = uIconID; ; ++i ) | |
284 { | |
285 v3->pTextures[i].uTextureID = pBitmaps_LOD->LoadTexture(v3->pTextures[i].pTextureName, TEXTURE_DEFAULT); | |
973 | 286 |
1108
a1fd8045ffb1
probably erroneous semicolons removed, mace and staff stun chance work as they should
Grumpy7
parents:
1104
diff
changeset
|
287 if (v3->pTextures[i].uTextureID != -1) |
973 | 288 pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID].palette_id1); |
711 | 289 //result = (unsigned int)v3->pTextures; |
290 //if ( !(*(char *)(result + i * 20 + 18) & 1) ) | |
973 | 291 if( v3->pTextures[i].uFlags & 1) |
0 | 292 break; |
293 } | |
294 } | |
711 | 295 return; |
0 | 296 } |
297 | |
298 //----- (0044E163) -------------------------------------------------------- | |
299 unsigned int TextureFrameTable::FindTextureByName(const char *Str2) | |
300 { | |
301 TextureFrameTable *v2; // esi@1 | |
302 int v3; // ebx@1 | |
303 unsigned int uID; // edi@1 | |
304 unsigned int result; // eax@4 | |
305 | |
306 v2 = this; | |
307 v3 = 0; | |
308 uID = 0; | |
711 | 309 if ( (signed int)this->sNumTextures <= 0 ) |
0 | 310 { |
311 LABEL_4: | |
312 result = -1; | |
313 } | |
314 else | |
315 { | |
1104 | 316 while ( _stricmp(v2->pTextures[v3].pTextureName, Str2) ) |
0 | 317 { |
318 ++uID; | |
319 ++v3; | |
711 | 320 if ( (signed int)uID >= (signed int)v2->sNumTextures ) |
0 | 321 goto LABEL_4; |
322 } | |
323 result = uID; | |
324 } | |
325 return result; | |
326 } | |
327 | |
328 //----- (0044E19A) -------------------------------------------------------- | |
329 unsigned int TextureFrameTable::GetFrameTexture(int uFrameID, signed int a3) | |
330 { | |
331 int v3; // esi@1 | |
332 TextureFrame *v4; // edi@1 | |
333 TextureFrame *v5; // ecx@1 | |
334 __int16 v6; // dx@2 | |
335 int v7; // edx@3 | |
336 char *i; // eax@3 | |
337 int v9; // ecx@5 | |
338 unsigned int result; // eax@6 | |
339 | |
340 v3 = uFrameID; | |
341 v4 = this->pTextures; | |
342 v5 = &v4[uFrameID]; | |
343 if ( v5->uFlags & 1 && (v6 = v5->uAnimLength) != 0 ) | |
344 { | |
345 v7 = (a3 >> 3) % v6; | |
346 for ( i = (char *)&v5->uAnimTime; ; i += 20 ) | |
347 { | |
348 v9 = *(short *)i; | |
349 if ( v7 <= v9 ) | |
350 break; | |
351 v7 -= v9; | |
352 ++v3; | |
353 } | |
354 result = v4[v3].uTextureID; | |
355 } | |
356 else | |
357 { | |
358 result = v5->uTextureID; | |
359 } | |
360 return result; | |
361 } | |
362 | |
363 | |
364 | |
365 | |
366 | |
367 | |
368 //----- (0040F806) -------------------------------------------------------- | |
369 void *Texture::UnzipPalette() | |
370 { | |
371 Texture *v1; // esi@1 | |
1093 | 372 |
0 | 373 void *v2; // edi@1 |
374 Texture *pSource; // [sp+0h] [bp-4h]@1 | |
375 | |
376 pSource = this; | |
377 v1 = this; | |
378 v2 = malloc(this->uDecompressedSize); | |
710 | 379 zlib::MemUnzip(v2, (unsigned int *)&pSource, v1->pLevelOfDetail0_prolly_alpha_mask, v1->uTextureSize); |
0 | 380 return v2; |
381 } | |
382 | |
383 //----- (0040F77C) -------------------------------------------------------- | |
384 void Texture::Release() | |
385 { | |
386 if (this) | |
387 { | |
388 pName[0] = 0; | |
389 | |
390 if (pBits & 0x0400) | |
391 { | |
1093 | 392 __debugbreak(); |
393 } | |
394 | |
395 pAllocator->FreeChunk(pLevelOfDetail0_prolly_alpha_mask); | |
0 | 396 pAllocator->FreeChunk(pPalette16); |
397 pAllocator->FreeChunk(pPalette24); | |
1093 | 398 |
0 | 399 |
710 | 400 pLevelOfDetail0_prolly_alpha_mask = nullptr; |
0 | 401 pLevelOfDetail1 = nullptr; |
402 pLevelOfDetail2 = nullptr; | |
403 pLevelOfDetail3 = nullptr; | |
404 | |
405 pPalette16 = nullptr; | |
406 pPalette24 = nullptr; | |
407 | |
408 uSizeOfMaxLevelOfDetail = 0; | |
409 uTextureSize = 0; | |
410 uTextureHeight = 0; | |
411 uTextureWidth = 0; | |
412 uHeightLn2 = 0; | |
413 uWidthLn2 = 0; | |
414 palette_id1 = 0; | |
415 palette_id2 = 0; | |
416 pBits &= 0xFFFF0000; | |
417 } | |
418 } | |
419 | |
420 //----- (0040F5F5) -------------------------------------------------------- | |
421 int RGBTexture::Reload(const char *pContainer) | |
422 { | |
423 RGBTexture *v2; // esi@1 | |
424 FILE *v3; // eax@3 | |
425 FILE *v4; // edi@3 | |
426 void *v5; // ebx@7 | |
427 signed int result; // eax@11 | |
428 unsigned int v7; // ecx@12 | |
429 unsigned __int16 *v8; // ST20_4@14 | |
430 int v9; // eax@14 | |
431 char color_map[48]; // [sp+8h] [bp-98h]@9 | |
432 Texture DstBuf; // [sp+38h] [bp-68h]@1 | |
433 PCXHeader1 header1; // [sp+80h] [bp-20h]@9 | |
434 PCXHeader2 header2; // [sp+90h] [bp-10h]@9 | |
435 FILE *File; // [sp+98h] [bp-8h]@3 | |
436 size_t Count; // [sp+9Ch] [bp-4h]@6 | |
437 void *uSourceLena; // [sp+A8h] [bp+8h]@7 | |
438 | |
439 v2 = this; | |
440 if ( !v2->pPixels ) | |
441 return 2; | |
442 v3 = pIcons_LOD->FindContainer(pContainer, 0); | |
443 v4 = v3; | |
444 File = v3; | |
445 if ( !v3 ) | |
446 { | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1165
diff
changeset
|
447 sprintf(pTmpBuf.data(), "Unable to load %s", pContainer); |
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1165
diff
changeset
|
448 Abortf(pTmpBuf.data()); |
0 | 449 } |
450 fread(&DstBuf, 1u, 0x30u, v3); | |
451 Count = DstBuf.uTextureSize; | |
452 if ( DstBuf.uDecompressedSize ) | |
453 { | |
454 v5 = malloc(DstBuf.uDecompressedSize); | |
455 uSourceLena = pAllocator->AllocNamedChunk(0, DstBuf.uTextureSize, DstBuf.pName); | |
456 fread(uSourceLena, 1u, Count, File); | |
457 zlib::MemUnzip(v5, &DstBuf.uDecompressedSize, uSourceLena, DstBuf.uTextureSize); | |
458 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
459 pAllocator->FreeChunk(uSourceLena); | |
460 } | |
461 else | |
462 { | |
463 v5 = malloc(DstBuf.uTextureSize); | |
464 fread(v5, 1u, Count, v4); | |
465 } | |
466 memcpy(&header1, v5, 0x10u); | |
467 memcpy(color_map, (char *)v5 + 16, 0x30u); | |
468 memcpy(&header2, (char *)v5 + 64, 6u); | |
469 if ( header1.bpp != 8 ) | |
470 return 3; | |
471 v7 = (signed __int16)(header1.right - header1.left + 1); | |
472 if ( (signed int)(v7 * (signed __int16)(header1.bottom - header1.up + 1)) <= (signed int)v2->uNumPixels ) | |
473 { | |
474 v2->uWidth = header1.right - header1.left + 1; | |
475 v8 = v2->pPixels; | |
476 v9 = v7 * v2->uHeight; | |
477 v2->uNumPixels = v9; | |
478 v2->uHeight = v9; | |
479 v2->DecodePCX((char *)v5, v8, v7); | |
480 free(v5); | |
481 result = 0; | |
482 } | |
483 else | |
484 { | |
485 result = -1; | |
486 } | |
487 return result; | |
488 } | |
489 | |
490 //----- (0040F5BE) -------------------------------------------------------- | |
491 Texture::Texture() | |
492 { | |
493 pName[0] = 0; | |
494 uSizeOfMaxLevelOfDetail = 0; | |
495 uTextureSize = 0; | |
496 uTextureHeight = 0; | |
497 uTextureWidth = 0; | |
498 uHeightLn2 = 0; | |
499 uWidthLn2 = 0; | |
500 palette_id1 = 0; | |
501 palette_id2 = 0; | |
710 | 502 pLevelOfDetail0_prolly_alpha_mask = 0; |
0 | 503 pLevelOfDetail3 = 0; |
504 pLevelOfDetail2 = 0; | |
505 pLevelOfDetail1 = 0; | |
506 pPalette16 = 0; | |
507 pPalette24 = 0; | |
508 } | |
509 | |
510 //----- (0040F414) -------------------------------------------------------- | |
511 int RGBTexture::Load(const char *pContainer, int mode) | |
512 { | |
513 RGBTexture *v3; // esi@1 | |
514 FILE *v4; // eax@1 | |
515 FILE *v5; // ebx@1 | |
516 void *v6; // ebx@5 | |
517 unsigned __int16 v7; // ax@9 | |
518 unsigned __int16 v8; // cx@9 | |
519 int v9; // ecx@9 | |
520 void *v10; // eax@9 | |
521 void *v11; // eax@13 | |
522 unsigned __int16 *v12; // eax@17 | |
523 char color_map[48]; // [sp+Ch] [bp-98h]@7 | |
524 Texture DstBuf; // [sp+3Ch] [bp-68h]@1 | |
525 PCXHeader1 header1; // [sp+84h] [bp-20h]@7 | |
526 PCXHeader2 header2; // [sp+94h] [bp-10h]@7 | |
527 FILE *File; // [sp+9Ch] [bp-8h]@1 | |
528 size_t Count; // [sp+A0h] [bp-4h]@4 | |
529 char *Str1a; // [sp+ACh] [bp+8h]@5 | |
530 | |
531 v3 = this; | |
532 v4 = pIcons_LOD->FindContainer(pContainer, 0); | |
533 v5 = v4; | |
534 File = v4; | |
535 if ( !v4 ) | |
536 { | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1165
diff
changeset
|
537 sprintf(pTmpBuf.data(), "Unable to load %s", pContainer); |
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1165
diff
changeset
|
538 Abortf(pTmpBuf.data()); |
0 | 539 } |
540 fread(&DstBuf, 1u, 0x30u, v4); | |
541 Count = DstBuf.uTextureSize; | |
542 if ( DstBuf.uDecompressedSize ) | |
543 { | |
544 Str1a = (char *)malloc(DstBuf.uDecompressedSize); | |
545 v6 = pAllocator->AllocNamedChunk(0, DstBuf.uTextureSize, DstBuf.pName); | |
546 fread(v6, 1u, Count, File); | |
547 zlib::MemUnzip(Str1a, &DstBuf.uDecompressedSize, v6, DstBuf.uTextureSize); | |
548 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
549 pAllocator->FreeChunk(v6); | |
550 } | |
551 else | |
552 { | |
553 Str1a = (char *)malloc(DstBuf.uTextureSize); | |
554 fread(Str1a, 1u, Count, v5); | |
555 } | |
556 memcpy(&header1, Str1a, 0x10u); | |
557 memcpy(color_map, Str1a + 16, 0x30u); | |
558 memcpy(&header2, Str1a + 64, 6u); | |
559 if ( header1.bpp != 8 ) | |
560 return 3; | |
561 v7 = header1.right - header1.left + 1; | |
562 v8 = header1.bottom - header1.up + 1; | |
563 v3->uWidth = v7; | |
564 v3->uHeight = v8; | |
565 v9 = (signed __int16)v7 * (signed __int16)v8; | |
566 v10 = v3->pPixels; | |
567 v3->uNumPixels = v9; | |
568 if ( v10 ) | |
569 { | |
570 if ( mode ) | |
571 goto LABEL_14; | |
572 pAllocator->FreeChunk(v10); | |
573 } | |
574 if ( !mode ) | |
575 { | |
576 v11 = pAllocator->AllocNamedChunk(v3->pPixels, 2 * v3->uNumPixels + 4, "16bit PCX"); | |
577 goto LABEL_16; | |
578 } | |
579 LABEL_14: | |
580 if ( mode != 2 ) | |
581 goto LABEL_17; | |
582 v11 = malloc(2 * v3->uNumPixels + 4); | |
583 *(unsigned int *)&v3->field_20 |= 1u; | |
584 LABEL_16: | |
585 v3->pPixels = (unsigned __int16 *)v11; | |
586 LABEL_17: | |
587 v12 = v3->pPixels; | |
588 if ( !v12 ) | |
589 return 2; | |
590 v3->DecodePCX(Str1a, v12, v3->uWidth); | |
591 free(Str1a); | |
592 return 0; | |
593 } | |
594 | |
595 | |
596 //----- (0040F037) -------------------------------------------------------- | |
597 signed int RGBTexture::DecodePCX(char *pPcx, unsigned __int16 *pOutPixels, unsigned int uNumPixels) | |
598 { | |
599 signed int result; // eax@2 | |
600 unsigned char test_byte; // edx@3 | |
601 unsigned int read_offset; // ebx@37 | |
602 unsigned int row_position; // edi@40 | |
603 unsigned char value; // cl@63 | |
604 char count; // [sp+50h] [bp-Ch]@43 | |
605 unsigned short current_line; // [sp+54h] [bp-8h]@38 | |
606 unsigned short *dec_position; | |
607 unsigned short *temp_dec_position; | |
608 PCXHeader1 psx_head1; | |
609 PCXHeader2 psx_head2; | |
610 short int width, height; | |
611 BYTE color_map[48]; // Colormap for 16-color images | |
612 | |
613 | |
614 memcpy(&psx_head1, pPcx , 16); | |
615 memcpy(&color_map, pPcx + 16, 48); | |
616 memcpy(&psx_head2, pPcx + 64, 6); | |
617 | |
618 | |
619 if (psx_head1.bpp!=8) | |
620 return 3; | |
621 uWidth=(short int )(psx_head1.right-psx_head1.left+1); // word @ 000014 | |
622 uHeight=(short int )(psx_head1.bottom-psx_head1.up+1); // word @ 000016 | |
623 | |
624 | |
625 uNumPixels=uWidth*uHeight; // dword @ 000010 | |
626 | |
627 memset(pOutPixels, 0, uNumPixels * sizeof(__int16)); | |
628 short i=1; | |
629 while ( (1<<i) !=uWidth) | |
630 { | |
631 ++i; | |
632 if (i >= 15) | |
633 break; | |
634 } | |
635 field_18=i; | |
636 short i_=1; | |
637 while ( (1<<i_) !=uHeight) | |
638 { | |
639 ++i_; | |
640 if (i_ >= 15) | |
641 break; | |
642 } | |
643 field_1A=i_; | |
644 switch (field_18) | |
645 { | |
646 case 2: field_1C = 3; break; | |
647 case 3: field_1C = 7; break; | |
648 case 4: field_1C = 15; break; | |
649 case 5: field_1C = 31; break; | |
650 case 6: field_1C = 63; break; | |
651 case 7: field_1C = 127; break; | |
652 case 8: field_1C = 255; break; | |
653 case 9: field_1C = 511; break; | |
654 case 10: field_1C = 1023; break; | |
655 case 11: field_1C = 2047; break; | |
656 case 12: field_1C = 4095; break; | |
657 } | |
658 | |
659 switch (field_1A) | |
660 { | |
661 case 2: field_1E = 3; break; | |
662 case 3: field_1E = 7; break; | |
663 case 4: field_1E = 15; break; | |
664 case 5: field_1E = 31; break; | |
665 case 6: field_1E = 63; break; | |
666 case 7: field_1E = 127; break; | |
667 case 8: field_1E = 255; break; | |
668 case 9: field_1E = 511; break; | |
669 case 10: field_1E = 1023; break; | |
670 case 11: field_1E = 2047; break; | |
671 case 12: field_1E = 4095; break; | |
672 } | |
673 | |
674 | |
675 read_offset = 128; | |
676 if (psx_head2.planes != 3) | |
677 return 0; | |
678 current_line = 0; | |
679 if ( uHeight > 0 ) | |
680 { | |
681 dec_position = pOutPixels; | |
682 do | |
683 { | |
684 temp_dec_position = dec_position; | |
685 row_position = 0; | |
686 //decode red line | |
687 if (psx_head2.pitch) | |
688 { | |
689 do | |
690 { | |
691 test_byte = pPcx[read_offset]; | |
692 ++read_offset; | |
693 if ((test_byte & 0xC0) == 0xC0) | |
694 { | |
695 value = pPcx[read_offset]; | |
696 ++read_offset; | |
697 | |
698 if ((test_byte & 0x3F) > 0) | |
699 { | |
700 count = test_byte & 0x3F; | |
701 do | |
702 { | |
703 | |
704 ++row_position; | |
705 //*temp_dec_position =0xFF000000; | |
706 //*temp_dec_position|=(unsigned long)value<<16; | |
707 *temp_dec_position |= LOWORD(pRenderer->uTargetRMask) & ((unsigned __int8)value << (LOBYTE(pRenderer->uTargetGBits) | |
708 + LOBYTE(pRenderer->uTargetRBits) | |
709 + LOBYTE(pRenderer->uTargetBBits) | |
710 - 8)); | |
711 | |
712 temp_dec_position++; | |
713 if (row_position == psx_head2.pitch) | |
714 break; | |
715 } | |
716 while (count-- != 1); | |
717 } | |
718 } | |
719 else | |
720 { | |
721 ++row_position; | |
722 //*temp_dec_position =0xFF000000; | |
723 //*temp_dec_position|= (unsigned long)test_byte<<16; | |
724 | |
725 *temp_dec_position |= LOWORD(pRenderer->uTargetRMask) & ((unsigned __int8)test_byte << (LOBYTE(pRenderer->uTargetGBits) | |
726 + LOBYTE(pRenderer->uTargetRBits) | |
727 + LOBYTE(pRenderer->uTargetBBits) | |
728 - 8)); | |
729 | |
730 temp_dec_position++; | |
731 } | |
732 | |
733 } | |
734 while (row_position < psx_head2.pitch); | |
735 } | |
736 | |
737 temp_dec_position = dec_position; | |
738 row_position=0; | |
739 //decode green line | |
740 while (row_position < psx_head2.pitch) | |
741 { | |
742 test_byte = *(pPcx + read_offset); | |
743 ++read_offset; | |
744 if ((test_byte & 0xC0) == 0xC0) | |
745 { | |
746 value = *(pPcx + read_offset); | |
747 ++read_offset; | |
748 if ((test_byte & 0x3F) > 0) | |
749 { | |
750 count = test_byte & 0x3F; | |
751 do | |
752 { | |
753 //*temp_dec_position|= (unsigned int)value<<8; | |
754 //temp_dec_position++; | |
755 | |
756 *temp_dec_position|= pRenderer->uTargetGMask & (unsigned __int16)((unsigned __int8)value << (LOBYTE(pRenderer->uTargetGBits) | |
757 + LOBYTE(pRenderer->uTargetBBits) | |
758 - 8)); | |
759 | |
760 temp_dec_position++; | |
761 ++row_position; | |
762 if (row_position == psx_head2.pitch) | |
763 break; | |
764 | |
765 } | |
766 while (count-- != 1); | |
767 } | |
768 } | |
769 else | |
770 { | |
771 //*temp_dec_position |=(unsigned int) test_byte<<8; | |
772 //temp_dec_position++; | |
773 | |
774 *temp_dec_position|= pRenderer->uTargetGMask & (unsigned __int16)((unsigned __int8)test_byte << (LOBYTE(pRenderer->uTargetGBits) | |
775 + LOBYTE(pRenderer->uTargetBBits) | |
776 - 8)); | |
777 temp_dec_position++; | |
778 ++row_position; | |
779 } | |
780 } | |
781 | |
782 temp_dec_position = dec_position; | |
783 row_position=0; | |
784 //decode blue line | |
785 while (row_position < psx_head2.pitch) | |
786 { | |
787 test_byte = *(pPcx + read_offset); | |
788 read_offset++; | |
789 if ((test_byte & 0xC0) == 0xC0) | |
790 { | |
791 value = *(pPcx + read_offset); | |
792 ++read_offset; | |
793 if ((test_byte & 0x3F) > 0) | |
794 { | |
795 count = test_byte & 0x3F; | |
796 do | |
797 { | |
798 //*temp_dec_position|= value; | |
799 //temp_dec_position++; | |
800 | |
801 *temp_dec_position |= value >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
802 temp_dec_position++; | |
803 | |
804 ++row_position; | |
805 if (row_position == psx_head2.pitch) | |
806 break; | |
807 } | |
808 while (count-- != 1); | |
809 } | |
810 } | |
811 else | |
812 { | |
813 //*temp_dec_position|= test_byte; | |
814 //temp_dec_position++; | |
815 *temp_dec_position |= test_byte >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
816 temp_dec_position++; | |
817 | |
818 ++row_position; | |
819 } | |
820 | |
821 } | |
822 ++current_line; | |
823 dec_position += uWidth; | |
824 } | |
825 while (current_line < uHeight); | |
826 } | |
827 return 0; | |
828 /* | |
829 RGBTexture *v4; // esi@1 | |
830 signed int result; // eax@2 | |
831 unsigned __int16 v6; // ax@3 | |
832 unsigned __int16 *v7; // ecx@3 | |
833 unsigned int v8; // edx@3 | |
834 signed int v9; // ecx@3 | |
835 signed int v10; // ecx@8 | |
836 signed int v11; // ebx@37 | |
837 unsigned __int16 *v12; // eax@40 | |
838 int v13; // edi@40 | |
839 int v14; // ebx@41 | |
840 char v15; // bl@42 | |
841 unsigned __int16 *v16; // eax@50 | |
842 int v17; // ebx@51 | |
843 char v18; // bl@52 | |
844 unsigned __int16 *v19; // eax@61 | |
845 unsigned __int8 v20; // dl@62 | |
846 unsigned __int8 v21; // dl@63 | |
847 unsigned __int8 v22; // cl@63 | |
848 char color_map[48]; // [sp+8h] [bp-54h]@1 | |
849 PCXHeader1 header1; // [sp+38h] [bp-24h]@1 | |
850 PCXHeader2 header2; // [sp+48h] [bp-14h]@1 | |
851 unsigned int v26; // [sp+50h] [bp-Ch]@43 | |
852 int v27; // [sp+54h] [bp-8h]@38 | |
853 unsigned __int16 *v28; // [sp+58h] [bp-4h]@3 | |
854 int pOutPixelsa; // [sp+68h] [bp+Ch]@41 | |
855 int pOutPixelsb; // [sp+68h] [bp+Ch]@51 | |
856 | |
857 v4 = this; | |
858 memcpy(&header1, pPcx, 0x10u); | |
859 memcpy(color_map, pPcx + 16, 0x30u); | |
860 memcpy(&header2, pPcx + 64, 6u); | |
861 if ( header1.bpp == 8 ) | |
862 { | |
863 v6 = header1.right - header1.left + 1; | |
864 LOWORD(v7) = header1.bottom - header1.up + 1; | |
865 v4->uWidth = v6; | |
866 v4->uHeight = (unsigned __int16)v7; | |
867 v7 = (unsigned __int16 *)(signed __int16)v7; | |
868 v28 = v7; | |
869 v4->uNumPixels = (signed __int16)v7 * (signed __int16)v6; | |
870 HIWORD(v8) = 0; | |
871 v9 = 1; | |
872 while ( 1 << v9 != (signed __int16)v6 ) | |
873 { | |
874 ++v9; | |
875 if ( v9 >= 15 ) | |
876 goto LABEL_8; | |
877 } | |
878 v4->field_18 = v9; | |
879 LABEL_8: | |
880 v10 = 1; | |
881 while ( (unsigned __int16 *)(1 << v10) != v28 ) | |
882 { | |
883 ++v10; | |
884 if ( v10 >= 15 ) | |
885 goto LABEL_13; | |
886 } | |
887 v4->field_1A = v10; | |
888 LABEL_13: | |
889 switch ( v4->field_18 ) | |
890 { | |
891 case 2: | |
892 v4->field_1C = 3; | |
893 break; | |
894 case 3: | |
895 v4->field_1C = 7; | |
896 break; | |
897 case 4: | |
898 v4->field_1C = 15; | |
899 break; | |
900 case 5: | |
901 v4->field_1C = 31; | |
902 break; | |
903 case 6: | |
904 v4->field_1C = 63; | |
905 break; | |
906 case 7: | |
907 v4->field_1C = 127; | |
908 break; | |
909 case 8: | |
910 v4->field_1C = 255; | |
911 break; | |
912 case 9: | |
913 v4->field_1C = 511; | |
914 break; | |
915 case 10: | |
916 v4->field_1C = 1023; | |
917 break; | |
918 case 11: | |
919 v4->field_1C = 2047; | |
920 break; | |
921 case 12: | |
922 v4->field_1C = 4095; | |
923 break; | |
924 default: | |
925 break; | |
926 } | |
927 switch ( v4->field_1A ) | |
928 { | |
929 case 2: | |
930 v4->field_1E = 3; | |
931 break; | |
932 case 3: | |
933 v4->field_1E = 7; | |
934 break; | |
935 case 4: | |
936 v4->field_1E = 15; | |
937 break; | |
938 case 5: | |
939 v4->field_1E = 31; | |
940 break; | |
941 case 6: | |
942 v4->field_1E = 63; | |
943 break; | |
944 case 7: | |
945 v4->field_1E = 127; | |
946 break; | |
947 case 8: | |
948 v4->field_1E = 255; | |
949 break; | |
950 case 9: | |
951 v4->field_1E = 511; | |
952 break; | |
953 case 10: | |
954 v4->field_1E = 1023; | |
955 break; | |
956 case 11: | |
957 v4->field_1E = 2047; | |
958 break; | |
959 case 12: | |
960 v4->field_1E = 4095; | |
961 break; | |
962 default: | |
963 break; | |
964 } | |
965 v11 = 128; | |
966 if ( header2.planes == 3 ) | |
967 { | |
968 v27 = 0; | |
969 if ( (signed int)v28 > 0 ) | |
970 { | |
971 v28 = pOutPixels; | |
972 do | |
973 { | |
974 v12 = v28; | |
975 v13 = 0; | |
976 if ( header2.pitch ) | |
977 { | |
978 do | |
979 { | |
980 LOBYTE(v8) = pPcx[v11]; | |
981 v14 = v11 + 1; | |
982 pOutPixelsa = v14; | |
983 if ( (v8 & 0xC0) == -64 ) | |
984 { | |
985 pOutPixelsa = v14 + 1; | |
986 v15 = pPcx[v14]; | |
987 if ( (signed int)(v8 & 0x3F) > 0 ) | |
988 { | |
989 v26 = v8 & 0x3F; | |
990 do | |
991 { | |
992 ++v13; | |
993 *v12 = LOWORD(pRenderer->uTargetRMask) & ((unsigned __int8)v15 << (LOBYTE(pRenderer->uTargetGBits) | |
994 + LOBYTE(pRenderer->uTargetRBits) | |
995 + LOBYTE(pRenderer->uTargetBBits) | |
996 - 8)); | |
997 ++v12; | |
998 if ( v13 == (unsigned __int16)header2.pitch ) | |
999 v12 = &v12[uNumPixels - (unsigned __int16)header2.pitch - 1]; | |
1000 --v26; | |
1001 } | |
1002 while ( v26 ); | |
1003 } | |
1004 } | |
1005 else | |
1006 { | |
1007 LOWORD(v8) = (unsigned __int8)v8; | |
1008 v8 = pRenderer->uTargetRMask & (v8 << (LOBYTE(pRenderer->uTargetGBits) | |
1009 + LOBYTE(pRenderer->uTargetRBits) | |
1010 + LOBYTE(pRenderer->uTargetBBits) | |
1011 - 8)); | |
1012 ++v13; | |
1013 *v12 = v8; | |
1014 ++v12; | |
1015 } | |
1016 v11 = pOutPixelsa; | |
1017 } | |
1018 while ( v13 < (unsigned __int16)header2.pitch ); | |
1019 } | |
1020 v16 = v28; | |
1021 while ( v13 < 2 * (unsigned __int16)header2.pitch ) | |
1022 { | |
1023 LOBYTE(v8) = pPcx[v11]; | |
1024 v17 = v11 + 1; | |
1025 pOutPixelsb = v17; | |
1026 if ( (v8 & 0xC0) == -64 ) | |
1027 { | |
1028 pOutPixelsb = v17 + 1; | |
1029 v18 = pPcx[v17]; | |
1030 if ( (signed int)(v8 & 0x3F) > 0 ) | |
1031 { | |
1032 v26 = v8 & 0x3F; | |
1033 do | |
1034 { | |
1035 *v16 |= pRenderer->uTargetGMask & (unsigned __int16)((unsigned __int8)v18 << (LOBYTE(pRenderer->uTargetGBits) | |
1036 + LOBYTE(pRenderer->uTargetBBits) | |
1037 - 8)); | |
1038 ++v13; | |
1039 ++v16; | |
1040 if ( v13 == (unsigned __int16)header2.pitch ) | |
1041 v16 = &v16[uNumPixels - (unsigned __int16)header2.pitch - 1]; | |
1042 --v26; | |
1043 } | |
1044 while ( v26 ); | |
1045 } | |
1046 } | |
1047 else | |
1048 { | |
1049 LOWORD(v8) = (unsigned __int8)v8; | |
1050 v8 = pRenderer->uTargetGMask & (v8 << (LOBYTE(pRenderer->uTargetGBits) + LOBYTE(pRenderer->uTargetBBits) - 8)); | |
1051 *v16 |= v8; | |
1052 ++v13; | |
1053 ++v16; | |
1054 } | |
1055 v11 = pOutPixelsb; | |
1056 } | |
1057 v19 = v28; | |
1058 while ( v13 < 3 * (unsigned __int16)header2.pitch ) | |
1059 { | |
1060 v20 = pPcx[v11++]; | |
1061 if ( (v20 & 0xC0) == -64 ) | |
1062 { | |
1063 v21 = v20 & 0x3F; | |
1064 v22 = pPcx[v11++]; | |
1065 if ( (signed int)v21 > 0 ) | |
1066 { | |
1067 v26 = v21; | |
1068 do | |
1069 { | |
1070 *v19 |= v22 >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1071 ++v13; | |
1072 ++v19; | |
1073 if ( v13 == (unsigned __int16)header2.pitch ) | |
1074 { | |
1075 v8 = uNumPixels - (unsigned __int16)header2.pitch; | |
1076 v19 = &v19[uNumPixels - (unsigned __int16)header2.pitch - 1]; | |
1077 } | |
1078 --v26; | |
1079 } | |
1080 while ( v26 ); | |
1081 } | |
1082 } | |
1083 else | |
1084 { | |
1085 *v19 |= v20 >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1086 ++v13; | |
1087 ++v19; | |
1088 } | |
1089 } | |
1090 ++v27; | |
1091 v28 += uNumPixels; | |
1092 } | |
1093 while ( v27 < v4->uHeight ); | |
1094 } | |
1095 } | |
1096 result = 0; | |
1097 } | |
1098 else | |
1099 { | |
1100 result = 3; | |
1101 } | |
1102 return result; | |
1103 */ | |
1104 } | |
1105 | |
1106 //----- (0040EAD8) -------------------------------------------------------- | |
1107 unsigned int RGBTexture::LoadFromFILE(FILE *pFile, unsigned int mode, unsigned int bCloseFile) | |
1108 { | |
1109 signed int result; // eax@2 | |
1110 unsigned char test_byte; // edx@3 | |
1111 //unsigned int read_offset; // ebx@37 | |
1112 unsigned int row_position; // edi@40 | |
1113 unsigned char value; // cl@63 | |
1114 char count; // [sp+50h] [bp-Ch]@43 | |
1115 unsigned short current_line; // [sp+54h] [bp-8h]@38 | |
1116 unsigned short *dec_position; | |
1117 unsigned short *temp_dec_position; | |
1118 PCXHeader1 psx_head1; | |
1119 PCXHeader2 psx_head2; | |
1120 short int width, height; | |
1121 BYTE color_map[48]; // Colormap for 16-color images | |
1122 | |
1123 if (!pFile) | |
1124 return 1; | |
1125 | |
1126 | |
1127 fread(&psx_head1, 1, 16, pFile); | |
1128 fread(&color_map, 1, 48, pFile); | |
1129 fread(&psx_head2, 1, 6, pFile); | |
1130 | |
1131 if (psx_head1.bpp!=8) | |
1132 return 3; | |
1133 uWidth=(short int )(psx_head1.right-psx_head1.left+1); // word @ 000014 | |
1134 uHeight=(short int )(psx_head1.bottom-psx_head1.up+1); // word @ 000016 | |
1135 | |
1136 | |
1137 uNumPixels=uWidth*uHeight; // dword @ 000010 | |
1138 | |
1139 | |
1140 if ( mode == 0 ) | |
1141 { | |
1142 if ( pPixels ) | |
1143 { | |
1144 pAllocator->FreeChunk(pPixels); | |
1145 pPixels = 0; | |
1146 } | |
1147 pPixels = (unsigned __int16 *)pAllocator->AllocNamedChunk( | |
1148 pPixels, | |
1149 2 * uNumPixels + 4, | |
1150 pName); | |
1151 } | |
1152 else | |
1153 { | |
1154 if ( mode != 1 && mode == 2 ) | |
1155 { | |
1156 pPixels = (unsigned __int16 *)malloc((uNumPixels + 2) * sizeof(unsigned __int16)); | |
1157 field_20 |= 1; | |
1158 } | |
1159 } | |
1160 | |
1161 | |
1162 | |
1163 | |
1164 auto pOutPixels = pPixels; | |
1165 | |
1166 memset(pOutPixels, 0, uNumPixels * sizeof(__int16)); | |
1167 | |
1168 short i=1; | |
1169 while ( (1<<i) !=uWidth) | |
1170 { | |
1171 ++i; | |
1172 if (i >= 15) | |
1173 break; | |
1174 } | |
1175 field_18=i; | |
1176 short i_=1; | |
1177 while ( (1<<i_) !=uHeight) | |
1178 { | |
1179 ++i_; | |
1180 if (i_ >= 15) | |
1181 break; | |
1182 } | |
1183 field_1A=i_; | |
1184 switch (field_18) | |
1185 { | |
1186 case 2: field_1C = 3; break; | |
1187 case 3: field_1C = 7; break; | |
1188 case 4: field_1C = 15; break; | |
1189 case 5: field_1C = 31; break; | |
1190 case 6: field_1C = 63; break; | |
1191 case 7: field_1C = 127; break; | |
1192 case 8: field_1C = 255; break; | |
1193 case 9: field_1C = 511; break; | |
1194 case 10: field_1C = 1023; break; | |
1195 case 11: field_1C = 2047; break; | |
1196 case 12: field_1C = 4095; break; | |
1197 } | |
1198 | |
1199 switch (field_1A) | |
1200 { | |
1201 case 2: field_1E = 3; break; | |
1202 case 3: field_1E = 7; break; | |
1203 case 4: field_1E = 15; break; | |
1204 case 5: field_1E = 31; break; | |
1205 case 6: field_1E = 63; break; | |
1206 case 7: field_1E = 127; break; | |
1207 case 8: field_1E = 255; break; | |
1208 case 9: field_1E = 511; break; | |
1209 case 10: field_1E = 1023; break; | |
1210 case 11: field_1E = 2047; break; | |
1211 case 12: field_1E = 4095; break; | |
1212 } | |
1213 | |
1214 | |
1215 fseek(pFile, 128 - 70, SEEK_CUR); | |
1216 | |
1217 | |
1218 for (uint y = 0; y < uHeight; ++y) | |
1219 { | |
1220 unsigned __int16 *pDst = pPixels + y * uWidth; | |
1221 | |
1222 uint x = 0; | |
1223 do | |
1224 { | |
1225 uint ctrl = 0; | |
1226 fread(&ctrl, 1, 1, pFile); | |
1227 if ((ctrl & 0xC0) == 0xC0) | |
1228 { | |
1229 uint uNumPixels = ctrl & 0x3F; | |
1230 uint clr = 0; | |
1231 fread(&clr, 1, 1, pFile); | |
1232 for (uint i = 0; i < uNumPixels; ++i) | |
1233 pDst[x++] = pRenderer->uTargetRMask & (clr << (pRenderer->uTargetGBits + | |
1234 pRenderer->uTargetRBits + | |
1235 pRenderer->uTargetBBits - 8)); | |
1236 } | |
1237 else | |
1238 { | |
1239 pDst[x++] = pRenderer->uTargetRMask & (ctrl << (pRenderer->uTargetGBits + | |
1240 pRenderer->uTargetRBits + | |
1241 pRenderer->uTargetBBits - 8)); | |
1242 } | |
1243 } while (x < psx_head2.pitch); | |
1244 | |
1245 | |
1246 | |
1247 | |
1248 | |
1249 x = 0; | |
1250 do | |
1251 { | |
1252 uint ctrl = 0; | |
1253 fread(&ctrl, 1, 1, pFile); | |
1254 if ((ctrl & 0xC0) == 0xC0) | |
1255 { | |
1256 uint uNumPixels = ctrl & 0x3F; | |
1257 uint clr = 0; | |
1258 fread(&clr, 1, 1, pFile); | |
1259 for (uint i = 0; i < uNumPixels; ++i) | |
1260 pDst[x++] |= pRenderer->uTargetGMask & (clr << (pRenderer->uTargetGBits + | |
1261 pRenderer->uTargetBBits - 8)); | |
1262 } | |
1263 else | |
1264 { | |
1265 pDst[x++] |= pRenderer->uTargetGMask & (ctrl << (pRenderer->uTargetGBits + | |
1266 pRenderer->uTargetBBits - 8)); | |
1267 } | |
1268 } while (x < psx_head2.pitch); | |
1269 | |
1270 | |
1271 | |
1272 | |
1273 | |
1274 x = 0; | |
1275 do | |
1276 { | |
1277 uint ctrl = 0; | |
1278 fread(&ctrl, 1, 1, pFile); | |
1279 if ((ctrl & 0xC0) == 0xC0) | |
1280 { | |
1281 uint uNumPixels = ctrl & 0x3F; | |
1282 uint clr = 0; | |
1283 fread(&clr, 1, 1, pFile); | |
1284 for (uint i = 0; i < uNumPixels; ++i) | |
1285 pDst[x++] |= pRenderer->uTargetBMask & (clr >> (8 - pRenderer->uTargetBBits)); | |
1286 } | |
1287 else | |
1288 { | |
1289 pDst[x++] |= pRenderer->uTargetBMask & (ctrl >> (8 - pRenderer->uTargetRBits)); | |
1290 } | |
1291 } while (x < psx_head2.pitch); | |
1292 } | |
1293 | |
1294 if (bCloseFile) | |
1295 fclose(pFile); | |
1296 return 0; | |
1297 } | |
1298 | |
1299 //----- (0040E51F) -------------------------------------------------------- | |
1300 void RGBTexture::Release() | |
1301 { | |
1302 RGBTexture *v1; // esi@1 | |
1303 char v2; // zf@1 | |
1304 void *v3; // [sp-4h] [bp-Ch]@1 | |
1305 | |
1306 v1 = this; | |
1307 v2 = (this->field_20 & 1) == 0; | |
1308 v3 = this->pPixels; | |
1309 this->pName[0] = 0; | |
1310 if ( v2 ) | |
1311 pAllocator->FreeChunk(v3); | |
1312 else | |
1313 free(v3); | |
1314 *(unsigned int *)&v1->field_20 = 0; | |
1315 v1->pPixels = 0; | |
1316 v1->uNumPixels = 0; | |
1317 v1->uHeight = 0; | |
1318 v1->uWidth = 0; | |
1319 v1->field_1A = 0; | |
1320 v1->field_18 = 0; | |
1321 } | |
1322 | |
1323 //----- (0040E55E) -------------------------------------------------------- | |
1324 int RGBTexture::_40E55E(const char *Filename, unsigned int a3) | |
1325 { | |
1326 RGBTexture *v3; // esi@1 | |
1327 signed int result; // eax@2 | |
1328 char *v6; // eax@3 | |
1329 int v7; // edx@3 | |
1330 char v8; // cl@4 | |
1331 unsigned __int16 v9; // cx@9 | |
1332 unsigned __int16 v10; // ax@9 | |
1333 int v11; // eax@9 | |
1334 char v12; // zf@9 | |
1335 void *v13; // eax@12 | |
1336 signed int v14; // ecx@19 | |
1337 signed int v15; // ecx@24 | |
1338 int v16; // eax@57 | |
1339 unsigned __int16 *v17; // ecx@57 | |
1340 unsigned __int16 *v18; // edi@57 | |
1341 signed int v19; // eax@59 | |
1342 unsigned __int16 *v20; // edi@64 | |
1343 signed int v21; // eax@66 | |
1344 unsigned __int16 *v22; // edi@71 | |
1345 signed int v23; // eax@73 | |
1346 int v24; // eax@78 | |
71 | 1347 char v25[48]; // [sp+Ch] [bp-54h]@3 |
1348 PCXHeader1 pcx_header1; | |
1349 PCXHeader2 pcx_header2; | |
0 | 1350 int v37; // [sp+54h] [bp-Ch]@3 |
1351 int v38; // [sp+58h] [bp-8h]@57 | |
1352 FILE *File; // [sp+5Ch] [bp-4h]@1 | |
1353 | |
1354 v3 = this; | |
1355 File = fopen(Filename, "rb"); | |
1356 if ( !File ) | |
1357 return 1; | |
71 | 1358 |
1359 fread(&pcx_header1, sizeof(pcx_header1), 1, File); | |
1360 fread(&v25,48,1,File); | |
1361 fread(&pcx_header2, 4, 1, File); | |
1362 | |
0 | 1363 v6 = (char *)Filename; |
1364 v37 = 0; | |
1365 v7 = (char *)v3 - Filename; | |
1366 do | |
1367 { | |
1368 v8 = *v6; | |
1369 if ( !*v6 ) | |
1370 break; | |
1371 if ( v8 == 46 ) | |
1372 break; | |
1373 ++v37; | |
1374 (v6++)[v7] = v8; | |
1375 } | |
1376 while ( v37 < 15 ); | |
1377 v3->pName[v37] = 0; | |
71 | 1378 if ( pcx_header1.bpp != 8 ) |
0 | 1379 return 3; |
71 | 1380 v9 = pcx_header1.right - pcx_header1.left + 1; |
1381 v10 = pcx_header1.bottom - pcx_header1.up; | |
0 | 1382 v3->uWidth = v9; |
1383 ++v10; | |
1384 v3->uHeight = v10; | |
1385 v11 = (signed __int16)v9 * (signed __int16)v10; | |
1386 v12 = a3 == 0; | |
1387 v3->uNumPixels = v11; | |
1388 if ( v12 ) | |
1389 { | |
1390 if ( v3->pPixels ) | |
1391 pAllocator->FreeChunk(v3->pPixels); | |
1392 v13 = pAllocator->AllocNamedChunk(v3->pPixels, 2 * v3->uNumPixels + 4, v3->pName); | |
1393 goto LABEL_16; | |
1394 } | |
1395 if ( a3 != 1 && a3 == 2 ) | |
1396 { | |
1397 v13 = operator new(4 * v11 + 8); | |
1398 *(unsigned int *)&v3->field_20 |= 1u; | |
1399 LABEL_16: | |
1400 v3->pPixels = (unsigned __int16 *)v13; | |
1401 } | |
1402 if ( v3->pPixels ) | |
1403 { | |
1404 v14 = 1; | |
1405 while ( 1 << v14 != v3->uWidth ) | |
1406 { | |
1407 ++v14; | |
1408 if ( v14 >= 15 ) | |
1409 goto LABEL_24; | |
1410 } | |
1411 v3->field_18 = v14; | |
1412 LABEL_24: | |
1413 v15 = 1; | |
1414 while ( 1 << v15 != v3->uHeight ) | |
1415 { | |
1416 ++v15; | |
1417 if ( v15 >= 15 ) | |
1418 goto LABEL_29; | |
1419 } | |
1420 v3->field_1A = v15; | |
1421 LABEL_29: | |
1422 switch ( v3->field_18 ) | |
1423 { | |
1424 case 2: | |
1425 v3->field_1C = 3; | |
1426 break; | |
1427 case 3: | |
1428 v3->field_1C = 7; | |
1429 break; | |
1430 case 4: | |
1431 v3->field_1C = 15; | |
1432 break; | |
1433 case 5: | |
1434 v3->field_1C = 31; | |
1435 break; | |
1436 case 6: | |
1437 v3->field_1C = 63; | |
1438 break; | |
1439 case 7: | |
1440 v3->field_1C = 127; | |
1441 break; | |
1442 case 8: | |
1443 v3->field_1C = 255; | |
1444 break; | |
1445 case 9: | |
1446 v3->field_1C = 511; | |
1447 break; | |
1448 case 10: | |
1449 v3->field_1C = 1023; | |
1450 break; | |
1451 case 11: | |
1452 v3->field_1C = 2047; | |
1453 break; | |
1454 case 12: | |
1455 v3->field_1C = 4095; | |
1456 break; | |
1457 default: | |
1458 break; | |
1459 } | |
1460 switch ( v3->field_1A ) | |
1461 { | |
1462 case 2: | |
1463 v3->field_1E = 3; | |
1464 break; | |
1465 case 3: | |
1466 v3->field_1E = 7; | |
1467 break; | |
1468 case 4: | |
1469 v3->field_1E = 15; | |
1470 break; | |
1471 case 5: | |
1472 v3->field_1E = 31; | |
1473 break; | |
1474 case 6: | |
1475 v3->field_1E = 63; | |
1476 break; | |
1477 case 7: | |
1478 v3->field_1E = 127; | |
1479 break; | |
1480 case 8: | |
1481 v3->field_1E = 255; | |
1482 break; | |
1483 case 9: | |
1484 v3->field_1E = 511; | |
1485 break; | |
1486 case 10: | |
1487 v3->field_1E = 1023; | |
1488 break; | |
1489 case 11: | |
1490 v3->field_1E = 2047; | |
1491 break; | |
1492 case 12: | |
1493 v3->field_1E = 4095; | |
1494 break; | |
1495 default: | |
1496 break; | |
1497 } | |
1498 fseek(File, 128, 0); | |
1499 ftell(File); | |
71 | 1500 if ( pcx_header2.planes == 1 ) |
0 | 1501 Abortf("24bit PCX Only!"); |
71 | 1502 if ( pcx_header2.planes == 3 ) |
0 | 1503 { |
1504 v37 = 0; | |
1505 if ( v3->uHeight > 0 ) | |
1506 { | |
1507 do | |
1508 { | |
1509 v16 = v37 * v3->uWidth; | |
1510 v17 = v3->pPixels; | |
1511 v38 = 0; | |
1512 v18 = &v17[v16]; | |
71 | 1513 if ( pcx_header2.pitch ) |
0 | 1514 { |
1515 do | |
1516 { | |
1517 fread((char *)&Filename + 3, 1u, 1u, File); | |
1518 if ( (BYTE3(Filename) & 0xC0) == -64 ) | |
1519 { | |
1520 BYTE3(Filename) &= 0x3Fu; | |
1521 fread((char *)&a3 + 3, 1u, 1u, File); | |
1522 v19 = 0; | |
1523 if ( BYTE3(Filename) ) | |
1524 { | |
1525 do | |
1526 { | |
1527 ++v38; | |
1528 *v18 = LOWORD(pRenderer->uTargetRMask) & (BYTE3(a3) << (LOBYTE(pRenderer->uTargetGBits) | |
1529 + LOBYTE(pRenderer->uTargetRBits) | |
1530 + LOBYTE(pRenderer->uTargetBBits) | |
1531 - 8)); | |
1532 ++v18; | |
1533 ++v19; | |
1534 } | |
1535 while ( v19 < BYTE3(Filename) ); | |
1536 } | |
1537 } | |
1538 else | |
1539 { | |
1540 ++v38; | |
1541 *v18 = LOWORD(pRenderer->uTargetRMask) & (BYTE3(Filename) << (LOBYTE(pRenderer->uTargetGBits) | |
1542 + LOBYTE(pRenderer->uTargetRBits) | |
1543 + LOBYTE(pRenderer->uTargetBBits) | |
1544 - 8)); | |
1545 ++v18; | |
1546 } | |
1547 } | |
71 | 1548 while ( v38 < (unsigned __int16)pcx_header2.pitch); |
0 | 1549 } |
1550 v20 = &v3->pPixels[v37 * v3->uWidth]; | |
71 | 1551 while ( v38 < 2 * (unsigned __int16)pcx_header2.pitch ) |
0 | 1552 { |
1553 fread((char *)&Filename + 3, 1u, 1u, File); | |
1554 if ( (BYTE3(Filename) & 0xC0) == -64 ) | |
1555 { | |
1556 BYTE3(Filename) &= 0x3Fu; | |
1557 fread((char *)&a3 + 3, 1u, 1u, File); | |
1558 v21 = 0; | |
1559 if ( BYTE3(Filename) ) | |
1560 { | |
1561 do | |
1562 { | |
1563 *v20 |= pRenderer->uTargetGMask & (unsigned __int16)(BYTE3(a3) << (LOBYTE(pRenderer->uTargetGBits) | |
1564 + LOBYTE(pRenderer->uTargetBBits) | |
1565 - 8)); | |
1566 ++v38; | |
1567 ++v20; | |
1568 ++v21; | |
1569 } | |
1570 while ( v21 < BYTE3(Filename) ); | |
1571 } | |
1572 } | |
1573 else | |
1574 { | |
1575 *v20 |= pRenderer->uTargetGMask & (unsigned __int16)(BYTE3(Filename) << (LOBYTE(pRenderer->uTargetGBits) | |
1576 + LOBYTE(pRenderer->uTargetBBits) | |
1577 - 8)); | |
1578 ++v38; | |
1579 ++v20; | |
1580 } | |
1581 } | |
1582 v22 = &v3->pPixels[v37 * v3->uWidth]; | |
71 | 1583 while ( v38 < 3 * (unsigned __int16)pcx_header2.pitch ) |
0 | 1584 { |
1585 fread((char *)&Filename + 3, 1u, 1u, File); | |
1586 if ( (BYTE3(Filename) & 0xC0) == -64 ) | |
1587 { | |
1588 BYTE3(Filename) &= 0x3Fu; | |
1589 fread((char *)&a3 + 3, 1u, 1u, File); | |
1590 v23 = 0; | |
1591 if ( BYTE3(Filename) ) | |
1592 { | |
1593 do | |
1594 { | |
1595 *v22 |= BYTE3(a3) >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1596 ++v38; | |
1597 ++v22; | |
1598 ++v23; | |
1599 } | |
1600 while ( v23 < BYTE3(Filename) ); | |
1601 } | |
1602 } | |
1603 else | |
1604 { | |
1605 *v22 |= BYTE3(Filename) >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1606 ++v38; | |
1607 ++v22; | |
1608 } | |
1609 } | |
1610 v24 = v3->uHeight; | |
1611 ++v37; | |
1612 } | |
1613 while ( v37 < v24 ); | |
1614 } | |
1615 } | |
1616 fclose(File); | |
1617 result = 0; | |
1618 } | |
1619 else | |
1620 { | |
1621 result = 2; | |
1622 } | |
1623 return result; | |
1624 } | |
1625 | |
1626 | |
1627 //----- (0040D73D) -------------------------------------------------------- | |
1628 RGBTexture::RGBTexture() | |
1629 { | |
1630 pName[0] = 0; | |
1631 pPixels = 0; | |
1632 uNumPixels = 0; | |
1633 uHeight = 0; | |
1634 uWidth = 0; | |
1635 field_1A = 0; | |
1636 field_18 = 0; | |
1637 field_20 = 0; | |
1638 field_22 = 0; | |
1297 | 1639 } |
1640 //----- (0044E1EC) -------------------------------------------------------- | |
1641 int TextureFrameTable::FromFileTxt(const char *Args) | |
1642 { | |
1643 TextureFrameTable *v2; // ebx@1 | |
1644 FILE *v3; // eax@1 | |
1645 int v4; // esi@3 | |
1646 const void *v5; // ST0C_4@10 | |
1647 void *v6; // eax@10 | |
1648 FILE *v7; // ST0C_4@12 | |
1649 char *i; // eax@12 | |
1650 signed int v9; // esi@15 | |
1651 int v10; // eax@17 | |
1652 int v11; // edx@22 | |
1653 int v12; // ecx@23 | |
1654 int v13; // eax@24 | |
1655 signed int j; // eax@27 | |
1656 TextureFrame *v15; // edx@28 | |
1657 int v16; // esi@28 | |
1658 int k; // ecx@29 | |
1659 char Buf; // [sp+Ch] [bp-2F8h]@3 | |
1660 FrameTableTxtLine v20; // [sp+200h] [bp-104h]@4 | |
1661 int v21; // [sp+27Ch] [bp-88h]@4 | |
1662 char *Str1; // [sp+280h] [bp-84h]@5 | |
1663 char *Str; // [sp+284h] [bp-80h]@15 | |
1664 int v24; // [sp+2F8h] [bp-Ch]@3 | |
1665 int v25; // [sp+2FCh] [bp-8h]@3 | |
1666 FILE *File; // [sp+300h] [bp-4h]@1 | |
1667 int Argsa; // [sp+30Ch] [bp+8h]@28 | |
1668 | |
1669 v2 = this; | |
1670 v3 = fopen(Args, "r"); | |
1671 File = v3; | |
1672 if ( !v3 ) | |
1673 Abortf("CTextureFrameTable::load - Unable to open file: %s.", Args); | |
1674 v4 = 0; | |
1675 v24 = 0; | |
1676 v25 = 1; | |
1677 if ( fgets(&Buf, 490, v3) ) | |
1678 { | |
1679 do | |
1680 { | |
1681 *strchr(&Buf, 10) = 0; | |
1682 memcpy(&v21, txt_file_frametable_parser(&Buf, &v20), 0x7Cu); | |
1683 if ( v21 && *Str1 != 47 ) | |
1684 { | |
1685 if ( v21 < 2 ) | |
1686 Abortf("CTextureFrameTable::load, too few arguments, %s line %i.", Args, v25); | |
1687 ++v24; | |
1688 } | |
1689 ++v25; | |
1690 } | |
1691 while ( fgets(&Buf, 490, File) ); | |
1692 v4 = v24; | |
1693 } | |
1694 v5 = v2->pTextures; | |
1695 v2->sNumTextures = v4; | |
1696 v6 = pAllocator->AllocNamedChunk(v5, 20 * v4, "Txt Frames"); | |
1697 v2->pTextures = (TextureFrame *)v6; | |
1698 if ( !v6 ) | |
1699 Abortf("CTextureFrameTable::load - Out of Memory!"); | |
1700 v7 = File; | |
1701 v2->sNumTextures = 0; | |
1702 fseek(v7, 0, 0); | |
1703 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
1704 { | |
1705 *strchr(&Buf, 10) = 0; | |
1706 memcpy(&v21, txt_file_frametable_parser(&Buf, &v20), 0x7Cu); | |
1707 if ( v21 && *Str1 != 47 ) | |
1708 { | |
1709 strcpy(v2->pTextures[v2->sNumTextures].pTextureName, Str1); | |
1710 v2->pTextures[v2->sNumTextures].uAnimTime = atoi(Str); | |
1711 v9 = 2; | |
1712 for ( v2->pTextures[v2->sNumTextures].uFlags = 0; v9 < v21; ++v9 ) | |
1713 { | |
1714 if ( !_stricmp((&Str1)[4 * v9], "New") ) | |
1715 { | |
1716 v10 = (int)&v2->pTextures[v2->sNumTextures].uFlags; | |
1717 *(char *)v10 |= 2u; | |
1718 } | |
1719 } | |
1720 ++v2->sNumTextures; | |
1721 } | |
1722 } | |
1723 fclose(File); | |
1724 v11 = 0; | |
1725 if ( (signed int)(v2->sNumTextures - 1) > 0 ) | |
1726 { | |
1727 v12 = 0; | |
1728 do | |
1729 { | |
1730 v13 = (int)&v2->pTextures[v12]; | |
1731 if ( !(*(char *)(v13 + 38) & 2) ) | |
1732 *(char *)(v13 + 18) |= 1u; | |
1733 ++v11; | |
1734 ++v12; | |
1735 } | |
1736 while ( v11 < (signed int)(v2->sNumTextures - 1) ); | |
1737 } | |
1738 for ( j = 0; j < (signed int)v2->sNumTextures; *(short *)(Argsa + 16) = v16 ) | |
1739 { | |
1740 v15 = v2->pTextures; | |
1741 Argsa = (int)&v15[j]; | |
1742 v16 = *(short *)(Argsa + 14); | |
1743 if ( *(char *)(Argsa + 18) & 1 ) | |
1744 { | |
1745 ++j; | |
1746 for ( k = (int)&v15[j]; *(char *)(k + 18) & 1; k += 20 ) | |
1747 { | |
1748 v16 += *(short *)(k + 14); | |
1749 ++j; | |
1750 } | |
1751 LOWORD(v16) = v15[j].uAnimTime + v16; | |
1752 } | |
1753 ++j; | |
1754 } | |
1755 return 1; | |
1756 } |