changeset 1148:ee6bccef32e8

sub_451007_scale_image_bicubic cleanup - final condition collapsing, remaining labels removed, etc
author Grumpy7
date Sun, 02 Jun 2013 05:01:51 +0200
parents 9ba9fd8e6d68
children 05b30ed00d7c
files mm7_2.cpp
diffstat 1 files changed, 98 insertions(+), 207 deletions(-) [+]
line wrap: on
line diff
--- a/mm7_2.cpp	Sun Jun 02 03:59:13 2013 +0200
+++ b/mm7_2.cpp	Sun Jun 02 05:01:51 2013 +0200
@@ -2163,7 +2163,7 @@
 }
 
 //----- (00451007) --------------------------------------------------------
-int stru350::sub_451007_scale_image_bicubic(unsigned short *pSrc, int srcWidth, int srcHeight, int srcPitch,
+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
                                             unsigned short *pDst, int dstWidth, int dstHeight, int dstPitch,
                                             int a10, int a11)
 {
@@ -2175,234 +2175,125 @@
   int v21; // eax@18
   unsigned int v22; // ecx@25
   unsigned int v23; // eax@29
-  int v112; // ecx@216
-  float v115; // ST34_4@218
-  float v116; // ST30_4@218
-  unsigned int v117; // esi@218
-  signed int v118; // eax@220
-  int v119; // eax@221
-  int v120; // eax@223
-  unsigned int v121; // ecx@231
-  char v122; // al@235
   unsigned int heightRatioPlusOne; // [sp+Ch] [bp-7Ch]@12
   unsigned int widthRatio; // [sp+Ch] [bp-7Ch]@218
   unsigned int heightRatio; // [sp+14h] [bp-74h]@12
   unsigned int widthRatioPlusOne; // [sp+14h] [bp-74h]@218
   int v160; // [sp+3Ch] [bp-4Ch]@13
-  int v161; // [sp+40h] [bp-48h]@15
-  int v169; // [sp+44h] [bp-44h]@219
   unsigned __int16 *v175; // [sp+4Ch] [bp-3Ch]@13
-  int *v176; // [sp+50h] [bp-38h]@15
-  char *v184; // [sp+50h] [bp-38h]@219
   unsigned __int16 *v193; // [sp+5Ch] [bp-2Ch]@7
-  unsigned __int16 *v201; // [sp+5Ch] [bp-2Ch]@213
   signed int v231; // [sp+78h] [bp-10h]@7
-  signed int v239; // [sp+78h] [bp-10h]@213
   __int64 v240; // [sp+7Ch] [bp-Ch]@12
-  unsigned int v248; // [sp+7Ch] [bp-Ch]@218
   unsigned int v251; // [sp+80h] [bp-8h]@218
-  unsigned int v252; // [sp+84h] [bp-4h]@12
-  unsigned int v260; // [sp+84h] [bp-4h]@218
-  float a6s; // [sp+A0h] [bp+18h]@12
-  float a6t; // [sp+A0h] [bp+18h]@12
-  unsigned int a6b; // [sp+A0h] [bp+18h]@12
-  float a6bi; // [sp+A0h] [bp+18h]@218
-  float a6bj; // [sp+A0h] [bp+18h]@218
-  unsigned int a6r; // [sp+A0h] [bp+18h]@218
-  int dstdiffmult;
+  unsigned int v252; // [sp+84h] [bp-4h]@218
+  float a6s; // [sp+A0h] [bp+18h]@218
+  float a6t; // [sp+A0h] [bp+18h]@218
+  unsigned int a6b; // [sp+A0h] [bp+18h]@218
+  int field_0_bits;
+  int field_20_bits;
   
   int field0value = this->field_0.field_C;
+  switch(field0value)
+  {
+  case 8: field_0_bits = 1;
+    break;
+  case 16: field_0_bits = 2;
+    break;
+  case 32: field_0_bits = 4;
+    break;
+  default:
+    return field0value;
+  }
   int field20value = this->field_20.field_C;
   switch(field20value)
   {
-  case 8: dstdiffmult = dstPitch - dstWidth;
+  case 8: field_20_bits = 1;
     break;
-  case 16: dstdiffmult = 2 * (dstPitch - dstWidth);
+  case 16: field_20_bits = 2;
     break;
-  case 32: dstdiffmult = 4 * (dstPitch - dstWidth);
+  case 32: field_20_bits = 4;
     break;
   default:
     return field20value;
   }
-  
-  result = this->field_0.field_C;
-  if ( result == 32 || result == 16)
-  {
-    result = (int)pDst;
-    v193 = pDst;
-    v231 = 0;
-    if ( dstHeight <= 0 )
-      return result;
-    while ( 1 )
-    {
-      v14 = 0;
-      if ( dstWidth <= 0 )
-        goto LABEL_30;
-      do
-      {
-        a6s = (double)v14 / (double)dstWidth * (double)srcWidth;
-        widthRatio = bankersRounding(a6s);
-        a6t = (double)(v14 + 1) / (double)dstWidth * (double)srcWidth;
-        widthRatioPlusOne = bankersRounding(a6t);
-        v17 = (double)v231 / (double)dstHeight * (double)srcHeight;
-        heightRatio = bankersRounding(v17);
-        v18 = (double)(v231 + 1) / (double)dstHeight * (double)srcHeight;
-        heightRatioPlusOne = bankersRounding(v18);
-        v251 = 0;
-        v19 = (heightRatioPlusOne - heightRatio) * (widthRatioPlusOne - widthRatio);
-        v252 = 0;
-        a6b = 0;
-        v240 = 0i64;
-        if ( heightRatio >= heightRatioPlusOne )
-          goto LABEL_25;
-        v160 = heightRatioPlusOne - heightRatio;
-        if(field0value == 32)
-          v175 = &pSrc[2 * (widthRatio + srcPitch * heightRatio)];
-        else
-          v175 = &pSrc[widthRatio + srcPitch * heightRatio];
-
-        do
-        {          
-          int ratioDiff = widthRatioPlusOne - widthRatio;
-          for(int i = 0; i < ratioDiff; i++)
-          {
-            if(field0value == 32)
-              v21 = _450FB1((int)v175[i]);
-            else
-              v21 = _450FB1((_WORD)v175[i]);
-            v240 += ((unsigned int)v21 >> 24);
-            a6b += BYTE2(v21);
-            v252 += BYTE1(v21);
-            v251 += (unsigned __int8)v21;
-          }
-          if(field0value == 32)
-            v175 += 2 * srcPitch;
-          else
-            v175 += srcPitch;
-          --v160;
-        }
-        while ( v160 );
-LABEL_25:
-        v22 = (unsigned int)v240 / ((heightRatioPlusOne - heightRatio) * (widthRatioPlusOne - widthRatio));
-        if ( v19 )
-        {
-          a6b /= v19;
-          v252 /= v19;
-          v251 /= v19;
-        }
-        if ( v22 != 255 )
-          v22 &= 0x7FFFFFFFu;
-        v23 = _450F55(v251 | ((v252 | ((a6b | (v22 << 8)) << 8)) << 8));
-        *(_DWORD *)v193 = v23;
-        switch(field20value)
-        {
-        case 8: v193 = (unsigned __int16 *)((char *)v193 + 1);
-          break;
-        case 16: ++v193;
-          break;
-        case 32: v193 += 2;
-          break;
-        default:
-          assert(false);
-          return result;
-        }
-        ++v14;
-      }
-      while ( v14 < dstWidth );
-LABEL_30:
-      v193 = (unsigned __int16 *)((char *)v193 + dstdiffmult);
-      ++v231;
-      result = v231;
-      if ( v231 >= dstHeight )
-        return result;
-    }
-  }
-
-  else if ( result == 8 )
-  {
-    result = (int)pDst;
-    v201 = pDst;
-    v239 = 0;
-    if ( dstHeight <= 0 )
-      return result;
-    while ( 1 )
-    {
-      v112 = 0;
-      if ( dstWidth <= 0 )
-        goto LABEL_236;
-      do
-      {
-        a6bi = (double)v112 / (double)dstWidth * (double)srcWidth;
-        widthRatio = bankersRounding(a6bi);
-        a6bj = (double)(v112 + 1) / (double)dstWidth * (double)srcWidth;
-        widthRatioPlusOne = bankersRounding(a6bj);
-        v115 = (double)v239 / (double)dstHeight * (double)srcHeight;
-        heightRatio = bankersRounding(v115);
-        v116 = (double)(v239 + 1) / (double)dstHeight * (double)srcHeight;
-        heightRatioPlusOne = bankersRounding(v116);
-        v251 = 0;
-        v117 = (heightRatioPlusOne - heightRatio) * (widthRatioPlusOne - widthRatio);
-        v260 = 0;
-        a6r = 0;
-        v248 = 0;
-        if ( heightRatio >= heightRatioPlusOne )
-          goto LABEL_231;
-        v169 = heightRatioPlusOne - heightRatio;
-        v184 = (char *)pSrc + widthRatio + srcPitch * heightRatio;
-        do
-        {
-          int ratioDiff = widthRatioPlusOne - widthRatio;
-          for(int i = 0; i < ratioDiff; i++)
-          {
-            v120 = _450FB1((unsigned __int8)v184[i]);
-            v248 += (unsigned int)v120 >> 24;
-            a6r += BYTE2(v120);
-            v260 += BYTE1(v120);
-            v251 += (unsigned __int8)v120;
-          }
-          v184 += srcPitch;
-          --v169;
-        }
-        while ( v169 );;
-LABEL_231:
-        v121 = v248 / ((heightRatioPlusOne - heightRatio) * (widthRatioPlusOne - widthRatio));
-        if ( v117 )
-        {
-          a6r /= v117;
-          v260 /= v117;
-          v251 /= v117;
-        }
-        if ( v121 != 255 )
-          v121 &= 0x7FFFFFFFu;
-        v122 = _450F55(v251 | ((v260 | ((a6r | (v121 << 8)) << 8)) << 8));
-        *v201 = v122;
-        switch(field20value)
-        {
-        case 8: v201 = (unsigned __int16 *)((char *)v201 + 1);
-          break;
-        case 16: ++v201;
-          break;
-        case 32: v201 += 2;
-          break;
-        default:
-          assert(false);
-          return result;
-        }
-        ++v112;
-      }
-      while ( v112 < dstWidth );
-LABEL_236:
-      v201 = (unsigned __int16 *)((char *)v201 + dstdiffmult);
-      ++v239;
-      result = v239;
-      if ( v239 >= dstHeight )
-        return result;
-    }
-  }
-  else //( result != 8 && result != 16 && result != 32 )
-  {
+
+  result = (int)pDst;
+  v193 = pDst;
+  v231 = 0;
+  if ( dstHeight <= 0 )
     return result;
-  }
+  do
+  {
+    v14 = 0;
+    if ( dstWidth > 0 )
+    {
+	    do
+	    {
+	      a6s = (double)v14 / (double)dstWidth * (double)srcWidth;
+	      widthRatio = bankersRounding(a6s);
+	      a6t = (double)(v14 + 1) / (double)dstWidth * (double)srcWidth;
+	      widthRatioPlusOne = bankersRounding(a6t);
+	      v17 = (double)v231 / (double)dstHeight * (double)srcHeight;
+	      heightRatio = bankersRounding(v17);
+	      v18 = (double)(v231 + 1) / (double)dstHeight * (double)srcHeight;
+	      heightRatioPlusOne = bankersRounding(v18);
+	      v251 = 0;
+	      v19 = (heightRatioPlusOne - heightRatio) * (widthRatioPlusOne - widthRatio);
+	      v252 = 0;
+	      a6b = 0;
+	      v240 = 0i64;
+	      if ( heightRatio < heightRatioPlusOne )
+	      {
+          v160 = heightRatioPlusOne - heightRatio;
+          v175 = (unsigned short*)((char *)pSrc + field_0_bits * (widthRatio + srcPitch * heightRatio));
+	        do
+	        {          
+	          int ratioDiff = widthRatioPlusOne - widthRatio;
+	          for(int i = 0; i < ratioDiff; i++)
+	          {
+	            if(field0value == 32)
+	              v21 = _450FB1((int)v175[i]);
+	            else if(field0value == 16)
+	              v21 = _450FB1((_WORD)v175[i]);
+	            else
+	              v21 = _450FB1((unsigned __int8)v175[i]);
+	            v240 += ((unsigned int)v21 >> 24);
+	            a6b += BYTE2(v21);
+	            v252 += BYTE1(v21);
+	            v251 += (unsigned __int8)v21;
+	          }
+	          if(field0value == 32)
+	            v175 += 2 * srcPitch;
+	          else if(field0value == 16)
+	            v175 += srcPitch;   
+	          else
+	            v175 = (unsigned short*)((char *)v175 + 2 * srcPitch);
+	          --v160;
+	        }
+	        while ( v160 );
+	      }
+	      v22 = (unsigned int)v240 / ((heightRatioPlusOne - heightRatio) * (widthRatioPlusOne - widthRatio));
+	      if ( v19 )
+	      {
+	        a6b /= v19;
+	        v252 /= v19;
+	        v251 /= v19;
+	      }
+	      if ( v22 != 255 )
+	        v22 &= 0x7FFFFFFFu;
+	      v23 = _450F55(v251 | ((v252 | ((a6b | (v22 << 8)) << 8)) << 8));
+	      *(_DWORD *)v193 = v23;
+        v193 = (unsigned __int16 *)((char *)v193 + field_20_bits);
+	      ++v14;
+	    }
+	    while ( v14 < dstWidth );
+    }
+    v193 = (unsigned __int16 *)((char *)v193 + field_20_bits * (dstPitch - dstWidth));
+    ++v231;
+    result = v231;
+  }
+  while(v231 < dstHeight);
+  return result;
 }
 
 //----- (0044E1EC) --------------------------------------------------------