better mask handling in wxBitmap to wxImage conversion (patch 754881)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21219 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
8b389fab25
commit
c8688869d9
@ -827,6 +827,13 @@ bool wxBitmap::CreateFromImage(const wxImage& image, int depth, WXHDC hdc )
|
|||||||
|
|
||||||
wxImage wxBitmap::ConvertToImage() const
|
wxImage wxBitmap::ConvertToImage() const
|
||||||
{
|
{
|
||||||
|
// the colour used as transparent one in wxImage and the one it is replaced
|
||||||
|
// with when it really occurs in the bitmap
|
||||||
|
static const int MASK_RED = 1;
|
||||||
|
static const int MASK_GREEN = 2;
|
||||||
|
static const int MASK_BLUE = 3;
|
||||||
|
static const int MASK_BLUE_REPLACEMENT = 2;
|
||||||
|
|
||||||
wxImage image;
|
wxImage image;
|
||||||
|
|
||||||
wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
|
wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
|
||||||
@ -918,27 +925,39 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
::SetBkColor( memdc, RGB( 255, 255, 255 ) );
|
::SetBkColor( memdc, RGB( 255, 255, 255 ) );
|
||||||
::GetDIBits( memdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS );
|
::GetDIBits( memdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS );
|
||||||
::DeleteDC( memdc );
|
::DeleteDC( memdc );
|
||||||
// background color set to RGB(16,16,16) in consistent with wxGTK
|
// background color set to mask colour
|
||||||
unsigned char r=16, g=16, b=16;
|
unsigned char r=MASK_RED, g=MASK_GREEN, b=MASK_BLUE;
|
||||||
ptdata = data;
|
ptdata = data;
|
||||||
ptbits = lpBits;
|
ptbits = lpBits;
|
||||||
for( i=0; i<height; i++ )
|
for( i=0; i<height; i++ )
|
||||||
{
|
{
|
||||||
for( j=0; j<width; j++ )
|
for( j=0; j<width; j++ )
|
||||||
{
|
{
|
||||||
if( *ptbits != 0 )
|
// is this pixel transparent?
|
||||||
ptdata += 3;
|
if ( *ptbits != 0 )
|
||||||
else
|
|
||||||
{
|
{
|
||||||
*(ptdata++) = r;
|
if ( (ptdata[0] == MASK_RED) &&
|
||||||
*(ptdata++) = g;
|
(ptdata[1] == MASK_GREEN) &&
|
||||||
*(ptdata++) = b;
|
(ptdata[2] == MASK_BLUE) )
|
||||||
|
{
|
||||||
|
// we have to fudge the colour a bit to prevent this
|
||||||
|
// pixel from appearing transparent
|
||||||
|
ptdata[2] = MASK_BLUE_REPLACEMENT;
|
||||||
|
}
|
||||||
|
ptdata += 3;
|
||||||
|
}
|
||||||
|
else // masked pixel
|
||||||
|
{
|
||||||
|
*(ptdata++) = MASK_RED;
|
||||||
|
*(ptdata++) = MASK_GREEN;
|
||||||
|
*(ptdata++) = MASK_BLUE;
|
||||||
}
|
}
|
||||||
ptbits += 3;
|
ptbits += 3;
|
||||||
}
|
}
|
||||||
ptbits += padding;
|
ptbits += padding;
|
||||||
}
|
}
|
||||||
image.SetMaskColour( r, g, b );
|
|
||||||
|
image.SetMaskColour( MASK_RED, MASK_GREEN, MASK_BLUE );
|
||||||
image.SetMask( TRUE );
|
image.SetMask( TRUE );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user