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