diff --git a/include/wx/quantize.h b/include/wx/quantize.h index dd50cf7102..592718e431 100644 --- a/include/wx/quantize.h +++ b/include/wx/quantize.h @@ -55,6 +55,12 @@ DECLARE_DYNAMIC_CLASS(wxQuantize) static bool Quantize(const wxImage& src, wxImage& dest, wxPalette** pPalette = NULL, int desiredNoColours = 236, unsigned char** eightBitData = 0, int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE|wxQUANTIZE_RETURN_8BIT_DATA); + // This version sets a palette in the destination image so you don't + // have to manage it yourself. + + static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236, + unsigned char** eightBitData = 0, int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE|wxQUANTIZE_RETURN_8BIT_DATA); + //// Helpers // Converts input bitmap(s) into 8bit representation with custom palette diff --git a/src/common/quantize.cpp b/src/common/quantize.cpp index 5f579ba9ef..331a620edd 100644 --- a/src/common/quantize.cpp +++ b/src/common/quantize.cpp @@ -1562,3 +1562,23 @@ bool wxQuantize::Quantize(const wxImage& src, wxImage& dest, wxPalette** pPalett return TRUE; } +// This version sets a palette in the destination image so you don't +// have to manage it yourself. + +bool wxQuantize::Quantize(const wxImage& src, wxImage& dest, int desiredNoColours, + unsigned char** eightBitData, int flags) +{ + wxPalette* palette = NULL; + if (Quantize(src, dest, & palette, desiredNoColours, eightBitData, flags)) + { + if (palette) + { + dest.SetPalette(* palette); + delete palette; + } + return TRUE; + } + else + return FALSE; +} +