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