diff Texture.cpp @ 2131:651b24553ae9

savegame screenshot fix
author Ritor1
date Sat, 28 Dec 2013 16:49:21 +0600
parents 23dbcaa651cc
children d44b7775fc06
line wrap: on
line diff
--- a/Texture.cpp	Sat Dec 28 13:13:54 2013 +0600
+++ b/Texture.cpp	Sat Dec 28 16:49:21 2013 +0600
@@ -1128,6 +1128,14 @@
 	short int width, height;
 	BYTE  color_map[48];	// Colormap for 16-color images
 
+  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;
+
   if (!pFile)
     return 1;
   
@@ -1163,9 +1171,6 @@
         }
       }
 
-
-
-
       ushort* pOutPixels = pPixels;
  
  memset(pOutPixels, 0, uNumPixels * sizeof(__int16));
@@ -1216,7 +1221,6 @@
   case 12:  field_1E = 4095; break;
 	  }
 
-
   fseek(pFile, 128 - 70, SEEK_CUR);
 
 
@@ -1235,15 +1239,11 @@
         uint clr = 0;
         fread(&clr, 1, 1, pFile);
         for (uint i = 0; i < uNumPixels; ++i)
-          pDst[x++] = pRenderer->uTargetRMask & (clr << (pRenderer->uTargetGBits +
-                                                         pRenderer->uTargetRBits +
-                                                         pRenderer->uTargetBBits - 8));
+          pDst[x++] = r_mask & (clr << (num_g_bits + num_r_bits + num_b_bits - 8));
       }
       else
       {
-        pDst[x++] = pRenderer->uTargetRMask & (ctrl << (pRenderer->uTargetGBits +
-                                                        pRenderer->uTargetRBits +
-                                                        pRenderer->uTargetBBits - 8));
+        pDst[x++] = r_mask & (ctrl << (num_g_bits + num_r_bits + num_b_bits - 8));
       }
     } while (x < psx_head2.pitch);
 
@@ -1258,13 +1258,11 @@
         uint clr = 0;
         fread(&clr, 1, 1, pFile);
         for (uint i = 0; i < uNumPixels; ++i)
-          pDst[x++] |= pRenderer->uTargetGMask & (clr << (pRenderer->uTargetGBits +
-                                                         pRenderer->uTargetBBits - 8));
+          pDst[x++] |= g_mask & (clr << (num_g_bits + num_b_bits - 8));
       }
       else
       {
-        pDst[x++] |= pRenderer->uTargetGMask & (ctrl << (pRenderer->uTargetGBits +
-                                                        pRenderer->uTargetBBits - 8));
+        pDst[x++] |= g_mask & (ctrl << (num_g_bits + num_b_bits - 8));
       }
     } while (x < psx_head2.pitch);
 
@@ -1279,11 +1277,11 @@
         uint clr = 0;
         fread(&clr, 1, 1, pFile);
         for (uint i = 0; i < uNumPixels; ++i)
-          pDst[x++] |= pRenderer->uTargetBMask & (clr >> (8 - pRenderer->uTargetBBits));
+          pDst[x++] |= b_mask & (clr >> (8 - num_b_bits));
       }
       else
       {
-        pDst[x++] |= pRenderer->uTargetBMask & (ctrl >> (8 - pRenderer->uTargetRBits));
+        pDst[x++] |= b_mask & (ctrl >> (8 - num_b_bits));
       }
     } while (x < psx_head2.pitch);
   }
