Display rendering of Tiny1-C frames into JPEG-ready Y/Cb/Cr scanlines. More...
#include "lwir_frame.h"

Go to the source code of this file.
Data Structures | |
| struct | lwir_profile |
| Measured display-correction profile for one camera, gain label and geometry. More... | |
| struct | lwir_render_options |
| Display policy for one rendering request; never affects stored samples. More... | |
| struct | lwir_render_range |
| Resolved display window and diagnostic counts from lwir_render_prepare(). More... | |
Macros | |
| #define | LWIR_MAX_BAD_PIXELS 128U |
| Capacity of the sorted bad-pixel list in struct lwir_profile. | |
Enumerations | |
| enum | lwir_view { LWIR_SENSOR , LWIR_FIXED , LWIR_PERCENTILE } |
| Source of display intensity. More... | |
| enum | lwir_palette { LWIR_WHITE_HOT , LWIR_BLACK_HOT , LWIR_IRON } |
| Thermal palette; ignored by LWIR_SENSOR. More... | |
Functions | |
| bool | lwir_profile_load (const char *path, struct lwir_profile *profile) |
| Load bounded measured display corrections, never vendor factory tables. | |
| bool | lwir_profile_matches (const struct lwir_profile *profile, unsigned width, unsigned height, const char *serial, const char *gain) |
| Require native geometry, serial and operator gain-label agreement. | |
| bool | lwir_render_prepare (const uint8_t *frame, size_t bytes, unsigned width, unsigned height, const struct lwir_render_options *options, struct lwir_render_range *range) |
| Resolve one deterministic display window while retaining original samples. | |
| bool | lwir_render_dimensions (unsigned width, unsigned height, const struct lwir_render_options *options, unsigned *display_width, unsigned *display_height) |
| Derive display dimensions; quarter-turns do not change thermal geometry. | |
| bool | lwir_render_native_coordinate (unsigned width, unsigned height, const struct lwir_render_options *options, unsigned display_x, unsigned display_y, unsigned *native_x, unsigned *native_y) |
| Invert display orientation before accessing calibration or native samples. | |
| bool | lwir_render_row (const uint8_t *frame, size_t bytes, unsigned width, unsigned height, unsigned row, const struct lwir_render_options *options, const struct lwir_render_range *range, uint8_t *output, size_t capacity) |
| Emit one bounded Y/Cb/Cr scanline, without a full RGB or rotated frame. | |
Detailed Description
Display rendering of Tiny1-C frames into JPEG-ready Y/Cb/Cr scanlines.
Rendering is strictly a display concern: it reads an immutable combined frame (see lwir_frame.h) and never reorders, rewrites or calibrates the stored raw thermal bytes, so measurements and saved data stay in native coordinates.
Workflow per frame: lwir_render_prepare() validates options and resolves one display window (struct lwir_render_range); lwir_render_dimensions() gives the oriented size; lwir_render_row() is then called once per display row to fill a caller-owned buffer of display_width * 3 bytes, so no full RGB or rotated frame is ever materialized.
Views: LWIR_SENSOR passes the camera's own YUYV image through; LWIR_FIXED maps an operator raw window; LWIR_PERCENTILE derives the window from the frame's histogram. Thermal views map the window through a palette, flag below/above/invalid samples with distinct colours, and may draw a legend strip. An optional measured correction profile applies scale/offset, a support range and bad-pixel replacement for display only.
Orientation is applied as clockwise rotation, then mirror, then flip; rows are produced by one inverse transform per scanline and a signed native stride.
SIMD: NEON (ARM64) and SSSE3 (x86-64, runtime-detected) accelerate +/-1-stride rows and produce the same bytes as the scalar code, which handles every remaining case.
Definition in file lwir_render.h.
Macro Definition Documentation
◆ LWIR_MAX_BAD_PIXELS
| #define LWIR_MAX_BAD_PIXELS 128U |
Capacity of the sorted bad-pixel list in struct lwir_profile.
Definition at line 64 of file lwir_render.h.
Enumeration Type Documentation
◆ lwir_palette
| enum lwir_palette |
Thermal palette; ignored by LWIR_SENSOR.
| Enumerator | |
|---|---|
| LWIR_WHITE_HOT | Greyscale, warmer is brighter. |
| LWIR_BLACK_HOT | Greyscale, warmer is darker. |
| LWIR_IRON | Six-anchor black-purple-red-orange-yellow ramp (scalar path only). |
Definition at line 57 of file lwir_render.h.
◆ lwir_view
| enum lwir_view |
Source of display intensity.
| Enumerator | |
|---|---|
| LWIR_SENSOR | Camera's own YUYV image; no thermal window, profile or denoise. |
| LWIR_FIXED | Fixed raw Kelvin*64 window from lwir_render_options low/high. |
| LWIR_PERCENTILE | Window from per-frame low/high percentiles of valid samples. |
Definition at line 51 of file lwir_render.h.
Function Documentation
◆ lwir_profile_load()
| bool lwir_profile_load | ( | const char * | path, |
| struct lwir_profile * | profile ) |
Load bounded measured display corrections, never vendor factory tables.
- Parameters
-
path Strict profile file. profile Caller-owned output, valid on success only.
- Returns
- True for a valid profile; physical support still requires measurement.
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 ) |
Require native geometry, serial and operator gain-label agreement.
- Parameters
-
profile Measured corrections. width Native width. height Native height. serial Device identity or explicit replay identity. gain Operator gain label, not an exposure-atomic gain measurement.
- Returns
- True for exact support matching; no silently broadened calibration.
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.
◆ lwir_render_dimensions()
| bool lwir_render_dimensions | ( | unsigned | width, |
| unsigned | height, | ||
| const struct lwir_render_options * | options, | ||
| unsigned * | display_width, | ||
| unsigned * | display_height ) |
Derive display dimensions; quarter-turns do not change thermal geometry.
- Parameters
-
width Native width. height Native height. options Rotation/mirror/flip policy. display_width Output width. display_height Output height.
- Returns
- True for supported native geometry and orientation.
Derive display dimensions; quarter-turns do not change thermal geometry.
90/270 degree rotations swap width and height; mirror and flip do not.
- Returns
- False for unsupported geometry, invalid options or NULL outputs (errno untouched).
Definition at line 136 of file lwir_render.c.
◆ lwir_render_native_coordinate()
| bool lwir_render_native_coordinate | ( | unsigned | width, |
| unsigned | height, | ||
| const struct lwir_render_options * | options, | ||
| unsigned | display_x, | ||
| unsigned | display_y, | ||
| unsigned * | native_x, | ||
| unsigned * | native_y ) |
Invert display orientation before accessing calibration or native samples.
- Parameters
-
width Native width. height Native height. options Rotate, then mirror, then flip policy. display_x Display column. display_y Display row. native_x Native column, written on success. native_y Native row, written on success.
- Returns
- True when both coordinate spaces are in bounds.
Invert display orientation before accessing calibration or native samples.
Uses the same row_source() transform as rendering, so overlays and measurements picked on the display address exactly the pixel that was shown.
- Returns
- False for invalid geometry/options, NULL outputs or out-of-range display points.
Definition at line 191 of file lwir_render.c.
◆ lwir_render_prepare()
| bool lwir_render_prepare | ( | const uint8_t * | frame, |
| size_t | bytes, | ||
| unsigned | width, | ||
| unsigned | height, | ||
| const struct lwir_render_options * | options, | ||
| struct lwir_render_range * | range ) |
Resolve one deterministic display window while retaining original samples.
LWIR_SENSOR returns {0, 255} without reading samples. LWIR_FIXED copies the requested window. LWIR_PERCENTILE ranks valid display samples in a 65536-bin histogram. All thermal views then count invalid/below/above samples for diagnostics.
- Parameters
-
frame Immutable combined frame, or image-only YUYV for LWIR_SENSOR. bytes Exact size. width Native width. height Native height. options Display-only policy. range Resolved bounds/clipping counts, valid only on success.
- Returns
- True for a supported rendering request. On failure errno is EINVAL for invalid arguments/options/profile/legend geometry, or ENODATA when a percentile view finds no valid sample.
- Warning
- Uses a static histogram: not re-entrant or thread-safe; call serially.
Resolve one deterministic display window while retaining original samples.
Percentile algorithm: histogram every valid uncorrected display value, then pick the values at 0-based ranks floor((samples-1) * percentile / 100) (lower nearest-rank) by scanning cumulative counts. The window is corrected afterwards, which is equivalent to ranking corrected values because correction is monotone. Afterwards every pixel is classified as invalid, below or above the window.
- Returns
- True on success; false with errno EINVAL for invalid input or ENODATA when a percentile view has no valid sample.
- Warning
- Not re-entrant: shares the static histogram.
Definition at line 418 of file lwir_render.c.
◆ lwir_render_row()
| bool lwir_render_row | ( | const uint8_t * | frame, |
| size_t | bytes, | ||
| unsigned | width, | ||
| unsigned | height, | ||
| unsigned | row, | ||
| const struct lwir_render_options * | options, | ||
| const struct lwir_render_range * | range, | ||
| uint8_t * | output, | ||
| size_t | capacity ) |
Emit one bounded Y/Cb/Cr scanline, without a full RGB or rotated frame.
- Parameters
-
frame Immutable combined frame, or image-only YUYV for LWIR_SENSOR. bytes Exact size. width Native width. height Native height. row Display row. options Display policy. range Window resolved by lwir_render_prepare. output Caller-owned interleaved Y/Cb/Cr row. capacity Available bytes, at least display width * 3.
- Returns
- True on success; scalar and SIMD paths preserve the same mapping. On failure errno is EINVAL (invalid arguments, row, capacity, range, profile or legend geometry) and the output is unspecified.
Emit one bounded Y/Cb/Cr scanline, without a full RGB or rotated frame.
Resolves the row's first native pixel and stride once, then either copies the camera image (LWIR_SENSOR) or maps each display value through the window: invalid -> yellow, below -> cyan-blue, above -> magenta, otherwise palette colour; legend rows are overdrawn. RGB is converted with integer full-range BT.601 coefficients.
- Returns
- True on success; false with errno EINVAL for invalid input.
Definition at line 665 of file lwir_render.c.