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