diff --git a/docs/changes.txt b/docs/changes.txt index d39ccd8a9e..d7f56d6e09 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/include/wx/image.h b/include/wx/image.h index b17ebe06a5..614c5cafce 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -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 diff --git a/interface/wx/image.h b/interface/wx/image.h index b083796d72..fa58c8cf25 100644 --- a/interface/wx/image.h +++ b/interface/wx/image.h @@ -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 diff --git a/src/common/image.cpp b/src/common/image.cpp index e82fa02082..19a690b0fc 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -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;