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