allow specifying the mask colour in wxImage::ConvertAlphaToMask() (closes #10143)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58404 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -322,9 +322,13 @@ public:
|
|||||||
bool SetMaskFromImage(const wxImage & mask,
|
bool SetMaskFromImage(const wxImage & mask,
|
||||||
unsigned char mr, unsigned char mg, unsigned char mb);
|
unsigned char mr, unsigned char mg, unsigned char mb);
|
||||||
|
|
||||||
// converts image's alpha channel to mask, if it has any, does nothing
|
// converts image's alpha channel to mask (choosing mask colour
|
||||||
// otherwise:
|
// automatically or using the specified colour for the mask), if it has
|
||||||
|
// any, does nothing otherwise:
|
||||||
bool ConvertAlphaToMask(unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
|
bool ConvertAlphaToMask(unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
|
||||||
|
void ConvertAlphaToMask(unsigned char mr, unsigned char mg, unsigned char mb,
|
||||||
|
unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
|
||||||
|
|
||||||
|
|
||||||
// This method converts an image where the original alpha
|
// This method converts an image where the original alpha
|
||||||
// information is only available as a shades of a colour
|
// information is only available as a shades of a colour
|
||||||
|
@@ -519,19 +519,49 @@ public:
|
|||||||
*/
|
*/
|
||||||
unsigned long ComputeHistogram(wxImageHistogram& histogram) const;
|
unsigned long ComputeHistogram(wxImageHistogram& histogram) const;
|
||||||
|
|
||||||
|
//@{
|
||||||
/**
|
/**
|
||||||
If the image has alpha channel, this method converts it to mask.
|
If the image has alpha channel, this method converts it to mask.
|
||||||
|
|
||||||
All pixels with alpha value less than @a threshold are replaced with mask
|
If the image has an alpha channel, all pixels with alpha value less
|
||||||
colour and the alpha channel is removed. Mask colour is chosen automatically
|
than @a threshold are replaced with the mask colour and the alpha
|
||||||
using FindFirstUnusedColour().
|
channel is removed. Otherwise nothing is done.
|
||||||
|
|
||||||
If the image image doesn't have alpha channel, ConvertAlphaToMask() does nothing.
|
The mask colour is chosen automatically using
|
||||||
|
FindFirstUnusedColour() by this function, see the overload below if you
|
||||||
|
this is not appropriate.
|
||||||
|
|
||||||
@return @false if FindFirstUnusedColour returns @false, @true otherwise.
|
@return @false if FindFirstUnusedColour returns @false, @true otherwise.
|
||||||
*/
|
*/
|
||||||
bool ConvertAlphaToMask(unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
|
bool ConvertAlphaToMask(unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
|
||||||
|
|
||||||
|
/**
|
||||||
|
If the image has alpha channel, this method converts it to mask using
|
||||||
|
the specified colour as the mask colour.
|
||||||
|
|
||||||
|
If the image has an alpha channel, all pixels with alpha value less
|
||||||
|
than @a threshold are replaced with the mask colour and the alpha
|
||||||
|
channel is removed. Otherwise nothing is done.
|
||||||
|
|
||||||
|
@since 2.9.0
|
||||||
|
|
||||||
|
@param mr
|
||||||
|
The red component of the mask colour.
|
||||||
|
@param mg
|
||||||
|
The green component of the mask colour.
|
||||||
|
@param mb
|
||||||
|
The blue component of the mask colour.
|
||||||
|
@param threshold
|
||||||
|
Pixels with alpha channel values below the given threshold are
|
||||||
|
considered to be transparent, i.e. the corresponding mask pixels
|
||||||
|
are set. Pixels with the alpha values above the threshold are
|
||||||
|
considered to be opaque.
|
||||||
|
|
||||||
|
*/
|
||||||
|
void ConvertAlphaToMask(unsigned char mr, unsigned char mg, unsigned char mb,
|
||||||
|
unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
|
||||||
|
//@}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a greyscale version of the image.
|
Returns a greyscale version of the image.
|
||||||
|
|
||||||
|
@@ -1905,16 +1905,28 @@ bool wxImage::SetMaskFromImage(const wxImage& mask,
|
|||||||
|
|
||||||
bool wxImage::ConvertAlphaToMask(unsigned char threshold)
|
bool wxImage::ConvertAlphaToMask(unsigned char threshold)
|
||||||
{
|
{
|
||||||
if (!HasAlpha())
|
if ( !HasAlpha() )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
unsigned char mr, mg, mb;
|
unsigned char mr, mg, mb;
|
||||||
if (!FindFirstUnusedColour(&mr, &mg, &mb))
|
if ( !FindFirstUnusedColour(&mr, &mg, &mb) )
|
||||||
{
|
{
|
||||||
wxLogError( _("No unused colour in image being masked.") );
|
wxLogError( _("No unused colour in image being masked.") );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConvertAlphaToMask(mr, mg, mb, threshold);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxImage::ConvertAlphaToMask(unsigned char mr,
|
||||||
|
unsigned char mg,
|
||||||
|
unsigned char mb,
|
||||||
|
unsigned char threshold)
|
||||||
|
{
|
||||||
|
if ( !HasAlpha() )
|
||||||
|
return;
|
||||||
|
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
|
|
||||||
SetMask(true);
|
SetMask(true);
|
||||||
@@ -1939,13 +1951,11 @@ bool wxImage::ConvertAlphaToMask(unsigned char threshold)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !M_IMGDATA->m_staticAlpha )
|
if ( !M_IMGDATA->m_staticAlpha )
|
||||||
free(M_IMGDATA->m_alpha);
|
free(M_IMGDATA->m_alpha);
|
||||||
|
|
||||||
M_IMGDATA->m_alpha = NULL;
|
M_IMGDATA->m_alpha = NULL;
|
||||||
M_IMGDATA->m_staticAlpha = false;
|
M_IMGDATA->m_staticAlpha = false;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user