X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dd9ea234f2e8802e182194bfe375079d1bdd1ccf..94113cc55572d23b2c86b9140543d32858c1eee6:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index e967b8ece9..02df26fdd9 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -380,7 +380,7 @@ wxImage wxImage::ShrinkBy( int xFactor , int yFactor ) const } } - // In case this is a cursor, make sure the hotspot is scalled accordingly: + // 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, (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X))/xFactor); @@ -466,7 +466,7 @@ wxImage wxImage::Scale( int width, int height ) const y += y_delta; } - // In case this is a cursor, make sure the hotspot is scalled accordingly: + // 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, (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X)*width)/old_width); @@ -769,6 +769,46 @@ void wxImage::Replace( unsigned char r1, unsigned char g1, unsigned char b1, } } +wxImage wxImage::ConvertToGreyscale( double lr, double lg, double lb ) const +{ + wxImage image; + + wxCHECK_MSG( Ok(), image, wxT("invalid image") ); + + image.Create(M_IMGDATA->m_width, M_IMGDATA->m_height, false); + + unsigned char *dest = image.GetData(); + + wxCHECK_MSG( dest, image, wxT("unable to create image") ); + + unsigned char *src = M_IMGDATA->m_data; + bool hasMask = M_IMGDATA->m_hasMask; + unsigned char maskRed = M_IMGDATA->m_maskRed; + unsigned char maskGreen = M_IMGDATA->m_maskGreen; + unsigned char maskBlue = M_IMGDATA->m_maskBlue; + + if ( hasMask ) + image.SetMaskColour(maskRed, maskGreen, maskBlue); + + const long size = M_IMGDATA->m_width * M_IMGDATA->m_height; + for ( long i = 0; i < size; i++, src += 3, dest += 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] = wx_static_cast(unsigned char, luma); + } + } + + return image; +} + wxImage wxImage::ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const { wxImage image; @@ -1554,7 +1594,7 @@ bool wxImage::LoadFile( wxInputStream& stream, long type, int index ) return false; } - if (!handler->CanRead(stream)) + if (stream.IsSeekable() && !handler->CanRead(stream)) { wxLogError(_("Image file is not of type %d."), type); return false; @@ -1578,7 +1618,7 @@ bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int ind return false; } - if (!handler->CanRead(stream)) + if (stream.IsSeekable() && !handler->CanRead(stream)) { wxLogError(_("Image file is not of type %s."), (const wxChar*) mimetype); return false;