]> git.saurik.com Git - wxWidgets.git/commitdiff
Optimize wxImage::Rotate90() by rotating alpha separately.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 24 Nov 2010 12:43:36 +0000 (12:43 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 24 Nov 2010 12:43:36 +0000 (12:43 +0000)
Bringing the alpha rotation out in a separate loop results in an
approximatively 10% performance improvement.

Closes #12712.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66254 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/image.cpp

index 89f35d5d5743ba4a0360fb514f6ea69f1a134aed..050ec43488f5190d30d89b6a52f4b555cb82138e 100644 (file)
@@ -1091,33 +1091,45 @@ wxImage wxImage::Rotate90( bool clockwise ) const
     unsigned char *data = image.GetData();
     const unsigned char *source_data = M_IMGDATA->m_data;
     unsigned char *target_data;
-    unsigned char *alpha_data = image.GetAlpha();
-    const unsigned char *source_alpha = M_IMGDATA->m_alpha;
-    unsigned char *target_alpha = 0 ;
 
     for (long j = 0; j < height; j++)
     {
         for (long i = 0; i < width; i++)
         {
-            if (clockwise)
+            if ( clockwise )
             {
                 target_data = data + (((i+1)*height) - j - 1)*3;
-                if (source_alpha)
-                    target_alpha = alpha_data + (((i+1)*height) - j - 1);
             }
             else
             {
                 target_data = data + ((height*(width-1)) + j - (i*height))*3;
-                if (source_alpha)
-                    target_alpha = alpha_data + ((height*(width-1)) + j - (i*height));
             }
             memcpy( target_data, source_data, 3 );
             source_data += 3;
+        }
+    }
 
-            if (source_alpha)
+    const unsigned char *source_alpha = M_IMGDATA->m_alpha;
+
+    if ( source_alpha )
+    {
+        unsigned char *alpha_data = image.GetAlpha();
+        unsigned char *target_alpha = 0 ;
+
+        for (long j = 0; j < height; j++)
+        {
+            for (long i = 0; i < width; i++)
             {
-                memcpy( target_alpha, source_alpha, 1 );
-                source_alpha += 1;
+                if ( clockwise )
+                {
+                    target_alpha = alpha_data + (((i+1)*height) - j - 1);
+                }
+                else
+                {
+                    target_alpha = alpha_data + ((height*(width-1)) + j - (i*height));
+                }
+
+                *target_alpha = *source_alpha++;
             }
         }
     }