X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8d3b6b8aa1cc0d2f927cedd36d490d412ed3da29..cb0791531fff2f3673e28d68be67a0ee5398a036:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index 16d436bbed..204c4b6657 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -912,6 +912,44 @@ unsigned char *wxImage::GetAlpha() const return M_IMGDATA->m_alpha; } +void wxImage::InitAlpha() +{ + wxCHECK_RET( !HasAlpha(), wxT("image already has an alpha channel") ); + + // initialize memory for alpha channel + SetAlpha(); + + unsigned char *alpha = M_IMGDATA->m_alpha; + const size_t lenAlpha = M_IMGDATA->m_width * M_IMGDATA->m_height; + + static const unsigned char ALPHA_TRANSPARENT = 0; + static const unsigned char ALPHA_OPAQUE = 0xff; + if ( HasMask() ) + { + // use the mask to initialize the alpha channel. + const unsigned char * const alphaEnd = alpha + lenAlpha; + + const unsigned char mr = M_IMGDATA->m_maskRed; + const unsigned char mg = M_IMGDATA->m_maskGreen; + const unsigned char mb = M_IMGDATA->m_maskBlue; + for ( unsigned char *src = M_IMGDATA->m_data; + alpha < alphaEnd; + src += 3, alpha++ ) + { + *alpha = (src[0] == mr && src[1] == mg && src[2] == mb) + ? ALPHA_TRANSPARENT + : ALPHA_OPAQUE; + } + + M_IMGDATA->m_hasMask = false; + } + else // no mask + { + // make the image fully opaque + memset(alpha, ALPHA_OPAQUE, lenAlpha); + } +} + // ---------------------------------------------------------------------------- // mask support // ---------------------------------------------------------------------------- @@ -1126,8 +1164,6 @@ wxString wxImage::GetOption(const wxString& name) const int wxImage::GetOptionInt(const wxString& name) const { - wxCHECK_MSG( Ok(), 0, wxT("invalid image") ); - return wxAtoi(GetOption(name)); }