22typedef enum : uint32_t {
107 if ((pull ==
nullptr) || (got ==
nullptr) || ((bytes ==
nullptr) && (cap != 0U))) {
115 if ((uint64_t)cap > remain) {
116 cap = (size_t)remain;
119 if ((rc ==
k_ra8_ok) && (*got <= cap)) {
148 return spool->
append(spool->
ctx, bytes, len);
184 .tile_w = need->
width,
187 .max_width = need->
width,
188 .max_height = need->
height,
190 .work_cap = work->work_cap,
191 .webp_work = work->webp_work,
192 .webp_work_cap = work->webp_work_cap,
225 return sink->
write(sink->
ctx, (
const uint8_t*)text,
strlen(text));
251 }
while (value != 0U);
253 for (
size_t i = 0U; i < count; ++i) {
254 text[i] = reverse[count - i - 1U];
256 return sink->
write(sink->
ctx, (
const uint8_t*)text, count);
277 static const uint8_t digits[] =
"0123456789ABCDEF";
278 const uint8_t text[2] = {
282 return sink->
write(sink->
ctx, text,
sizeof(text));
393 if ((state->
dump !=
nullptr) && (state->
dump->
ops !=
nullptr) &&
442 }
while (value != 0U);
444 for (
size_t i = 0U; i < count; ++i) {
445 text[i] = reverse[count - i - 1U];
464 const uint8_t magic[3] = {
'P', (state->
need->
bpp == 1U) ?
'5' :
'6',
'\n'};
494 for (uint32_t x = 0U; x < state->
need->
width; ++x) {
495 (void)
memcpy(&state->work->row[(
size_t)x * 3U], &row[(
size_t)x * 4U], 3U);
524 uint8_t*
const buffer = reference ? work->row : work->band_tile;
525 const uint32_t cap = reference ? work->row_cap : work->band_tile_cap;
526 for (uint16_t y = 0U; y < info->
tile_rows; ++y) {
540 if ((rc !=
k_ra8_ok) || (out_w != info->
width) || (reference && (out_h != 1U))) {
564 if (state->work->row[i] != band_row[i]) {
567 (uint64_t)(i / state->
need->
bpp),
594 if (state->
dump !=
nullptr) {
598 uint16_t global_y = 0U;
599 for (uint16_t band_y = 0U; band_y < state->
ginfo->
tile_rows; ++band_y) {
600 uint16_t band_w = 0U;
601 uint16_t band_h = 0U;
607 state->work->scratch,
608 state->work->scratch_cap,
609 state->work->band_tile,
610 state->work->band_tile_cap,
616 for (uint16_t row = 0U; row < band_h; ++row) {
624 state->work->scratch,
625 state->work->scratch_cap,
627 state->work->row_cap,
633 const uint8_t* band_row = &state->work->band_tile[(size_t)row * state->
need->
row_bytes];
661 const uint16_t rows = (uint16_t)(((uint32_t)need->
height + tile_h - 1U) / tile_h);
703 if (state->
dump ==
nullptr) {
736 (diffs == 0U) ?
"ROUND-TRIP EXACT -- the produced file is correct"
775 if ((reference_source ==
nullptr) || (banded_source ==
nullptr) ||
776 (reference_source->
read_at ==
nullptr) || (banded_source->
read_at ==
nullptr) ||
777 (reference_source->
ctx == banded_source->
ctx) || (need ==
nullptr) || (work ==
nullptr) ||
778 (ref_spool ==
nullptr) || (got_spool ==
nullptr) || (ref_spool->
read_at ==
nullptr) ||
779 (ref_spool->
append ==
nullptr) || (ref_spool->
seal ==
nullptr) ||
780 (got_spool->
read_at ==
nullptr) || (got_spool->
append ==
nullptr) ||
781 (got_spool->
seal ==
nullptr) || (ref_spool->
ctx == got_spool->
ctx) || (report ==
nullptr) ||
782 (report->write ==
nullptr)) {
788 const bool webp_bad =
790 ((work->webp_work ==
nullptr) || (work->webp_work_cap < need->
webp_work_bytes));
791 if ((work->work ==
nullptr) || (work->work_cap < producer) || webp_bad ||
792 (work->band_tile ==
nullptr) || (work->band_tile_cap < need->
band_tile_bytes) ||
793 (work->scratch ==
nullptr) || (work->scratch_cap < need->
scratch_bytes) ||
794 (work->row ==
nullptr) || (work->row_cap < need->
row_bytes)) {
820 if ((dump !=
nullptr) && (dump->
ops !=
nullptr) && (dump->
ops->
abort !=
nullptr)) {
851 const uint16_t tile_h = reference ? 1U : need->
band_height;
920 const char* dump_name,
930 const bool dump_bad =
933 (dump->
ops->
abort ==
nullptr) || (dump_name ==
nullptr));
952 .need = requirements,
954 .ref = reference_spool,
960 .dump_ok = dump !=
nullptr,
ra8_err_t jof_read_tile(jof_pread_fn pread, void *pread_ctx, const jof_info_t *info, uint16_t tile_x, uint16_t tile_y, uint8_t *scratch, uint32_t scratch_cap, uint8_t *out_px, uint32_t out_cap, uint16_t *out_w, uint16_t *out_h)
Read + decode one tile into caller pixels, in bounded RAM.
ra8_err_t jof_parse(jof_pread_fn pread, void *pread_ctx, uint64_t total_size, jof_info_t *out_info)
Parse + validate a JOF atlas's header, footer and index bounds.
@ k_jof_codec_deflate
Tile stream is one raw-DEFLATE run.
Import-time transcode producer: JPEG/PNG/WebP -> JOF band-tile atlas in bounded RAM (#231,...
ra8_err_t jof_produce(const jof_produce_cfg_t *cfg, jof_info_t *out_info)
Transcode one encoded JPEG/PNG/WebP source into a JOF atlas (#231, #290).
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_protocol_error
Protocol-level error (e.g.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Caller-workspace I/O contracts for portable format-tool engines.
static ra8_err_t internal_pull(void *ctx, uint8_t *bytes, size_t cap, size_t *got)
Producer pull adapter over positioned source reads.
static ra8_err_t internal_check(const ra8_fmt_source_t *reference_source, const ra8_fmt_source_t *banded_source, const ra8_fmt_jof_verify_requirements_t *need, const ra8_fmt_jof_verify_workspace_t *work, const ra8_fmt_spool_t *ref_spool, const ra8_fmt_spool_t *got_spool, const ra8_fmt_sink_t *report)
Reject incomplete callbacks, aliased contexts, or undersized arenas.
static ra8_err_t internal_stable(const ra8_fmt_source_t *source)
Validate a source through its optional stability callback.
static void internal_difference(verify_compare_t *state, uint64_t x, uint64_t y, uint8_t reference, uint8_t banded)
Record and optionally report one differing byte.
static void internal_dump_row(verify_compare_t *state, const uint8_t *row)
Stage one subject row in PPM channel order.
verify_const_t
Verification geometry, report, and probe constants.
@ k_verify_decimal_max
Digits in one uint64_t.
@ k_verify_diffs_max
Maximum detailed byte differences.
@ k_verify_ppm_max_text
Bytes in the PPM maximum line.
@ k_verify_decimal
Decimal report radix.
@ k_verify_band_height
Production band height under test.
@ k_verify_hex_radix
Hexadecimal report radix.
static ra8_err_t internal_compare(verify_compare_t *state)
Compare all subject bands against streamed reference rows.
static bool internal_info(const jof_info_t *info, const ra8_fmt_jof_verify_requirements_t *need, uint16_t tile_h)
Check parsed atlas geometry against exact planned policy.
static ra8_err_t internal_text(const ra8_fmt_sink_t *sink, const char *text)
Append one NUL-terminated report fragment.
static void internal_verdict(const ra8_fmt_sink_t *report, uint64_t diffs)
Emit the exact legacy final verdict line.
static void internal_finish_dump(verify_compare_t *state, const char *dump_name)
Commit or abort the optional PPM and emit its legacy status line.
static void internal_phase_error(const ra8_fmt_sink_t *report, const char *prefix, ra8_err_t status)
Report one exact legacy phase-failure line.
static void internal_abort_dump(verify_compare_t *state)
Abort an incomplete optional PPM stage once.
static void internal_compare_row(verify_compare_t *state, const uint8_t *band_row, uint16_t y)
Compare one decoded subject row with its reference row.
static ra8_err_t internal_prepare(const ra8_fmt_source_t *reference_source, const ra8_fmt_source_t *banded_source, const ra8_fmt_jof_verify_requirements_t *need, ra8_fmt_jof_verify_workspace_t *work, ra8_fmt_spool_t *reference_spool, ra8_fmt_spool_t *banded_spool, const ra8_fmt_sink_t *report, verify_atlases_t *atlases)
Produce, seal, parse, and preflight both independent atlases.
static void internal_dump_header(verify_compare_t *state)
Stage the exact P5 or P6 header for subject geometry.
ra8_err_t ra8_fmt_jof_verify_stream(const ra8_fmt_source_t *reference_source, const ra8_fmt_source_t *banded_source, const ra8_fmt_jof_verify_requirements_t *requirements, ra8_fmt_jof_verify_workspace_t *workspace, ra8_fmt_spool_t *reference_spool, ra8_fmt_spool_t *banded_spool, ra8_fmt_transaction_t *dump, const char *dump_name, const ra8_fmt_sink_t *report)
Verify banded JOF pixels against an independently decoded row reference.
static void internal_field(const ra8_fmt_sink_t *sink, uint64_t value, const char *suffix, ra8_err_t *status)
Append one numeric field and suffix while status succeeds.
static ra8_err_t internal_hex(const ra8_fmt_sink_t *sink, uint8_t value)
Append one byte as two uppercase hexadecimal digits.
static ra8_err_t internal_accept(const ra8_fmt_spool_t *spool, const ra8_fmt_jof_verify_requirements_t *need, ra8_fmt_jof_verify_workspace_t *work, bool reference, jof_info_t *info)
Parse, check geometry, and decode every tile of one sealed spool.
static void internal_geometry(const ra8_fmt_sink_t *report, const jof_info_t *info, const jof_info_t *subject)
Emit the exact legacy verifier geometry line.
static ra8_err_t internal_produce(const ra8_fmt_source_t *source, const ra8_fmt_jof_verify_requirements_t *need, uint16_t tile_h, ra8_fmt_jof_verify_workspace_t *work, ra8_fmt_spool_t *spool, jof_info_t *info)
Produce and seal one deflate JOF into an injected spool.
static void internal_dump_bytes(verify_compare_t *state, const uint8_t *bytes, size_t len)
Append optional PPM bytes or mark the dump failed.
static ra8_err_t internal_pull(void *ctx, uint8_t *bytes, size_t cap, size_t *got)
Pull the next bounded source prefix for streamed JOF production.
static ra8_err_t internal_preflight(const ra8_fmt_spool_t *spool, const jof_info_t *info, ra8_fmt_jof_verify_workspace_t *work, bool reference)
Decode every sealed atlas tile before reporting or output staging.
static ra8_err_t internal_u64(const ra8_fmt_sink_t *sink, uint64_t value)
Append one uint64_t as canonical decimal.
static void internal_dump_u64(verify_compare_t *state, uint64_t value)
Append one decimal PPM header field.
static ra8_err_t internal_spool_append(void *ctx, const uint8_t *bytes, size_t len)
Append one produced JOF span to the injected verifier spool.
static void internal_abort_transaction(ra8_fmt_transaction_t *dump)
Abort an optional complete transaction binding.
size_t strlen(const char *s)
Calculate string length.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
Parsed + validated geometry of one JOF atlas.
uint8_t bpp
Bytes per pixel (1, 3 or 4).
uint8_t codec
jof_codec_t member.
uint16_t tile_w
Tile width, pixels.
uint16_t width
Image width, pixels.
uint16_t tile_rows
Ceil(height / tile_h) tile rows.
uint16_t tile_h
Tile height, pixels.
uint32_t tile_count
Total tiles (== cols * rows).
uint16_t height
Image height, pixels.
uint32_t total_size
Whole atlas byte length (footer included).
uint16_t tile_cols
Ceil(width / tile_w) tile columns.
Producer configuration: source, sink, tile geometry and work arena.
Exact phase-reused storage requirements for JOF verification.
uint32_t row_bytes
One decoded reference row.
uint8_t bpp
Decoder output bytes per pixel.
uint16_t band_height
Subject tile height under test.
uint32_t reference_work_bytes
One-row reference producer arena.
uint16_t width
Source width in pixels.
uint16_t height
Source height in pixels.
uint32_t band_tile_bytes
Largest decoded subject tile.
uint32_t scratch_bytes
Largest stored-tile staging buffer.
uint32_t webp_work_bytes
Whole-frame WebP arena, or zero.
uint32_t banded_work_bytes
Banded subject producer arena.
Caller-owned phase-overlaid arenas for one bounded JOF verification.
Injected append-only sink.
ra8_fmt_sink_write_fn write
Exact append callback.
void * ctx
Backend-owned context.
Immutable, randomly readable input object.
uint64_t size
Exact object byte length.
void * ctx
Backend-owned context.
ra8_fmt_source_validate_fn validate
Optional stability callback.
jof_pread_fn read_at
Positioned-read callback.
Caller-owned scratch artifact with append, seal, and read seams.
ra8_fmt_sink_write_fn append
Append before seal.
jof_pread_fn read_at
Positioned reader after seal.
ra8_fmt_spool_seal_fn seal
Seal exact produced bytes.
void * ctx
Backend-owned state.
ra8_err_t(* commit)(void *ctx)
Sync and atomically install.
ra8_fmt_sink_write_fn append
Append artifact bytes.
void(* abort)(void *ctx)
Discard owned staging data.
One caller-owned artifact transaction.
void * ctx
Backend-owned state.
const ra8_fmt_transaction_ops_t * ops
Transaction implementation.
Parsed and fully preflighted reference and subject atlases.
jof_info_t banded
Production-band geometry.
jof_info_t reference
One-row reference geometry.
Comparison state shared by bounded tile/row helpers.
const ra8_fmt_spool_t * ref
Sealed reference atlas.
uint32_t shown
Detailed differences emitted.
const jof_info_t * ginfo
Parsed subject geometry.
const ra8_fmt_sink_t * report
Human-readable report sink.
ra8_fmt_transaction_t * dump
Optional unpublished PPM stage.
const jof_info_t * rinfo
Parsed reference geometry.
bool dump_ok
PPM stage remains complete.
const ra8_fmt_jof_verify_requirements_t * need
Exact geometry and capacities.
uint64_t diffs
Differing byte count.
const ra8_fmt_spool_t * got
Sealed banded atlas.
Sequential cursor over one positioned source context.
const ra8_fmt_source_t * source
Immutable positioned source.
uint64_t offset
Next sequential byte offset.