Applied patch [ 1339764 ] Add wxImage::ConvertToGreyscale

Jamie Gadd


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36995 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2006-01-19 09:55:15 +00:00
parent f96a9d34e6
commit ec85956ae9
3 changed files with 56 additions and 2 deletions

View File

@@ -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;