OptrisOptrisDocumentation

Documentation/OTC SDK/Overviewv12.0

Custom Palettes

The shape a palette has to be, setting one, what is rejected and why, saving and loading one, and the legacy Sdk API that does the same thing.

The palette chapter is four pages, each answering one question:

Page Question
Colour Palettes Which palettes are there, how do I set one, and how do I read its colours?
Colour Range Which temperatures do the colours span, and how is that chosen for me?
Custom Palettes How do I supply a palette of my own?
The Palette Library Where does the SDK look for palette files on this machine?

On this page

Supplying Your Own Palette

A palette does not have to be one of the seventeen. An application can hand a camera 240 colours of its own and they are used for the picture from the next frame on.

The shape of it, and why

A custom palette is a value you hand over, not an entry in a registry. There is nothing to register, no name to look up, no handle to keep alive and nothing that outlives the camera you gave it to. Two cameras in the same program can be using two different custom palettes at the same time, and neither can see or overwrite the other's. Nothing is visible to another process.

That falls out of one decision. Palette is an enum, and a palette you invent has no enum value; the alternative was a registry keyed by name, which is what the legacy API had. The registry answers "what happens when a saved file names a palette the reader never registered?" with a rule someone eventually gets wrong. Handing the colours over as a value means the question cannot arise: the colours travel with the configuration, so a program reading it back has them whether or not it has ever heard of the palette.

Setting one

#include <optrissdk.h>

optris::sdk::CustomPalette palette;
palette.name = "Furnace";
palette.colors.resize(optris::sdk::kPaletteColorCount);   // 240
// ... fill in colors[i].r / .g / .b, coldest first ...

imager->SetCustomPalette(palette);

The colours are copied, so the CustomPalette does not have to outlive the call.

Going back to a built-in

imager->ClearCustomPalette();          // back to what GetPalette() reports
imager->SetPalette(Palette::kJet);     // or just choose one; same effect

Setting a built-in palette clears any custom one, so there is no separate step to forget.

What GetPalette() reports

GetPalette() is unchanged and keeps reporting the built-in selection, the one ClearCustomPalette() would return to. It is not affected by a custom palette being in force. Ask GetCustomPalette() which palette is actually on screen:

if (auto custom = imager->GetCustomPalette()) {
  draw_legend(custom->name, custom->colors);
} else {
  const auto p = imager->GetPalette();
  draw_legend(GetPaletteDisplayName(p), GetPaletteColors(p));
}

The colours read back the same way the built-in ones do, so a legend, a slider gradient or a colour-coded readout is drawn from one code path either way.

GetAllPalettes() and Palettes.All

Built-in palettes only, always. A custom palette belongs to the camera it was given to, not to the process, so there is no list of them for a free function or a static class to return. A palette picker built from GetAllPalettes() shows the seventeen; whatever custom palettes an application offers are its own to list, because it is the one that has them.

What is rejected

SetCustomPalette() throws ConfigException rather than drawing something wrong:

Rejected Why
An empty name It is what a legend caption and the saved configuration use.
Anything other than 240 colours Including an empty table. 256 is the usual wrong guess; that is the GPU lookup table, not a palette.
A table where all 240 entries are the same colour Not a palette. It draws a blank legend and a flat picture, and it is what a zeroed or misparsed buffer looks like.

A palette with two colours is fine: a threshold palette is a reasonable thing to want, and the alarm palettes are nearly flat on purpose. The bar is at exactly one colour, not at "looks flat".

To test rather than catch:

const auto verdict = ValidateCustomPalette(palette);
if (verdict != PaletteValidation::kOk) {
  show_error(DescribePaletteValidation(verdict));
}

Saving and loading

A custom palette is saved and restored by SaveConfig() / LoadConfig() with the rest of the camera's configuration. The colours go into the file, not a name for them, so a program that reads the file back draws the right picture whether or not it has ever seen this palette.

If the saved table cannot be read (a truncated or edited file), it is dropped with a warning and the built-in palette field applies. Loading a configuration does not fail over its colour scheme, and it never falls back to a half-read table. Likewise a palette value this version does not know, which a file from a later version could carry, is refused and the current selection is kept.

A recording and a snapshot record how the picture was coloured. They store temperatures, so a viewer is free to colour them however it likes; alongside that they record how the picture was coloured, so a reader can reproduce it or put a legend beside it. The field is rec::RenderMeta::palette, and it holds what GetPaletteName() returns ("Iron", "GrayBW") or the literal "custom" when the application had supplied its own colours, with the name it gave them in palette_name. A recording carries the block twice: once for the file as it opened, and again per frame on the frames where the file-level value would be wrong, because the palette can be switched while a recording runs.

