Mercurial > mm7
changeset 2129:23dbcaa651cc
LoadPCXFile
author | Ritor1 |
---|---|
date | Sat, 28 Dec 2013 13:12:52 +0600 |
parents | 400f3db2e4e5 |
children | 4f6c52ed6f7c |
files | Game.cpp Texture.cpp Texture.h |
diffstat | 3 files changed, 134 insertions(+), 229 deletions(-) [+] |
line wrap: on
line diff
--- a/Game.cpp Fri Dec 27 17:52:31 2013 +0600 +++ b/Game.cpp Sat Dec 28 13:12:52 2013 +0600 @@ -2650,7 +2650,7 @@ uNumSeconds = (unsigned int)MakeScreenshot(155, 117); pRenderer->SavePCXImage("gamma.pcx", (char *)uNumSeconds, 155, 117); free((void *)uNumSeconds); - stru_506E40._40E55E("gamma.pcx", 0); + stru_506E40.LoadPCXFile("gamma.pcx", 0); continue; } pGUIWindow_Settings->Release(); @@ -3922,7 +3922,7 @@ uNumSeconds = (unsigned int)MakeScreenshot(155, 117); pRenderer->SavePCXImage("gamma.pcx", (char *)uNumSeconds, 155, 117); free((void *)uNumSeconds); - stru_506E40._40E55E("gamma.pcx", 0); + stru_506E40.LoadPCXFile("gamma.pcx", 0); GUIWindow::Create(0x25Au, 0x1C2u, 0, 0, WINDOW_PressedButton, (int)pBtn_GameSettings, 0); //LABEL_453: /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
--- a/Texture.cpp Fri Dec 27 17:52:31 2013 +0600 +++ b/Texture.cpp Sat Dec 28 13:12:52 2013 +0600 @@ -431,7 +431,7 @@ //----- (0040F5F5) -------------------------------------------------------- int RGBTexture::Reload(const char *pContainer) { - RGBTexture *v2; // esi@1 + //RGBTexture *v2; // esi@1 FILE *v3; // eax@3 FILE *v4; // edi@3 void *v5; // ebx@7 @@ -447,8 +447,8 @@ size_t Count; // [sp+9Ch] [bp-4h]@6 void *uSourceLena; // [sp+A8h] [bp+8h]@7 - v2 = this; - if ( !v2->pPixels ) + // v2 = this; + if ( !this->pPixels ) return 2; v3 = pIcons_LOD->FindContainer(pContainer, 0); v4 = v3; @@ -456,13 +456,13 @@ if ( !v3 ) Error("Unable to load %s", pContainer); - fread(&DstBuf, 1u, 0x30u, v3); + fread(&DstBuf, 1, 0x30, v3); Count = DstBuf.uTextureSize; if ( DstBuf.uDecompressedSize ) { v5 = malloc(DstBuf.uDecompressedSize); uSourceLena = malloc(DstBuf.uTextureSize); - fread(uSourceLena, 1u, Count, File); + fread(uSourceLena, 1, Count, File); zlib::MemUnzip(v5, &DstBuf.uDecompressedSize, uSourceLena, DstBuf.uTextureSize); DstBuf.uTextureSize = DstBuf.uDecompressedSize; free(uSourceLena); @@ -470,22 +470,22 @@ else { v5 = malloc(DstBuf.uTextureSize); - fread(v5, 1u, Count, v4); + fread(v5, 1, Count, v4); } memcpy(&header1, v5, 0x10u); - memcpy(color_map, (char *)v5 + 16, 0x30u); - memcpy(&header2, (char *)v5 + 64, 6u); + memcpy(color_map, (char *)v5 + 16, 0x30); + memcpy(&header2, (char *)v5 + 64, 6); if ( header1.bpp != 8 ) return 3; v7 = (signed __int16)(header1.right - header1.left + 1); - if ( (signed int)(v7 * (signed __int16)(header1.bottom - header1.up + 1)) <= (signed int)v2->uNumPixels ) + if ( (signed int)(v7 * (signed __int16)(header1.bottom - header1.up + 1)) <= (signed int)this->uNumPixels ) { - v2->uWidth = header1.right - header1.left + 1; - v8 = v2->pPixels; - v9 = v7 * v2->uHeight; - v2->uNumPixels = v9; - v2->uHeight = v9; - v2->DecodePCX((char *)v5, v8, v7); + this->uWidth = header1.right - header1.left + 1; + v8 = this->pPixels; + v9 = v7 * this->uHeight; + this->uNumPixels = v9; + this->uHeight = v9; + this->DecodePCX((char *)v5, v8, v7); free(v5); result = 0; } @@ -1247,10 +1247,6 @@ } } while (x < psx_head2.pitch); - - - - x = 0; do { @@ -1271,10 +1267,6 @@ pRenderer->uTargetBBits - 8)); } } while (x < psx_head2.pitch); - - - - x = 0; do @@ -1304,40 +1296,28 @@ //----- (0040E51F) -------------------------------------------------------- void RGBTexture::Release() { - RGBTexture *v1; // esi@1 - char v2; // zf@1 - void *v3; // [sp-4h] [bp-Ch]@1 - - v1 = this; - v2 = (this->_allocation_flags & 1) == 0; - v3 = this->pPixels; this->pName[0] = 0; - if ( v2 ) - free(v3); - else - free(v3); - v1->_allocation_flags = 0; - v1->pPixels = 0; - v1->uNumPixels = 0; - v1->uHeight = 0; - v1->uWidth = 0; - v1->field_1A = 0; - v1->field_18 = 0; + //if ( !(this->_allocation_flags & 1) ) + //free(this->pPixels); + //else + free(this->pPixels); + this->_allocation_flags = 0; + this->pPixels = 0; + this->uNumPixels = 0; + this->uHeight = 0; + this->uWidth = 0; + this->field_1A = 0; + this->field_18 = 0; } //----- (0040E55E) -------------------------------------------------------- -int RGBTexture::_40E55E(const char *Filename, unsigned int a3) +int RGBTexture::LoadPCXFile(const char *Filename, unsigned int a3) { - RGBTexture *v3; // esi@1 + //RGBTexture *v3; // esi@1 signed int result; // eax@2 char *v6; // eax@3 int v7; // edx@3 char v8; // cl@4 - unsigned __int16 v9; // cx@9 - unsigned __int16 v10; // ax@9 - int v11; // eax@9 - char v12; // zf@9 - void *v13; // eax@12 signed int v14; // ecx@19 signed int v15; // ecx@24 int v16; // eax@57 @@ -1352,11 +1332,19 @@ char v25[48]; // [sp+Ch] [bp-54h]@3 PCXHeader1 pcx_header1; PCXHeader2 pcx_header2; - int v37; // [sp+54h] [bp-Ch]@3 - int v38; // [sp+58h] [bp-8h]@57 + int y; // [sp+54h] [bp-Ch]@3 + int x; // [sp+58h] [bp-8h]@57 FILE *File; // [sp+5Ch] [bp-4h]@1 - v3 = this; + unsigned int num_r_bits = 5; + unsigned int num_g_bits = 6; + unsigned int num_b_bits = 5; + + unsigned int r_mask = 0xF800; + unsigned int g_mask = 0x07E0; + unsigned int b_mask = 0x001F; + + File = fopen(Filename, "rb"); if ( !File ) return 1; @@ -1366,139 +1354,77 @@ fread(&pcx_header2, 4, 1, File); v6 = (char *)Filename; - v37 = 0; - v7 = (char *)v3 - Filename; - do + v7 = (char *)this - Filename; + uint i = 0; + for ( i; i < 15; ++i ) { v8 = *v6; if ( !*v6 ) break; if ( v8 == 46 ) break; - ++v37; (v6++)[v7] = v8; } - while ( v37 < 15 ); - v3->pName[v37] = 0; + this->pName[i] = 0; if ( pcx_header1.bpp != 8 ) return 3; - v9 = pcx_header1.right - pcx_header1.left + 1; - v10 = pcx_header1.bottom - pcx_header1.up; - v3->uWidth = v9; - ++v10; - v3->uHeight = v10; - v11 = (signed __int16)v9 * (signed __int16)v10; - v12 = a3 == 0; - v3->uNumPixels = v11; - if ( v12 ) + this->uWidth = pcx_header1.right - pcx_header1.left + 1; + this->uHeight = pcx_header1.bottom - pcx_header1.up + 1; + this->uNumPixels = (signed __int16)this->uWidth * (signed __int16)this->uHeight; + if ( !a3 ) { - if ( v3->pPixels ) - free(v3->pPixels); - v13 = malloc(2 * v3->uNumPixels + 4); - goto LABEL_16; - } - if ( a3 != 1 && a3 == 2 ) - { - v13 = malloc(4 * v11 + 8); - v3->_allocation_flags |= 1u; -LABEL_16: - v3->pPixels = (unsigned __int16 *)v13; + if ( this->pPixels ) + free(this->pPixels); + //v13 = malloc(2 * this->uNumPixels + 4); + this->pPixels = (unsigned __int16 *)malloc(2 * this->uNumPixels + 4); } - if ( v3->pPixels ) + if ( a3 == 2 ) { - v14 = 1; - while ( 1 << v14 != v3->uWidth ) + //v13 = malloc(4 * this->uNumPixels + 8); + this->_allocation_flags |= 1; + this->pPixels = (unsigned __int16 *)malloc(4 * this->uNumPixels + 8); + } + if ( this->pPixels ) + { + for ( v14 = 1; v14 < 15; ++v14 ) { - ++v14; - if ( v14 >= 15 ) - goto LABEL_24; + if ( 1 << v14 == this->uWidth ) + this->field_18 = v14; } - v3->field_18 = v14; -LABEL_24: - v15 = 1; - while ( 1 << v15 != v3->uHeight ) - { - ++v15; - if ( v15 >= 15 ) - goto LABEL_29; - } - v3->field_1A = v15; -LABEL_29: - switch ( v3->field_18 ) + for ( v15 = 1; v15 < 15; ++v15 ) { - case 2: - v3->field_1C = 3; - break; - case 3: - v3->field_1C = 7; - break; - case 4: - v3->field_1C = 15; - break; - case 5: - v3->field_1C = 31; - break; - case 6: - v3->field_1C = 63; - break; - case 7: - v3->field_1C = 127; - break; - case 8: - v3->field_1C = 255; - break; - case 9: - v3->field_1C = 511; - break; - case 10: - v3->field_1C = 1023; - break; - case 11: - v3->field_1C = 2047; - break; - case 12: - v3->field_1C = 4095; - break; - default: - break; + if ( 1 << v15 == this->uHeight ) + this->field_1A = v15; } - switch ( v3->field_1A ) + switch ( this->field_18 ) { - case 2: - v3->field_1E = 3; - break; - case 3: - v3->field_1E = 7; - break; - case 4: - v3->field_1E = 15; - break; - case 5: - v3->field_1E = 31; - break; - case 6: - v3->field_1E = 63; - break; - case 7: - v3->field_1E = 127; - break; - case 8: - v3->field_1E = 255; - break; - case 9: - v3->field_1E = 511; - break; - case 10: - v3->field_1E = 1023; - break; - case 11: - v3->field_1E = 2047; - break; - case 12: - v3->field_1E = 4095; - break; - default: - break; + case 2: this->field_1C = 3; break; + case 3: this->field_1C = 7; break; + case 4: this->field_1C = 15; break; + case 5: this->field_1C = 31; break; + case 6: this->field_1C = 63; break; + case 7: this->field_1C = 127; break; + case 8: this->field_1C = 255; break; + case 9: this->field_1C = 511; break; + case 10: this->field_1C = 1023; break; + case 11: this->field_1C = 2047; break; + case 12: this->field_1C = 4095; break; + default: break; + } + switch ( this->field_1A ) + { + case 2: this->field_1E = 3; break; + case 3: this->field_1E = 7; break; + case 4: this->field_1E = 15; break; + case 5: this->field_1E = 31; break; + case 6: this->field_1E = 63; break; + case 7: this->field_1E = 127; break; + case 8: this->field_1E = 255; break; + case 9: this->field_1E = 511; break; + case 10: this->field_1E = 1023; break; + case 11: this->field_1E = 2047; break; + case 12: this->field_1E = 4095; break; + default: break; } fseek(File, 128, 0); ftell(File); @@ -1507,117 +1433,96 @@ if ( pcx_header2.planes == 3 ) { - v37 = 0; - if ( v3->uHeight > 0 ) - { - do + //if ( this->uHeight > 0 ) + //{ + for ( y = 0; y < this->uHeight; ++y ) { - v16 = v37 * v3->uWidth; - v17 = v3->pPixels; - v38 = 0; + v16 = y * this->uWidth; + v17 = this->pPixels; v18 = &v17[v16]; - if ( pcx_header2.pitch ) - { - do + //if ( pcx_header2.pitch ) + //{ + for ( x = 0; x < (unsigned __int16)pcx_header2.pitch; ++x ) { - fread((char *)&Filename + 3, 1u, 1u, File); + fread((char *)&Filename + 3, 1, 1, File); if ( (BYTE3(Filename) & 0xC0) == -64 ) { BYTE3(Filename) &= 0x3Fu; - fread((char *)&a3 + 3, 1u, 1u, File); - v19 = 0; + fread((char *)&a3 + 3, 1, 1, File); + if ( BYTE3(Filename) ) { - do + for ( v19 = 0; v19 < BYTE3(Filename); ++v19 ) { - ++v38; - *v18 = LOWORD(pRenderer->uTargetRMask) & (BYTE3(a3) << (LOBYTE(pRenderer->uTargetGBits) - + LOBYTE(pRenderer->uTargetRBits) - + LOBYTE(pRenderer->uTargetBBits) - - 8)); + *v18 = r_mask & (BYTE3(a3) << (num_r_bits + num_g_bits + num_b_bits - 8)); ++v18; - ++v19; } - while ( v19 < BYTE3(Filename) ); } } else { - ++v38; - *v18 = LOWORD(pRenderer->uTargetRMask) & (BYTE3(Filename) << (LOBYTE(pRenderer->uTargetGBits) - + LOBYTE(pRenderer->uTargetRBits) - + LOBYTE(pRenderer->uTargetBBits) - - 8)); + *v18 = r_mask & (BYTE3(Filename) << (num_g_bits + num_r_bits + num_b_bits - 8)); ++v18; } } - while ( v38 < (unsigned __int16)pcx_header2.pitch); - } - v20 = &v3->pPixels[v37 * v3->uWidth]; - while ( v38 < 2 * (unsigned __int16)pcx_header2.pitch ) + //while ( v38 < (unsigned __int16)pcx_header2.pitch); + //} + v20 = &this->pPixels[y * this->uWidth]; + while ( x < 2 * (unsigned __int16)pcx_header2.pitch ) { - fread((char *)&Filename + 3, 1u, 1u, File); + fread((char *)&Filename + 3, 1, 1, File); if ( (BYTE3(Filename) & 0xC0) == -64 ) { BYTE3(Filename) &= 0x3Fu; - fread((char *)&a3 + 3, 1u, 1u, File); - v21 = 0; + fread((char *)&a3 + 3, 1, 1, File); + if ( BYTE3(Filename) ) { - do + for ( v21 = 0; v21 < BYTE3(Filename); ++v21 ) { - *v20 |= pRenderer->uTargetGMask & (unsigned __int16)(BYTE3(a3) << (LOBYTE(pRenderer->uTargetGBits) - + LOBYTE(pRenderer->uTargetBBits) - - 8)); - ++v38; + *v20 |= g_mask & (unsigned __int16)(BYTE3(a3) << (num_g_bits + num_b_bits - 8)); + //++v38; ++v20; - ++v21; } - while ( v21 < BYTE3(Filename) ); } } else { - *v20 |= pRenderer->uTargetGMask & (unsigned __int16)(BYTE3(Filename) << (LOBYTE(pRenderer->uTargetGBits) - + LOBYTE(pRenderer->uTargetBBits) - - 8)); - ++v38; + *v20 |= g_mask & (unsigned __int16)(BYTE3(Filename) << (num_g_bits + num_b_bits - 8)); + //++v38; ++v20; } } - v22 = &v3->pPixels[v37 * v3->uWidth]; - while ( v38 < 3 * (unsigned __int16)pcx_header2.pitch ) + v22 = &this->pPixels[y * this->uWidth]; + while ( x < 3 * (unsigned __int16)pcx_header2.pitch ) { - fread((char *)&Filename + 3, 1u, 1u, File); + fread((char *)&Filename + 3, 1, 1, File); if ( (BYTE3(Filename) & 0xC0) == -64 ) { BYTE3(Filename) &= 0x3Fu; - fread((char *)&a3 + 3, 1u, 1u, File); - v23 = 0; + fread((char *)&a3 + 3, 1, 1, File); if ( BYTE3(Filename) ) { - do + for ( v23 = 0; v23 < BYTE3(Filename); ++v23 ) { - *v22 |= BYTE3(a3) >> (8 - LOBYTE(pRenderer->uTargetBBits)); - ++v38; + *v22 |= BYTE3(a3) >> (8 - num_b_bits); + //++v38; ++v22; - ++v23; } - while ( v23 < BYTE3(Filename) ); } } else { - *v22 |= BYTE3(Filename) >> (8 - LOBYTE(pRenderer->uTargetBBits)); - ++v38; + *v22 |= BYTE3(Filename) >> (8 - num_b_bits); + //++v38; ++v22; } } - v24 = v3->uHeight; - ++v37; + //v24 = this->uHeight; + //++v37; } - while ( v37 < v24 ); - } + //while ( v37 < v24 ); + //} } fclose(File); result = 0;
--- a/Texture.h Fri Dec 27 17:52:31 2013 +0600 +++ b/Texture.h Sat Dec 28 13:12:52 2013 +0600 @@ -10,7 +10,7 @@ { RGBTexture(); void Release(); - int _40E55E(const char *Filename, unsigned int a3); + int LoadPCXFile(const char *Filename, unsigned int a3); unsigned int LoadFromFILE(FILE *pFile, unsigned int mode, unsigned int bCloseFile); int DecodePCX(char *pPcx, unsigned __int16 *pOutPixels, unsigned int uNumPixels); int Load(const char *pContainer, int mode);