Mercurial > mm7
annotate Texture.cpp @ 2466:5a6cd79069ae
project and filter
author | zipi |
---|---|
date | Sun, 17 Aug 2014 20:34:56 +0100 |
parents | b054ea5daf45 |
children | 7b076fe64f23 |
rev | line source |
---|---|
2415 | 1 #define _CRTDBG_MAP_ALLOC |
2 #include <stdlib.h> | |
3 #include <crtdbg.h> | |
4 | |
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
|
5 #define _CRT_SECURE_NO_WARNINGS |
0 | 6 #include <stdlib.h> |
7 | |
8 #include "Texture.h" | |
9 #include "FrameTableInc.h" | |
10 #include "LOD.h" | |
11 #include "PaletteManager.h" | |
2336 | 12 #include "ErrorHandling.h" |
2352 | 13 #include "ZlibWrapper.h" |
0 | 14 |
15 #include "mm7_data.h" | |
16 | |
2463 | 17 #include "OurMath.h" |
0 | 18 |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 struct TextureFrameTable *pTextureFrameTable; | |
27 | |
28 | |
29 | |
30 | |
31 | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
32 std::array<Texture *, 2> pTexture_LloydBeacons; |
0 | 33 Texture *pTexture_50635C; |
1453 | 34 Texture *pTex_book_button8_off; |
35 Texture *pTex_book_button8_on; | |
36 Texture *pTex_book_button7_off; | |
37 Texture *pTex_book_button7_on; | |
38 Texture *pTex_book_button6_off; | |
39 Texture *pTex_book_button6_on; | |
40 Texture *pTex_book_button5_off; | |
41 Texture *pTex_book_button5_on; | |
42 Texture *pTex_book_button4_off; | |
43 Texture *pTex_book_button4_on; | |
44 Texture *pTex_book_button3_off; | |
45 Texture *pTex_book_button3_on; | |
46 Texture *pTex_book_button2_off; | |
47 Texture *pTex_book_button1_off; | |
48 Texture *pTex_book_button2_on; | |
49 Texture *pTex_book_button1_on; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
50 std::array<Texture *, 6> pTexture_TownPortalIcons; // [0]Harmonale, [1]Pierpont, [2]Nighon, [3]Evenmorn Island, [4]Celestia, [5]The Pit |
1402 | 51 std::array<Texture *, 12> SBPageCSpellsTextureList; |
52 std::array<Texture *, 12> SBPageSSpellsTextureList; | |
53 Texture *pSBQuickSpellBtnTextr; | |
54 Texture *pSpellBookClickCloseBtnTextr; | |
55 Texture *pSBClickQuickSpellBtnTextr; | |
56 Texture *pSpellBookCloseBtnTextr; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
57 std::array<std::array<Texture *, 2>, 9> pTextures_tabs; |
0 | 58 Texture *pTexture_mapbordr; // idb |
59 Texture *pTexture_pagemask; // idb | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
60 std::array<Texture *, 9> pSpellBookPagesTextr; |
688 | 61 Texture *pSpellBookPagesTextr_9; |
62 Texture *pSpellBookPagesTextr_10; | |
63 Texture *pSpellBookPagesTextr_11; | |
64 Texture *pSpellBookPagesTextr_12; | |
65 Texture *pSpellBookPagesTextr_13; | |
0 | 66 Texture *pTexture_AutonotesBook; |
67 Texture *pTexture_CurrentBook; | |
68 Texture *pTex_moon_new; | |
69 Texture *pTex_moon_4; | |
70 Texture *pTex_moon_2; | |
71 Texture *pTex_moon_2_2; | |
72 Texture *pTex_moon_ful; | |
73 | |
74 | |
75 | |
76 RGBTexture stru_506E40; // weak | |
77 RGBTexture pTexture_PCX; | |
78 | |
79 | |
80 int uTextureID_RestUI_restb4; // weak | |
81 int uTextureID_RestUI_restexit; // weak | |
82 int uTextureID_RestUI_restb3; // weak | |
83 int uTextureID_RestUI_restb1; // weak | |
84 int uTextureID_RestUI_restb2; // weak | |
85 int uTextureID_RestUI_restmain; // weak | |
86 unsigned int uTextureID_Leather; | |
87 int uTextureID_ar_dn_dn; // weak | |
88 int uTextureID_ar_dn_up; // weak | |
89 int uTextureID_ar_up_dn; // weak | |
90 int uTextureID_ar_up_up; // weak | |
91 | |
92 | |
93 int uTextureID_507698; // weak | |
94 int uTextureID_50769C; // weak | |
95 int uTextureID_5076A0; // weak | |
96 int uTextureID_5076A4; // weak | |
97 int uTextureID_5076A8; // weak | |
98 int uTextureID_5076AC; // weak | |
99 int uTextureID_5076B0; // weak | |
100 int uTextureID_5076B4; // weak | |
101 int uTextureID_Parchment; // weak | |
102 unsigned int uTextureID_mhp_yel; | |
103 unsigned int uTextureID_mhp_red; | |
104 unsigned int uTextureID_mhp_grn; | |
105 unsigned int uTextureID_mhp_capr; | |
106 unsigned int uTextureID_mhp_capl; | |
107 unsigned int uTextureID_mhp_bd; | |
108 unsigned int uTextureID_BUTTDESC2; | |
109 unsigned int uTextureID_x_x_u; | |
110 unsigned int uTextureID_BUTTMAKE2; | |
111 unsigned int uTextureID_BUTTMAKE; | |
112 unsigned int uTextureID_BUTTYES2; | |
113 unsigned int uTextureID_x_ok_u; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
114 std::array<Texture *, 22> pPlayerPortraits; |
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
115 std::array<Texture *, 9> pTexture_IC_KNIGHT; |
0 | 116 Texture *pTexture_MAKESKY; |
117 Texture *pTexture_MAKETOP; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
118 std::array<Texture *, 20> pTextures_arrowr; |
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
119 std::array<Texture *, 20> pTextures_arrowl; |
0 | 120 Texture *pTexture_presleft; |
121 Texture *pTexture_pressrigh; | |
122 Texture *pTexture_buttminu; | |
123 Texture *pTexture_buttplus; | |
362 | 124 unsigned int uTextureID_Quit1; // weak |
125 unsigned int uTextureID_Resume1; // weak | |
126 unsigned int uTextureID_Controls1; // weak | |
127 unsigned int uTextureID_Save1; // weak | |
128 unsigned int uTextureID_Load1; // weak | |
129 unsigned int uTextureID_New1; // weak | |
130 unsigned int uTextureID_Options; // weak | |
0 | 131 |
132 | |
133 unsigned int uTextureID_ib_td5_A; | |
1667 | 134 unsigned int uTextureID_ib_td4_A; |
135 unsigned int uTextureID_ib_td3_A; | |
136 unsigned int uTextureID_ib_td2_A; | |
0 | 137 unsigned int uTextureID_ib_td1_A; |
984 | 138 int uTextureID_CharacterUI_InventoryBackground; // weak |
0 | 139 int uTextureID_50795C; // weak |
140 | |
141 | |
319 | 142 unsigned int uTextureID_Btn_GameSettings; |
0 | 143 |
144 | |
319 | 145 unsigned int uTextureID_Btn_Rest; |
146 unsigned int uTextureID_Btn_CastSpell; | |
147 unsigned int uTextureID_Btn_ZoomIn; | |
148 unsigned int uTextureID_Btn_ZoomOut; | |
0 | 149 unsigned int uTextureID_FONTPAL; |
319 | 150 unsigned int uTextureID_Btn_NPCRight; |
151 unsigned int uTextureID_Btn_NPCLeft; | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
152 std::array<unsigned int, 8> pTextureIDs_pMapDirs; |
0 | 153 |
154 | |
155 unsigned int uTextureID_BarRed; | |
156 unsigned int uTextureID_BarYellow; | |
157 unsigned int uTextureID_BarGreen; | |
158 unsigned int uTextureID_BarBlue; | |
159 | |
160 | |
161 unsigned int uTextureID_right_panel; // weak | |
162 | |
163 | |
164 RGBTexture *pTexture_StatusBar = new RGBTexture; | |
165 RGBTexture *pTexture_LeftFrame = new RGBTexture; | |
166 RGBTexture *pTexture_TopFrame = new RGBTexture; | |
167 RGBTexture *pTexture_BottomFrame = new RGBTexture; | |
168 RGBTexture *pTexture_RightFrame = new RGBTexture; | |
169 | |
170 | |
910 | 171 unsigned int uTextureID_right_panel_loop; |
0 | 172 |
173 | |
174 Texture *pTexture_Leather; | |
175 Texture *pTexture_RestUI_CurrentSkyFrame; // idb | |
176 Texture *pTexture_RestUI_CurrentHourglassFrame; // idb | |
177 | |
178 | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
179 std::array<unsigned int, 5> uTextureID_Optkb; |
0 | 180 |
1676
483cc7f0d86c
GameMenuUI_DrawKeyBindings() and GameMenuUI_DrawVideoOptions() cleared
Ritor1
parents:
1667
diff
changeset
|
181 unsigned int optvid_base_texture_id; |
1677 | 182 unsigned int bloodsplats_texture_id; |
183 unsigned int us_colored_lights_texture_id; | |
184 unsigned int tinting_texture_id; | |
0 | 185 unsigned int uTextureID_507C20; // weak |
186 unsigned int uTextureID_507C24; // weak | |
1207
96a81634669e
arrays to std::arrays phase 3 - finishing global arrays
Grumpy7
parents:
1205
diff
changeset
|
187 std::array<unsigned int, 10> pTextureIDs_GammaPositions; |
1677 | 188 unsigned int not_available_bloodsplats_texture_id; |
189 unsigned int not_available_us_colored_lights_texture_id; | |
190 unsigned int not_available_tinting_texture_id; | |
0 | 191 |
192 | |
910 | 193 unsigned int uTextureID_detaliz_close_button; // weak |
0 | 194 unsigned int uTextureID_MAGNIF_B; // weak |
195 unsigned int uTextureID_BACKDOLL; // weak | |
196 unsigned int uTextureID_BACKHAND; // weak | |
197 | |
1262 | 198 stru355 stru_4E82A4 = {0x20, 0x41, 0, 0x20, 0xFF0000, 0xFF00, 0xFF, 0xFF000000}; |
199 stru355 stru_4EFCBC = {0x20, 0x41, 0, 0x10, 0x7C00, 0x3E0, 0x1F, 0x8000}; | |
0 | 200 |
201 Texture pTex_F7CE30; | |
202 | |
203 | |
204 RGBTexture stru_5773C4; // idb | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 /* 245 */ | |
217 #pragma pack(push, 1) | |
218 struct PCXHeader1 | |
219 { | |
220 char magic; | |
221 char version; | |
222 char encoding; | |
223 char bpp; | |
224 __int16 left; | |
225 __int16 up; | |
226 __int16 right; | |
227 __int16 bottom; | |
228 __int16 hres; | |
229 __int16 vres; | |
230 }; | |
231 #pragma pack(pop) | |
232 | |
233 /* 246 */ | |
234 #pragma pack(push, 1) | |
235 struct PCXHeader2 | |
236 { | |
237 char reserved; | |
238 char planes; | |
239 __int16 pitch; | |
240 __int16 palette_info; | |
241 }; | |
242 #pragma pack(pop) | |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 //----- (0044E054) -------------------------------------------------------- | |
253 void TextureFrameTable::ToFile() | |
254 { | |
255 TextureFrameTable *v1; // esi@1 | |
256 FILE *v2; // eax@1 | |
257 FILE *v3; // edi@1 | |
258 | |
259 v1 = this; | |
260 v2 = fopen("data\\dtft.bin", "wb"); | |
261 v3 = v2; | |
262 if ( !v2 ) | |
1545 | 263 Error("Unable to save dtft.bin!"); |
0 | 264 fwrite(v1, 4u, 1u, v2); |
711 | 265 fwrite(v1->pTextures, 0x14u, v1->sNumTextures, v3); |
0 | 266 fclose(v3); |
267 } | |
268 | |
269 //----- (0044E0A0) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1453
diff
changeset
|
270 void TextureFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
0 | 271 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1453
diff
changeset
|
272 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
|
273 num_mm7_frames = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1453
diff
changeset
|
274 num_mm8_frames = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1453
diff
changeset
|
275 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1453
diff
changeset
|
276 sNumTextures = num_mm6_frames + num_mm7_frames + num_mm8_frames; |
1545 | 277 Assert(sNumTextures); |
278 Assert(!num_mm8_frames); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1453
diff
changeset
|
279 |
1583 | 280 pTextures = (TextureFrame *)malloc(sNumTextures * sizeof(TextureFrame)); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1453
diff
changeset
|
281 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1453
diff
changeset
|
282 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
|
283 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
|
284 memcpy(pTextures + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 4, num_mm8_frames * sizeof(TextureFrame)); |
0 | 285 } |
286 | |
287 //----- (0044E0ED) -------------------------------------------------------- | |
711 | 288 void TextureFrameTable::LoadAnimationSequenceAndPalettes( signed int uIconID ) |
2378 | 289 { |
290 //TextureFrameTable *v3; // ebx@1 | |
0 | 291 unsigned int i; // edi@3 |
292 | |
2378 | 293 //v3 = this; |
711 | 294 if ( (uIconID <= this->sNumTextures) && uIconID >= 0 ) |
0 | 295 { |
296 for ( i = uIconID; ; ++i ) | |
297 { | |
2378 | 298 this->pTextures[i].uTextureID = pBitmaps_LOD->LoadTexture(this->pTextures[i].pTextureName, TEXTURE_DEFAULT); |
973 | 299 |
2378 | 300 if (this->pTextures[i].uTextureID != -1) |
301 pBitmaps_LOD->pTextures[this->pTextures[i].uTextureID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[this->pTextures[i].uTextureID].palette_id1); | |
711 | 302 //result = (unsigned int)v3->pTextures; |
303 //if ( !(*(char *)(result + i * 20 + 18) & 1) ) | |
2378 | 304 if( this->pTextures[i].uFlags & 1) |
0 | 305 break; |
306 } | |
307 } | |
711 | 308 return; |
0 | 309 } |
310 | |
311 //----- (0044E163) -------------------------------------------------------- | |
312 unsigned int TextureFrameTable::FindTextureByName(const char *Str2) | |
313 { | |
314 TextureFrameTable *v2; // esi@1 | |
315 int v3; // ebx@1 | |
316 unsigned int uID; // edi@1 | |
317 unsigned int result; // eax@4 | |
318 | |
319 v2 = this; | |
320 v3 = 0; | |
321 uID = 0; | |
711 | 322 if ( (signed int)this->sNumTextures <= 0 ) |
0 | 323 { |
324 LABEL_4: | |
325 result = -1; | |
326 } | |
327 else | |
328 { | |
1104 | 329 while ( _stricmp(v2->pTextures[v3].pTextureName, Str2) ) |
0 | 330 { |
331 ++uID; | |
332 ++v3; | |
711 | 333 if ( (signed int)uID >= (signed int)v2->sNumTextures ) |
0 | 334 goto LABEL_4; |
335 } | |
336 result = uID; | |
337 } | |
338 return result; | |
339 } | |
340 | |
341 //----- (0044E19A) -------------------------------------------------------- | |
1632 | 342 int TextureFrameTable::GetFrameTexture(int uFrameID, signed int a3) |
0 | 343 { |
344 int v3; // esi@1 | |
345 TextureFrame *v4; // edi@1 | |
346 TextureFrame *v5; // ecx@1 | |
347 __int16 v6; // dx@2 | |
348 int v7; // edx@3 | |
349 char *i; // eax@3 | |
350 int v9; // ecx@5 | |
351 unsigned int result; // eax@6 | |
352 | |
353 v3 = uFrameID; | |
354 v4 = this->pTextures; | |
355 v5 = &v4[uFrameID]; | |
356 if ( v5->uFlags & 1 && (v6 = v5->uAnimLength) != 0 ) | |
357 { | |
358 v7 = (a3 >> 3) % v6; | |
359 for ( i = (char *)&v5->uAnimTime; ; i += 20 ) | |
360 { | |
361 v9 = *(short *)i; | |
362 if ( v7 <= v9 ) | |
363 break; | |
364 v7 -= v9; | |
365 ++v3; | |
366 } | |
367 result = v4[v3].uTextureID; | |
368 } | |
369 else | |
370 { | |
371 result = v5->uTextureID; | |
372 } | |
373 return result; | |
374 } | |
375 | |
376 | |
377 | |
378 | |
379 | |
380 | |
381 //----- (0040F806) -------------------------------------------------------- | |
382 void *Texture::UnzipPalette() | |
383 { | |
384 Texture *v1; // esi@1 | |
1093 | 385 |
0 | 386 void *v2; // edi@1 |
387 Texture *pSource; // [sp+0h] [bp-4h]@1 | |
388 | |
389 pSource = this; | |
390 v1 = this; | |
391 v2 = malloc(this->uDecompressedSize); | |
710 | 392 zlib::MemUnzip(v2, (unsigned int *)&pSource, v1->pLevelOfDetail0_prolly_alpha_mask, v1->uTextureSize); |
0 | 393 return v2; |
394 } | |
395 | |
396 //----- (0040F77C) -------------------------------------------------------- | |
397 void Texture::Release() | |
398 { | |
399 if (this) | |
400 { | |
401 pName[0] = 0; | |
402 | |
403 if (pBits & 0x0400) | |
404 { | |
1093 | 405 __debugbreak(); |
406 } | |
407 | |
1583 | 408 free(pLevelOfDetail0_prolly_alpha_mask); |
409 free(pPalette16); | |
410 free(pPalette24); | |
1093 | 411 |
0 | 412 |
710 | 413 pLevelOfDetail0_prolly_alpha_mask = nullptr; |
0 | 414 pLevelOfDetail1 = nullptr; |
415 pLevelOfDetail2 = nullptr; | |
416 pLevelOfDetail3 = nullptr; | |
417 | |
418 pPalette16 = nullptr; | |
419 pPalette24 = nullptr; | |
420 | |
421 uSizeOfMaxLevelOfDetail = 0; | |
422 uTextureSize = 0; | |
423 uTextureHeight = 0; | |
424 uTextureWidth = 0; | |
425 uHeightLn2 = 0; | |
426 uWidthLn2 = 0; | |
427 palette_id1 = 0; | |
428 palette_id2 = 0; | |
429 pBits &= 0xFFFF0000; | |
430 } | |
431 } | |
432 | |
433 //----- (0040F5F5) -------------------------------------------------------- | |
434 int RGBTexture::Reload(const char *pContainer) | |
435 { | |
2129 | 436 //RGBTexture *v2; // esi@1 |
0 | 437 FILE *v3; // eax@3 |
438 FILE *v4; // edi@3 | |
439 void *v5; // ebx@7 | |
440 signed int result; // eax@11 | |
441 unsigned int v7; // ecx@12 | |
442 unsigned __int16 *v8; // ST20_4@14 | |
443 int v9; // eax@14 | |
444 char color_map[48]; // [sp+8h] [bp-98h]@9 | |
445 Texture DstBuf; // [sp+38h] [bp-68h]@1 | |
446 PCXHeader1 header1; // [sp+80h] [bp-20h]@9 | |
447 PCXHeader2 header2; // [sp+90h] [bp-10h]@9 | |
448 FILE *File; // [sp+98h] [bp-8h]@3 | |
449 size_t Count; // [sp+9Ch] [bp-4h]@6 | |
450 void *uSourceLena; // [sp+A8h] [bp+8h]@7 | |
451 | |
2129 | 452 // v2 = this; |
453 if ( !this->pPixels ) | |
0 | 454 return 2; |
455 v3 = pIcons_LOD->FindContainer(pContainer, 0); | |
456 v4 = v3; | |
457 File = v3; | |
458 if ( !v3 ) | |
1545 | 459 Error("Unable to load %s", pContainer); |
460 | |
2129 | 461 fread(&DstBuf, 1, 0x30, v3); |
0 | 462 Count = DstBuf.uTextureSize; |
463 if ( DstBuf.uDecompressedSize ) | |
464 { | |
465 v5 = malloc(DstBuf.uDecompressedSize); | |
1583 | 466 uSourceLena = malloc(DstBuf.uTextureSize); |
2129 | 467 fread(uSourceLena, 1, Count, File); |
0 | 468 zlib::MemUnzip(v5, &DstBuf.uDecompressedSize, uSourceLena, DstBuf.uTextureSize); |
469 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
1583 | 470 free(uSourceLena); |
0 | 471 } |
472 else | |
473 { | |
474 v5 = malloc(DstBuf.uTextureSize); | |
2129 | 475 fread(v5, 1, Count, v4); |
0 | 476 } |
477 memcpy(&header1, v5, 0x10u); | |
2129 | 478 memcpy(color_map, (char *)v5 + 16, 0x30); |
479 memcpy(&header2, (char *)v5 + 64, 6); | |
0 | 480 if ( header1.bpp != 8 ) |
481 return 3; | |
482 v7 = (signed __int16)(header1.right - header1.left + 1); | |
2129 | 483 if ( (signed int)(v7 * (signed __int16)(header1.bottom - header1.up + 1)) <= (signed int)this->uNumPixels ) |
0 | 484 { |
2129 | 485 this->uWidth = header1.right - header1.left + 1; |
486 v8 = this->pPixels; | |
487 v9 = v7 * this->uHeight; | |
488 this->uNumPixels = v9; | |
489 this->uHeight = v9; | |
490 this->DecodePCX((char *)v5, v8, v7); | |
0 | 491 free(v5); |
492 result = 0; | |
493 } | |
494 else | |
495 { | |
496 result = -1; | |
497 } | |
498 return result; | |
499 } | |
500 | |
501 //----- (0040F5BE) -------------------------------------------------------- | |
502 Texture::Texture() | |
503 { | |
504 pName[0] = 0; | |
505 uSizeOfMaxLevelOfDetail = 0; | |
506 uTextureSize = 0; | |
507 uTextureHeight = 0; | |
508 uTextureWidth = 0; | |
509 uHeightLn2 = 0; | |
510 uWidthLn2 = 0; | |
511 palette_id1 = 0; | |
512 palette_id2 = 0; | |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
513 pLevelOfDetail0_prolly_alpha_mask = nullptr; |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
514 pLevelOfDetail3 = nullptr; |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
515 pLevelOfDetail2 = nullptr; |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
516 pLevelOfDetail1 = nullptr; |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
517 pPalette16 = nullptr; |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
518 pPalette24 = nullptr; |
0 | 519 } |
520 | |
521 //----- (0040F414) -------------------------------------------------------- | |
522 int RGBTexture::Load(const char *pContainer, int mode) | |
523 { | |
2278 | 524 FILE *file; // eax@1 |
0 | 525 void *v6; // ebx@5 |
526 char color_map[48]; // [sp+Ch] [bp-98h]@7 | |
527 Texture DstBuf; // [sp+3Ch] [bp-68h]@1 | |
528 PCXHeader1 header1; // [sp+84h] [bp-20h]@7 | |
529 PCXHeader2 header2; // [sp+94h] [bp-10h]@7 | |
530 size_t Count; // [sp+A0h] [bp-4h]@4 | |
531 char *Str1a; // [sp+ACh] [bp+8h]@5 | |
532 | |
2278 | 533 file = pIcons_LOD->FindContainer(pContainer, 0); |
534 if ( !file ) | |
2279 | 535 Error("Unable to load %s", pContainer); |
1545 | 536 |
2278 | 537 fread(&DstBuf, 1, 0x30u, file); |
0 | 538 Count = DstBuf.uTextureSize; |
539 if ( DstBuf.uDecompressedSize ) | |
540 { | |
541 Str1a = (char *)malloc(DstBuf.uDecompressedSize); | |
1583 | 542 v6 = malloc(DstBuf.uTextureSize); |
2278 | 543 fread(v6, 1, Count, file); |
0 | 544 zlib::MemUnzip(Str1a, &DstBuf.uDecompressedSize, v6, DstBuf.uTextureSize); |
545 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
1583 | 546 free(v6); |
0 | 547 } |
548 else | |
549 { | |
550 Str1a = (char *)malloc(DstBuf.uTextureSize); | |
2278 | 551 fread(Str1a, 1, Count, file); |
0 | 552 } |
553 memcpy(&header1, Str1a, 0x10u); | |
554 memcpy(color_map, Str1a + 16, 0x30u); | |
1835 | 555 memcpy(&header2, Str1a + 64, 6); |
0 | 556 if ( header1.bpp != 8 ) |
557 return 3; | |
1835 | 558 this->uWidth = header1.right - header1.left + 1; |
559 this->uHeight = header1.bottom - header1.up + 1; | |
560 this->uNumPixels = (signed __int16)this->uWidth * (signed __int16)this->uHeight; | |
1846 | 561 this->pPixels = (unsigned __int16 *)malloc(2 * this->uNumPixels + 4); |
1835 | 562 if ( this->pPixels ) |
0 | 563 { |
564 if ( mode ) | |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
565 { |
1835 | 566 if ( mode != 2 ) |
567 { | |
568 if ( !this->pPixels ) | |
569 return 2; | |
570 this->DecodePCX(Str1a, this->pPixels, this->uWidth); | |
571 free(Str1a); | |
572 return 0; | |
573 } | |
574 this->_allocation_flags |= 1; | |
575 this->pPixels = (unsigned __int16 *)malloc(2 * this->uNumPixels + 4); | |
576 if ( !this->pPixels ) | |
577 return 2; | |
578 this->DecodePCX(Str1a, this->pPixels, this->uWidth); | |
579 free(Str1a); | |
580 return 0; | |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
581 } |
1835 | 582 free(this->pPixels); |
0 | 583 } |
584 if ( !mode ) | |
585 { | |
1835 | 586 this->pPixels = (unsigned __int16 *)malloc(2 * this->uNumPixels + 4); |
587 if ( !this->pPixels ) | |
588 return 2; | |
589 this->DecodePCX(Str1a, this->pPixels, this->uWidth); | |
590 free(Str1a); | |
591 return 0; | |
0 | 592 } |
593 if ( mode != 2 ) | |
1835 | 594 { |
595 if ( !this->pPixels ) | |
596 return 2; | |
597 this->DecodePCX(Str1a, this->pPixels, this->uWidth); | |
598 free(Str1a); | |
599 return 0; | |
600 } | |
601 this->_allocation_flags |= 1; | |
602 this->pPixels = (unsigned __int16 *)malloc(2 * this->uNumPixels + 4); | |
603 if ( !this->pPixels ) | |
0 | 604 return 2; |
1835 | 605 this->DecodePCX(Str1a, this->pPixels, this->uWidth); |
0 | 606 free(Str1a); |
607 return 0; | |
608 } | |
609 | |
610 //----- (0040F037) -------------------------------------------------------- | |
611 signed int RGBTexture::DecodePCX(char *pPcx, unsigned __int16 *pOutPixels, unsigned int uNumPixels) | |
612 { | |
2334 | 613 // signed int result; // eax@2 |
0 | 614 unsigned char test_byte; // edx@3 |
615 unsigned int read_offset; // ebx@37 | |
616 unsigned int row_position; // edi@40 | |
617 unsigned char value; // cl@63 | |
618 char count; // [sp+50h] [bp-Ch]@43 | |
619 unsigned short current_line; // [sp+54h] [bp-8h]@38 | |
620 unsigned short *dec_position; | |
621 unsigned short *temp_dec_position; | |
622 PCXHeader1 psx_head1; | |
623 PCXHeader2 psx_head2; | |
2334 | 624 // short int width, height; |
0 | 625 BYTE color_map[48]; // Colormap for 16-color images |
626 | |
627 | |
628 memcpy(&psx_head1, pPcx , 16); | |
629 memcpy(&color_map, pPcx + 16, 48); | |
630 memcpy(&psx_head2, pPcx + 64, 6); | |
631 | |
632 | |
633 if (psx_head1.bpp!=8) | |
634 return 3; | |
635 uWidth=(short int )(psx_head1.right-psx_head1.left+1); // word @ 000014 | |
636 uHeight=(short int )(psx_head1.bottom-psx_head1.up+1); // word @ 000016 | |
637 | |
638 | |
639 uNumPixels=uWidth*uHeight; // dword @ 000010 | |
640 | |
641 memset(pOutPixels, 0, uNumPixels * sizeof(__int16)); | |
642 short i=1; | |
643 while ( (1<<i) !=uWidth) | |
644 { | |
645 ++i; | |
646 if (i >= 15) | |
647 break; | |
648 } | |
649 field_18=i; | |
650 short i_=1; | |
651 while ( (1<<i_) !=uHeight) | |
652 { | |
653 ++i_; | |
654 if (i_ >= 15) | |
655 break; | |
656 } | |
657 field_1A=i_; | |
658 switch (field_18) | |
659 { | |
660 case 2: field_1C = 3; break; | |
661 case 3: field_1C = 7; break; | |
662 case 4: field_1C = 15; break; | |
663 case 5: field_1C = 31; break; | |
664 case 6: field_1C = 63; break; | |
665 case 7: field_1C = 127; break; | |
666 case 8: field_1C = 255; break; | |
667 case 9: field_1C = 511; break; | |
668 case 10: field_1C = 1023; break; | |
669 case 11: field_1C = 2047; break; | |
670 case 12: field_1C = 4095; break; | |
671 } | |
672 | |
673 switch (field_1A) | |
674 { | |
675 case 2: field_1E = 3; break; | |
676 case 3: field_1E = 7; break; | |
677 case 4: field_1E = 15; break; | |
678 case 5: field_1E = 31; break; | |
679 case 6: field_1E = 63; break; | |
680 case 7: field_1E = 127; break; | |
681 case 8: field_1E = 255; break; | |
682 case 9: field_1E = 511; break; | |
683 case 10: field_1E = 1023; break; | |
684 case 11: field_1E = 2047; break; | |
685 case 12: field_1E = 4095; break; | |
686 } | |
687 | |
2069 | 688 unsigned int r_mask = 0xF800; |
689 unsigned int num_r_bits = 5; | |
690 unsigned int g_mask = 0x07E0; | |
691 unsigned int num_g_bits = 6; | |
692 unsigned int b_mask = 0x001F; | |
693 unsigned int num_b_bits = 5; | |
2127 | 694 //Ïðè ñîõðàíåíèè èçîáðàæåíèÿ ïîäðÿä èäóùèå ïèêñåëè îäèíàêîâîãî öâåòà îáúåäèíÿþòñÿ è âìåñòî óêàçàíèÿ öâåòà äëÿ êàæäîãî ïèêñåëÿ |
695 //óêàçûâàåòñÿ öâåò ãðóïïû ïèêñåëåé è èõ êîëè÷åñòâî. | |
0 | 696 read_offset = 128; |
697 if (psx_head2.planes != 3) | |
698 return 0; | |
699 current_line = 0; | |
700 if ( uHeight > 0 ) | |
701 { | |
702 dec_position = pOutPixels; | |
703 do | |
704 { | |
705 temp_dec_position = dec_position; | |
706 row_position = 0; | |
707 //decode red line | |
708 if (psx_head2.pitch) | |
709 { | |
710 do | |
711 { | |
712 test_byte = pPcx[read_offset]; | |
713 ++read_offset; | |
2127 | 714 if ((test_byte & 0xC0) == 0xC0)//èìååòñÿ ëè îáúåäèíåíèå |
0 | 715 { |
716 value = pPcx[read_offset]; | |
717 ++read_offset; | |
718 | |
719 if ((test_byte & 0x3F) > 0) | |
720 { | |
2127 | 721 count = test_byte & 0x3F;//êîëè÷åñòâî îäèíàêîâûõ ïèêñåëåé |
0 | 722 do |
723 { | |
724 ++row_position; | |
725 //*temp_dec_position =0xFF000000; | |
2127 | 726 //*temp_dec_position|=(unsigned long)value<<16; |
2069 | 727 *temp_dec_position |= r_mask & ((unsigned __int8)value << (num_g_bits + num_r_bits + num_b_bits - 8)); |
2127 | 728 temp_dec_position++; |
729 if (row_position == psx_head2.pitch) | |
730 break; | |
0 | 731 } |
732 while (count-- != 1); | |
733 } | |
734 } | |
735 else | |
736 { | |
737 ++row_position; | |
738 //*temp_dec_position =0xFF000000; | |
739 //*temp_dec_position|= (unsigned long)test_byte<<16; | |
740 | |
2069 | 741 *temp_dec_position |= r_mask & ((unsigned __int8)test_byte << (num_g_bits + num_r_bits + num_b_bits - 8)); |
0 | 742 |
743 temp_dec_position++; | |
744 } | |
745 | |
746 } | |
747 while (row_position < psx_head2.pitch); | |
748 } | |
749 | |
750 temp_dec_position = dec_position; | |
751 row_position=0; | |
752 //decode green line | |
753 while (row_position < psx_head2.pitch) | |
754 { | |
755 test_byte = *(pPcx + read_offset); | |
756 ++read_offset; | |
757 if ((test_byte & 0xC0) == 0xC0) | |
758 { | |
759 value = *(pPcx + read_offset); | |
760 ++read_offset; | |
761 if ((test_byte & 0x3F) > 0) | |
762 { | |
763 count = test_byte & 0x3F; | |
764 do | |
765 { | |
766 //*temp_dec_position|= (unsigned int)value<<8; | |
767 //temp_dec_position++; | |
768 | |
2069 | 769 *temp_dec_position|= g_mask & (unsigned __int16)((unsigned __int8)value << (num_g_bits + num_b_bits - 8)); |
0 | 770 |
771 temp_dec_position++; | |
772 ++row_position; | |
773 if (row_position == psx_head2.pitch) | |
774 break; | |
775 | |
776 } | |
777 while (count-- != 1); | |
778 } | |
779 } | |
780 else | |
781 { | |
782 //*temp_dec_position |=(unsigned int) test_byte<<8; | |
783 //temp_dec_position++; | |
784 | |
2069 | 785 *temp_dec_position|= g_mask & (unsigned __int16)((unsigned __int8)test_byte << (num_g_bits + num_b_bits - 8)); |
0 | 786 temp_dec_position++; |
787 ++row_position; | |
788 } | |
789 } | |
790 | |
791 temp_dec_position = dec_position; | |
792 row_position=0; | |
793 //decode blue line | |
794 while (row_position < psx_head2.pitch) | |
795 { | |
796 test_byte = *(pPcx + read_offset); | |
797 read_offset++; | |
798 if ((test_byte & 0xC0) == 0xC0) | |
799 { | |
800 value = *(pPcx + read_offset); | |
801 ++read_offset; | |
802 if ((test_byte & 0x3F) > 0) | |
803 { | |
804 count = test_byte & 0x3F; | |
805 do | |
806 { | |
807 //*temp_dec_position|= value; | |
808 //temp_dec_position++; | |
809 | |
2069 | 810 *temp_dec_position |= value >> (8 - num_b_bits); |
0 | 811 temp_dec_position++; |
812 | |
813 ++row_position; | |
814 if (row_position == psx_head2.pitch) | |
815 break; | |
816 } | |
817 while (count-- != 1); | |
818 } | |
819 } | |
820 else | |
821 { | |
822 //*temp_dec_position|= test_byte; | |
823 //temp_dec_position++; | |
2069 | 824 *temp_dec_position |= test_byte >> (8 - num_b_bits); |
0 | 825 temp_dec_position++; |
826 | |
827 ++row_position; | |
828 } | |
829 | |
830 } | |
831 ++current_line; | |
832 dec_position += uWidth; | |
833 } | |
834 while (current_line < uHeight); | |
835 } | |
836 return 0; | |
837 /* | |
838 RGBTexture *v4; // esi@1 | |
839 signed int result; // eax@2 | |
840 unsigned __int16 v6; // ax@3 | |
841 unsigned __int16 *v7; // ecx@3 | |
842 unsigned int v8; // edx@3 | |
843 signed int v9; // ecx@3 | |
844 signed int v10; // ecx@8 | |
845 signed int v11; // ebx@37 | |
846 unsigned __int16 *v12; // eax@40 | |
847 int v13; // edi@40 | |
848 int v14; // ebx@41 | |
849 char v15; // bl@42 | |
850 unsigned __int16 *v16; // eax@50 | |
851 int v17; // ebx@51 | |
852 char v18; // bl@52 | |
853 unsigned __int16 *v19; // eax@61 | |
854 unsigned __int8 v20; // dl@62 | |
855 unsigned __int8 v21; // dl@63 | |
856 unsigned __int8 v22; // cl@63 | |
857 char color_map[48]; // [sp+8h] [bp-54h]@1 | |
858 PCXHeader1 header1; // [sp+38h] [bp-24h]@1 | |
859 PCXHeader2 header2; // [sp+48h] [bp-14h]@1 | |
860 unsigned int v26; // [sp+50h] [bp-Ch]@43 | |
861 int v27; // [sp+54h] [bp-8h]@38 | |
862 unsigned __int16 *v28; // [sp+58h] [bp-4h]@3 | |
863 int pOutPixelsa; // [sp+68h] [bp+Ch]@41 | |
864 int pOutPixelsb; // [sp+68h] [bp+Ch]@51 | |
865 | |
866 v4 = this; | |
867 memcpy(&header1, pPcx, 0x10u); | |
868 memcpy(color_map, pPcx + 16, 0x30u); | |
869 memcpy(&header2, pPcx + 64, 6u); | |
870 if ( header1.bpp == 8 ) | |
871 { | |
872 v6 = header1.right - header1.left + 1; | |
873 LOWORD(v7) = header1.bottom - header1.up + 1; | |
874 v4->uWidth = v6; | |
875 v4->uHeight = (unsigned __int16)v7; | |
876 v7 = (unsigned __int16 *)(signed __int16)v7; | |
877 v28 = v7; | |
878 v4->uNumPixels = (signed __int16)v7 * (signed __int16)v6; | |
879 HIWORD(v8) = 0; | |
880 v9 = 1; | |
881 while ( 1 << v9 != (signed __int16)v6 ) | |
882 { | |
883 ++v9; | |
884 if ( v9 >= 15 ) | |
885 goto LABEL_8; | |
886 } | |
887 v4->field_18 = v9; | |
888 LABEL_8: | |
889 v10 = 1; | |
890 while ( (unsigned __int16 *)(1 << v10) != v28 ) | |
891 { | |
892 ++v10; | |
893 if ( v10 >= 15 ) | |
894 goto LABEL_13; | |
895 } | |
896 v4->field_1A = v10; | |
897 LABEL_13: | |
898 switch ( v4->field_18 ) | |
899 { | |
900 case 2: | |
901 v4->field_1C = 3; | |
902 break; | |
903 case 3: | |
904 v4->field_1C = 7; | |
905 break; | |
906 case 4: | |
907 v4->field_1C = 15; | |
908 break; | |
909 case 5: | |
910 v4->field_1C = 31; | |
911 break; | |
912 case 6: | |
913 v4->field_1C = 63; | |
914 break; | |
915 case 7: | |
916 v4->field_1C = 127; | |
917 break; | |
918 case 8: | |
919 v4->field_1C = 255; | |
920 break; | |
921 case 9: | |
922 v4->field_1C = 511; | |
923 break; | |
924 case 10: | |
925 v4->field_1C = 1023; | |
926 break; | |
927 case 11: | |
928 v4->field_1C = 2047; | |
929 break; | |
930 case 12: | |
931 v4->field_1C = 4095; | |
932 break; | |
933 default: | |
934 break; | |
935 } | |
936 switch ( v4->field_1A ) | |
937 { | |
938 case 2: | |
939 v4->field_1E = 3; | |
940 break; | |
941 case 3: | |
942 v4->field_1E = 7; | |
943 break; | |
944 case 4: | |
945 v4->field_1E = 15; | |
946 break; | |
947 case 5: | |
948 v4->field_1E = 31; | |
949 break; | |
950 case 6: | |
951 v4->field_1E = 63; | |
952 break; | |
953 case 7: | |
954 v4->field_1E = 127; | |
955 break; | |
956 case 8: | |
957 v4->field_1E = 255; | |
958 break; | |
959 case 9: | |
960 v4->field_1E = 511; | |
961 break; | |
962 case 10: | |
963 v4->field_1E = 1023; | |
964 break; | |
965 case 11: | |
966 v4->field_1E = 2047; | |
967 break; | |
968 case 12: | |
969 v4->field_1E = 4095; | |
970 break; | |
971 default: | |
972 break; | |
973 } | |
974 v11 = 128; | |
975 if ( header2.planes == 3 ) | |
976 { | |
977 v27 = 0; | |
978 if ( (signed int)v28 > 0 ) | |
979 { | |
980 v28 = pOutPixels; | |
981 do | |
982 { | |
983 v12 = v28; | |
984 v13 = 0; | |
985 if ( header2.pitch ) | |
986 { | |
987 do | |
988 { | |
989 LOBYTE(v8) = pPcx[v11]; | |
990 v14 = v11 + 1; | |
991 pOutPixelsa = v14; | |
992 if ( (v8 & 0xC0) == -64 ) | |
993 { | |
994 pOutPixelsa = v14 + 1; | |
995 v15 = pPcx[v14]; | |
996 if ( (signed int)(v8 & 0x3F) > 0 ) | |
997 { | |
998 v26 = v8 & 0x3F; | |
999 do | |
1000 { | |
1001 ++v13; | |
1002 *v12 = LOWORD(pRenderer->uTargetRMask) & ((unsigned __int8)v15 << (LOBYTE(pRenderer->uTargetGBits) | |
1003 + LOBYTE(pRenderer->uTargetRBits) | |
1004 + LOBYTE(pRenderer->uTargetBBits) | |
1005 - 8)); | |
1006 ++v12; | |
1007 if ( v13 == (unsigned __int16)header2.pitch ) | |
1008 v12 = &v12[uNumPixels - (unsigned __int16)header2.pitch - 1]; | |
1009 --v26; | |
1010 } | |
1011 while ( v26 ); | |
1012 } | |
1013 } | |
1014 else | |
1015 { | |
1016 LOWORD(v8) = (unsigned __int8)v8; | |
1017 v8 = pRenderer->uTargetRMask & (v8 << (LOBYTE(pRenderer->uTargetGBits) | |
1018 + LOBYTE(pRenderer->uTargetRBits) | |
1019 + LOBYTE(pRenderer->uTargetBBits) | |
1020 - 8)); | |
1021 ++v13; | |
1022 *v12 = v8; | |
1023 ++v12; | |
1024 } | |
1025 v11 = pOutPixelsa; | |
1026 } | |
1027 while ( v13 < (unsigned __int16)header2.pitch ); | |
1028 } | |
1029 v16 = v28; | |
1030 while ( v13 < 2 * (unsigned __int16)header2.pitch ) | |
1031 { | |
1032 LOBYTE(v8) = pPcx[v11]; | |
1033 v17 = v11 + 1; | |
1034 pOutPixelsb = v17; | |
1035 if ( (v8 & 0xC0) == -64 ) | |
1036 { | |
1037 pOutPixelsb = v17 + 1; | |
1038 v18 = pPcx[v17]; | |
1039 if ( (signed int)(v8 & 0x3F) > 0 ) | |
1040 { | |
1041 v26 = v8 & 0x3F; | |
1042 do | |
1043 { | |
1044 *v16 |= pRenderer->uTargetGMask & (unsigned __int16)((unsigned __int8)v18 << (LOBYTE(pRenderer->uTargetGBits) | |
1045 + LOBYTE(pRenderer->uTargetBBits) | |
1046 - 8)); | |
1047 ++v13; | |
1048 ++v16; | |
1049 if ( v13 == (unsigned __int16)header2.pitch ) | |
1050 v16 = &v16[uNumPixels - (unsigned __int16)header2.pitch - 1]; | |
1051 --v26; | |
1052 } | |
1053 while ( v26 ); | |
1054 } | |
1055 } | |
1056 else | |
1057 { | |
1058 LOWORD(v8) = (unsigned __int8)v8; | |
1059 v8 = pRenderer->uTargetGMask & (v8 << (LOBYTE(pRenderer->uTargetGBits) + LOBYTE(pRenderer->uTargetBBits) - 8)); | |
1060 *v16 |= v8; | |
1061 ++v13; | |
1062 ++v16; | |
1063 } | |
1064 v11 = pOutPixelsb; | |
1065 } | |
1066 v19 = v28; | |
1067 while ( v13 < 3 * (unsigned __int16)header2.pitch ) | |
1068 { | |
1069 v20 = pPcx[v11++]; | |
1070 if ( (v20 & 0xC0) == -64 ) | |
1071 { | |
1072 v21 = v20 & 0x3F; | |
1073 v22 = pPcx[v11++]; | |
1074 if ( (signed int)v21 > 0 ) | |
1075 { | |
1076 v26 = v21; | |
1077 do | |
1078 { | |
1079 *v19 |= v22 >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1080 ++v13; | |
1081 ++v19; | |
1082 if ( v13 == (unsigned __int16)header2.pitch ) | |
1083 { | |
1084 v8 = uNumPixels - (unsigned __int16)header2.pitch; | |
1085 v19 = &v19[uNumPixels - (unsigned __int16)header2.pitch - 1]; | |
1086 } | |
1087 --v26; | |
1088 } | |
1089 while ( v26 ); | |
1090 } | |
1091 } | |
1092 else | |
1093 { | |
1094 *v19 |= v20 >> (8 - LOBYTE(pRenderer->uTargetBBits)); | |
1095 ++v13; | |
1096 ++v19; | |
1097 } | |
1098 } | |
1099 ++v27; | |
1100 v28 += uNumPixels; | |
1101 } | |
1102 while ( v27 < v4->uHeight ); | |
1103 } | |
1104 } | |
1105 result = 0; | |
1106 } | |
1107 else | |
1108 { | |
1109 result = 3; | |
1110 } | |
1111 return result; | |
1112 */ | |
1113 } | |
1114 | |
1115 //----- (0040EAD8) -------------------------------------------------------- | |
1116 unsigned int RGBTexture::LoadFromFILE(FILE *pFile, unsigned int mode, unsigned int bCloseFile) | |
1117 { | |
2334 | 1118 // signed int result; // eax@2 |
1119 // unsigned char test_byte; // edx@3 | |
0 | 1120 //unsigned int read_offset; // ebx@37 |
2334 | 1121 // unsigned int row_position; // edi@40 |
1122 // unsigned char value; // cl@63 | |
1123 // char count; // [sp+50h] [bp-Ch]@43 | |
1124 // unsigned short current_line; // [sp+54h] [bp-8h]@38 | |
1125 // unsigned short *dec_position; | |
1126 // unsigned short *temp_dec_position; | |
0 | 1127 PCXHeader1 psx_head1; |
1128 PCXHeader2 psx_head2; | |
2334 | 1129 // short int width, height; |
0 | 1130 BYTE color_map[48]; // Colormap for 16-color images |
1131 | |
2131 | 1132 unsigned int num_r_bits = 5; |
1133 unsigned int num_g_bits = 6; | |
1134 unsigned int num_b_bits = 5; | |
1135 | |
1136 unsigned int r_mask = 0xF800; | |
1137 unsigned int g_mask = 0x07E0; | |
1138 unsigned int b_mask = 0x001F; | |
1139 | |
0 | 1140 if (!pFile) |
1141 return 1; | |
1142 | |
1143 | |
1144 fread(&psx_head1, 1, 16, pFile); | |
1145 fread(&color_map, 1, 48, pFile); | |
1146 fread(&psx_head2, 1, 6, pFile); | |
1147 | |
1148 if (psx_head1.bpp!=8) | |
1149 return 3; | |
1150 uWidth=(short int )(psx_head1.right-psx_head1.left+1); // word @ 000014 | |
1151 uHeight=(short int )(psx_head1.bottom-psx_head1.up+1); // word @ 000016 | |
1152 | |
1153 | |
1154 uNumPixels=uWidth*uHeight; // dword @ 000010 | |
1155 | |
1156 | |
1157 if ( mode == 0 ) | |
1158 { | |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
1159 free(pPixels); |
1583 | 1160 pPixels = (unsigned __int16 *)malloc(2 * uNumPixels + 4); |
0 | 1161 } |
1162 else | |
1163 { | |
1164 if ( mode != 1 && mode == 2 ) | |
1165 { | |
1166 pPixels = (unsigned __int16 *)malloc((uNumPixels + 2) * sizeof(unsigned __int16)); | |
1583 | 1167 _allocation_flags |= 1; |
0 | 1168 } |
1169 } | |
1170 | |
1980 | 1171 ushort* pOutPixels = pPixels; |
0 | 1172 |
1173 memset(pOutPixels, 0, uNumPixels * sizeof(__int16)); | |
1174 | |
1175 short i=1; | |
1176 while ( (1<<i) !=uWidth) | |
1177 { | |
1178 ++i; | |
1179 if (i >= 15) | |
1180 break; | |
1181 } | |
1182 field_18=i; | |
1183 short i_=1; | |
1184 while ( (1<<i_) !=uHeight) | |
1185 { | |
1186 ++i_; | |
1187 if (i_ >= 15) | |
1188 break; | |
1189 } | |
1190 field_1A=i_; | |
1191 switch (field_18) | |
1192 { | |
1193 case 2: field_1C = 3; break; | |
1194 case 3: field_1C = 7; break; | |
1195 case 4: field_1C = 15; break; | |
1196 case 5: field_1C = 31; break; | |
1197 case 6: field_1C = 63; break; | |
1198 case 7: field_1C = 127; break; | |
1199 case 8: field_1C = 255; break; | |
1200 case 9: field_1C = 511; break; | |
1201 case 10: field_1C = 1023; break; | |
1202 case 11: field_1C = 2047; break; | |
1203 case 12: field_1C = 4095; break; | |
1204 } | |
1205 | |
1206 switch (field_1A) | |
1207 { | |
1208 case 2: field_1E = 3; break; | |
1209 case 3: field_1E = 7; break; | |
1210 case 4: field_1E = 15; break; | |
1211 case 5: field_1E = 31; break; | |
1212 case 6: field_1E = 63; break; | |
1213 case 7: field_1E = 127; break; | |
1214 case 8: field_1E = 255; break; | |
1215 case 9: field_1E = 511; break; | |
1216 case 10: field_1E = 1023; break; | |
1217 case 11: field_1E = 2047; break; | |
1218 case 12: field_1E = 4095; break; | |
1219 } | |
1220 | |
1221 fseek(pFile, 128 - 70, SEEK_CUR); | |
1222 | |
1223 | |
1224 for (uint y = 0; y < uHeight; ++y) | |
1225 { | |
1226 unsigned __int16 *pDst = pPixels + y * uWidth; | |
1227 | |
1228 uint x = 0; | |
1229 do | |
1230 { | |
1231 uint ctrl = 0; | |
1232 fread(&ctrl, 1, 1, pFile); | |
1233 if ((ctrl & 0xC0) == 0xC0) | |
1234 { | |
1235 uint uNumPixels = ctrl & 0x3F; | |
1236 uint clr = 0; | |
1237 fread(&clr, 1, 1, pFile); | |
1238 for (uint i = 0; i < uNumPixels; ++i) | |
2131 | 1239 pDst[x++] = r_mask & (clr << (num_g_bits + num_r_bits + num_b_bits - 8)); |
0 | 1240 } |
1241 else | |
1242 { | |
2131 | 1243 pDst[x++] = r_mask & (ctrl << (num_g_bits + num_r_bits + num_b_bits - 8)); |
0 | 1244 } |
1245 } while (x < psx_head2.pitch); | |
1246 | |
1247 x = 0; | |
1248 do | |
1249 { | |
1250 uint ctrl = 0; | |
1251 fread(&ctrl, 1, 1, pFile); | |
1252 if ((ctrl & 0xC0) == 0xC0) | |
1253 { | |
1254 uint uNumPixels = ctrl & 0x3F; | |
1255 uint clr = 0; | |
1256 fread(&clr, 1, 1, pFile); | |
1257 for (uint i = 0; i < uNumPixels; ++i) | |
2131 | 1258 pDst[x++] |= g_mask & (clr << (num_g_bits + num_b_bits - 8)); |
0 | 1259 } |
1260 else | |
1261 { | |
2131 | 1262 pDst[x++] |= g_mask & (ctrl << (num_g_bits + num_b_bits - 8)); |
0 | 1263 } |
1264 } while (x < psx_head2.pitch); | |
1265 | |
1266 x = 0; | |
1267 do | |
1268 { | |
1269 uint ctrl = 0; | |
1270 fread(&ctrl, 1, 1, pFile); | |
1271 if ((ctrl & 0xC0) == 0xC0) | |
1272 { | |
1273 uint uNumPixels = ctrl & 0x3F; | |
1274 uint clr = 0; | |
1275 fread(&clr, 1, 1, pFile); | |
1276 for (uint i = 0; i < uNumPixels; ++i) | |
2131 | 1277 pDst[x++] |= b_mask & (clr >> (8 - num_b_bits)); |
0 | 1278 } |
1279 else | |
1280 { | |
2131 | 1281 pDst[x++] |= b_mask & (ctrl >> (8 - num_b_bits)); |
0 | 1282 } |
1283 } while (x < psx_head2.pitch); | |
1284 } | |
1285 | |
1286 if (bCloseFile) | |
1287 fclose(pFile); | |
1288 return 0; | |
1289 } | |
1290 | |
1291 //----- (0040E51F) -------------------------------------------------------- | |
1292 void RGBTexture::Release() | |
1293 { | |
1294 this->pName[0] = 0; | |
2129 | 1295 //if ( !(this->_allocation_flags & 1) ) |
1296 //free(this->pPixels); | |
1297 //else | |
1298 free(this->pPixels); | |
1299 this->_allocation_flags = 0; | |
1300 this->pPixels = 0; | |
1301 this->uNumPixels = 0; | |
1302 this->uHeight = 0; | |
1303 this->uWidth = 0; | |
1304 this->field_1A = 0; | |
1305 this->field_18 = 0; | |
0 | 1306 } |
1307 | |
1308 //----- (0040E55E) -------------------------------------------------------- | |
2129 | 1309 int RGBTexture::LoadPCXFile(const char *Filename, unsigned int a3) |
0 | 1310 { |
1311 signed int result; // eax@2 | |
1312 char *v6; // eax@3 | |
1313 int v7; // edx@3 | |
1314 char v8; // cl@4 | |
1315 signed int v14; // ecx@19 | |
1316 signed int v15; // ecx@24 | |
2334 | 1317 // int v16; // eax@57 |
1318 // unsigned __int16 *v17; // ecx@57 | |
1319 // unsigned __int16 *v18; // edi@57 | |
1320 // signed int x; // eax@59 | |
1321 // unsigned __int16 *v20; // edi@64 | |
1322 // signed int v21; // eax@66 | |
1323 // unsigned __int16 *v22; // edi@71 | |
1324 // signed int v23; // eax@73 | |
1325 // int v24; // eax@78 | |
71 | 1326 char v25[48]; // [sp+Ch] [bp-54h]@3 |
1327 PCXHeader1 pcx_header1; | |
1328 PCXHeader2 pcx_header2; | |
2129 | 1329 int y; // [sp+54h] [bp-Ch]@3 |
0 | 1330 FILE *File; // [sp+5Ch] [bp-4h]@1 |
1331 | |
2129 | 1332 unsigned int num_r_bits = 5; |
1333 unsigned int num_g_bits = 6; | |
1334 unsigned int num_b_bits = 5; | |
1335 | |
1336 unsigned int r_mask = 0xF800; | |
1337 unsigned int g_mask = 0x07E0; | |
1338 unsigned int b_mask = 0x001F; | |
1339 | |
1340 | |
0 | 1341 File = fopen(Filename, "rb"); |
1342 if ( !File ) | |
1343 return 1; | |
71 | 1344 |
1345 fread(&pcx_header1, sizeof(pcx_header1), 1, File); | |
1346 fread(&v25,48,1,File); | |
1347 fread(&pcx_header2, 4, 1, File); | |
1348 | |
0 | 1349 v6 = (char *)Filename; |
2129 | 1350 v7 = (char *)this - Filename; |
1351 uint i = 0; | |
1352 for ( i; i < 15; ++i ) | |
0 | 1353 { |
1354 v8 = *v6; | |
1355 if ( !*v6 ) | |
1356 break; | |
1357 if ( v8 == 46 ) | |
1358 break; | |
1359 (v6++)[v7] = v8; | |
1360 } | |
2129 | 1361 this->pName[i] = 0; |
71 | 1362 if ( pcx_header1.bpp != 8 ) |
0 | 1363 return 3; |
2129 | 1364 this->uWidth = pcx_header1.right - pcx_header1.left + 1; |
1365 this->uHeight = pcx_header1.bottom - pcx_header1.up + 1; | |
1366 this->uNumPixels = (signed __int16)this->uWidth * (signed __int16)this->uHeight; | |
1367 if ( !a3 ) | |
0 | 1368 { |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2353
diff
changeset
|
1369 free(this->pPixels); |
2129 | 1370 this->pPixels = (unsigned __int16 *)malloc(2 * this->uNumPixels + 4); |
0 | 1371 } |
2129 | 1372 if ( a3 == 2 ) |
0 | 1373 { |
2129 | 1374 this->_allocation_flags |= 1; |
2131 | 1375 this->pPixels = (unsigned __int16 *)malloc((uNumPixels + 2) * sizeof(unsigned __int16)); |
2129 | 1376 } |
1377 if ( this->pPixels ) | |
1378 { | |
1379 for ( v14 = 1; v14 < 15; ++v14 ) | |
0 | 1380 { |
2129 | 1381 if ( 1 << v14 == this->uWidth ) |
1382 this->field_18 = v14; | |
0 | 1383 } |
2129 | 1384 for ( v15 = 1; v15 < 15; ++v15 ) |
0 | 1385 { |
2129 | 1386 if ( 1 << v15 == this->uHeight ) |
1387 this->field_1A = v15; | |
0 | 1388 } |
2129 | 1389 switch ( this->field_18 ) |
0 | 1390 { |
2129 | 1391 case 2: this->field_1C = 3; break; |
1392 case 3: this->field_1C = 7; break; | |
1393 case 4: this->field_1C = 15; break; | |
1394 case 5: this->field_1C = 31; break; | |
1395 case 6: this->field_1C = 63; break; | |
1396 case 7: this->field_1C = 127; break; | |
1397 case 8: this->field_1C = 255; break; | |
1398 case 9: this->field_1C = 511; break; | |
1399 case 10: this->field_1C = 1023; break; | |
1400 case 11: this->field_1C = 2047; break; | |
1401 case 12: this->field_1C = 4095; break; | |
1402 default: break; | |
1403 } | |
1404 switch ( this->field_1A ) | |
1405 { | |
1406 case 2: this->field_1E = 3; break; | |
1407 case 3: this->field_1E = 7; break; | |
1408 case 4: this->field_1E = 15; break; | |
1409 case 5: this->field_1E = 31; break; | |
1410 case 6: this->field_1E = 63; break; | |
1411 case 7: this->field_1E = 127; break; | |
1412 case 8: this->field_1E = 255; break; | |
1413 case 9: this->field_1E = 511; break; | |
1414 case 10: this->field_1E = 1023; break; | |
1415 case 11: this->field_1E = 2047; break; | |
1416 case 12: this->field_1E = 4095; break; | |
1417 default: break; | |
0 | 1418 } |
1419 fseek(File, 128, 0); | |
1420 ftell(File); | |
2131 | 1421 if ( pcx_header2.planes == 1 ) |
1545 | 1422 Error("24bit PCX Only!"); |
1423 | |
71 | 1424 if ( pcx_header2.planes == 3 ) |
0 | 1425 { |
2131 | 1426 for ( y = 0; y < this->uHeight; ++y ) |
1427 { | |
1428 unsigned __int16 *pDst = pPixels + y * uWidth; | |
1429 uint x = 0; | |
1430 do | |
0 | 1431 { |
2131 | 1432 uint ctrl = 0; |
1433 fread(&ctrl, 1, 1, File); | |
1434 if ( (ctrl & 0xC0) == 0xC0 ) | |
1435 { | |
1436 uint uNumPixels = ctrl & 0x3F; | |
1437 uint clr = 0; | |
1438 ctrl &= 0x3F; | |
1439 fread(&clr, 1, 1, File); | |
1440 for ( uint i = 0; i < uNumPixels; ++i ) | |
1441 pDst[x++] = r_mask & (clr << (num_r_bits + num_g_bits + num_b_bits - 8)); | |
1442 } | |
1443 else | |
1444 pDst[x++] = r_mask & (ctrl << (num_g_bits + num_r_bits + num_b_bits - 8)); | |
1445 } | |
1446 while ( x < pcx_header2.pitch ); | |
1447 | |
1448 x = 0; | |
1449 do | |
1450 { | |
1451 uint ctrl = 0; | |
1452 fread(&ctrl, 1, 1, File); | |
1453 if ( (ctrl & 0xC0) == 0xC0 ) | |
0 | 1454 { |
2131 | 1455 uint uNumPixels = ctrl & 0x3F; |
1456 uint clr = 0; | |
1457 ctrl &= 0x3F; | |
1458 fread(&clr, 1, 1, File); | |
1459 for ( uint i = 0; i < uNumPixels; ++i ) | |
1460 pDst[x++] |= g_mask & (clr << (num_g_bits + num_b_bits - 8)); | |
0 | 1461 } |
2131 | 1462 else |
1463 pDst[x++] |= g_mask & (ctrl << (num_g_bits + num_b_bits - 8)); | |
1464 } | |
1465 while (x < pcx_header2.pitch); | |
1466 | |
1467 x = 0; | |
1468 do | |
1469 { | |
1470 uint ctrl = 0; | |
1471 fread(&ctrl, 1, 1, File); | |
1472 if ( (ctrl & 0xC0) == 0xC0 ) | |
0 | 1473 { |
2131 | 1474 uint uNumPixels = ctrl & 0x3F; |
1475 uint clr = 0; | |
1476 fread(&clr, 1, 1, File); | |
1477 for ( uint i = 0; i < uNumPixels; ++i ) | |
1478 pDst[x++] |= b_mask & (clr >> (8 - num_b_bits)); | |
0 | 1479 } |
2131 | 1480 else |
1481 pDst[x++] |= b_mask & (ctrl >> (8 - num_b_bits)); | |
0 | 1482 } |
2131 | 1483 while (x < pcx_header2.pitch); |
1484 } | |
0 | 1485 } |
1486 fclose(File); | |
1487 result = 0; | |
1488 } | |
1489 else | |
1490 { | |
1491 result = 2; | |
1492 } | |
1493 return result; | |
1494 } | |
1495 | |
1496 //----- (0040D73D) -------------------------------------------------------- | |
1497 RGBTexture::RGBTexture() | |
1498 { | |
1499 pName[0] = 0; | |
1500 pPixels = 0; | |
1501 uNumPixels = 0; | |
1502 uHeight = 0; | |
1503 uWidth = 0; | |
1504 field_1A = 0; | |
1505 field_18 = 0; | |
1583 | 1506 _allocation_flags = 0; |
1297 | 1507 } |
1508 //----- (0044E1EC) -------------------------------------------------------- | |
1509 int TextureFrameTable::FromFileTxt(const char *Args) | |
1510 { | |
1511 TextureFrameTable *v2; // ebx@1 | |
1512 FILE *v3; // eax@1 | |
1513 int v4; // esi@3 | |
1514 const void *v5; // ST0C_4@10 | |
1515 void *v6; // eax@10 | |
1516 FILE *v7; // ST0C_4@12 | |
1517 char *i; // eax@12 | |
1518 signed int v9; // esi@15 | |
1519 int v10; // eax@17 | |
1520 int v11; // edx@22 | |
1521 int v12; // ecx@23 | |
1522 int v13; // eax@24 | |
1523 signed int j; // eax@27 | |
1524 TextureFrame *v15; // edx@28 | |
1525 int v16; // esi@28 | |
1526 int k; // ecx@29 | |
1527 char Buf; // [sp+Ch] [bp-2F8h]@3 | |
1528 FrameTableTxtLine v20; // [sp+200h] [bp-104h]@4 | |
1529 int v21; // [sp+27Ch] [bp-88h]@4 | |
1530 char *Str1; // [sp+280h] [bp-84h]@5 | |
1531 char *Str; // [sp+284h] [bp-80h]@15 | |
1532 int v24; // [sp+2F8h] [bp-Ch]@3 | |
1533 int v25; // [sp+2FCh] [bp-8h]@3 | |
1534 FILE *File; // [sp+300h] [bp-4h]@1 | |
1535 int Argsa; // [sp+30Ch] [bp+8h]@28 | |
1536 | |
1537 v2 = this; | |
1538 v3 = fopen(Args, "r"); | |
1539 File = v3; | |
1540 if ( !v3 ) | |
1545 | 1541 Error("CTextureFrameTable::load - Unable to open file: %s.", Args); |
1542 | |
1297 | 1543 v4 = 0; |
1544 v24 = 0; | |
1545 v25 = 1; | |
1546 if ( fgets(&Buf, 490, v3) ) | |
1547 { | |
1548 do | |
1549 { | |
1550 *strchr(&Buf, 10) = 0; | |
1551 memcpy(&v21, txt_file_frametable_parser(&Buf, &v20), 0x7Cu); | |
1409
c9e3b93ec570
Highlighted locations with "using uninitialized variable" warning.
Nomad
parents:
1402
diff
changeset
|
1552 __debugbreak(); // warning C4700: uninitialized local variable 'Str1' used |
1297 | 1553 if ( v21 && *Str1 != 47 ) |
1554 { | |
1555 if ( v21 < 2 ) | |
1545 | 1556 Error("CTextureFrameTable::load, too few arguments, %s line %i.", Args, v25); |
1297 | 1557 ++v24; |
1558 } | |
1559 ++v25; | |
1560 } | |
1561 while ( fgets(&Buf, 490, File) ); | |
1562 v4 = v24; | |
1563 } | |
1564 v5 = v2->pTextures; | |
1565 v2->sNumTextures = v4; | |
1583 | 1566 v6 = malloc(20 * v4); |
1297 | 1567 v2->pTextures = (TextureFrame *)v6; |
1568 if ( !v6 ) | |
1545 | 1569 Error("CTextureFrameTable::load - Out of Memory!"); |
1297 | 1570 v7 = File; |
1571 v2->sNumTextures = 0; | |
1572 fseek(v7, 0, 0); | |
1573 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
1574 { | |
1575 *strchr(&Buf, 10) = 0; | |
1576 memcpy(&v21, txt_file_frametable_parser(&Buf, &v20), 0x7Cu); | |
1577 if ( v21 && *Str1 != 47 ) | |
1578 { | |
1579 strcpy(v2->pTextures[v2->sNumTextures].pTextureName, Str1); | |
1409
c9e3b93ec570
Highlighted locations with "using uninitialized variable" warning.
Nomad
parents:
1402
diff
changeset
|
1580 __debugbreak(); // warning C4700: uninitialized local variable 'Str' used |
1297 | 1581 v2->pTextures[v2->sNumTextures].uAnimTime = atoi(Str); |
1582 v9 = 2; | |
1583 for ( v2->pTextures[v2->sNumTextures].uFlags = 0; v9 < v21; ++v9 ) | |
1584 { | |
1585 if ( !_stricmp((&Str1)[4 * v9], "New") ) | |
1586 { | |
2335 | 1587 //v10 = (int)&v2->pTextures[v2->sNumTextures].uFlags; |
1588 v2->pTextures[v2->sNumTextures].uFlags |= 2; | |
1297 | 1589 } |
1590 } | |
1591 ++v2->sNumTextures; | |
1592 } | |
1593 } | |
1594 fclose(File); | |
1595 v11 = 0; | |
1596 if ( (signed int)(v2->sNumTextures - 1) > 0 ) | |
1597 { | |
1598 v12 = 0; | |
1599 do | |
1600 { | |
1601 v13 = (int)&v2->pTextures[v12]; | |
1602 if ( !(*(char *)(v13 + 38) & 2) ) | |
1603 *(char *)(v13 + 18) |= 1u; | |
1604 ++v11; | |
1605 ++v12; | |
1606 } | |
1607 while ( v11 < (signed int)(v2->sNumTextures - 1) ); | |
1608 } | |
1609 for ( j = 0; j < (signed int)v2->sNumTextures; *(short *)(Argsa + 16) = v16 ) | |
1610 { | |
1611 v15 = v2->pTextures; | |
1612 Argsa = (int)&v15[j]; | |
1613 v16 = *(short *)(Argsa + 14); | |
1614 if ( *(char *)(Argsa + 18) & 1 ) | |
1615 { | |
1616 ++j; | |
1617 for ( k = (int)&v15[j]; *(char *)(k + 18) & 1; k += 20 ) | |
1618 { | |
1619 v16 += *(short *)(k + 14); | |
1620 ++j; | |
1621 } | |
1622 LOWORD(v16) = v15[j].uAnimTime + v16; | |
1623 } | |
1624 ++j; | |
1625 } | |
1626 return 1; | |
1627 } | |
2463 | 1628 |
1629 //----- (00451007) -------------------------------------------------------- | |
1630 int stru350::sub_451007_scale_image_bicubic(unsigned short *pSrc, int srcWidth, int srcHeight, int srcPitch, //changing this to some library function might be a good idea | |
1631 unsigned short *pDst, int dstWidth, int dstHeight, int dstPitch, | |
1632 int a10, int a11) | |
1633 { | |
1634 int result; // eax@1 | |
1635 float v17; // ST3C_4@12 | |
1636 float v18; // ST38_4@12 | |
1637 unsigned int v19; // esi@12 | |
1638 int v21; // eax@18 | |
1639 unsigned int v22; // ecx@25 | |
1640 unsigned int v23; // eax@29 | |
1641 unsigned int heightRatioPlusOne; // [sp+Ch] [bp-7Ch]@12 | |
1642 unsigned int widthRatio; // [sp+Ch] [bp-7Ch]@218 | |
1643 unsigned int heightRatio; // [sp+14h] [bp-74h]@12 | |
1644 unsigned int widthRatioPlusOne; // [sp+14h] [bp-74h]@218 | |
1645 // int v160; // [sp+3Ch] [bp-4Ch]@13 | |
1646 unsigned __int16 *v175; // [sp+4Ch] [bp-3Ch]@13 | |
1647 unsigned __int16 *v193; // [sp+5Ch] [bp-2Ch]@7 | |
1648 //signed int v231; // [sp+78h] [bp-10h]@7 | |
1649 __int64 v240; // [sp+7Ch] [bp-Ch]@12 | |
1650 unsigned int v251; // [sp+80h] [bp-8h]@218 | |
1651 unsigned int v252; // [sp+84h] [bp-4h]@218 | |
1652 float a6s; // [sp+A0h] [bp+18h]@218 | |
1653 float a6t; // [sp+A0h] [bp+18h]@218 | |
1654 unsigned int a6b; // [sp+A0h] [bp+18h]@218 | |
1655 int field_0_bits; | |
1656 int field_20_bits; | |
1657 | |
1658 int field0value = this->field_0.field_C; | |
1659 switch (field0value) | |
1660 { | |
1661 case 8: field_0_bits = 1; | |
1662 break; | |
1663 case 16: field_0_bits = 2; | |
1664 break; | |
1665 case 32: field_0_bits = 4; | |
1666 break; | |
1667 default: | |
1668 return field0value; | |
1669 } | |
1670 int field20value = this->field_20.field_C; | |
1671 switch (field20value) | |
1672 { | |
1673 case 8: field_20_bits = 1; | |
1674 break; | |
1675 case 16: field_20_bits = 2; | |
1676 break; | |
1677 case 32: field_20_bits = 4; | |
1678 break; | |
1679 default: | |
1680 return field20value; | |
1681 } | |
1682 | |
1683 result = (int)pDst; | |
1684 v193 = pDst; | |
1685 if (dstHeight <= 0) | |
1686 return result; | |
1687 | |
1688 //do | |
1689 for (int height = 0; height < dstHeight; height++) | |
1690 { | |
1691 for (int width = 0; width < dstWidth; width++) | |
1692 { | |
1693 a6s = (double)width / (double)dstWidth * (double)srcWidth; | |
1694 widthRatio = bankersRounding(a6s); | |
1695 a6t = (double)(width + 1) / (double)dstWidth * (double)srcWidth; | |
1696 widthRatioPlusOne = bankersRounding(a6t); | |
1697 | |
1698 v17 = (double)height / (double)dstHeight * (double)srcHeight; | |
1699 heightRatio = bankersRounding(v17); | |
1700 v18 = (double)(height + 1) / (double)dstHeight * (double)srcHeight; | |
1701 heightRatioPlusOne = bankersRounding(v18); | |
1702 | |
1703 v251 = 0; | |
1704 v19 = (heightRatioPlusOne - heightRatio) * (widthRatioPlusOne - widthRatio); | |
1705 v252 = 0; | |
1706 a6b = 0; | |
1707 v240 = 0i64; | |
1708 | |
1709 v175 = (unsigned short*)((char *)pSrc + field_0_bits * (widthRatio + srcPitch * heightRatio)); | |
1710 for (int heightDiff = 0; heightDiff < heightRatioPlusOne - heightRatio; heightDiff++) | |
1711 { | |
1712 //int ratioDiff = widthRatioPlusOne - widthRatio; | |
1713 for (int ratioDiff = 0; ratioDiff < widthRatioPlusOne - widthRatio; ratioDiff++) | |
1714 { | |
1715 if (field0value == 32) | |
1716 v21 = _450FB1(((int*)v175)[ratioDiff]); | |
1717 else if (field0value == 16) | |
1718 v21 = _450FB1(((_WORD*)v175)[ratioDiff]); | |
1719 else if (field0value == 8) | |
1720 v21 = _450FB1(((unsigned __int8*)v175)[ratioDiff]); | |
1721 v240 += ((unsigned int)v21 >> 24); | |
1722 a6b += BYTE2(v21); | |
1723 v252 += BYTE1(v21); | |
1724 v251 += (unsigned __int8)v21; | |
1725 } | |
1726 if (field0value == 32) | |
1727 v175 += 2 * srcPitch; | |
1728 else if (field0value == 16) | |
1729 v175 += srcPitch; | |
1730 else if (field0value == 8) | |
1731 v175 = (unsigned short*)((char *)v175 + 2 * srcPitch); | |
1732 } | |
1733 | |
1734 v22 = (unsigned int)v240 / ((heightRatioPlusOne - heightRatio) * (widthRatioPlusOne - widthRatio)); | |
1735 if (v19) | |
1736 { | |
1737 a6b /= v19; | |
1738 v252 /= v19; | |
1739 v251 /= v19; | |
1740 } | |
1741 if (v22 != 255) | |
1742 v22 &= 0x7FFFFFFFu; | |
1743 v23 = _450F55(v251 | ((v252 | ((a6b | (v22 << 8)) << 8)) << 8)); | |
1744 *(_DWORD *)v193 = v23; //Invalid memory access | |
1745 v193 = (unsigned __int16 *)((char *)v193 + field_20_bits); | |
1746 } | |
1747 v193 = (unsigned __int16 *)((char *)v193 + field_20_bits * (dstPitch - dstWidth)); | |
1748 //++v231; | |
1749 result = height; | |
1750 } | |
1751 //while(v231 < dstHeight); | |
1752 return result; | |
1753 } | |
1754 | |
1755 | |
1756 //----- (00450DDE) -------------------------------------------------------- | |
1757 stru350 *stru350::_450DDE() | |
1758 { | |
1759 _450DF1(&stru_4E82A4, &stru_4E82A4); | |
1760 return this; | |
1761 } | |
1762 | |
1763 //----- (00450DF1) -------------------------------------------------------- | |
1764 bool stru350::_450DF1(const stru355 *p1, const stru355 *p2) | |
1765 { | |
1766 //stru350 *v3; // esi@1 | |
1767 //void *result; // eax@1 | |
1768 unsigned int v5; // ecx@2 | |
1769 int v6; // edi@2 | |
1770 int v7; // edx@2 | |
1771 unsigned int v8; // ecx@8 | |
1772 int v9; // edi@8 | |
1773 int v10; // edx@8 | |
1774 int v11; // ecx@12 | |
1775 int v12; // edi@12 | |
1776 unsigned int v13; // ecx@12 | |
1777 int v14; // edx@12 | |
1778 int v15; // ecx@16 | |
1779 unsigned int v16; // edx@16 | |
1780 int v17; // ecx@16 | |
1781 int v18; // edi@16 | |
1782 char v19; // zf@20 | |
1783 unsigned int v20; // ecx@21 | |
1784 int v21; // edi@21 | |
1785 int v22; // edx@21 | |
1786 unsigned int v23; // ecx@27 | |
1787 int v24; // edi@27 | |
1788 int v25; // edx@27 | |
1789 int v26; // ecx@31 | |
1790 int v27; // edi@31 | |
1791 unsigned int v28; // ecx@31 | |
1792 int v29; // edx@31 | |
1793 int v30; // ebx@35 | |
1794 int v31; // ecx@35 | |
1795 int v32; // edi@35 | |
1796 int v33; // edx@35 | |
1797 unsigned int i; // ecx@35 | |
1798 int v35; // ecx@39 | |
1799 unsigned int v36; // edx@39 | |
1800 int v37; // ecx@39 | |
1801 int v38; // ebx@39 | |
1802 | |
1803 //v3 = this; | |
1804 memcpy(&field_0, p1, sizeof(stru355)); | |
1805 memcpy(&field_20, p2, sizeof(stru355)); | |
1806 //result = memcpy(&v3->field_20, p2, 0x20u); | |
1807 //LOBYTE(result) = 1; | |
1808 if (field_0.field_4 & 1) | |
1809 { | |
1810 v5 = field_0.field_1C; | |
1811 v6 = 0; | |
1812 v7 = 0; | |
1813 while (!(v5 & 1)) | |
1814 { | |
1815 ++v6; | |
1816 v5 >>= 1; | |
1817 } | |
1818 do | |
1819 { | |
1820 v5 >>= 1; | |
1821 ++v7; | |
1822 } while (v5 & 1); | |
1823 field_40 = 32 - v7 - v6; | |
1824 } | |
1825 else | |
1826 { | |
1827 field_40 = 0; | |
1828 } | |
1829 v8 = field_0.field_10; | |
1830 v9 = 0; | |
1831 v10 = 0; | |
1832 while (!(v8 & 1)) | |
1833 { | |
1834 ++v9; | |
1835 v8 >>= 1; | |
1836 } | |
1837 do | |
1838 { | |
1839 v8 >>= 1; | |
1840 ++v10; | |
1841 } while (v8 & 1); | |
1842 v11 = 24 - v10 - v9; | |
1843 v12 = 0; | |
1844 field_48 = v11; | |
1845 v13 = field_0.field_14; | |
1846 v14 = 0; | |
1847 while (!(v13 & 1)) | |
1848 { | |
1849 ++v12; | |
1850 v13 >>= 1; | |
1851 } | |
1852 do | |
1853 { | |
1854 v13 >>= 1; | |
1855 ++v14; | |
1856 } while (v13 & 1); | |
1857 v15 = 16 - v14; | |
1858 v16 = field_0.field_18; | |
1859 field_50 = v15 - v12; | |
1860 v17 = 0; | |
1861 v18 = 0; | |
1862 while (!(v16 & 1)) | |
1863 { | |
1864 ++v17; | |
1865 v16 >>= 1; | |
1866 } | |
1867 do | |
1868 { | |
1869 v16 >>= 1; | |
1870 ++v18; | |
1871 } while (v16 & 1); | |
1872 v19 = (field_20.field_4 & 1) == 0; | |
1873 field_58 = v17 - v18 + 8; | |
1874 if (v19) | |
1875 { | |
1876 field_44 = 0; | |
1877 } | |
1878 else | |
1879 { | |
1880 v20 = field_20.field_1C; | |
1881 v21 = 0; | |
1882 v22 = 0; | |
1883 while (!(v20 & 1)) | |
1884 { | |
1885 ++v21; | |
1886 v20 >>= 1; | |
1887 } | |
1888 do | |
1889 { | |
1890 v20 >>= 1; | |
1891 ++v22; | |
1892 } while (v20 & 1); | |
1893 field_44 = 32 - v22 - v21; | |
1894 } | |
1895 v23 = field_20.field_10; | |
1896 v24 = 0; | |
1897 v25 = 0; | |
1898 while (!(v23 & 1)) | |
1899 { | |
1900 ++v24; | |
1901 v23 >>= 1; | |
1902 } | |
1903 do | |
1904 { | |
1905 v23 >>= 1; | |
1906 ++v25; | |
1907 } while (v23 & 1); | |
1908 v26 = 24 - v25 - v24; | |
1909 v27 = 0; | |
1910 field_4C = v26; | |
1911 v28 = field_20.field_14; | |
1912 v29 = 0; | |
1913 while (!(v28 & 1)) | |
1914 { | |
1915 ++v27; | |
1916 v28 >>= 1; | |
1917 } | |
1918 do | |
1919 { | |
1920 v28 >>= 1; | |
1921 ++v29; | |
1922 } while (v28 & 1); | |
1923 v30 = 0; | |
1924 v31 = 16 - v29 - v27; | |
1925 v32 = field_20.field_18; | |
1926 field_54 = v31; | |
1927 v33 = 0; | |
1928 for (i = v32; !(i & 1); i >>= 1) | |
1929 ++v30; | |
1930 do | |
1931 { | |
1932 i >>= 1; | |
1933 ++v33; | |
1934 } while (i & 1); | |
1935 v35 = 32 - v33; | |
1936 v36 = v32; | |
1937 field_5C = v35 - v30; | |
1938 v37 = 0; | |
1939 v38 = 0; | |
1940 while (!(v36 & 1)) | |
1941 { | |
1942 ++v37; | |
1943 v36 >>= 1; | |
1944 } | |
1945 do | |
1946 { | |
1947 v36 >>= 1; | |
1948 ++v38; | |
1949 } while (v36 & 1); | |
1950 field_5C = v37 - v38 + 8; | |
1951 return true; | |
1952 } | |
1953 | |
1954 //----- (00450F55) -------------------------------------------------------- | |
1955 unsigned int stru350::_450F55(int a2) | |
1956 { | |
1957 int v2 = a2 & stru_4E82A4.field_1C; | |
1958 if (field_20.field_4 & 1) | |
1959 v2 = (unsigned int)v2 >> this->field_44; | |
1960 return v2 & field_20.field_1C | | |
1961 field_20.field_10 & ((a2 & (unsigned int)stru_4E82A4.field_10) >> field_4C) | | |
1962 field_20.field_14 & ((a2 & (unsigned int)stru_4E82A4.field_14) >> field_54) | | |
1963 field_20.field_18 & ((a2 & (unsigned int)stru_4E82A4.field_18) >> field_5C); | |
1964 } | |
1965 | |
1966 //----- (00450FB1) -------------------------------------------------------- | |
1967 int stru350::_450FB1(int a2) | |
1968 { | |
1969 int v2 = 0; | |
1970 int v4 = field_0.field_4 & 1; | |
1971 if (v4) | |
1972 v2 = a2 & field_0.field_1C; | |
1973 if (v4) | |
1974 v2 <<= field_40; | |
1975 return v2 | ((a2 & field_0.field_10) << field_48) | ((a2 & field_0.field_14) << field_50) | ((a2 & field_0.field_18) << field_58); | |
1976 } | |
1977 |