From 90fbb09ae248c93b0cf62eb7cf4ecfd94f88023f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 9 Apr 2010 13:15:20 +0000 Subject: [PATCH] Add wxImage::ClearAlpha(). This simple method can be used to remove alpha channel from the image. See #10915. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63922 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/image.h | 1 + interface/wx/image.h | 10 ++++++++++ src/common/image.cpp | 11 +++++++++++ 4 files changed, 23 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index ac8bcb5aed..db31c5502c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -428,6 +428,7 @@ All: - Fix output buffer overflow in wxBase64Decode() (Eric W. Savage). - Added bilinear image resizing algorithm to wxImage (bishop). - Fix bug with position argument in wxImage::Size() (Byron Sorgdrager). +- Added wxImage::ClearAlpha() (Javier Torres). - Fix bug with parsing concatenated switches in wxCmdLineParser (Mike Funduc). - Added wxMBConv::cMB2WC(wxCharBuffer) and cWC2MB(wxWCharBuffer) overloads. - Added wxAny class; a modern, backwards-incompatible replacement for diff --git a/include/wx/image.h b/include/wx/image.h index e0e05f67e2..cb602383d1 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -451,6 +451,7 @@ public: bool HasAlpha() const { return GetAlpha() != NULL; } void SetAlpha(unsigned char *alpha = NULL, bool static_data=false); void InitAlpha(); + void ClearAlpha(); // return true if this pixel is masked or has alpha less than specified // threshold diff --git a/interface/wx/image.h b/interface/wx/image.h index 0477244094..77c7321e9d 100644 --- a/interface/wx/image.h +++ b/interface/wx/image.h @@ -1396,6 +1396,16 @@ public: */ void SetAlpha(int x, int y, unsigned char alpha); + /** + Removes the alpha channel from the image. + + This function should only be called if the image has alpha channel data, + use HasAlpha() to check for this. + + @since 2.9.1 + */ + void ClearAlpha(); + /** Sets the image data without performing checks. diff --git a/src/common/image.cpp b/src/common/image.cpp index 6dddaefb3c..4fb2b0c254 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -1857,6 +1857,17 @@ void wxImage::InitAlpha() } } +void wxImage::ClearAlpha() +{ + wxCHECK_RET( HasAlpha(), wxT("image already doesn't have an alpha channel") ); + + if ( !M_IMGDATA->m_staticAlpha ) + free( M_IMGDATA->m_alpha ); + + M_IMGDATA->m_alpha = NULL; +} + + // ---------------------------------------------------------------------------- // mask support // ----------------------------------------------------------------------------