add support for reading alpha channel from BMP images (#9741)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@54942 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -98,6 +98,7 @@ All:
|
|||||||
|
|
||||||
All (GUI):
|
All (GUI):
|
||||||
|
|
||||||
|
- Added support for reading alpha channel in BMP format (Kevin Wright).
|
||||||
- Fixed help viewer bug whereby the splitter sash in wxHtmlHelpWindow could
|
- Fixed help viewer bug whereby the splitter sash in wxHtmlHelpWindow could
|
||||||
go underneath the left-hand pane, permanently, after resizing the
|
go underneath the left-hand pane, permanently, after resizing the
|
||||||
help window.
|
help window.
|
||||||
|
@@ -454,9 +454,9 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
|
|||||||
wxFileOffset bmpOffset, wxInputStream& stream,
|
wxFileOffset bmpOffset, wxInputStream& stream,
|
||||||
bool verbose, bool IsBmp, bool hasPalette)
|
bool verbose, bool IsBmp, bool hasPalette)
|
||||||
{
|
{
|
||||||
wxInt32 aDword, rmask = 0, gmask = 0, bmask = 0;
|
wxInt32 aDword, rmask = 0, gmask = 0, bmask = 0, amask = 0;
|
||||||
int rshift = 0, gshift = 0, bshift = 0;
|
int rshift = 0, gshift = 0, bshift = 0, ashift = 0;
|
||||||
int rbits = 0, gbits = 0, bbits = 0;
|
int rbits = 0, gbits = 0, bbits = 0, abits = 0;
|
||||||
wxInt32 dbuf[4];
|
wxInt32 dbuf[4];
|
||||||
wxInt8 bbuf[4];
|
wxInt8 bbuf[4];
|
||||||
wxUint8 aByte;
|
wxUint8 aByte;
|
||||||
@@ -488,11 +488,29 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
|
|||||||
{
|
{
|
||||||
if ( verbose )
|
if ( verbose )
|
||||||
wxLogError( _("BMP: Couldn't allocate memory.") );
|
wxLogError( _("BMP: Couldn't allocate memory.") );
|
||||||
if ( cmap )
|
delete[] cmap;
|
||||||
delete[] cmap;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned char *alpha;
|
||||||
|
if ( bpp == 32 )
|
||||||
|
{
|
||||||
|
// tell the image to allocate an alpha buffer
|
||||||
|
image->SetAlpha();
|
||||||
|
alpha = image->GetAlpha();
|
||||||
|
if ( !alpha )
|
||||||
|
{
|
||||||
|
if ( verbose )
|
||||||
|
wxLogError(_("BMP: Couldn't allocate memory."));
|
||||||
|
delete[] cmap;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // no alpha
|
||||||
|
{
|
||||||
|
alpha = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Reading the palette, if it exists:
|
// Reading the palette, if it exists:
|
||||||
if ( bpp < 16 && ncolors != 0 )
|
if ( bpp < 16 && ncolors != 0 )
|
||||||
{
|
{
|
||||||
@@ -577,9 +595,13 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
|
|||||||
rmask = 0x00FF0000;
|
rmask = 0x00FF0000;
|
||||||
gmask = 0x0000FF00;
|
gmask = 0x0000FF00;
|
||||||
bmask = 0x000000FF;
|
bmask = 0x000000FF;
|
||||||
|
amask = 0xFF000000;
|
||||||
|
|
||||||
|
ashift = 24;
|
||||||
rshift = 16;
|
rshift = 16;
|
||||||
gshift = 8;
|
gshift = 8;
|
||||||
bshift = 0;
|
bshift = 0;
|
||||||
|
abits = 8;
|
||||||
rbits = 8;
|
rbits = 8;
|
||||||
gbits = 8;
|
gbits = 8;
|
||||||
bbits = 8;
|
bbits = 8;
|
||||||
@@ -815,6 +837,11 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
|
|||||||
ptr[poffset + 1] = temp;
|
ptr[poffset + 1] = temp;
|
||||||
temp = (unsigned char)((aDword & bmask) >> bshift);
|
temp = (unsigned char)((aDword & bmask) >> bshift);
|
||||||
ptr[poffset + 2] = temp;
|
ptr[poffset + 2] = temp;
|
||||||
|
if ( alpha )
|
||||||
|
{
|
||||||
|
temp = (unsigned char)((aDword & amask) >> ashift);
|
||||||
|
alpha[line * width + column] = temp;
|
||||||
|
}
|
||||||
column++;
|
column++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user