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