palettes
palettes
Color palette toolkit for pydisplay.
Provides named color sets, RGB/HSV wheels, RGB cubes, and Material Design swatches. Palettes map integer indices to display-ready color values at several bit depths (4, 8, 16, or 24).
Example
from palettes import get_palette palette = get_palette(name="wheel", length=256, saturation=1.0) palette[0] palette.color_name(0)
Attributes:
| Name | Type | Description |
|---|---|---|
WIN16 |
Mapping of |
MappedPalette(name, color_depth, swapped, color_map)
Bases: Palette
Palette backed by a flat RGB byte map.
Each color occupies three consecutive bytes (r, g, b) in
color_map. Subclasses such as :class:~palettes.material_design.MDPalette
supply a pre-built map and named-color attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional label stored in :attr: |
required | |
color_depth
|
Output format for :meth: |
required | |
swapped
|
Byte-swap 16-bit colors when |
required | |
color_map
|
|
required |
Palette(name='', color_depth=16, swapped=False, cached=False)
Indexed color palette with optional named color attributes.
Subclasses override :meth:_get_rgb to define how each index maps to
red, green, and blue components. :meth:__getitem__ converts those
components to the configured color_depth.
Named colors from the palette's name table (for example palette.RED)
are attached as attributes during initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional label stored in :attr: |
''
|
|
color_depth
|
Output format for :meth: |
16
|
|
swapped
|
If |
False
|
|
cached
|
If |
False
|
name
property
Human-readable palette label.
brightness(index)
Average channel brightness of the color at index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
Palette index. |
required |
Returns:
| Type | Description |
|---|---|
|
Normalized brightness in |
color332(r, g=None, b=None)
Convert RGB to an 8-bit RGB332 value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
Red component (0–255), a 24-bit |
required | |
g
|
Green component when |
None
|
|
b
|
Blue component when |
None
|
Returns:
| Type | Description |
|---|---|
|
8-bit RGB332 color. |
color565(r, g=None, b=None)
Convert RGB to a 16-bit RGB565 value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
Red component (0–255), a 24-bit |
required | |
g
|
Green component when |
None
|
|
b
|
Blue component when |
None
|
Returns:
| Type | Description |
|---|---|
|
16-bit color, optionally byte-swapped when |
color_name(index)
Return the name of the color at index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
Palette index (supports wrapping). |
required |
Returns:
| Type | Description |
|---|---|
|
A name from the palette name table, or a |
|
|
when no name matches. |
color_rgb(color)
Expand a packed color to an (r, g, b) tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
A 16-bit integer, or a 2- or 3-byte sequence in display byte order. |
required |
Returns:
| Type | Description |
|---|---|
|
|
luminance(index)
Perceived brightness of the color at index (ITU-R BT.601).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
Palette index. |
required |
Returns:
| Type | Description |
|---|---|
|
Luminance in |
rgb_name(r, g=None, b=None)
Look up a color name from RGB components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
Red (0–255), a 24-bit integer, or an |
required | |
g
|
Green when |
None
|
|
b
|
Blue when |
None
|
Returns:
| Type | Description |
|---|---|
|
Matching name from :attr: |
get_palette(name='default', **kwargs)
Construct a palette by logical name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Palette type. One of |
'default'
|
|
**kwargs
|
Forwarded to the palette constructor (for example
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
class: |
Example
get_palette(name="cube", size=3, color_depth=16)