| Version: 3.3.1

Public Member Functions | List of all members
wxPalette Class Reference
Class List by Category » Graphics Device Interface (GDI)

`#include <wx/palette.h>`

Inheritance diagram for wxPalette:
[legend]

## Detailed Description

A palette is a table that maps pixel values to RGB colours.

It allows the colours of a low-depth bitmap, for example, to be mapped to the available colours in a display. The notion of palettes is becoming more and more obsolete nowadays and only the MSW port is still using a native palette. All other ports use generic code which is basically just an array of colours.

It is likely that in the future the only use for palettes within wxWidgets will be for representing colour indices from images (such as GIF or PNG). The image handlers for these formats have been modified to create a palette if there is such information in the original image file (usually 256 or less colour images). See wxImage for more information.

##

Library: wxCore
Category: Graphics Device Interface (GDI)

Predefined objects/pointers: wxNullPalette

See also
  wxDC::SetPalette(), wxBitmap

## Public Member Functions
| wxPalette ()
| Default constructor. More...
| wxPalette (const wxPalette &palette)
| Copy constructor, uses Reference Counting. More...
| wxPalette (int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
| Creates a palette from arrays of size n, one for each red, blue or green component. More...
bool | Create (int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
| Creates a palette from arrays of size n, one for each red, blue or green component. More...
virtual int | GetColoursCount () const
| Returns number of entries in palette. More...
int | GetPixel (unsigned char red, unsigned char green, unsigned char blue) const
| Returns a pixel value (index into the palette) for the given RGB values. More...
bool | GetRGB (int pixel, unsigned char *red, unsigned char *green, unsigned char *blue) const
| Returns RGB values for a given palette index. More...
virtual bool | IsOk () const
| Returns true if palette data is present. More...
wxPalette & | operator= (const wxPalette &palette)
| Assignment operator, using Reference Counting. More...
Public Member Functions inherited from wxGDIObject
| wxGDIObject ()
| Default constructor. More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to nullptr the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=nullptr, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...

## Additional Inherited Members
Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Constructor & Destructor Documentation

## ◆ wxPalette() [1/3]

wxPalette::wxPalette | ( |  | ) |

Default constructor.

## ◆ wxPalette() [2/3]

wxPalette::wxPalette | ( | const wxPalette & | palette | ) |

Copy constructor, uses Reference Counting.

Parameters

  palette | A reference to the palette to copy.

## ◆ wxPalette() [3/3]

wxPalette::wxPalette | ( | int | n,
|  | const unsigned char * | red,
|  | const unsigned char * | green,
|  | const unsigned char * | blue
| ) |  |

Creates a palette from arrays of size n, one for each red, blue or green component.

Parameters

  n | The number of indices in the palette.
  red | An array of red values.
  green | An array of green values.
  blue | An array of blue values.

wxPerl Note: In wxPerl this method takes as parameters 3 array references (they must be of the same length).

See also
  Create()

## Member Function Documentation

## ◆ Create()

bool wxPalette::Create | ( | int | n,
|  | const unsigned char * | red,
|  | const unsigned char * | green,
|  | const unsigned char * | blue
| ) |  |

Creates a palette from arrays of size n, one for each red, blue or green component.

Parameters

  n | The number of indices in the palette.
  red | An array of red values.
  green | An array of green values.
  blue | An array of blue values.

Returns
  true if the creation was successful, false otherwise.

See also
  wxPalette()

## ◆ GetColoursCount()

virtual int wxPalette::GetColoursCount | ( |  | ) | const
| virtual

Returns number of entries in palette.

## ◆ GetPixel()

int wxPalette::GetPixel | ( | unsigned char | red,
|  | unsigned char | green,
|  | unsigned char | blue
| ) |  | const

Returns a pixel value (index into the palette) for the given RGB values.

Parameters

  red | Red value.
  green | Green value.
  blue | Blue value.

Returns
  The nearest palette index or `wxNOT_FOUND` for unexpected errors.

See also
  GetRGB()

## ◆ GetRGB()

bool wxPalette::GetRGB | ( | int | pixel,
|  | unsigned char * | red,
|  | unsigned char * | green,
|  | unsigned char * | blue
| ) |  | const

Returns RGB values for a given palette index.

Parameters

  pixel | The palette index.
  red | Receives the red value.
  green | Receives the green value.
  blue | Receives the blue value.

Returns
  true if the operation was successful.

wxPerl Note: In wxPerl this method takes only the pixel parameter and returns a 3-element list (or the empty list upon failure).

See also
  GetPixel()

## ◆ IsOk()

virtual bool wxPalette::IsOk | ( |  | ) | const
| virtual

Returns true if palette data is present.

## ◆ operator=()

wxPalette& wxPalette::operator= | ( | const wxPalette & | palette | ) |

Assignment operator, using Reference Counting.