A recording also carries a custom palette's 240 entries; a snapshot does not need to. In a recording they are written once for the file, in otc-meta.json under palette_colors, as 240 "#rrggbb" strings, about 2.4 KB. Not per frame: that would be 720 bytes beside every one of them. Playback opens such a recording in those colours, so GetCustomPalette() on a Player gives your palette straight back, and so does any other reader. A snapshot has no need of them, because a colour snapshot already is the picture drawn with them.

The colours a recording carries are the ones in force when the file opened (a segmented recording carries its own per segment) because a Matroska header is written as the file opens and cannot be added to afterwards. If you change your palette while recording, change its name too: that is what makes the change visible to a reader, and two palettes sharing one name cannot be told apart in the file.

A recording written before 2026-09-29 carries no colours at all. A reader that meets one, or a damaged table, should draw with a palette of its own and say that it did. The colour scale is recorded exactly in every case, so the numbers on a legend are right regardless.

Loading one from a CSV file

The SDK's own palettes ship as CSV files, and that is the format the legacy Sdk::loadPalettes() read: 240 lines of R,G,B, coldest first. A directory of palettes from a v11 installation loads unchanged:

optris::sdk::CustomPalette palette =
    optris::sdk::LoadPaletteCsv("/etc/optris/palettes/Furnace.csv");
imager->SetCustomPalette(palette);

The palette's name is the file's stem, so Furnace.csv loads as "Furnace". Blank lines and lines starting with # are skipped.

SavePaletteCsv(palette, path) writes one back in the same format.

These are plain functions over a file: you name the file, you get a palette, nothing is registered anywhere. If what you want instead is "whatever the operator put in the palette folder", see The Palette Library; that is the part that scans.

LoadPaletteCsv throws IoException if the file cannot be read and ConfigException if its contents are not a palette, naming the line at fault; a parse error in a 240-line file is not much use without one.

From C

optris_sdk_rgb24 colors[OPTRIS_SDK_PALETTE_COLOR_COUNT];
/* ... fill in ... */

optris_sdk_imager_set_custom_palette(imager, "Furnace", colors,
                                     OPTRIS_SDK_PALETTE_COLOR_COUNT);

optris_sdk_imager_clear_custom_palette(), optris_sdk_imager_get_custom_palette_name() and optris_sdk_imager_read_custom_palette_colors() complete the set. The two readers return OPTRIS_SDK_ERROR_NOT_FOUND when a built-in palette is in force; that is the routine answer, not a failure. A table the SDK will not take comes back as OPTRIS_SDK_ERROR_CONFIGURATION with the reason in optris_sdk_last_error_message().

From C#

var colors = new Rgb24[Palettes.ColorCount];
// ... fill in ...

camera.SetCustomPalette(new CustomPalette("Furnace", colors));

CustomPalette? inForce = camera.CustomPalette;   // null when a built-in is
camera.ClearCustomPalette();

ThermalCamera.Palette is unchanged and still takes only the enum. A custom palette arrives through SetCustomPalette instead, so the property keeps its meaning and a picker bound to it does not have to model a value it cannot represent.

From Python

import optris_sdk

