Loading...
Searching...
No Matches
lwir_profile.c
Go to the documentation of this file.
46 bool bad_seen[LWIR_MAX_BAD_PIXELS]; /**< Seen flags per bad_pixel_N index; detects duplicates and gaps. */
47 uint16_t bad_x[LWIR_MAX_BAD_PIXELS]; /**< Bad-pixel columns; linearized only once width is known. */
83 static const char *const keys[] = {"format", "serial", "gain", "width", "height", "scale_ppm", "offset_mk", "range_min_raw", "range_max_raw", "bad_pixel_count"};
94 for (size_t position = 0; position <= strlen(value); ++position) coordinates[position] = value[position];
99 if (!ini_uint(coordinates, &column) || !ini_uint(separator, &row) || column >= LWIR_MAX_WIDTH || row >= LWIR_MAX_HEIGHT) return false;
107 if (field == 1) return copy_label(parser->profile.serial, sizeof(parser->profile.serial), value);
115 case 3: if (number < 2 || number > LWIR_MAX_WIDTH || number % 2) return false; parser->profile.width = (unsigned)number; break;
116 case 4: if (number == 0 || number > LWIR_MAX_HEIGHT) return false; parser->profile.height = (unsigned)number; break;
117 case 5: if (number < 500000 || number > 1500000) return false; parser->profile.scale_ppm = (unsigned)number; break;
118 case 6: if (number > 50000) return false; parser->profile.offset_mk = negative ? -(int)number : (int)number; break;
120 case 7: if (number == 0 || number >= UINT16_MAX) return false; parser->profile.range_min = (uint16_t)number; break;
121 case 8: if (number == 0 || number >= UINT16_MAX) return false; parser->profile.range_max = (uint16_t)number; break;
122 case 9: if (number > LWIR_MAX_BAD_PIXELS) return false; parser->profile.bad_count = (unsigned)number; break;
147 for (unsigned field = 0; field < 10; ++field) if (!parser.fields[field]) { errno = EINVAL; return false; }
151 if (parser.bad_seen[index] != (index < parser.profile.bad_count)) { errno = EINVAL; return false; }
153 if (parser.bad_x[index] >= parser.profile.width || parser.bad_y[index] >= parser.profile.height) { errno = EINVAL; return false; }
154 parser.profile.bad_pixels[index] = (uint32_t)parser.bad_y[index] * parser.profile.width + parser.bad_x[index];
163 while (position && parser.profile.bad_pixels[position - 1] > value) { parser.profile.bad_pixels[position] = parser.profile.bad_pixels[position - 1]; --position; }
166 for (unsigned index = 1; index < parser.profile.bad_count; ++index) if (parser.profile.bad_pixels[index] == parser.profile.bad_pixels[index - 1]) { errno = EINVAL; return false; }
Allocation-free flat key=value mechanics; callers own schemas and storage.
static bool ini_uint(const char *text, uint64_t *number)
Parse digits-only uint64; overflow and signs are rejected.
Definition bounded_ini.h:52
static bool ini_read_file(const char *filename, char *buffer, size_t capacity, size_t *length)
Read a nonempty regular file smaller than capacity and append NUL.
Definition bounded_ini.h:98
static bool ini_parse(char *buffer, size_t length, ini_field_handler handler, void *context)
Destructively parse flat fields with blank lines and #/; comment lines.
Definition bounded_ini.h:132
bool lwir_profile_load(const char *path, struct lwir_profile *profile)
Load and fully validate a profile; see lwir_render.h.
Definition lwir_profile.c:137
static bool copy_label(char *destination, size_t capacity, const char *value)
Copy a serial or gain label after validating it.
Definition lwir_profile.c:59
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.
Definition lwir_profile.c:178
static bool profile_field(void *context, const char *key, const char *value)
ini_parse() callback for one profile key.
Definition lwir_profile.c:80
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
void sha256_hex(const void *data, size_t length, char *output)
Hash one memory region to a lowercase hexadecimal string.
Definition sha256fst.c:272
Allocation-free, portable SHA-256 checksums for memory and streams.
Measured display-correction profile for one camera, gain label and geometry.
Definition lwir_render.h:70
Parse state; kept apart from the caller's profile until fully validated.
Definition lwir_profile.c:43