Add support for saving 32bpp icons too.
Save in 32bpp format if alpha channel is present in the image being saved in ICO format. See #15918. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76134 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -54,7 +54,7 @@ wxMSW:
|
|||||||
- Support multiline strings in wxDC::DrawRotatedText() (Artur Wieczorek).
|
- Support multiline strings in wxDC::DrawRotatedText() (Artur Wieczorek).
|
||||||
- Fix stretchable spacers in vertical toolbars (Artur Wieczorek).
|
- Fix stretchable spacers in vertical toolbars (Artur Wieczorek).
|
||||||
- Add wxEnhMetaFile::Detach() (Luca Bacci).
|
- Add wxEnhMetaFile::Detach() (Luca Bacci).
|
||||||
- Add support for saving 256*256 24bpp ICOs in PNG format (Artur Wieczorek).
|
- Add support for saving 256*256 32bpp ICOs in PNG format (Artur Wieczorek).
|
||||||
|
|
||||||
wxOSX/Cocoa:
|
wxOSX/Cocoa:
|
||||||
|
|
||||||
|
@@ -100,9 +100,13 @@ bool wxBMPHandler::SaveDib(wxImage *image,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the format of the BMP file to save, else use 24bpp
|
// For icons, save alpha channel if available.
|
||||||
|
const bool saveAlpha = !IsBmp && image->HasAlpha();
|
||||||
|
|
||||||
|
// get the format of the BMP file to save,
|
||||||
|
// else (and always if alpha channel is present) use 24bpp
|
||||||
unsigned format = wxBMP_24BPP;
|
unsigned format = wxBMP_24BPP;
|
||||||
if ( image->HasOption(wxIMAGE_OPTION_BMP_FORMAT) )
|
if ( image->HasOption(wxIMAGE_OPTION_BMP_FORMAT) && !saveAlpha )
|
||||||
format = image->GetOptionInt(wxIMAGE_OPTION_BMP_FORMAT);
|
format = image->GetOptionInt(wxIMAGE_OPTION_BMP_FORMAT);
|
||||||
|
|
||||||
wxUint16 bpp; // # of bits per pixel
|
wxUint16 bpp; // # of bits per pixel
|
||||||
@@ -138,10 +142,10 @@ bool wxBMPHandler::SaveDib(wxImage *image,
|
|||||||
bpp = 8;
|
bpp = 8;
|
||||||
palette_size = 256;
|
palette_size = 256;
|
||||||
}
|
}
|
||||||
else // you get 24bpp
|
else // you get 24bpp or 32bpp with alpha
|
||||||
{
|
{
|
||||||
format = wxBMP_24BPP;
|
format = wxBMP_24BPP;
|
||||||
bpp = 24;
|
bpp = saveAlpha ? 32 : 24;
|
||||||
palette_size = 0;
|
palette_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,12 +355,14 @@ bool wxBMPHandler::SaveDib(wxImage *image,
|
|||||||
|
|
||||||
// pointer to the image data, use quantized if available
|
// pointer to the image data, use quantized if available
|
||||||
wxUint8 *data = (wxUint8*) image->GetData();
|
wxUint8 *data = (wxUint8*) image->GetData();
|
||||||
|
const unsigned char* const alpha = saveAlpha ? image->GetAlpha() : NULL;
|
||||||
if (q_image) if (q_image->IsOk()) data = (wxUint8*) q_image->GetData();
|
if (q_image) if (q_image->IsOk()) data = (wxUint8*) q_image->GetData();
|
||||||
|
|
||||||
wxUint8 *buffer = new wxUint8[row_width];
|
wxUint8 *buffer = new wxUint8[row_width];
|
||||||
memset(buffer, 0, row_width);
|
memset(buffer, 0, row_width);
|
||||||
int y; unsigned x;
|
int y; unsigned x;
|
||||||
long int pixel;
|
long int pixel;
|
||||||
|
const int dstPixLen = saveAlpha ? 4 : 3;
|
||||||
|
|
||||||
for (y = image->GetHeight() -1; y >= 0; y--)
|
for (y = image->GetHeight() -1; y >= 0; y--)
|
||||||
{
|
{
|
||||||
@@ -366,9 +372,11 @@ bool wxBMPHandler::SaveDib(wxImage *image,
|
|||||||
{
|
{
|
||||||
pixel = 3*(y*width + x);
|
pixel = 3*(y*width + x);
|
||||||
|
|
||||||
buffer[3*x ] = data[pixel+2];
|
buffer[dstPixLen*x ] = data[pixel+2];
|
||||||
buffer[3*x + 1] = data[pixel+1];
|
buffer[dstPixLen*x + 1] = data[pixel+1];
|
||||||
buffer[3*x + 2] = data[pixel];
|
buffer[dstPixLen*x + 2] = data[pixel];
|
||||||
|
if ( saveAlpha )
|
||||||
|
buffer[dstPixLen*x + 3] = alpha[y*width + x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((format == wxBMP_8BPP) || // 1 byte per pixel in color
|
else if ((format == wxBMP_8BPP) || // 1 byte per pixel in color
|
||||||
@@ -1281,7 +1289,13 @@ bool wxICOHandler::SaveFile(wxImage *image,
|
|||||||
const int colours = image->CountColours(257);
|
const int colours = image->CountColours(257);
|
||||||
int bppFormat;
|
int bppFormat;
|
||||||
int bpp;
|
int bpp;
|
||||||
if ( colours > 256 )
|
if ( image->HasAlpha() )
|
||||||
|
{
|
||||||
|
// Icons with alpha channel are always stored in ARGB format.
|
||||||
|
bppFormat = wxBMP_24BPP;
|
||||||
|
bpp = 32;
|
||||||
|
}
|
||||||
|
else if ( colours > 256 )
|
||||||
{
|
{
|
||||||
bppFormat = wxBMP_24BPP;
|
bppFormat = wxBMP_24BPP;
|
||||||
bpp = 24;
|
bpp = 24;
|
||||||
|
Reference in New Issue
Block a user