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