Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
lwir_profile.c File Reference

Strict loader for measured LWIR display-correction profiles. More...

#include "lwir_render.h"
#include "bounded_ini.h"
#include "sha256fst.h"
Include dependency graph for lwir_profile.c:

Go to the source code of this file.

Data Structures

struct  profile_parser
 Parse state; kept apart from the caller's profile until fully validated. More...

Functions

static bool copy_label (char *destination, size_t capacity, const char *value)
 Copy a serial or gain label after validating it.
static bool profile_field (void *context, const char *key, const char *value)
 ini_parse() callback for one profile key.
bool lwir_profile_load (const char *path, struct lwir_profile *profile)
 Load and fully validate a profile; see lwir_render.h.
bool lwir_profile_matches (const struct lwir_profile *profile, unsigned width, unsigned height, const char *serial, const char *gain)
 Exact match of geometry, serial and gain label; see lwir_render.h.

Detailed Description

Strict loader for measured LWIR display-correction profiles.

Parses a flat INI file whose format key is "LWIR_CORRECTIONS_V1": serial, gain label, width, height, scale_ppm (500000..1500000), offset_mk (-50000..50000), range_min_raw/range_max_raw (supported raw code range, excluding the endpoint codes 0 and 65535), bad_pixel_count and bad_pixel_0..bad_pixel_N-1 as "column,row" pairs.

The renderer applies these corrections to display pixels only; native temperatures, measurements and stored APP15 data are never altered. The SHA-256 of the exact file bytes becomes the profile identity recorded in each JPEG's provenance text.

Invariants: the whole file is bounded to 8192 bytes; all fields are mandatory and unique; bad pixels are bounded by LWIR_MAX_BAD_PIXELS, inside the profile geometry, sorted ascending and duplicate-free. The caller's struct is written only after every check passed (all-or-nothing), using a byte loop rather than memcpy per project policy.

Definition in file lwir_profile.c.

Function Documentation

◆ copy_label()

bool copy_label ( char * destination,
size_t capacity,
const char * value )
static

Copy a serial or gain label after validating it.

Parameters
destinationLabel buffer in the candidate profile.
capacityBuffer size including the terminator.
valueNUL-terminated label text.
Returns
False for empty, too long, control characters or DEL, or "unknown".

"unknown" is the placeholder written to evidence when a label is missing, so a profile must not match a camera whose label was never given.

Definition at line 59 of file lwir_profile.c.

◆ lwir_profile_load()

bool lwir_profile_load ( const char * path,
struct lwir_profile * profile )

Load and fully validate a profile; see lwir_render.h.

Load bounded measured display corrections, never vendor factory tables.

Steps: bounded read (8192-byte buffer) -> SHA-256 of the raw bytes -> strict parse -> completeness and range checks -> bad-pixel geometry check and linearization -> sort -> duplicate rejection -> byte copy to caller. On any failure errno is EINVAL, including read failures, whose original errno is not preserved; profile is then left untouched.

Note
The digest covers comments and whitespace too, so any byte change yields a new profile identity.

Definition at line 137 of file lwir_profile.c.

◆ lwir_profile_matches()

bool lwir_profile_matches ( const struct lwir_profile * profile,
unsigned width,
unsigned height,
const char * serial,
const char * gain )

Exact match of geometry, serial and gain label; see lwir_render.h.

Require native geometry, serial and operator gain-label agreement.

Plain string equality: no case folding or trimming, so a profile never silently applies to a different camera or gain setting.

Definition at line 178 of file lwir_profile.c.

◆ profile_field()

bool profile_field ( void * context,
const char * key,
const char * value )
static

ini_parse() callback for one profile key.

Parameters
contextstruct profile_parser.
keyINI key.
valueNUL-terminated value.
Returns
False aborts the load: unknown or repeated key, wrong format string, invalid label, malformed number or a value out of range.

Unlike the provenance reader, unknown keys are errors: a profile changes rendered output, so a misspelled key must not be silently ignored. Bad-pixel coordinates are only bounded by LWIR_MAX_WIDTH/HEIGHT here because width and height may appear later in the file; lwir_profile_load() rechecks them against the declared geometry.

Definition at line 80 of file lwir_profile.c.