From 000c2be40d8e0231f6565ba2931f4c88add433d9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 14 Nov 2010 01:02:27 +0000 Subject: [PATCH] Handle hot spots in wxImage::Rotate90(). Set hot spot coordinates for the rotated image if the original one had them. Also handle the case when the source image has both alpha and mask correctly. Closes #3680. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66145 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/image.cpp | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/common/image.cpp b/src/common/image.cpp index 4a07012039..e82fa02082 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -1068,26 +1068,36 @@ wxImage wxImage::Rotate90( bool clockwise ) const unsigned char *source_data = M_IMGDATA->m_data; unsigned char *target_data; unsigned char *alpha_data = 0 ; - unsigned char *source_alpha = 0 ; + unsigned char *source_alpha = M_IMGDATA->m_alpha; unsigned char *target_alpha = 0 ; - if (M_IMGDATA->m_hasMask) + if ( source_alpha ) { + image.SetAlpha(); + alpha_data = image.GetAlpha(); + wxCHECK_MSG( alpha_data, 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 ); - } - else - { - source_alpha = M_IMGDATA->m_alpha ; - if ( source_alpha ) - { - image.SetAlpha() ; - alpha_data = image.GetAlpha() ; - } - } long height = M_IMGDATA->m_height; long width = M_IMGDATA->m_width; + if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) ) + { + int hot_x = GetOptionInt( wxIMAGE_OPTION_CUR_HOTSPOT_X ); + image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, + clockwise ? hot_x : width - 1 - hot_x); + } + + if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ) + { + int hot_y = GetOptionInt( wxIMAGE_OPTION_CUR_HOTSPOT_Y ); + image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, + clockwise ? height - 1 - hot_y : hot_y); + } + for (long j = 0; j < height; j++) { for (long i = 0; i < width; i++)