span = optris_sdk.PALETTE_COLOR_COUNT - 1
table = [optris_sdk.Color(i * 255 // span, 0, 255 - i * 255 // span)
         for i in range(optris_sdk.PALETTE_COLOR_COUNT)]

with optris_sdk.Camera.simulated() as camera:
  camera.palette = optris_sdk.PALETTE_MEDICAL
  camera.set_custom_palette('Furnace', table)

  assert camera.custom_palette_name == 'Furnace'
  assert camera.custom_palette_colors() == table
  # The built-in selection is overridden, not replaced:
  assert camera.palette == optris_sdk.PALETTE_MEDICAL

  camera.clear_custom_palette()
  assert camera.custom_palette_name == ''

camera.palette keeps its meaning and still takes only a built-in, exactly as in C#. Plain (r, g, b) tuples are accepted as well as Color.

The length is fixed at optris_sdk.PALETTE_COLOR_COUNT, which is 240, and the binding refuses any other length itself, naming both the required count and the one you passed, which the SDK's own error does not. A table whose every entry is the same colour is refused too, by the SDK.

Where C# returns null for "no custom palette", Python returns 'fromcustom_palette_nameand[]fromcustom_palette_colors(). The C ABI reports that case asNOT_FOUND`; the binding translates the absence and nothing else, so any other failure still raises.

From Rust

let span = 239u32;
let table: Vec<Rgb24> = (0..240u32)
    .map(|i| Rgb24 {
        r: (i * 255 / span) as u8,
        g: 0,
        b: (255 - i * 255 / span) as u8,
    })
    .collect();

camera.set_custom_palette("Furnace", &table)?;

// Some while a custom palette is in force, None when a built-in is.
let in_force = camera.custom_palette_name()?;
let colors = camera.custom_palette_colors()?;

camera.clear_custom_palette()?;

camera.palette() keeps its meaning and still reports the built-in selection, exactly as in C# and Python. Where C# returns null and Python returns ', Rust returnsNone; the C ABI'sNOT_FOUNDis translated into the absence and nothing else, so any other failure is still anErr`.

Custom Palettes (legacy Sdk API)

Legacy. This is the v11 route, kept for existing code. New code should use Supplying Your Own Palette above, which needs no registry, no loadPalettes() call at startup, and no shared process-wide state.

The optris::Sdk class provides a file-based palette registry that sits alongside the built-in Palette enum. Each palette is a CSV file of 240 RGB entries. Custom palettes extend or override the built-ins and are available in all three language bindings (C++, Python, C#).

It is a different header and a different namespace. Sdk is optris::Sdk, not optris::sdk::Sdk, and it comes from the legacy header tree rather than from optris/sdk.h:

#include "otcsdk/Sdk.h"

The header is installed beside optris/, so it is on the include path of any project that links the SDK; nothing extra has to be configured to reach it. Everything in this section needs that include; nothing in the rest of this page does.

Loading palettes

// Load built-in SDK palettes and any user palettes in the default directories.
// Call once at startup, before accessing palette names or colors.
optris::Sdk::loadPalettes();

// Load palettes from a custom directory (additive, does not clear existing).
optris::Sdk::loadPalettes("/path/to/my/palettes");

On Windows, loadPalettes(directory) reads its string in the ANSI code page, as version 11 did. A folder whose name that code page cannot hold (a Chinese or Cyrillic name on a Western system) cannot be named through it, and "Müller" written in UTF-8 names a different folder. loadPalettesUtf8() takes the path as UTF-8 and reaches any folder; on Linux the two are the same. The same pair exists for the data directory (setCustomDataDirectoryUtf8()) and the calibration source directory (setCalibrationFileSourceDirectoryUtf8()).

// "Müller" as UTF-8 bytes, so it does not depend on the compiler's
// source encoding.
optris::Sdk::loadPalettesUtf8("C:\\Users\\M\xC3\xBCller\\palettes");

From Python, always use the Utf8 functions for a folder that is not plain English: a Python string reaches the SDK as UTF-8, which the narrow functions read in the ANSI code page. From C#, the Utf8 functions receive the string as UTF-8 and the narrow ones in the ANSI code page, so only the Utf8 ones reach a folder that code page cannot hold.

After loadPalettes(), use getPaletteNames() to list everything that was found:

for (const auto& name : optris::Sdk::getPaletteNames()) {
  std::println("  {}", name);
}

Reading palette colors

// Returns 240 RGB triples: each entry is { R, G, B }.
auto colors = optris::Sdk::getPaletteColors("Iron");
// colors[0][0] = red channel of the first entry, etc.

Throws SDKException if the palette name is not found.

Registering a palette at runtime

// Build 240 RGB entries programmatically.
std::vector<std::array<uint8_t, 3>> colors(240);
for (int i = 0; i < 240; ++i) {
  colors[i] = {static_cast<uint8_t>(i), 0, 0}; // red ramp
}

// Register without writing to disk.
optris::Sdk::registerPalette("MyRed", colors);

Throws SDKException if colors does not contain exactly 240 entries.

Saving a palette to disk

// Writes <name>.csv to the user palette directory. The palette must
// already be registered -- savePalette() does not register it.
optris::Sdk::savePalette("MyRed");

The user palette directory is ~/.config/optris/palettes/ on Linux and APPDATA%\Imager\palettes\ on Windows, the same User folder the palette library scans. It is not created for you: saving into a directory that does not exist fails. Throws SDKException if the palette is not registered or the file cannot be written.

Python example

import otcsdk

otcsdk.Sdk.loadPalettes()
print(otcsdk.Sdk.getPaletteNames())

colors = otcsdk.Sdk.getPaletteColors("Iron")
# colors is a list of 240 [R, G, B] lists

custom = [[i, 0, 0] for i in range(240)]
otcsdk.Sdk.registerPalette("MyRed", custom)
otcsdk.Sdk.savePalette("MyRed")

C# example

using Optris.OtcSdk;

Sdk.loadPalettes();
foreach (var name in Sdk.getPaletteNames()) {
  Console.WriteLine(name);
}

RgbColorVector colors = Sdk.getPaletteColors("Iron");
// colors holds 240 RgbColor entries, each three bytes

var custom = new RgbColorVector();
for (int i = 0; i < 240; ++i) {
  custom.Add(new RgbColor(new byte[] { (byte)i, 0, 0 }));
}
Sdk.registerPalette("MyRed", custom);
Sdk.savePalette("MyRed");

The legacy binding is generated by SWIG, so the method names keep their C++ spelling and the collection types are the generated RgbColorVector and RgbColor, not List<byte[]>.