diff --git a/src/common/imagpng.cpp b/src/common/imagpng.cpp index f2f625c40e..f5f0d82924 100644 --- a/src/common/imagpng.cpp +++ b/src/common/imagpng.cpp @@ -772,12 +772,16 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos } #else bool bUsePalette = false; +#endif // wxUSE_PALETTE - if (iColorType == wxPNG_TYPE_PALETTE) + /* + If saving palettised was requested but it was decided we can't use a + palette then reset the colour type to RGB. + */ + if (!bUsePalette && iColorType == wxPNG_TYPE_PALETTE) { iColorType = wxPNG_TYPE_COLOUR; } -#endif // wxUSE_PALETTE bool bUseAlpha = !bUsePalette && (bHasAlpha || bHasMask); diff --git a/tests/image/image.cpp b/tests/image/image.cpp index 53d9243199..8d7dae6ce1 100644 --- a/tests/image/image.cpp +++ b/tests/image/image.cpp @@ -1038,6 +1038,14 @@ void ImageTestCase::CompareSavedImage() } } + /* + Explicitly make known we want a palettised PNG. If we don't then this + particular image gets saved as a true colour image because there's an + alpha channel present and the PNG saver prefers to keep the alpha over + saving as a palettised image that has alpha converted to a mask. + */ + expected8.SetOption(wxIMAGE_OPTION_PNG_FORMAT, wxPNG_TYPE_PALETTE); + /* The image contains 256 indexed colours and needs another palette entry for storing the transparency index. This results in wanting 257 palette @@ -1066,13 +1074,6 @@ void ImageTestCase::CompareSavedImage() red[paletteCount-2], green[paletteCount-2], blue[paletteCount-2]); expected8.SetPalette(newPal); - /* - Explicitly make known we want a palettised PNG. If we don't then this - particular image gets saved as a true colour image because there's an - alpha channel present and the PNG saver prefers to keep the alpha over - saving as a palettised image that has alpha converted to a mask. - */ - expected8.SetOption(wxIMAGE_OPTION_PNG_FORMAT, wxPNG_TYPE_PALETTE); wxImage ref8 = expected8;