Phoenix Logo

phoenix_title wx.Palette

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 wx.Image for more information.


class_hierarchy Class Hierarchy

Inheritance diagram for class Palette:


method_summary Methods Summary

__init__ Default constructor.
Create Creates a palette from 3 sequences of integers, one for each red, blue or green component.
GetColoursCount Returns number of entries in palette.
GetPixel Returns a pixel value (index into the palette) for the given RGB values.
GetRGB Returns RGB values for a given palette index.
IsOk Returns True if palette data is present.

property_summary Properties Summary

ColoursCount See GetColoursCount
RGB See GetRGB

api Class API



class wx.Palette(GDIObject)

Possible constructors:

Palette()

Palette(palette)

Palette(red, green, blue)

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


Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default constructor.



__init__ (self, palette)

Copy constructor, uses Reference Counting.

Parameters:palette (wx.Palette) – A reference to the palette to copy.



__init__ (self, red, green, blue)

Creates a palette from a set of sequences of integers, one for each red, green and blue color components.

Parameters:
  • red – A sequence of integer values in the range 0..255 inclusive.
  • green – A sequence of integer values in the range 0..255 inclusive.
  • blue – A sequence of integer values in the range 0..255 inclusive.

Note

All sequences must be the same length.





Create(self, red, green, blue)

Creates a palette from 3 sequences of integers, one for each red, blue or green component.

Parameters:
  • red – A sequence of integer values in the range 0..255 inclusive.
  • green – A sequence of integer values in the range 0..255 inclusive.
  • blue – A sequence of integer values in the range 0..255 inclusive.

Note

All sequences must be the same length.

Return type:bool


GetColoursCount(self)

Returns number of entries in palette.

Return type:int


GetPixel(self, red, green, blue)

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

Parameters:
  • red (int) – Red value.
  • green (int) – Green value.
  • blue (int) – Blue value.
Return type:

int

Returns:

The nearest palette index or NOT_FOUND for unexpected errors.

See also

GetRGB



GetRGB(self, pixel)

Returns RGB values for a given palette index.

Return type:tuple
Returns:( red, green, blue )


IsOk(self)

Returns True if palette data is present.

Return type:bool

Properties



ColoursCount

See GetColoursCount



RGB

See GetRGB