]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxImage::Rotate180() function.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 14 Nov 2010 01:02:35 +0000 (01:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 14 Nov 2010 01:02:35 +0000 (01:02 +0000)
Closes #12679.

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

docs/changes.txt
include/wx/image.h
interface/wx/image.h
src/common/image.cpp

index d39ccd8a9edbff334949730f4803175797452209..d7f56d6e09dfd6e1d81a20edb3e410ddf6977b52 100644 (file)
@@ -429,6 +429,7 @@ All (GUI):
 - Added wxDocManager::FindTemplate() (troelsk).
 - Return bool, not void, from wxImage::ConvertAlphaToMask() (troelsk).
 - Fixed resizing columns in wxGrid when they were reordered.
+- Added wxImage::Rotate180() (Jeff Tupper).
 
 MSW:
 
index b17ebe06a560b5a24e8658d92ce0ad789d11d842..614c5cafce0e6a0fa1ed3ec079c09de068e66557 100644 (file)
@@ -347,6 +347,7 @@ public:
                    bool interpolating = true, wxPoint * offset_after_rotation = NULL) const;
 
     wxImage Rotate90( bool clockwise = true ) const;
+    wxImage Rotate180() const;
     wxImage Mirror( bool horizontally = true ) const;
 
     // replace one colour with another
index b083796d72434ae5719689c26732d057983ffb06..fa58c8cf25e390a362eb1d360e43f72181281454 100644 (file)
@@ -728,6 +728,13 @@ public:
     */
     wxImage Rotate90(bool clockwise = true) const;
 
+    /**
+        Returns a copy of the image rotated by 180 degrees.
+
+        @since 2.9.2
+    */
+    wxImage Rotate180() const;
+
     /**
         Rotates the hue of each pixel in the image by @e angle, which is a double in
         the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0
index e82fa02082d78a84026d5a5a92ecd6f7a3b797ea..19a690b0fc5446bcccf700309c0a114ef654b34d 100644 (file)
@@ -1128,6 +1128,62 @@ wxImage wxImage::Rotate90( bool clockwise ) const
     return image;
 }
 
+wxImage wxImage::Rotate180() const
+{
+    wxImage image;
+
+    wxCHECK_MSG( Ok(), image, wxS("invalid image") );
+
+    image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
+
+    unsigned char *data = image.GetData();
+    unsigned char *alpha = NULL;
+
+    wxCHECK_MSG( data, image, wxS("unable to create image") );
+
+    if ( M_IMGDATA->m_alpha != NULL )
+    {
+        image.SetAlpha();
+        alpha = image.GetAlpha();
+        wxCHECK_MSG( alpha, image, wxS("unable to create alpha channel") );
+    }
+
+    if ( M_IMGDATA->m_hasMask )
+        image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
+
+    long height = M_IMGDATA->m_height;
+    long width  = M_IMGDATA->m_width;
+
+    const unsigned char *source_data = M_IMGDATA->m_data;
+    unsigned char *target_data = data + width * height * 3;
+
+    for (long j = 0; j < height; j++)
+    {
+        for (long i = 0; i < width; i++)
+        {
+            target_data -= 3;
+            memcpy( target_data, source_data, 3 );
+            source_data += 3;
+        }
+    }
+
+    if ( alpha )
+    {
+        const unsigned char *src_alpha = M_IMGDATA->m_alpha;
+        unsigned char *dest_alpha = alpha + width * height;
+
+        for (long j = 0; j < height; ++j)
+        {
+            for (long i = 0; i < width; ++i)
+            {
+                *(--dest_alpha) = *(src_alpha++);
+            }
+        }
+    }
+
+    return image;
+}
+
 wxImage wxImage::Mirror( bool horizontally ) const
 {
     wxImage image;