@@ -1313,7 +1311,6 @@
 //----- (0040E55E) --------------------------------------------------------
 int RGBTexture::LoadPCXFile(const char *Filename, unsigned int a3)
 {
-  //RGBTexture *v3; // esi@1
   signed int result; // eax@2
   char *v6; // eax@3
   int v7; // edx@3
@@ -1323,7 +1320,7 @@
   int v16; // eax@57
   unsigned __int16 *v17; // ecx@57
   unsigned __int16 *v18; // edi@57
-  signed int v19; // eax@59
+  signed int x; // eax@59
   unsigned __int16 *v20; // edi@64
   signed int v21; // eax@66
   unsigned __int16 *v22; // edi@71
@@ -1333,7 +1330,6 @@
   PCXHeader1 pcx_header1;
   PCXHeader2 pcx_header2;
   int y; // [sp+54h] [bp-Ch]@3
-  int x; // [sp+58h] [bp-8h]@57
   FILE *File; // [sp+5Ch] [bp-4h]@1
 
   unsigned int num_r_bits = 5;
@@ -1375,14 +1371,12 @@
   {
     if ( this->pPixels )
       free(this->pPixels);
-    //v13 = malloc(2 * this->uNumPixels + 4);
     this->pPixels = (unsigned __int16 *)malloc(2 * this->uNumPixels + 4);
   }
   if ( a3 == 2 )
   {
-    //v13 = malloc(4 * this->uNumPixels + 8);
     this->_allocation_flags |= 1;
-    this->pPixels = (unsigned __int16 *)malloc(4 * this->uNumPixels + 8);
+    this->pPixels = (unsigned __int16 *)malloc((uNumPixels + 2) * sizeof(unsigned __int16));
   }
   if ( this->pPixels )
   {
@@ -1428,101 +1422,70 @@
     }
     fseek(File, 128, 0);
     ftell(File);
-	if ( pcx_header2.planes == 1 )
+    if ( pcx_header2.planes == 1 )
       Error("24bit PCX Only!");
 
     if ( pcx_header2.planes == 3 )
     {
-      //if ( this->uHeight > 0 )
-      //{
-        for ( y = 0; y < this->uHeight; ++y )
+      for ( y = 0; y < this->uHeight; ++y )
+      {
+        unsigned __int16 *pDst = pPixels + y * uWidth;
+        uint x = 0;
+        do
         {
-          v16 = y * this->uWidth;
-          v17 = this->pPixels;
-          v18 = &v17[v16];
-		  //if ( pcx_header2.pitch )
-          //{
-            for ( x = 0; x < (unsigned __int16)pcx_header2.pitch; ++x )
-            {
-              fread((char *)&Filename + 3, 1, 1, File);
-              if ( (BYTE3(Filename) & 0xC0) == -64 )
-              {
-                BYTE3(Filename) &= 0x3Fu;
-                fread((char *)&a3 + 3, 1, 1, File);
-                
-                if ( BYTE3(Filename) )
-                {
-                  for ( v19 = 0; v19 < BYTE3(Filename); ++v19 )
-                  {
-                    *v18 = r_mask & (BYTE3(a3) << (num_r_bits + num_g_bits + num_b_bits - 8));
-                    ++v18;
-                  }
-                }
-              }
-              else
-              {
-                *v18 = r_mask & (BYTE3(Filename) << (num_g_bits + num_r_bits + num_b_bits - 8));
-                ++v18;
-              }
-            }
-			//while ( v38 < (unsigned __int16)pcx_header2.pitch);
-          //}
-          v20 = &this->pPixels[y * this->uWidth];
-		  while ( x < 2 * (unsigned __int16)pcx_header2.pitch )
+          uint ctrl = 0;
+          fread(&ctrl, 1, 1, File);
+          if ( (ctrl & 0xC0) == 0xC0 )
+          {
+            uint uNumPixels = ctrl & 0x3F;
+            uint clr = 0;
+            ctrl &= 0x3F;
+            fread(&clr, 1, 1, File);
+            for ( uint i = 0; i < uNumPixels; ++i )
+              pDst[x++] = r_mask & (clr << (num_r_bits + num_g_bits + num_b_bits - 8));
+          }
+          else
+            pDst[x++] = r_mask & (ctrl << (num_g_bits + num_r_bits + num_b_bits - 8));
+        }
+        while ( x < pcx_header2.pitch );
+
+        x = 0;
+        do
+        {
+          uint ctrl = 0;
+          fread(&ctrl, 1, 1, File);
+          if ( (ctrl & 0xC0) == 0xC0 )
           {
-            fread((char *)&Filename + 3, 1, 1, File);
-            if ( (BYTE3(Filename) & 0xC0) == -64 )
-            {
-              BYTE3(Filename) &= 0x3Fu;
-              fread((char *)&a3 + 3, 1, 1, File);
-              
-              if ( BYTE3(Filename) )
-              {
-                for ( v21 = 0; v21 < BYTE3(Filename); ++v21 )
-                {
-                  *v20 |= g_mask & (unsigned __int16)(BYTE3(a3) << (num_g_bits + num_b_bits - 8));
-                  //++v38;
-                  ++v20;
-                }
-              }
-            }
-            else
-            {
-              *v20 |= g_mask & (unsigned __int16)(BYTE3(Filename) << (num_g_bits + num_b_bits - 8));
-              //++v38;
-              ++v20;
-            }
+            uint uNumPixels = ctrl & 0x3F;
+            uint clr = 0;
+            ctrl &= 0x3F;
+            fread(&clr, 1, 1, File);
+            for ( uint i = 0; i < uNumPixels; ++i )
+              pDst[x++] |= g_mask & (clr << (num_g_bits + num_b_bits - 8));
           }
-          v22 = &this->pPixels[y * this->uWidth];
-		  while ( x < 3 * (unsigned __int16)pcx_header2.pitch )
+          else
+            pDst[x++] |= g_mask & (ctrl << (num_g_bits + num_b_bits - 8));
+        }
+        while (x < pcx_header2.pitch);
+
+        x = 0;
+        do
+        {
+          uint ctrl = 0;
+          fread(&ctrl, 1, 1, File);
+          if ( (ctrl & 0xC0) == 0xC0 )
           {
-            fread((char *)&Filename + 3, 1, 1, File);
-            if ( (BYTE3(Filename) & 0xC0) == -64 )
-            {
-              BYTE3(Filename) &= 0x3Fu;
-              fread((char *)&a3 + 3, 1, 1, File);
-              if ( BYTE3(Filename) )
-              {
-                for ( v23 = 0; v23 < BYTE3(Filename); ++v23 )
-                {
-                  *v22 |= BYTE3(a3) >> (8 - num_b_bits);
-                  //++v38;
-                  ++v22;
-                }
-              }
-            }
-            else
-            {
-              *v22 |= BYTE3(Filename) >> (8 - num_b_bits);
-              //++v38;
-              ++v22;
-            }
+            uint uNumPixels = ctrl & 0x3F;
+            uint clr = 0;
+            fread(&clr, 1, 1, File);
+            for ( uint i = 0; i < uNumPixels; ++i )
+              pDst[x++] |= b_mask & (clr >> (8 - num_b_bits));
           }
-          //v24 = this->uHeight;
-          //++v37;
+          else
+            pDst[x++] |= b_mask & (ctrl >> (8 - num_b_bits));
         }
-        //while ( v37 < v24 );
-      //}
+        while (x < pcx_header2.pitch);
+      }
     }
     fclose(File);
     result = 0;
@@ -1534,7 +1497,6 @@
   return result;
 }
 
-
 //----- (0040D73D) --------------------------------------------------------
 RGBTexture::RGBTexture()
 {