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