OptrisOptrisDocumentation

Documentation/OTC SDK/Overviewv12.0

Colour Palettes

Which palettes ship, how to set one, and how to read the colours back in each language. A palette changes nothing a region measures; it decides only what the picture looks like.

In Fahrenheit: with the SDK switched to Fahrenheit (SetTemperatureUnit() and its counterparts, see Temperatures in Fahrenheit), every temperature on this page is read and written in Fahrenheit, and every difference in Fahrenheit degrees; the samples are unchanged.

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

Overview

Color palettes map temperature values to colors in the RGBA output frames. The SDK has 17 built-in palettes as entries in the optris::sdk::Palette enum. Palette selection and color range are set directly on the Imager (or a Player) via SetPalette() and SetColorRange().

When you register an RGBA callback via SetBgraCallback(), the SDK delivers each frame colorized with the active palette as a BGRA8 image. On a camera the processing pipeline, GPU or CPU, does the colorizing; both use the same palette tables and the same color range.

An application can also supply a palette of its own. See Supplying Your Own Palette.

Warning: There are two types called Palette, and everything on this page means the first one. - optris::sdk::Palette, declared in optris/sdk/imager_config.h and reached through optris/sdk/palette.h. Seventeen enumerators, all spelled with a k prefix: kIronBow, kGrayscaleBW. This is what SetPalette() takes and what everything below refers to. - optris::sdk::view::Palette, declared in optris/sdk/view/palette.h. Sixteen enumerators, spelled without a prefix: Iron, GrayscaleBW. It belongs to the view layer, which is a lower layer with a namespace of its own; it is installed and exported, so it will appear in your editor's completion list next to the other one.

They are not the same numbering, and the difference starts at the second entry. This one runs kIronBow, kGrayscale, kRainbow, kIronHi, kRainbowHi, kGrayscaleBW, …; the view enum runs Iron, IronHi, Rainbow, RainbowHi, GrayscaleBW, …, because it has no counterpart to kGrayscale, the second name for kGrayscaleBW. So Palette::kIronHi is 3 while 3 in the view enum is RainbowHi, kGrayscaleBW is 5 while GrayscaleBW is 4, and kLava is 16, a value the view enum has no member for at all. Casting between them by integer value silently selects a different palette, or none. There is no conversion function in the public API; select with the enumerator, never with a number.

A third spelling exists on disk. view::PaletteToString() writes "GrayscaleBW", while what goes into a recording, a snapshot and a palette filename is GetPaletteName()'s "GrayBW". See Names and grouping below.

Available Palettes

The optris::sdk::Palette enum defines all 17 palettes, in this order; the enumerator values are 0 to 16 as listed:

Enum Value Display name Library name Description
kIronBow Iron Bow Iron Classic iron/fire gradient. Default palette.
kGrayscale Grayscale GrayBW The same table as kGrayscaleBW, under a second name.
kRainbow Rainbow Rainbow Full-spectrum rainbow.
kIronHi Iron Bow High Contrast IronHi High-contrast iron palette.
kRainbowHi Rainbow High Contrast RainbowHi High-contrast rainbow.
kGrayscaleBW Grayscale Black to White GrayBW Grayscale, black (cold) to white (hot).
kGrayscaleWB Grayscale White to Black GrayWB Grayscale, white (cold) to black (hot).
kMedical Medical Medical Medical imaging palette.
kAlarmBlue Alarm Blue AlarmBlue Blue gradient alarm palette.
kAlarmBlueHi Alarm Blue High Contrast AlarmBlueHi High-contrast blue alarm palette.
kAlarmGreen Alarm Green AlarmGreen Green gradient alarm palette.
kAlarmRed Alarm Red AlarmRed Red gradient alarm palette.
kJet Jet Jet Jet colormap (blue to red).
kHot Hot Hot Hot colormap (black to white through red/yellow).
kPlasma Plasma Plasma Perceptually uniform purple-to-yellow.
kArctic Arctic Arctic Pale cyan (cold) to deep blue (hot).
kLava Lava Lava Black through red and orange to bright yellow.

The display name is what GetPaletteDisplayName() returns, for a caption or a drop-down. The library name is what GetPaletteName() returns and the stem of the palette's CSV file; that is the name the palette library lists it under and the one GetPalette("Iron") takes.

Setting a Palette

Set the active palette on the Imager, and read it back:

imager->SetPalette(optris::sdk::Palette::kIronBow);

auto current = imager->GetPalette();

The palette takes effect immediately. The next RGBA frame delivered to SetBgraCallback() uses the new palette. In Python it is a property on the camera rather than a getter-setter pair.

Reading a Palette's Colors

Setting a palette tells the SDK how to color the picture. Reading one goes the other way: it hands back the colors so an application can draw the palette itself: the gradient strip on a temperature slider, the legend beside a camera, or a readout colored by where its value sits in the range.

#include <optrissdk.h>

Span<const Rgb24> colors = GetPaletteColors(Palette::kJet);
// colors.size() == 240, coldest first.
// colors[0].r, colors[0].g, colors[0].b

This needs no camera and no loadPalettes() call. A palette is a fixed table compiled into the SDK, so a palette picker can be drawn before anything is connected.

