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