palette.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: palette.h
  3. // Purpose: interface of wxPalette
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxPalette
  9. A palette is a table that maps pixel values to RGB colours. It allows the
  10. colours of a low-depth bitmap, for example, to be mapped to the available
  11. colours in a display. The notion of palettes is becoming more and more
  12. obsolete nowadays and only the MSW port is still using a native palette.
  13. All other ports use generic code which is basically just an array of
  14. colours.
  15. It is likely that in the future the only use for palettes within wxWidgets
  16. will be for representing colour indices from images (such as GIF or PNG).
  17. The image handlers for these formats have been modified to create a palette
  18. if there is such information in the original image file (usually 256 or less
  19. colour images). See wxImage for more information.
  20. @library{wxcore}
  21. @category{gdi}
  22. @stdobjects
  23. ::wxNullPalette
  24. @see wxDC::SetPalette(), wxBitmap
  25. */
  26. class wxPalette : public wxGDIObject
  27. {
  28. public:
  29. /**
  30. Default constructor.
  31. */
  32. wxPalette();
  33. /**
  34. Copy constructor, uses @ref overview_refcount.
  35. @param palette
  36. A reference to the palette to copy.
  37. */
  38. wxPalette(const wxPalette& palette);
  39. /**
  40. Creates a palette from arrays of size @a n, one for each red, blue or
  41. green component.
  42. @param n
  43. The number of indices in the palette.
  44. @param red
  45. An array of red values.
  46. @param green
  47. An array of green values.
  48. @param blue
  49. An array of blue values.
  50. @beginWxPerlOnly
  51. In wxPerl this method takes as parameters
  52. 3 array references (they must be of the same length).
  53. @endWxPerlOnly
  54. @see Create()
  55. */
  56. wxPalette(int n, const unsigned char* red,
  57. const unsigned char* green,
  58. const unsigned char* blue);
  59. /**
  60. Destructor.
  61. @see @ref overview_refcount_destruct "reference-counted object destruction"
  62. */
  63. virtual ~wxPalette();
  64. /**
  65. Creates a palette from arrays of size @a n, one for each red, blue or
  66. green component.
  67. @param n
  68. The number of indices in the palette.
  69. @param red
  70. An array of red values.
  71. @param green
  72. An array of green values.
  73. @param blue
  74. An array of blue values.
  75. @return @true if the creation was successful, @false otherwise.
  76. @see wxPalette()
  77. */
  78. bool Create(int n, const unsigned char* red,
  79. const unsigned char* green,
  80. const unsigned char* blue);
  81. /**
  82. Returns number of entries in palette.
  83. */
  84. virtual int GetColoursCount() const;
  85. /**
  86. Returns a pixel value (index into the palette) for the given RGB values.
  87. @param red
  88. Red value.
  89. @param green
  90. Green value.
  91. @param blue
  92. Blue value.
  93. @return The nearest palette index or @c wxNOT_FOUND for unexpected errors.
  94. @see GetRGB()
  95. */
  96. int GetPixel(unsigned char red, unsigned char green,
  97. unsigned char blue) const;
  98. /**
  99. Returns RGB values for a given palette index.
  100. @param pixel
  101. The palette index.
  102. @param red
  103. Receives the red value.
  104. @param green
  105. Receives the green value.
  106. @param blue
  107. Receives the blue value.
  108. @return @true if the operation was successful.
  109. @beginWxPerlOnly
  110. In wxPerl this method takes only the @a pixel parameter and
  111. returns a 3-element list (or the empty list upon failure).
  112. @endWxPerlOnly
  113. @see GetPixel()
  114. */
  115. bool GetRGB(int pixel, unsigned char* red, unsigned char* green,
  116. unsigned char* blue) const;
  117. /**
  118. Returns @true if palette data is present.
  119. */
  120. virtual bool IsOk() const;
  121. /**
  122. Assignment operator, using @ref overview_refcount.
  123. */
  124. wxPalette& operator =(const wxPalette& palette);
  125. };
  126. /**
  127. An empty palette.
  128. */
  129. wxPalette wxNullPalette;