quantize.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/quantize.h
  3. // Purpose: wxQuantizer class
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 22/6/2000
  7. // Copyright: (c) Julian Smart
  8. // Licence:
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_QUANTIZE_H_
  11. #define _WX_QUANTIZE_H_
  12. #include "wx/object.h"
  13. /*
  14. * From jquant2.c
  15. *
  16. * Copyright (C) 1991-1996, Thomas G. Lane.
  17. * This file is part of the Independent JPEG Group's software.
  18. * For conditions of distribution and use, see the accompanying README file.
  19. */
  20. class WXDLLIMPEXP_FWD_CORE wxImage;
  21. class WXDLLIMPEXP_FWD_CORE wxPalette;
  22. /*
  23. * wxQuantize
  24. * Based on the JPEG quantization code. Reduces the number of colours in a wxImage.
  25. */
  26. #define wxQUANTIZE_INCLUDE_WINDOWS_COLOURS 0x01
  27. #define wxQUANTIZE_RETURN_8BIT_DATA 0x02
  28. #define wxQUANTIZE_FILL_DESTINATION_IMAGE 0x04
  29. class WXDLLIMPEXP_CORE wxQuantize: public wxObject
  30. {
  31. public:
  32. DECLARE_DYNAMIC_CLASS(wxQuantize)
  33. //// Constructor
  34. wxQuantize() {}
  35. virtual ~wxQuantize() {}
  36. //// Operations
  37. // Reduce the colours in the source image and put the result into the
  38. // destination image. Both images may be the same, to overwrite the source image.
  39. // Specify an optional palette pointer to receive the resulting palette.
  40. // This palette may be passed to ConvertImageToBitmap, for example.
  41. // If you pass a palette pointer, you must free the palette yourself.
  42. static bool Quantize(const wxImage& src, wxImage& dest, wxPalette** pPalette, int desiredNoColours = 236,
  43. unsigned char** eightBitData = 0, int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE|wxQUANTIZE_RETURN_8BIT_DATA);
  44. // This version sets a palette in the destination image so you don't
  45. // have to manage it yourself.
  46. static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236,
  47. unsigned char** eightBitData = 0, int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE|wxQUANTIZE_RETURN_8BIT_DATA);
  48. //// Helpers
  49. // Converts input bitmap(s) into 8bit representation with custom palette
  50. // in_rows and out_rows are arrays [0..h-1] of pointer to rows
  51. // (in_rows contains w * 3 bytes per row, out_rows w bytes per row)
  52. // fills out_rows with indexes into palette (which is also stored into palette variable)
  53. static void DoQuantize(unsigned w, unsigned h, unsigned char **in_rows, unsigned char **out_rows, unsigned char *palette, int desiredNoColours);
  54. };
  55. #endif
  56. // _WX_QUANTIZE_H_