palettes — functions
Palettes: the colours a thermal picture is drawn with.
Three things, and keeping them apart is most of understanding this module:
The built-ins. A closed set of seventeen tables compiled into the
library, named by the PALETTE_* constants here. all_palettes
lists them, colors reads one out, and
optris_sdk.Camera.palette applies one. A built-in survives a
configuration round-trip as a number, which is why it is the cheaper
path and the one to persist.
The library. Every palette on the machine: the CSV files the SDK
installs plus any an operator dropped into a palette directory, the way
they have with PIX Connect and SDK 11 for years. It is a list of
names, not a second enum -- a file cannot join a closed set.
library_names enumerates it, library_colors reads one,
and optris_sdk.Camera.set_palette_by_name applies one.
A table you built yourself. Any sequence of Color, handed
to optris_sdk.Camera.set_custom_palette. A file-backed palette
is applied through this same route, so there is no third way to
colorize a picture.
The gradient and the picture disagree about byte order
A palette entry is R-G-B. A colorized pixel in a frame's image is
B-G-R-A. Blitting a colour table straight into a BGRA surface
therefore draws the legend with red and blue swapped, which looks
entirely plausible and is wrong. Color is named rather than a
bare 3-tuple so that the mistake has somewhere to be noticed.
Reading the gradient out
import optris_sdk
for color in optris_sdk.palette_colors(optris_sdk.PALETTE_IRON_BOW):
print(color.r, color.g, color.b)
display_name(palette)
The human-readable name of a built-in palette.
For a menu or a label. Not an identifier: it is meant to be
read, it may be translated, and it is not what the library takes
back. library_names is where identifiers come from.
is_alarm(palette)
Whether this built-in is one of the alarm palettes.
all_palettes()
Every built-in palette, as a list of PALETTE_* values.
colors(palette)
The colours of a built-in palette, coldest first.
library_refresh()
Re-read the palette directories, and say how many there are now.
Not needed to get started -- the library builds itself on first use. Call it when a file may have been added while the program was running, such as an operator dropping a CSV in while your picker is open.
Never fails on a missing directory or a malformed file: both are skipped, the files either side of a bad one still load, and the built-ins are always present, so the library is never empty.
library_count()
How many palettes the machine has. Never zero.
library_names()
Every palette name on the machine, in sorted order.
These are identifiers -- each is the stem of the palette's file,
it is stable, and every other library call takes it back. Safe to
enumerate without locking: the library is rebuilt only by
library_refresh, so nothing changes it underneath you.
library_info(name)
What a named palette is, as a LibraryEntry.
Raises optris_sdk.errors.SdkError when there is no
palette by that name. Matching is exact and case-sensitive, like
the filenames it comes from.
library_file(name)
The file a named palette was read from.
For a log line or a tooltip answering "which of my palette directories is this one actually coming from".
Returns '' when the palette exists but no file was found for
it, which for a built-in means an incomplete installation. The
palette still works either way: the compiled table does not depend
on the file being there.
library_colors(name)
The colours of a named palette, coldest first.
For a built-in name these are the compiled table, so this and
colors can never disagree.
library_directories()
Every directory searched for palette files, in scan order.
The first is the SDK's own share directory. The rest are where an operator puts theirs, and among those the last to supply a name wins -- except that a file named after one of the SDK's own palettes outside the first directory is refused, with the reason logged, and the built-in kept.