X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2e51fb3041e78ef15506ed746ed5898536be5955..af7e24c33e1e6e00a7687ee965b921dbe60cdb36:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index ce383eff93..cc63e385c1 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -26,6 +26,7 @@ #include "wx/module.h" #include "wx/palette.h" #include "wx/intl.h" + #include "wx/colour.h" #endif #include "wx/filefn.h" @@ -616,8 +617,11 @@ wxImage wxImage::ResampleBilinear(int width, int height) const double srcpixy, srcpixy1, srcpixy2, dy, dy1; double srcpixx, srcpixx1, srcpixx2, dx, dx1; - double r1, g1, b1, a1; - double r2, g2, b2, a2; + + // initialize alpha values to avoid g++ warnings about possibly + // uninitialized variables + double r1, g1, b1, a1 = 0; + double r2, g2, b2, a2 = 0; for ( int dsty = 0; dsty < height; dsty++ ) { @@ -664,13 +668,13 @@ wxImage wxImage::ResampleBilinear(int width, int height) const //result lines - dst_data[0] = r1 * dy1 + r2 * dy; - dst_data[1] = g1 * dy1 + g2 * dy; - dst_data[2] = b1 * dy1 + b2 * dy; + dst_data[0] = static_cast(r1 * dy1 + r2 * dy); + dst_data[1] = static_cast(g1 * dy1 + g2 * dy); + dst_data[2] = static_cast(b1 * dy1 + b2 * dy); dst_data += 3; if ( src_alpha ) - *dst_alpha++ = a1 * dy1 + a2 * dy; + *dst_alpha++ = static_cast(a1 * dy1 + a2 * dy); } } @@ -1433,7 +1437,12 @@ void wxImage::Replace( unsigned char r1, unsigned char g1, unsigned char b1, } } -wxImage wxImage::ConvertToGreyscale( double lr, double lg, double lb ) const +wxImage wxImage::ConvertToGreyscale(void) const +{ + return ConvertToGreyscale(0.299, 0.587, 0.114); +} + +wxImage wxImage::ConvertToGreyscale(double weight_r, double weight_g, double weight_b) const { wxImage image; @@ -1457,16 +1466,14 @@ wxImage wxImage::ConvertToGreyscale( double lr, double lg, double lb ) const const long size = M_IMGDATA->m_width * M_IMGDATA->m_height; for ( long i = 0; i < size; i++, src += 3, dest += 3 ) { + memcpy(dest, src, 3); // don't modify the mask if ( hasMask && src[0] == maskRed && src[1] == maskGreen && src[2] == maskBlue ) { - memcpy(dest, src, 3); } else { - // calculate the luma - double luma = (src[0] * lr + src[1] * lg + src[2] * lb) + 0.5; - dest[0] = dest[1] = dest[2] = static_cast(luma); + wxColour::MakeGrey(dest + 0, dest + 1, dest + 2, weight_r, weight_g, weight_b); } } @@ -1511,15 +1518,43 @@ wxImage wxImage::ConvertToMono( unsigned char r, unsigned char g, unsigned char for ( long i = 0; i < size; i++, srcd += 3, tard += 3 ) { - if (srcd[0] == r && srcd[1] == g && srcd[2] == b) - tard[0] = tard[1] = tard[2] = 255; - else - tard[0] = tard[1] = tard[2] = 0; + bool on = (srcd[0] == r) && (srcd[1] == g) && (srcd[2] == b); + wxColourBase::MakeMono(tard + 0, tard + 1, tard + 2, on); } return image; } +wxImage wxImage::ConvertToDisabled(unsigned char brightness) const +{ + wxImage image = *this; + + unsigned char mr = image.GetMaskRed(); + unsigned char mg = image.GetMaskGreen(); + unsigned char mb = image.GetMaskBlue(); + + int width = image.GetWidth(); + int height = image.GetHeight(); + bool has_mask = image.HasMask(); + + for (int y = height-1; y >= 0; --y) + { + for (int x = width-1; x >= 0; --x) + { + unsigned char* data = image.GetData() + (y*(width*3))+(x*3); + unsigned char* r = data; + unsigned char* g = data+1; + unsigned char* b = data+2; + + if (has_mask && (*r == mr) && (*g == mg) && (*b == mb)) + continue; + + wxColour::MakeDisabled(r, g, b, brightness); + } + } + return image; +} + int wxImage::GetWidth() const { wxCHECK_MSG( Ok(), 0, wxT("invalid image") );