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