better handling of transparent colour in wxImage conversion (patch 726208)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20420 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-05-01 19:59:40 +00:00
parent 8e0a317c4f
commit 2eefae6efa
2 changed files with 96 additions and 60 deletions

View File

@@ -121,20 +121,21 @@ bool wxMask::Create( const wxBitmap& bitmap,
GdkVisual *visual = wxTheApp->GetGdkVisual();
int bpp = visual->depth;
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
if ((bpp == 16) && (visual->red_mask != 0xf800))
bpp = 15;
if (bpp == 15)
{
red = red & 0xf8;
green = green & 0xf8;
blue = blue & 0xf8;
} else
if (bpp == 16)
}
else if (bpp == 16)
{
red = red & 0xf8;
green = green & 0xfc;
blue = blue & 0xf8;
} else
if (bpp == 12)
}
else if (bpp == 12)
{
red = red & 0xf0;
green = green & 0xf0;
@@ -458,8 +459,10 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
SetDepth( bpp );
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
if (bpp < 8) bpp = 8;
if ((bpp == 16) && (visual->red_mask != 0xf800))
bpp = 15;
else if (bpp < 8)
bpp = 8;
// We handle 8-bit bitmaps ourselves using the colour cube, 12-bit
// visuals are not supported by GDK so we do these ourselves, too.
@@ -677,6 +680,13 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
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 MASK_RED = 1;
static const MASK_GREEN = 2;
static const MASK_BLUE = 3;
static const MASK_BLUE_REPLACEMENT = 2;
wxImage image;
wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
@@ -687,13 +697,14 @@ wxImage wxBitmap::ConvertToImage() const
gdk_image = gdk_image_get( GetPixmap(),
0, 0,
GetWidth(), GetHeight() );
} else
if (GetBitmap())
}
else if (GetBitmap())
{
gdk_image = gdk_image_get( GetBitmap(),
0, 0,
GetWidth(), GetHeight() );
} else
}
else
{
wxFAIL_MSG( wxT("Ill-formed bitmap") );
}
@@ -717,7 +728,7 @@ wxImage wxBitmap::ConvertToImage() const
0, 0,
GetWidth(), GetHeight() );
image.SetMaskColour( 16, 16, 16 ); // anything unlikely and dividable
image.SetMaskColour( MASK_RED, MASK_GREEN, MASK_BLUE );
}
int bpp = -1;
@@ -736,7 +747,8 @@ wxImage wxBitmap::ConvertToImage() const
visual = wxTheApp->GetGdkVisual();
bpp = visual->depth;
if (bpp == 16) bpp = visual->red_prec + visual->green_prec + visual->blue_prec;
if (bpp == 16)
bpp = visual->red_prec + visual->green_prec + visual->blue_prec;
red_shift_right = visual->red_shift;
red_shift_left = 8-visual->red_prec;
green_shift_right = visual->green_shift;
@@ -797,9 +809,15 @@ wxImage wxBitmap::ConvertToImage() const
int mask_pixel = gdk_image_get_pixel( gdk_image_mask, i, j );
if (mask_pixel == 0)
{
data[pos] = 16;
data[pos+1] = 16;
data[pos+2] = 16;
data[pos] = MASK_RED;
data[pos+1] = MASK_GREEN;
data[pos+2] = MASK_BLUE;
}
else if ( data[pos] == MASK_RED &&
data[pos+1] == MASK_GREEN &&
data[pos+2] == MASK_BLUE )
{
data[pos+2] = MASK_BLUE_REPLACEMENT;
}
}

View File

@@ -121,20 +121,21 @@ bool wxMask::Create( const wxBitmap& bitmap,
GdkVisual *visual = wxTheApp->GetGdkVisual();
int bpp = visual->depth;
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
if ((bpp == 16) && (visual->red_mask != 0xf800))
bpp = 15;
if (bpp == 15)
{
red = red & 0xf8;
green = green & 0xf8;
blue = blue & 0xf8;
} else
if (bpp == 16)
}
else if (bpp == 16)
{
red = red & 0xf8;
green = green & 0xfc;
blue = blue & 0xf8;
} else
if (bpp == 12)
}
else if (bpp == 12)
{
red = red & 0xf0;
green = green & 0xf0;
@@ -458,8 +459,10 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
SetDepth( bpp );
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
if (bpp < 8) bpp = 8;
if ((bpp == 16) && (visual->red_mask != 0xf800))
bpp = 15;
else if (bpp < 8)
bpp = 8;
// We handle 8-bit bitmaps ourselves using the colour cube, 12-bit
// visuals are not supported by GDK so we do these ourselves, too.
@@ -677,6 +680,13 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
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 MASK_RED = 1;
static const MASK_GREEN = 2;
static const MASK_BLUE = 3;
static const MASK_BLUE_REPLACEMENT = 2;
wxImage image;
wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
@@ -687,13 +697,14 @@ wxImage wxBitmap::ConvertToImage() const
gdk_image = gdk_image_get( GetPixmap(),
0, 0,
GetWidth(), GetHeight() );
} else
if (GetBitmap())
}
else if (GetBitmap())
{
gdk_image = gdk_image_get( GetBitmap(),
0, 0,
GetWidth(), GetHeight() );
} else
}
else
{
wxFAIL_MSG( wxT("Ill-formed bitmap") );
}
@@ -717,7 +728,7 @@ wxImage wxBitmap::ConvertToImage() const
0, 0,
GetWidth(), GetHeight() );
image.SetMaskColour( 16, 16, 16 ); // anything unlikely and dividable
image.SetMaskColour( MASK_RED, MASK_GREEN, MASK_BLUE );
}
int bpp = -1;
@@ -736,7 +747,8 @@ wxImage wxBitmap::ConvertToImage() const
visual = wxTheApp->GetGdkVisual();
bpp = visual->depth;
if (bpp == 16) bpp = visual->red_prec + visual->green_prec + visual->blue_prec;
if (bpp == 16)
bpp = visual->red_prec + visual->green_prec + visual->blue_prec;
red_shift_right = visual->red_shift;
red_shift_left = 8-visual->red_prec;
green_shift_right = visual->green_shift;
@@ -797,9 +809,15 @@ wxImage wxBitmap::ConvertToImage() const
int mask_pixel = gdk_image_get_pixel( gdk_image_mask, i, j );
if (mask_pixel == 0)
{
data[pos] = 16;
data[pos+1] = 16;
data[pos+2] = 16;
data[pos] = MASK_RED;
data[pos+1] = MASK_GREEN;
data[pos+2] = MASK_BLUE;
}
else if ( data[pos] == MASK_RED &&
data[pos+1] == MASK_GREEN &&
data[pos+2] == MASK_BLUE )
{
data[pos+2] = MASK_BLUE_REPLACEMENT;
}
}