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_mock.c File Reference

Development replay: convert an ordinary JPEG into LWIR evidence (LWIR_ENABLE_MOCK). More...

#include "lwir_mock.h"
#include "lwir_container.h"
#include "lwir_frame.h"
#include "lwir_image.h"
#include "lwir_render.h"
#include "exifite.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <jpeglib.h>
Include dependency graph for lwir_mock.c:

Go to the source code of this file.

Functions

static void mock_jpeg_error (j_common_ptr decoder)
 libjpeg fatal-error hook.
static uint16_t synthetic_raw (uint8_t luminance)
 Map display luminance to a synthetic Kelvin*64 sample.
static bool decode_mock (FILE *input, unsigned *width, unsigned *height, bool embedded)
 Decode a JPEG into the combined workspace frame.
static void write_u32 (uint8_t *output, uint32_t number)
 Store a 32-bit value little-endian.
static bool attach_layer (FILE *input, FILE *output, unsigned width, unsigned height)
 Copy a JPEG while inserting the workspace temperature plane as LWIRSIM1 APP15 chunks.
int lwir_process_mock (const char *input_path, const char *output_path, bool layer_only)
 Produce mock LWIR evidence from input_path at output_path.

Variables

struct { 
   struct jpeg_decompress_struct   decoder 
   struct jpeg_error_mgr   error 
   jmp_buf   recovery 
   uint8_t   frame [LWIR_MAX_FRAME_BYTES] 
   uint8_t   thermal [LWIR_MAX_WIDTH
      *LWIR_MAX_HEIGHT *2] 
   uint8_t   row [LWIR_MAX_WIDTH *3] 
   uint8_t   marker [65020] 
   uint8_t   exif [EXIF_MAX_PAYLOAD] 
} mock_workspace
 Static workspace: maximum-size buffers would be too large for the stack and the heap is avoided.

Detailed Description

Development replay: convert an ordinary JPEG into LWIR evidence (LWIR_ENABLE_MOCK).

Two modes:

  • layer only: keep the source's compressed bytes and insert LWIRSIM1 APP15 temperature chunks derived from luminance;
  • full: decode, build a combined image+temperature frame, re-render it with the normal LWIR renderer, and carry the source EXIF across. An existing embedded temperature layer is always reused rather than synthesized. Output goes to a same-directory temporary file, is fsynced, then published without overwriting unrelated files. All buffers are static (no heap).

Definition in file lwir_mock.c.

Function Documentation

◆ attach_layer()

bool attach_layer ( FILE * input,
FILE * output,
unsigned width,
unsigned height )
static

Copy a JPEG while inserting the workspace temperature plane as LWIRSIM1 APP15 chunks.

Parameters
inputSource JPEG; rewound here.
outputDestination stream.
widthTemperature width.
heightTemperature height.
Returns
True if everything was copied; false on a non-JPEG source or any I/O error.

Each chunk is "LWIRSIM1", width, height, byte offset (all u32 LE) and up to 65000 data bytes, keeping the segment under JPEG's 65535-byte limit. Chunks go right after SOI; the remaining source bytes, including its own segments and compressed pixels, are copied unchanged.

Definition at line 171 of file lwir_mock.c.

◆ decode_mock()

bool decode_mock ( FILE * input,
unsigned * width,
unsigned * height,
bool embedded )
static

Decode a JPEG into the combined workspace frame.

Parameters
inputOpen stream positioned at the start of the JPEG.
widthIn: required width when embedded; out: decoded width.
heightIn: required height when embedded; out: decoded height.
embeddedTrue to take temperatures from the workspace thermal layer instead of synthesizing them.
Returns
True only for a complete decode with no libjpeg warnings and a size accepted by lwir_frame_bytes(); false otherwise (frame contents undefined).

Converts RGB to integer BT.601-style luma (77/150/29 >> 8) and stores Y with neutral chroma 128 so the image plane matches the camera's layout.

Definition at line 104 of file lwir_mock.c.

◆ lwir_process_mock()

int lwir_process_mock ( const char * input_path,
const char * output_path,
bool layer_only )

Produce mock LWIR evidence from input_path at output_path.

Preserve embedded temperatures or attach explicitly synthetic evidence.

Returns
0 on success, -1 on any failure.

Steps: open and identify the source; read any embedded layer; decode if needed; write a mode-matched temporary file next to the output; check that the source did not change meanwhile; publish with link() (fails if the name exists) or, in place, rename() after confirming the path still names the same inode; finally fsync the directory.

Warning
-1 is also returned if only the final directory fsync fails, after the file has already been published.

Definition at line 208 of file lwir_mock.c.

◆ mock_jpeg_error()

void mock_jpeg_error ( j_common_ptr decoder)
static

libjpeg fatal-error hook.

Parameters
decoderUnused; the workspace is global.

libjpeg's default handler calls exit(); jumping back to decode_mock() turns corrupt input into an ordinary false return.

Definition at line 71 of file lwir_mock.c.

◆ synthetic_raw()

uint16_t synthetic_raw ( uint8_t luminance)
static

Map display luminance to a synthetic Kelvin*64 sample.

Parameters
luminance0..255 grey level.
Returns
round((celsius + 273.15) * 64).

Piecewise: 0..128 spans 15..20 degC (background), 129..229 rises steeply to about 594 degC (hot objects), and >= 230 saturates at 600 degC. Only gives tests a plausible scene; it is not a calibration.

Definition at line 85 of file lwir_mock.c.

◆ write_u32()

void write_u32 ( uint8_t * output,
uint32_t number )
static

Store a 32-bit value little-endian.

Parameters
outputDestination of at least 4 bytes.
numberValue to store.

Definition at line 154 of file lwir_mock.c.

Variable Documentation

◆ decoder

struct jpeg_decompress_struct decoder

Definition at line 55 of file lwir_mock.c.

◆ error

struct jpeg_error_mgr error

Definition at line 56 of file lwir_mock.c.

◆ exif

uint8_t exif[EXIF_MAX_PAYLOAD]

Definition at line 62 of file lwir_mock.c.

◆ frame

uint8_t frame[LWIR_MAX_FRAME_BYTES]

Definition at line 58 of file lwir_mock.c.

◆ marker

uint8_t marker[65020]

Definition at line 61 of file lwir_mock.c.

◆ [struct]

struct { ... } mock_workspace

Static workspace: maximum-size buffers would be too large for the stack and the heap is avoided.

frame holds the combined layout (image plane of Y/neutral-chroma pairs, then little-endian Kelvin*64 temperatures); thermal receives an embedded layer; marker is one APP15 segment body (20-byte header + 65000 data) and doubles as the copy buffer. Makes the module non-reentrant.

◆ recovery

jmp_buf recovery

Definition at line 57 of file lwir_mock.c.

◆ row

uint8_t row[LWIR_MAX_WIDTH *3]

Definition at line 60 of file lwir_mock.c.

◆ thermal

uint8_t thermal[LWIR_MAX_WIDTH *LWIR_MAX_HEIGHT *2]

Definition at line 59 of file lwir_mock.c.