Every value of the Palette enum returns a full table, whether or not a palette CSV file is installed on the machine. An application does not have to find and parse the shipped palettes/*.csv files to draw a legend.

kGrayscale and kGrayscaleBW return the same table. They are one palette under two names, and the renderer already treats them as one, which is why the SDK ships sixteen CSV files for seventeen enum values.

The span points at storage with static lifetime that is never modified, so it stays valid for the life of the process and there is nothing to free.

How many entries

240, for every palette. kPaletteColorCount says so, but prefer GetPaletteColors(p).size(); the point of returning a span is that a caller never has to assume a length.

240 rather than 256 is not an accident: it is what the CSV files hold, what the compiled-in tables hold, and what the legacy Sdk::getPaletteColors returns. The renderer resamples to 256 when it builds a GPU lookup table, but that is a detail of colorizing and not the shape of a palette.

Names and grouping

std::string_view name = GetPaletteDisplayName(Palette::kIronBow);  // "Iron Bow"
std::string_view id = GetPaletteName(Palette::kIronBow);           // "Iron"
bool grouped_apart = IsAlarmPalette(Palette::kAlarmRed);           // true
Span<const Palette> all = GetAllPalettes();                        // all 17

GetPaletteDisplayName() is for a caption or a drop-down entry. It is not an identifier; do not parse it and do not persist it. Persist the enum value.

GetPaletteName() is the other one: the stem of the palette's CSV file, stable, and the name the palette library and FindPalette() know it by. kGrayscale and kGrayscaleBW are one palette under two enum values and both return "GrayBW".

IsAlarmPalette() is true for kAlarmBlue, kAlarmBlueHi, kAlarmGreen and kAlarmRed. An alarm palette holds most of its range in one flat color and spends the rest on a narrow band at the top, so it shows that a threshold was crossed rather than the shape of a scene. A user interface usually wants them grouped apart from the measuring palettes for that reason.

GetAllPalettes() exists so a picker can be built without a hard-coded list that goes stale when a palette is added.

From C

#include <optris/sdk_c.h>

optris_sdk_rgb24 colors[OPTRIS_SDK_PALETTE_COLOR_COUNT];
size_t count;

optris_sdk_palette_read_colors(OPTRIS_SDK_PALETTE_JET, colors,
                               OPTRIS_SDK_PALETTE_COLOR_COUNT, &count);

Passing NULL for the buffer is a count query, like every other array getter in the C header. optris_sdk_palette_get_display_name(), optris_sdk_palette_is_alarm() and optris_sdk_palette_read_all() complete the set.

From C#

ReadOnlyMemory<Rgb24> colors = Palettes.GetColors(Palette.Jet);
string name = Palettes.GetDisplayName(Palette.Jet);   // "Jet"
bool isAlarm = Palettes.IsAlarm(Palette.AlarmRed);    // true

foreach (Palette p in Palettes.All) { /* build a picker */ }

Rgb24 is three bytes with no padding, so the memory is byte-for-byte an RGB image one pixel high and can go straight to a texture upload or a bitmap constructor. The table is cached after the first call, so repainting a legend every frame costs nothing.

From Python

import optris_sdk

colors = optris_sdk.palette_colors(optris_sdk.PALETTE_JET)
name = optris_sdk.palette_display_name(optris_sdk.PALETTE_JET)
is_alarm = optris_sdk.palette_is_alarm(optris_sdk.PALETTE_ALARM_RED)

for palette in optris_sdk.all_palettes():
  print(optris_sdk.palette_display_name(palette))

colors is a list of optris_sdk.Color, a named triple of r, g and b. It is named rather than a plain tuple on purpose: a colorized frame is BGRA, so blitting a palette table straight into one draws the legend with red and blue swapped, which looks plausible and is wrong.

The two-call buffer pattern of the C header does not appear here. The binding issues both calls and returns a list.

This is the v12 binding, optris_sdk. The otcsdk examples later on this page are the legacy v11 SWIG package, which is a different API and unrelated to these.

From Rust

let colors = Palette::Jet.colors()?;
let name = Palette::Jet.display_name()?;
let is_alarm = Palette::AlarmRed.is_alarm()?;

for palette in Palette::all()? {
    println!("{}", palette.display_name()?);
}

colors is a Vec<Rgb24>, 240 entries, coldest first. The reads are methods on the enum value itself, so a picker needs no camera; like the other bindings, the table is compiled into the SDK.

Complete Example

#include <optrissdk.h>
#include <print>
#include <thread>

using namespace optris::sdk;

int main() {
  SimulatedConfig sim_cfg{
      .width = 160,
      .height = 120,
      .framerate = 30,
      .pattern = TestPattern::kGradient,
  };
  auto imager = Imager::Create(sim_cfg);

  // Set the initial palette and color range.
  imager->SetPalette(Palette::kIronBow);
  imager->SetColorRange(20.0f, 80.0f);

  int frame_count = 0;
  imager->SetBgraCallback(
      [&](const BgraFrame& f) {
        ++frame_count;
        std::println("RGBA frame {}: {}x{}, "
                     "first pixel BGRA=({},{},{},{})",
                     frame_count,
                     f.GetWidth(), f.GetHeight(),
                     f.GetData()[0], f.GetData()[1],
                     f.GetData()[2], f.GetData()[3]);
      });

  imager->Start();
  std::this_thread::sleep_for(std::chrono::seconds(2));

  // Switch palette mid-stream.
  imager->SetPalette(Palette::kPlasma);
  std::println("Switched to Plasma palette.");

  std::this_thread::sleep_for(std::chrono::seconds(2));

  // Cycle through all palettes.
  for (int p = 0; p <= static_cast<int>(Palette::kLava); ++p) {
    imager->SetPalette(static_cast<Palette>(p));
    std::this_thread::sleep_for(
        std::chrono::milliseconds(500));
  }

  imager->Stop();
  std::println("Received {} RGBA frames total.",
               frame_count);

  return 0;
}