X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/30f27c00d6c93974a51edcde11152b81b11eb336..ce7208d49d5ce2ca1dc0b3b83f14f1d04f29c4bf:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index 6f1a729952..a2674529de 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -30,10 +30,7 @@ #include "wx/filefn.h" #include "wx/wfstream.h" - -#if wxUSE_XPM - #include "wx/xpmdecod.h" -#endif +#include "wx/xpmdecod.h" // For memcpy #include @@ -51,6 +48,10 @@ #endif // wxUSE_FILE/wxUSE_FFILE #endif // HAS_FILE_STREAMS +#if wxUSE_VARIANT +IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxImage,WXDLLEXPORT) +#endif + //----------------------------------------------------------------------------- // wxImage //----------------------------------------------------------------------------- @@ -161,17 +162,12 @@ wxImage::wxImage( wxInputStream& stream, const wxString& mimetype, int index ) } #endif // wxUSE_STREAMS -wxImage::wxImage( const char** xpmData ) +wxImage::wxImage(const char* const* xpmData) { Create(xpmData); } -wxImage::wxImage( char** xpmData ) -{ - Create((const char**) xpmData); -} - -bool wxImage::Create( const char** xpmData ) +bool wxImage::Create(const char* const* xpmData) { #if wxUSE_XPM UnRef(); @@ -469,13 +465,7 @@ wxImage wxImage::Scale( int width, int height, int quality ) const unsigned char *source_alpha = 0 ; unsigned char *target_alpha = 0 ; - if (M_IMGDATA->m_hasMask) - { - image.SetMaskColour( M_IMGDATA->m_maskRed, - M_IMGDATA->m_maskGreen, - M_IMGDATA->m_maskBlue ); - } - else + if ( !M_IMGDATA->m_hasMask ) { source_alpha = M_IMGDATA->m_alpha ; if ( source_alpha ) @@ -514,6 +504,14 @@ wxImage wxImage::Scale( int width, int height, int quality ) const } } + // If the original image has a mask, apply the mask to the new image + if (M_IMGDATA->m_hasMask) + { + image.SetMaskColour( M_IMGDATA->m_maskRed, + M_IMGDATA->m_maskGreen, + M_IMGDATA->m_maskBlue ); + } + // In case this is a cursor, make sure the hotspot is scaled accordingly: if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) ) image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, @@ -573,7 +571,7 @@ wxImage wxImage::ResampleBox(int width, int height) const averaged_pixels = 0; sum_r = sum_g = sum_b = sum_a = 0.0; - for ( int j = src_y - scale_factor_y_2 + 1; + for ( int j = int(src_y - scale_factor_y/2.0 + 1); j <= int(src_y + scale_factor_y_2); j++ ) { @@ -581,7 +579,7 @@ wxImage wxImage::ResampleBox(int width, int height) const if ( j < 0 || j > M_IMGDATA->m_height ) continue; - for ( int i = src_x - scale_factor_x_2 + 1; + for ( int i = int(src_x - scale_factor_x/2.0 + 1); i <= src_x + scale_factor_x_2; i++ ) { @@ -809,11 +807,11 @@ wxImage wxImage::BlurHorizontal(int blurRadius) } dst = dst_data + y * M_IMGDATA->m_width*3; - dst[0] = sum_r / blurArea; - dst[1] = sum_g / blurArea; - dst[2] = sum_b / blurArea; + dst[0] = (unsigned char)(sum_r / blurArea); + dst[1] = (unsigned char)(sum_g / blurArea); + dst[2] = (unsigned char)(sum_b / blurArea); if ( src_alpha ) - dst_alpha[y * M_IMGDATA->m_width] = sum_a / blurArea; + dst_alpha[y * M_IMGDATA->m_width] = (unsigned char)(sum_a / blurArea); // Now average the values of the rest of the pixels by just moving the // blur radius box along the row @@ -850,12 +848,12 @@ wxImage wxImage::BlurHorizontal(int blurRadius) sum_a += src_alpha[pixel_idx]; // Save off the averaged data - dst = dst_data + x*3 + y*M_IMGDATA->m_width; - dst[0] = sum_r / blurArea; - dst[1] = sum_g / blurArea; - dst[2] = sum_b / blurArea; + dst = dst_data + x*3 + y*M_IMGDATA->m_width*3; + dst[0] = (unsigned char)(sum_r / blurArea); + dst[1] = (unsigned char)(sum_g / blurArea); + dst[2] = (unsigned char)(sum_b / blurArea); if ( src_alpha ) - dst_alpha[x + y * M_IMGDATA->m_width] = sum_a / blurArea; + dst_alpha[x + y * M_IMGDATA->m_width] = (unsigned char)(sum_a / blurArea); } } @@ -927,11 +925,11 @@ wxImage wxImage::BlurVertical(int blurRadius) } dst = dst_data + x*3; - dst[0] = sum_r / blurArea; - dst[1] = sum_g / blurArea; - dst[2] = sum_b / blurArea; + dst[0] = (unsigned char)(sum_r / blurArea); + dst[1] = (unsigned char)(sum_g / blurArea); + dst[2] = (unsigned char)(sum_b / blurArea); if ( src_alpha ) - dst_alpha[x] = sum_a / blurArea; + dst_alpha[x] = (unsigned char)(sum_a / blurArea); // Now average the values of the rest of the pixels by just moving the // box along the column from top to bottom @@ -969,11 +967,11 @@ wxImage wxImage::BlurVertical(int blurRadius) // Save off the averaged data dst = dst_data + (x + y * M_IMGDATA->m_width) * 3; - dst[0] = sum_r / blurArea; - dst[1] = sum_g / blurArea; - dst[2] = sum_b / blurArea; + dst[0] = (unsigned char)(sum_r / blurArea); + dst[1] = (unsigned char)(sum_g / blurArea); + dst[2] = (unsigned char)(sum_b / blurArea); if ( src_alpha ) - dst_alpha[x + y * M_IMGDATA->m_width] = sum_a / blurArea; + dst_alpha[x + y * M_IMGDATA->m_width] = (unsigned char)(sum_a / blurArea); } } @@ -1313,8 +1311,8 @@ void wxImage::Paste( const wxImage &image, int x, int y ) { for (int i = 0; i < width; i+=3) { - if ((source_data[i] != r) && - (source_data[i+1] != g) && + if ((source_data[i] != r) || + (source_data[i+1] != g) || (source_data[i+2] != b)) { memcpy( target_data+i, source_data+i, 3 ); @@ -1546,7 +1544,7 @@ unsigned char wxImage::GetBlue( int x, int y ) const return M_IMGDATA->m_data[pos+2]; } -bool wxImage::Ok() const +bool wxImage::IsOk() const { // image of 0 width or height can't be considered ok - at least because it // causes crashes in ConvertToBitmap() if we don't catch it in time