Loading...
Searching...
No Matches
lwir_render.c
Go to the documentation of this file.
61 * @note Caller guarantees bounds; byte assembly keeps it independent of host endianness and alignment.
104static bool render_frame_valid(const uint8_t *frame, size_t bytes, unsigned width, unsigned height,
124 options->palette >= LWIR_WHITE_HOT && options->palette <= LWIR_IRON && options->denoise_raw <= 640 &&
127 (options->view != LWIR_FIXED || (options->low >= 0 && options->high <= 65535 && options->low < options->high)) &&
128 (options->view != LWIR_PERCENTILE || (options->low_percentile < options->high_percentile && options->high_percentile <= 100));
136bool lwir_render_dimensions(unsigned width, unsigned height, const struct lwir_render_options *options,
139 if (!lwir_frame_bytes(width, height) || !valid_options(options) || !display_width || !display_height) return false;
170static ptrdiff_t row_source(unsigned width, unsigned height, const struct lwir_render_options *options,
178 case 90: *step = -direction * width; return (ptrdiff_t)(height - 1 - horizontal) * width + vertical;
179 case 180: *step = -direction; return (ptrdiff_t)(height - 1 - vertical) * width + width - 1 - horizontal;
191bool lwir_render_native_coordinate(unsigned width, unsigned height, const struct lwir_render_options *options,
195 if (!native_x || !native_y || !lwir_render_dimensions(width, height, options, &display_width, &display_height) ||
198 const ptrdiff_t first = row_source(width, height, options, display_width, display_height, display_y, &step);
216 available = __get_cpuid(1, &leaf, &vendor, &features, &extended) && (features & bit_SSSE3) != 0;
235static void sensor_row(const uint8_t *frame, ptrdiff_t first, ptrdiff_t step, unsigned width, uint8_t *output)
239 if ((step == 1 || step == -1) && width >= 8 && ssse3_available()) column = lwir_sensor_ssse3(frame, first, step, width, output);
338 const size_t positions[4] = {column ? pixel - 1 : pixel, column + 1 < width ? pixel + 1 : pixel,
342 if (positions[index] != pixel && original_sample(frame, width, height, positions[index], options->profile, &candidate)) neighbors[count++] = candidate;
349 while (position && neighbors[position - 1] > value) { neighbors[position] = neighbors[position - 1]; --position; }
357 for (int vertical = -1; vertical <= 1; ++vertical) for (int horizontal = -1; horizontal <= 1; ++horizontal) {
358 if ((!vertical && !horizontal) || column + horizontal < 0 || column + horizontal >= (int)width || row + vertical < 0 || row + vertical >= (int)height) continue;
399 if (profile->width != width || profile->height != height || profile->bad_count > LWIR_MAX_BAD_PIXELS ||
400 profile->scale_ppm < 500000 || profile->scale_ppm > 1500000 || profile->offset_mk < -50000 || profile->offset_mk > 50000 ||
401 !profile->range_min || profile->range_min >= profile->range_max || profile->range_max == UINT16_MAX) return false;
422 if (!render_frame_valid(frame, bytes, width, height, options) || !lwir_render_dimensions(width, height, options, &display_width, &display_height) ||
424 (options->legend && (options->view == LWIR_SENSOR || display_width < 112 || display_height < 24))) { errno = EINVAL; return false; }
426 if (options->view == LWIR_SENSOR) { *range = (struct lwir_render_range){.high = 255}; return true; }
433 if (display_sample(frame, width, height, pixel, options, &raw)) { ++histogram[raw]; ++samples; }
451 result.low = corrected(result.low, options->profile); result.high = corrected(result.high, options->profile);
459 if (!options->profile && !options->denoise_raw && result.low >= 0 && result.high <= UINT16_MAX) {
461 const uint16x8_t raw = thermal_block(frame + pixels * 2, pixel), invalid = invalid_block(raw), valid = vmvnq_u16(invalid);
464 result.below += vaddlvq_u16(vshrq_n_u16(vandq_u16(valid, vcltq_u16(raw, vdupq_n_u16((uint16_t)result.low))), 15));
465 result.above += vaddlvq_u16(vshrq_n_u16(vandq_u16(valid, vcgtq_u16(raw, vdupq_n_u16((uint16_t)result.high))), 15));
490static void color(unsigned intensity, enum lwir_palette palette, unsigned *red, unsigned *green, unsigned *blue)
563 if (row < height - 9) { color(column * 255 / (width - 1), options->palette, red, green, blue); return; }
574 unsigned position = column < width / 2 ? column : column >= right_start ? column - right_start : width;
576 if (position / 6 < length && position % 6 < 5 && (glyph(text[position / 6], font_row) & (16U >> (position % 6))))
601 quotient = vsubq_u32(quotient, vshrq_n_u32(vcgtq_u32(vmulq_u32(quotient, denominator), numerator), 31));
603 quotient = vaddq_u32(quotient, vshrq_n_u32(vcleq_u32(vmulq_u32(next, denominator), numerator), 31));
626static unsigned thermal_neon(const uint8_t *plane, ptrdiff_t first, ptrdiff_t step, unsigned width,
627 const struct lwir_render_options *options, const struct lwir_render_range *range, uint8_t *output)
629 const uint16x8_t low = vdupq_n_u16((uint16_t)range->low), high = vdupq_n_u16((uint16_t)range->high);
633 static const uint8_t below_color[3] = {134, 196, 32}, above_color[3] = {106, 213, 235}, invalid_color[3] = {226, 1, 149};
639 if (step < 0) raw = vcombine_u16(vrev64_u16(vget_high_u16(raw)), vrev64_u16(vget_low_u16(raw)));
641 uint8x8_t intensity = vmovn_u16(vcombine_u16(window_intensity(vget_low_u16(delta), span, reciprocal), window_intensity(vget_high_u16(delta), span, reciprocal)));
644 const uint8x8_t below = vmovn_u16(vcltq_u16(raw, low)), above = vmovn_u16(vcgtq_u16(raw, high)), invalid = vmovn_u16(invalid_block(raw));
649 expanded.val[channel] = vbsl_u8(invalid, vdup_n_u8(invalid_color[channel]), expanded.val[channel]);
665bool lwir_render_row(const uint8_t *frame, size_t bytes, unsigned width, unsigned height, unsigned row,
670 if (!render_frame_valid(frame, bytes, width, height, options) || !lwir_render_dimensions(width, height, options, &display_width, &display_height) || !range ||
671 !output || row >= display_height || capacity < (size_t)display_width * 3 || range->low >= range->high ||
674 (options->legend && (options->view == LWIR_SENSOR || display_width < 112 || display_height < 24))) { errno = EINVAL; return false; }
676 ptrdiff_t source = row_source(width, height, options, display_width, display_height, row, &step);
677 if (options->view == LWIR_SENSOR) { sensor_row(frame, source, step, display_width, output); return true; }
680 if ((step == 1 || step == -1) && !options->profile && !options->denoise_raw && options->palette != LWIR_IRON &&
681 range->low >= 0 && range->high <= UINT16_MAX && (!options->legend || row < display_height - 16)) {
682 column = thermal_neon(frame + (size_t)width * height * 2, source, step, display_width, options, range, output);
697 const unsigned intensity = (unsigned)((int64_t)(value - range->low) * 255 / (range->high - range->low));
static bool range(size_t total, size_t offset, size_t length)
Check a byte span without forming a potentially overflowing end offset.
Definition exifite.c:133
size_t lwir_frame_bytes(unsigned width, unsigned height)
Combined frame size for supported geometry.
Definition lwir_frame.c:56
static uint16_t temperature(const uint8_t *frame, size_t pixels, size_t pixel)
Read one little-endian thermal code.
Definition lwir_render.c:63
static void legend_pixel(unsigned row, unsigned column, unsigned width, unsigned height, const struct lwir_render_options *options, const struct lwir_render_range *range, unsigned *red, unsigned *green, unsigned *blue)
Colour of one pixel inside the 16-row legend strip at the bottom of the display.
Definition lwir_render.c:559
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)
Convert a display coordinate into native sensor coordinates.
Definition lwir_render.c:191
bool lwir_render_dimensions(unsigned width, unsigned height, const struct lwir_render_options *options, unsigned *display_width, unsigned *display_height)
Display size after orientation.
Definition lwir_render.c:136
static bool valid_options(const struct lwir_render_options *options)
Validate enumerations, orientation and view-specific option ranges.
Definition lwir_render.c:121
static bool display_sample(const uint8_t *frame, unsigned width, unsigned height, size_t pixel, const struct lwir_render_options *options, uint16_t *raw)
Produce the uncorrected display value of one native pixel.
Definition lwir_render.c:328
static bool original_sample(const uint8_t *frame, unsigned width, unsigned height, size_t pixel, const struct lwir_profile *profile, uint16_t *raw)
Read an unreplaced sample usable as-is or as a neighbour.
Definition lwir_render.c:301
static uint8_t glyph(char character, unsigned row)
One row of a built-in 5x7 bitmap font.
Definition lwir_render.c:512
static bool bad_pixel(const struct lwir_profile *profile, size_t pixel)
Test whether a native pixel is listed as bad in the profile.
Definition lwir_render.c:279
static ptrdiff_t row_source(unsigned width, unsigned height, const struct lwir_render_options *options, unsigned display_width, unsigned display_height, unsigned row, ptrdiff_t *step)
Map a display row to its first native pixel and per-column native stride.
Definition lwir_render.c:170
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)
Validate a render request and resolve its display window and counts.
Definition lwir_render.c:418
static bool render_frame_valid(const uint8_t *frame, size_t bytes, unsigned width, unsigned height, const struct lwir_render_options *options)
Check pointers, native geometry and buffer size for the requested view.
Definition lwir_render.c:104
static void sensor_row(const uint8_t *frame, ptrdiff_t first, ptrdiff_t step, unsigned width, uint8_t *output)
Copy the camera's own YUYV image row into Y/Cb/Cr output (LWIR_SENSOR).
Definition lwir_render.c:235
static int32_t corrected(int32_t raw, const struct lwir_profile *profile)
Apply the profile's linear display correction.
Definition lwir_render.c:381
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)
Render one oriented display row as interleaved Y/Cb/Cr.
Definition lwir_render.c:665
static void color(unsigned intensity, enum lwir_palette palette, unsigned *red, unsigned *green, unsigned *blue)
Map a window intensity to RGB for the selected palette.
Definition lwir_render.c:490
static void legend_label(char text[16], int32_t raw)
Format a window bound as degrees Celsius with one decimal.
Definition lwir_render.c:534
static bool valid_profile(const struct lwir_profile *profile, unsigned width, unsigned height)
Check a profile against the native geometry and renderer limits.
Definition lwir_render.c:396
Display rendering of Tiny1-C frames into JPEG-ready Y/Cb/Cr scanlines.
#define LWIR_MAX_BAD_PIXELS
Capacity of the sorted bad-pixel list in struct lwir_profile.
Definition lwir_render.h:64
unsigned lwir_sensor_ssse3(const uint8_t *frame, ptrdiff_t first, ptrdiff_t step, unsigned width, uint8_t *output)
Expand eight YUYV pixels per iteration into interleaved Y/Cb/Cr, forwards or reversed.
Definition lwir_ssse3.c:58
Measured display-correction profile for one camera, gain label and geometry.
Definition lwir_render.h:70
Display policy for one rendering request; never affects stored samples.
Definition lwir_render.h:103
Resolved display window and diagnostic counts from lwir_render_prepare().
Definition lwir_render.h:127