Bounded thermal-marker reader; JPEG pixels are deliberately left alone. More...
#include "lwir_container.h"#include "lwir_frame.h"#include "exifite.h"#include "bounded_ini.h"#include <fcntl.h>#include <stdio.h>#include <string.h>#include <sys/stat.h>#include <unistd.h>
Go to the source code of this file.
Data Structures | |
| struct | geometry_fields |
| Accumulator for the INI callback over the APP14 provenance text. More... | |
Functions | |
| static uint32_t | read_u32_le (const uint8_t *bytes) |
| Decode a little-endian uint32 from four bytes. | |
| static bool | geometry_field (void *context, const char *key, const char *value) |
| ini_parse() callback that extracts the eleven geometry keys. | |
| static int | read_temperature_stream (FILE *input, uint8_t *destination, size_t capacity, unsigned *width, unsigned *height, bool *synthetic, struct lwir_saved_geometry *geometry) |
| Walk JPEG markers, reassemble the APP15 plane and optionally check APP14. | |
| int | lwir_read_temperature_stream (FILE *input, uint8_t *destination, size_t capacity, unsigned *width, unsigned *height, bool *synthetic) |
| Public stream reader without geometry; see lwir_container.h. | |
| int | lwir_read_temperature_evidence (const char *filename, uint8_t *destination, size_t capacity, struct lwir_saved_geometry *geometry) |
Open filename safely and read layer plus geometry; see lwir_container.h. | |
| int | lwir_read_temperature_layer (const char *filename, uint8_t *destination, size_t capacity, unsigned *width, unsigned *height, bool *synthetic) |
Open filename safely and read the layer only; see lwir_container.h. | |
Detailed Description
Bounded thermal-marker reader; JPEG pixels are deliberately left alone.
Walks JPEG marker segments from SOI up to the first SOS or EOI and reassembles the APP15 temperature plane written by lwir_image.c. Optionally parses the APP14 "LWIREV02" text for native geometry and identity. The walk uses one fixed 65534-byte segment buffer on the stack and copies samples straight into the caller's destination, so no heap or intermediate plane is needed.
Defensive rules: regular files of at most 256 MiB only; every chunk is checked for signature, dimensions, offset continuity and capacity; and the file's identity, size and timestamps must be identical before and after the walk, so a file replaced or rewritten mid-read is rejected.
Definition in file lwir_container.c.
Function Documentation
◆ geometry_field()
|
static |
ini_parse() callback that extracts the eleven geometry keys.
- Parameters
-
context struct geometry_fields accumulator. key Key from the LWIREV02 text. value Value text, NUL-terminated.
- Returns
- False aborts the parse: duplicate key, malformed number, or a value out of range. Unrelated keys return true and are ignored, so newer writers can add fields without breaking older readers.
Table index drives both validation and the seen bit. Ranges: width/height and flags at most 65535, rotation a multiple of 90 up to 270, mirror/flip/legend 0 or 1, source "camera" or "replay", boot_id non-empty and shorter than its buffer, frame_sha256 exactly 64 lowercase hex digits.
Definition at line 72 of file lwir_container.c.
◆ lwir_read_temperature_evidence()
| int lwir_read_temperature_evidence | ( | const char * | filename, |
| uint8_t * | destination, | ||
| size_t | capacity, | ||
| struct lwir_saved_geometry * | geometry ) |
Open filename safely and read layer plus geometry; see lwir_container.h.
Extract the temperature plane plus its recorded provenance geometry.
O_NOFOLLOW refuses a symlinked final component; O_NONBLOCK keeps a FIFO from blocking the open so the regular-file check can reject it. Results go through locals and are copied out only on success.
Definition at line 250 of file lwir_container.c.
◆ lwir_read_temperature_layer()
| int lwir_read_temperature_layer | ( | const char * | filename, |
| uint8_t * | destination, | ||
| size_t | capacity, | ||
| unsigned * | width, | ||
| unsigned * | height, | ||
| bool * | synthetic ) |
Open filename safely and read the layer only; see lwir_container.h.
Extract native little-endian Kelvin*64 samples without decoding pixels.
Same open flags as lwir_read_temperature_evidence(). Outputs are written only when the result is 1 and the stream closed cleanly.
Definition at line 272 of file lwir_container.c.
◆ lwir_read_temperature_stream()
| int lwir_read_temperature_stream | ( | FILE * | input, |
| uint8_t * | destination, | ||
| size_t | capacity, | ||
| unsigned * | width, | ||
| unsigned * | height, | ||
| bool * | synthetic ) |
Public stream reader without geometry; see lwir_container.h.
Extract thermal evidence from an already-open regular JPEG stream.
Definition at line 239 of file lwir_container.c.
◆ read_temperature_stream()
|
static |
Walk JPEG markers, reassemble the APP15 plane and optionally check APP14.
- Parameters
-
input Borrowed stream; rewound to the start, never closed here. destination Caller-owned sample storage; may be partially written on failure. capacity Writable bytes in destination. width Native width, written only on result 1. height Native height, written only on result 1. synthetic True for LWIRSIM1, written only on result 1. geometry Optional; when non-NULL, LWIREV02 evidence becomes mandatory and is cross-checked against the layer and the JPEG dimensions.
- Returns
- 1 complete layer, 0 no layer (only possible with
geometryNULL), -1 invalid input, inconsistency or I/O failure. errno is not normalized.
Stops at SOS or EOI because the custom markers are always written before the scan; entropy-coded data is never inspected. APP15 segments with foreign signatures are skipped, since other software may also use APP15. A file stability check (device, inode, size, mtime, ctime) runs last, even after failures, and overrides any earlier success.
Definition at line 128 of file lwir_container.c.
◆ read_u32_le()
|
static |
Decode a little-endian uint32 from four bytes.
- Parameters
-
bytes At least four readable bytes.
- Returns
- Decoded value, independent of host endianness.
Definition at line 48 of file lwir_container.c.