OptrisOptrisDocumentation

Documentation/OTC SDK/Optris.Sdk — C# API referencev12.0

PaletteLibrary

public static class PaletteLibrary

The palettes that are on this machine, by name.

Palettes is about a palette you already have: one of the built-ins, or a table your own code produced. This is about the palettes that are installed -- the CSV files the SDK ships and the CSV files an operator dropped into the palette directory, the way they have with PIX Connect and SDK 11 for years.

It is a list of names, not a second Palette. That enum is a closed set and a file cannot join it, so a file-backed palette is reached by name and applied as a table of colours -- which is exactly what ThermalCamera.SetCustomPalette(…) already takes. ThermalCamera.SetPaletteByName(…) does both steps.

The SDK's own palettes are always in the list, so it is never empty and a picker built from it is never blank -- even on a machine where nothing was installed. A file named after one of them in an operator directory is refused, with a warning in the SDK log, and the built-in is kept.

foreach (PaletteInfo palette in PaletteLibrary.All)
{
    Console.WriteLine($"{palette.Name} ({palette.Source})");
}
camera.SetPaletteByName("Furnace");

PaletteLibrary: properties

public static IReadOnlyList<PaletteInfo> All { get; }

Every palette this machine has, sorted by name.

Read fresh on every call, and never empty. It changes only after PaletteLibrary.Refresh, so two enumerations in a row see the same thing.

public static IReadOnlyList<string> Directories { get; }

The directories searched for palette files, in scan order.

The first is the system directory, where the palettes that ship with the SDK are installed. The rest are where an operator puts their own; among those the last to supply a name wins. By default there are three: the SDK's share directory, then palettes under the working directory, then palettes under the user data directory.

Worth showing in a diagnostics page. "My palette does not appear" is nearly always a file in a fourth directory.

PaletteLibrary: methods

public static PaletteInfo? Find(string name)

The palette called name, or null if the machine has none.

  • name: A PaletteInfo.Name. Matching is exact and case-sensitive, like the filenames it comes from.
public static CustomPalette Get(string name)

The palette called name, as a CustomPalette ready for ThermalCamera.SetCustomPalette(…).

  • Throws SdkObjectNotFoundException: The machine has no palette by that name.
public static ReadOnlyMemory<Rgb24> GetColors(string name)

The colours of a named palette, coldest first.

Returns: Its Palettes.ColorCount entries, in display order. A fresh array each call -- unlike Palettes.GetColors(…), which caches, because a file can change on disk.

  • Throws SdkObjectNotFoundException: The machine has no palette by that name.

For a built-in name these are the compiled table, so this and Palettes.GetColors(…) can never disagree.

public static int Refresh()

Re-read the palette directories.

Returns: How many palettes the library holds afterwards.

Not needed to get started -- the library builds itself the first time it is asked for anything, and nothing else ever rebuilds it. Call this when a file may have been added while the program was running.

Never throws over a missing directory or a malformed file: a directory that is not there is skipped, a file that is not a palette is logged with the reason and skipped, and the files either side of it still load.