diff Render.cpp @ 2132:49de109bbab5

SavePCXScreenshot() continue
author Ritor1
date Sun, 29 Dec 2013 01:26:15 +0600
parents 651b24553ae9
children e378232bfd36
line wrap: on
line diff
--- a/Render.cpp	Sat Dec 28 16:49:21 2013 +0600
+++ b/Render.cpp	Sun Dec 29 01:26:15 2013 +0600
@@ -2193,84 +2193,74 @@
 //----- (0049EDB6) --------------------------------------------------------
 void Render::SavePCXScreenshot()
 {
-  Render *v1; // esi@1
-  __int16 v2; // di@1
-  int v3; // eax@4
-  int v4; // ecx@4
   int v5; // eax@8
-  FILE *v6; // edi@10
-  int v7; // ecx@11
-  int v8; // eax@11
+  FILE *pOutFile; // edi@10
+  unsigned short * v8; // eax@11
   int v9; // eax@13
   int v10; // ecx@15
-  unsigned __int8 v11; // dl@15
   signed int v12; // eax@18
-  char v13; // zf@27
   HRESULT v14; // eax@29
   char v15[56]; // [sp+Ch] [bp-158h]@10
-  __int16 v16; // [sp+44h] [bp-120h]@10
   DDSURFACEDESC2 Dst; // [sp+48h] [bp-11Ch]@7
   char color_map[48]; // [sp+C4h] [bp-A0h]@10
   char Filename[40]; // [sp+F4h] [bp-70h]@3
-  char *v20; // [sp+11Ch] [bp-48h]@14
-  char *v21; // [sp+120h] [bp-44h]@14
-  int v24; // [sp+124h] [bp-40h]@11
+  char *lineB; // [sp+11Ch] [bp-48h]@14
+  char *lineG; // [sp+120h] [bp-44h]@14
+  //int v24; // [sp+124h] [bp-40h]@11
   FILE *File; // [sp+128h] [bp-3Ch]@3
-  int var38; // [sp+12Ch] [bp-38h]@4
   PCXHeader_1 header1; // [sp+130h] [bp-34h]@10
   PCXHeader_2 header2; // [sp+140h] [bp-24h]@10
-  void *ptr; // [sp+148h] [bp-1Ch]@10
-  void *v28; // [sp+14Ch] [bp-18h]@8
-  int v29; // [sp+150h] [bp-14h]@4
-  int v30; // [sp+154h] [bp-10h]@4
+  char *lineRGB; // [sp+148h] [bp-1Ch]@10
+  void *surface; // [sp+14Ch] [bp-18h]@8
+  int image_width; // [sp+150h] [bp-14h]@4
+  int pitch; // [sp+154h] [bp-10h]@4
   char v31; // [sp+15Ah] [bp-Ah]@25
-  unsigned __int8 v32; // [sp+15Bh] [bp-9h]@17
-  int i; // [sp+15Ch] [bp-8h]@10
-  unsigned __int8 v34; // [sp+163h] [bp-1h]@17
-
-  v1 = this;
-  v2 = 0;
+  unsigned char pict_byte; // [sp+15Bh] [bp-9h]@17
+  unsigned short *line_picture_data; // [sp+15Ch] [bp-8h]@10
+  byte test_byte; // [sp+163h] [bp-1h]@17
+
+  int num_r_bits = 5;
+  int num_g_bits = 6;
+  int num_b_bits = 5;
+
+  int r_mask = 0xF800;
+  int g_mask = 0x7E0;
+  int b_mask = 0x1F;
+
   if ( !this->pRenderD3D || this->using_software_screen_buffer )
   {
-    sprintf(Filename, "screen%0.2i.pcx", dword_4EFA80++ % 100);
+    sprintf(Filename, "screen%0.2i.pcx", ScreenshotFileNumber++ % 100);
     File = fopen(Filename, "wb");
     if ( File )
     {
-      v3 = v1->field_10;
-      v4 = v1->field_14;
-      var38 = v3;
-      v29 = v4;
-      v30 = v3;
-      if ( v3 & 1 )
-        v30 = v3 + 1;
-      if ( v1->pRenderD3D )
-      {
-        memset(&Dst, 0, 0x7Cu);
+      pitch = this->field_10;
+      if ( this->field_10 & 1 )
+        pitch = this->field_10 + 1;
+      if ( this->pRenderD3D )
+      {
+        memset(&Dst, 0, 0x7C);
         Dst.dwSize = 124;
         if ( !pRenderer->LockSurface_DDraw4(pRenderer->pBackBuffer4, &Dst, DDLOCK_WAIT) )
           return;
-        v28 = Dst.lpSurface;
-        v5 = Dst.lPitch >> 1;
-        v2 = 0;
+        surface = Dst.lpSurface;
+        v5 = Dst.lPitch / 2;
       }
       else
       {
         pRenderer->BeginScene();
-        v28 = pRenderer->pTargetSurface;
+        surface = pRenderer->pTargetSurface;
         v5 = pRenderer->uTargetSurfacePitch;
       }
-      i = v5;
-      header1.right = var38 - 1;
-      header1.left = v2;
-      header1.bottom = v29 - 1;
-      header1.up = v2;
-      header2.pitch = v30;
+      header1.right = this->field_10 - 1;
+      header1.left = 0;
+      header1.bottom = this->field_14 - 1;
+      header1.up = 0;
+      header2.pitch = pitch;
       memset(color_map, 0, sizeof(color_map));
       memset(v15, 0, sizeof(v15));
       header2.reserved = 0;
       header1.manufacturer = 10;
-      v16 = 0;
-      v6 = File;
+      pOutFile = File;
       header1.version = 5;
       header1.encoding = 1;
       header1.bpp = 8;
@@ -2278,97 +2268,73 @@
       header1.vdpi = 75;
       header2.planes = 3;
       header2.palette_info = 1;
-      fwrite(&header1, 1u, 1u, File);
-      fwrite(&header1.version, 1u, 1u, v6);
-      fwrite(&header1.encoding, 1u, 1u, v6);
-      fwrite(&header1.bpp, 1u, 1u, v6);
-      fwrite(&header1.left, 2u, 1u, v6);
-      fwrite(&header1.up, 2u, 1u, v6);
-      fwrite(&header1.right, 2u, 1u, v6);
-      fwrite(&header1.bottom, 2u, 1u, v6);
-      fwrite(&header1.hdpi, 2u, 1u, v6);
-      fwrite(&header1.vdpi, 2u, 1u, v6);
-      fwrite(color_map, 0x30u, 1u, v6);
-      fwrite(&header2, 1u, 1u, v6);
-      fwrite(&header2.planes, 1u, 1u, v6);
-      fwrite(&header2.pitch, 2u, 1u, v6);
-      fwrite(&header2.palette_info, 2u, 1u, v6);
-      fwrite(v15, 0x3Au, 1u, v6);
-      ptr = malloc(3 * var38 + 6);
-      if ( v29 > 0 )
-      {
-        v7 = v30;
-        File = (FILE *)v29;
-        v29 = 3 * v30;
-        v24 = 2 * i;
-        v8 = (int)v28;
-        while ( 1 )
+      fwrite(&header1, 1, 1, File);
+      fwrite(&header1.version, 1, 1, pOutFile);
+      fwrite(&header1.encoding, 1, 1, pOutFile);
+      fwrite(&header1.bpp, 1, 1, pOutFile);
+      fwrite(&header1.left, 2, 1, pOutFile);
+      fwrite(&header1.up, 2, 1, pOutFile);
+      fwrite(&header1.right, 2, 1, pOutFile);
+      fwrite(&header1.bottom, 2, 1, pOutFile);
+      fwrite(&header1.hdpi, 2, 1, pOutFile);
+      fwrite(&header1.vdpi, 2, 1, pOutFile);
+      fwrite(color_map, 0x30u, 1, pOutFile);
+      fwrite(&header2, 1, 1, pOutFile);
+      fwrite(&header2.planes, 1, 1, pOutFile);
+      fwrite(&header2.pitch, 2, 1, pOutFile);
+      fwrite(&header2.palette_info, 2, 1, pOutFile);
+      fwrite(v15, 0x3Au, 1, pOutFile);
+      lineRGB = (char *)malloc(3 * this->field_10 + 6);
+      if ( this->field_14 > 0 )
+      {
+        image_width = 3 * pitch;
+        //v24 = 2 * v5;
+        v8 = (unsigned short *)surface;
+        for ( int y = 0; y < this->field_14; y++ )
         {
-          i = v8;
-          v9 = 0;
-          if ( var38 > 0 )
+          line_picture_data = v8;
+          if ( this->field_10 > 0 )
           {
-            v21 = (char *)ptr + v7;
-            v20 = (char *)ptr + 2 * v30;
-            do
+            lineG = (char *)lineRGB + pitch;
+            lineB = (char *)lineRGB + 2 * pitch;
+            for ( uint x = 0; x < this->field_10; x++ )
             {
-              *((char *)ptr + v9) = (signed int)(v1->uTargetRMask & *(short *)i) >> (LOBYTE(v1->uTargetGBits)
-                                                                                    + LOBYTE(v1->uTargetBBits)
-                                                                                    + v1->uTargetRBits
-                                                                                    - 8);
-              v21[v9] = (signed int)(v1->uTargetGMask & *(short *)i) >> (LOBYTE(v1->uTargetBBits)
-                                                                       + LOBYTE(v1->uTargetGBits)
-                                                                       - 8);
-              v10 = i;
-              v11 = LOBYTE(v1->uTargetBMask);
-              i += 2;
-              v20[v9++] = (*(char *)v10 & v11) << (8 - LOBYTE(v1->uTargetBBits));
+              lineRGB[x] = (signed int)(r_mask & *line_picture_data) >> (num_g_bits + num_b_bits + num_r_bits - 8);
+              lineG[x] = (signed int)(g_mask & *line_picture_data) >> (num_b_bits + num_g_bits - 8);
+              lineB[x] = (b_mask & *line_picture_data) << (8 - num_b_bits);
+              line_picture_data += 2;
             }
-            while ( v9 < var38 );
           }
-          for ( i = 0; i < v29; i += v34 )
+          for ( uint i = 0; i < image_width; i += test_byte )
           {
-            v34 = 1;
-            v32 = *((char *)ptr + i);
-            do
+            pict_byte = lineRGB[i];
+            for ( test_byte = 1; test_byte < 0x3F; ++test_byte )
             {
-              v12 = i + v34;
-              if ( *((char *)ptr + v12) != v32 )
+              v12 = i + test_byte;
+              if ( lineRGB[v12] != pict_byte )
                 break;
-              if ( !(v12 % v30) )
+              if ( !(v12 % pitch) )
                 break;
-              ++v34;
-            }
-            while ( v34 < 0x3Fu );
-            if ( i + v34 > v29 )
-              v34 = 3 * v30 - i;
-            if ( v34 > 1u || v32 >= 0xC0u )
-            {
-              v31 = v34 | 0xC0;
-              fwrite(&v31, 1u, 1u, v6);
             }
-            fwrite(&v32, 1u, 1u, v6);
+            if ( i + test_byte > image_width )
+              test_byte = 3 * pitch - i;
+            if ( test_byte > 1 || pict_byte >= 0xC0 )
+            {
+              v31 = test_byte | 0xC0;
+              fwrite(&v31, 1, 1, pOutFile);
+            }
+            fwrite(&pict_byte, 1, 1, pOutFile);
           }
-          v8 = (int)((char *)v28 + v24);
-          v13 = File == (FILE *)1;
-          File = (FILE *)((char *)File - 1);
-          v28 = (char *)v28 + v24;
-          if ( v13 )
-            break;
-          v7 = v30;
+          v8 += v5;
         }
       }
-      if ( v1->pRenderD3D )
-      {
+      if ( this->pRenderD3D )
         ErrD3D(pRenderer->pBackBuffer4->Unlock(0));
-      }
       else
-      {
         pRenderer->EndScene();
-      }
-
-      free(ptr);
-      fclose(v6);
+
+      free(lineRGB);
+      fclose(pOutFile);
     }
   }
 }
@@ -2595,7 +2561,7 @@
   int pitch; // [sp+ACh] [bp-Ch]@1
   char v43; // [sp+B3h] [bp-5h]@18
   int i; // [sp+B4h] [bp-4h]@6
-  unsigned short* line_pictute_data;
+  unsigned short* line_picture_data;
   byte test_byte;
   unsigned char pict_byte;
 
@@ -2670,17 +2636,17 @@
     v24 = (int)picture_data;
     for ( v25 = heidth; v25; v25-- )
     {
-      line_pictute_data = v11;
+      line_picture_data = v11;
       if ( wight > 0 )
       {
         lineG = (char *)lineRGB + pitch;
         lineB = (char *)lineRGB + 2 * pitch;
         for ( uint i = 0; i < wight; i++ )
         {
-          lineRGB[i] = (signed int)(r_mask & *line_pictute_data) >> (num_g_bits  + num_b_bits  + num_r_bits  - 8);
-          lineG[i] = (signed int)(g_mask & *line_pictute_data) >> ( num_b_bits + num_g_bits- 8);
-          lineB[i] = (b_mask & *line_pictute_data) << (8 - num_b_bits);
-          line_pictute_data += 1;
+          lineRGB[i] = (signed int)(r_mask & *line_picture_data) >> (num_g_bits  + num_b_bits  + num_r_bits  - 8);
+          lineG[i] = (signed int)(g_mask & *line_picture_data) >> ( num_b_bits + num_g_bits- 8);
+          lineB[i] = (b_mask & *line_picture_data) << (8 - num_b_bits);
+          line_picture_data += 1;
         }
       }
       for ( i = 0; i < v26; v9 = (char *)v9 + 1 )
@@ -3777,7 +3743,6 @@
 //----- (004A0EB6) --------------------------------------------------------
 void Render::ParseTargetPixelFormat()
 {
-  Render *v1; // eax@1
   signed int v2; // ecx@1
   DWORD uRedMask; // edx@1
   unsigned int uGreenMask; // esi@5
@@ -3786,58 +3751,57 @@
   signed int v7; // ecx@9
   //unsigned int v8; // ecx@13
 
-  v1 = this;
   v2 = 0;
-  uRedMask = v1->ddpfPrimarySuface.dwRBitMask;
-  v1->uTargetBBits = 0;
-  v1->uTargetGBits = 0;
-  v1->uTargetRBits = 0;
+  uRedMask = this->ddpfPrimarySuface.dwRBitMask;
+  this->uTargetBBits = 0;
+  this->uTargetGBits = 0;
+  this->uTargetRBits = 0;
   do
   {
     if ( (1 << v2) & uRedMask )
-      ++v1->uTargetRBits;
+      ++this->uTargetRBits;
     ++v2;
   }
   while ( v2 < 32 );
-  uGreenMask = v1->ddpfPrimarySuface.dwGBitMask;
+  uGreenMask = this->ddpfPrimarySuface.dwGBitMask;
   v5 = 0;
   do
   {
     if ( (1 << v5) & uGreenMask )
-      ++v1->uTargetGBits;
+      ++this->uTargetGBits;
     ++v5;
   }
   while ( v5 < 32 );
-  uBlueMask = v1->ddpfPrimarySuface.dwBBitMask;
+  uBlueMask = this->ddpfPrimarySuface.dwBBitMask;
   v7 = 0;
   do
   {
     if ( (1 << v7) & uBlueMask )
-      ++v1->uTargetBBits;
+      ++this->uTargetBBits;
     ++v7;
   }
   while ( v7 < 32 );
-  v1->uTargetGMask = uGreenMask;
-  v1->uTargetRMask = v1->ddpfPrimarySuface.dwRBitMask;
-  v1->uTargetBMask = uBlueMask;
+  this->uTargetGMask = uGreenMask;
+  this->uTargetRMask = this->ddpfPrimarySuface.dwRBitMask;
+  this->uTargetBMask = uBlueMask;
 }
 
 //----- (004A0F40) --------------------------------------------------------
 bool Render::LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags)
 {
-  IDirectDrawSurface4 *v4; // esi@1
+  //IDirectDrawSurface4 *v4; // esi@1
   HRESULT result; // eax@1
   HRESULT v6; // eax@4
   int v7; // [sp-8h] [bp-14h]@10
   unsigned int v8; // [sp-4h] [bp-10h]@10
   char v9; // [sp+Bh] [bp-1h]@1
 
-  v4 = pSurface;
+  //v4 = pSurface;
   v9 = 1;
   result = pSurface->Lock(0, pDesc, uLockFlags, 0);
   if ( result == DDERR_SURFACELOST )
   {
-    v6 = v4->Restore();
+    v6 = pSurface->Restore();
     if ( v6 )
     {
       if ( v6 != DDERR_IMPLICITLYCREATED )
@@ -3848,9 +3812,9 @@
         goto LABEL_21;
       }
       pRenderer->pFrontBuffer4->Restore();
-      v4->Restore();
-    }
-    result = v4->Lock(0, pDesc, DDLOCK_WAIT, 0);
+      pSurface->Restore();
+    }
+    result = pSurface->Lock(0, pDesc, DDLOCK_WAIT, 0);
     if ( result == DDERR_INVALIDRECT || result == DDERR_SURFACEBUSY )
       goto LABEL_20;
     ErrD3D(result);
@@ -4191,17 +4155,15 @@
 //----- (004A1605) --------------------------------------------------------
 void Render::LockRenderSurface(void **pOutSurfacePtr, unsigned int *pOutPixelsPerRow)
 {
-  Render *v3; // esi@1
   signed int v4; // eax@3
 
-  v3 = this;
   if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
       pVersion->pVersionInfo.dwMajorVersion != 4 )
   {
   DDSURFACEDESC2 pDesc; // [sp+4h] [bp-7Ch]@3
     memset(&pDesc, 0, 0x7Cu);
     pDesc.dwSize = 124;
-    LockSurface_DDraw4(v3->pBackBuffer4, &pDesc, DDLOCK_WAIT);
+    LockSurface_DDraw4(this->pBackBuffer4, &pDesc, DDLOCK_WAIT);
     *pOutSurfacePtr = pDesc.lpSurface;
     v4 = pDesc.lPitch;
   }
@@ -4210,7 +4172,7 @@
   DDSURFACEDESC pDesc; // [sp+4h] [bp-7Ch]@3
     memset(&pDesc.lPitch, 0, 0x6Cu);
     pDesc.lPitch = 108;
-    LockSurface_DDraw2(v3->pBackBuffer2, &pDesc, 1u);
+    LockSurface_DDraw2(this->pBackBuffer2, &pDesc, 1);
     *pOutSurfacePtr = (void *)pDesc.lpSurface;
     v4 = pDesc.dwReserved;
   }
@@ -4230,16 +4192,14 @@
 //----- (004A172E) --------------------------------------------------------
 void Render::LockFrontBuffer(void **pOutSurface, unsigned int *pOutPixelsPerRow)
 {
-  Render *v3; // esi@1
   signed int v4; // eax@3
 
-  v3 = this;
   if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
   {
   DDSURFACEDESC2 pDesc; // [sp+4h] [bp-7Ch]@3
     memset(&pDesc, 0, 0x7Cu);
     pDesc.dwSize = 124;
-    LockSurface_DDraw4(v3->pFrontBuffer4, &pDesc, DDLOCK_WAIT);
+    LockSurface_DDraw4(this->pFrontBuffer4, &pDesc, DDLOCK_WAIT);
     *pOutSurface = pDesc.lpSurface;
     v4 = pDesc.lPitch;
   }
@@ -4248,7 +4208,7 @@
   DDSURFACEDESC pDesc; // [sp+4h] [bp-7Ch]@3
     memset(&pDesc.lPitch, 0, 0x6Cu);
     pDesc.lPitch = 108;
-    LockSurface_DDraw2(v3->pFrontBuffer2, &pDesc, 1u);
+    LockSurface_DDraw2(this->pFrontBuffer2, &pDesc, 1);
     *pOutSurface = (void *)pDesc.lpSurface;
     v4 = pDesc.dwReserved;
   }