29typedef enum : uint32_t {
63 const ra8_err_t rc = pread(ctx, offset, buf, len, &got);
85 return (uint32_t)p[0] | ((uint32_t)p[1] << 8U) | ((uint32_t)p[2] << 16U) |
108 for (
size_t i = 0U; i < len; ++i) {
110 if (bytes[i] != bytes[0]) {
114 h ^= (uint32_t)bytes[i];
117 *out_uniform = uniform;
144 if (ptr ==
nullptr) {
147 uintptr_t begin = 0U;
148 static_assert(
sizeof(begin) ==
sizeof(ptr),
"uintptr_t must preserve a pointer representation");
149 (void)
memcpy((
void*)&begin, (
const void*)&ptr,
sizeof(begin));
150 if (len > (
size_t)(UINTPTR_MAX - begin)) {
153 *out = (
internal_span_t){.begin = begin, .end = begin + (uintptr_t)len};
242 if (pread ==
nullptr) {
245 if (out ==
nullptr) {
253 const uint64_t tile64 = (uint64_t)info.
tile_w * (uint64_t)info.
tile_h * (uint64_t)info.
bpp;
254 if (tile64 > UINT32_MAX) {
257 const uint32_t tile = (uint32_t)tile64;
358 if (ws->
tile ==
nullptr) {
408 uint32_t matches = 0U;
409 for (uint32_t i = 0U; i < count; ++i) {
410 if (records[i].uniform) {
413 if (records[i].payload != item->
payload) {
469 const uint64_t next = (uint64_t)record->
offset + (uint64_t)record->
length;
470 if (next > UINT32_MAX) {
493 uint16_t want_w = 0U;
494 uint16_t want_h = 0U;
499 bool geometry_error = record->
width != want_w;
500 if (record->
height != want_h) {
501 geometry_error =
true;
503 if (geometry_error) {
519 if (pread ==
nullptr) {
522 if (out ==
nullptr) {
535 rc =
jof_parse(pread, pread_ctx, total_size, &candidate.
info);
541 .pread_ctx = pread_ctx,
542 .workspace = workspace,
543 .candidate = &candidate,
@ k_jof_index_entry
Bytes per tile-index entry.
@ k_jof_hdr_bytes
Header length.
@ k_jof_idx_ofs_length
Index entry: u32 tile length.
@ k_jof_idx_ofs_offset
Index entry: u32 tile offset.
ra8_err_t(* jof_pread_fn)(void *ctx, uint64_t offset, uint8_t *buf, size_t len, size_t *got)
Positioned-read seam over an atlas backing store (DIP).
ra8_err_t jof_tile_dims(const jof_info_t *info, uint16_t tile_x, uint16_t tile_y, uint16_t *out_w, uint16_t *out_h)
Report the true (edge-clamped) pixel dimensions of one tile.
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.
uint32_t jof_stored_bound(uint32_t raw_bytes)
Worst-case stored-tile byte bound for scratch/cell sizing.
static uint32_t internal_rd_u32(const uint8_t *p)
Decode a little-endian u32 from an index entry.
static ra8_err_t internal_check_workspace_spans(const jof_audit_workspace_t *ws, const jof_audit_requirements_t *need, const jof_audit_result_t *out, size_t record_bytes)
Validate the writable audit span layout.
static ra8_err_t internal_make_span(const void *ptr, size_t len, internal_span_t *out)
Convert one caller region into an overflow-checked address span.
jof_audit_hash_t
FNV-1a constants used for decoded tile evidence.
@ k_jof_audit_fnv_prime
FNV-1a 32-bit prime.
@ k_jof_audit_u32_b3_shift
LE32 high-byte shift.
@ k_jof_audit_fnv_basis
FNV-1a 32-bit offset basis.
static ra8_err_t internal_audit_tile(internal_audit_context_t *context, uint32_t index_number)
Audit one index entry and its decoded tile evidence.
static bool internal_any_workspace_overlap(const internal_span_t *workspace, const internal_span_t *records, const internal_span_t *tile, const internal_span_t *scratch, const internal_span_t *result)
Check every pair of writable audit spans for overlap.
ra8_err_t jof_audit_requirements(jof_pread_fn pread, void *pread_ctx, uint64_t total_size, jof_audit_requirements_t *out)
Parse an atlas and report exact caller-storage requirements.
static uint32_t internal_hash(const uint8_t *bytes, size_t len, bool *out_uniform)
Hash decoded bytes and report whether all bytes are equal.
static uint32_t internal_duplicate_count(const jof_audit_record_t *records, uint32_t count, const jof_audit_record_t *item)
Count earlier records matching one non-uniform tile fingerprint.
static bool internal_spans_overlap(const internal_span_t *left, const internal_span_t *right)
Report whether two non-wrapping half-open spans overlap.
static ra8_err_t internal_read_exact(jof_pread_fn pread, void *ctx, uint64_t offset, uint8_t *buf, size_t len)
Read exactly one bounded window from the injected backing.
ra8_err_t jof_audit(jof_pread_fn pread, void *pread_ctx, uint64_t total_size, jof_audit_workspace_t *workspace, jof_audit_result_t *out)
Audit coverage, geometry and duplicate-content evidence in bounded RAM.
static ra8_err_t internal_check_workspace(const jof_audit_workspace_t *ws, const jof_audit_requirements_t *need, const jof_audit_result_t *out)
Validate caller workspace against parsed requirements.
No-heap, backing-agnostic structural audit for JOF atlases.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ 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_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.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
Mutable state shared by the bounded per-tile audit operation.
jof_pread_fn pread
Injected positioned reader.
uint32_t expected_offset
Next canonical payload offset.
jof_audit_workspace_t * workspace
Caller-owned reusable storage.
jof_audit_result_t * candidate
Transactional result candidate.
void * pread_ctx
Reader-specific context.
Half-open address span used for caller-buffer separation checks.
uintptr_t end
One-past-last byte address.
uintptr_t begin
First byte address.
One decoded tile's stored window and content evidence.
uint16_t height
Edge-clamped decoded height.
uint32_t length
Stored-stream length.
uint16_t width
Edge-clamped decoded width.
uint32_t offset
Absolute stored-stream offset.
bool uniform
All decoded bytes have the same value.
uint32_t content_hash
FNV-1a over decoded bytes.
uint32_t payload
Exact decoded payload bytes.
Exact caller-storage requirements derived from a parsed atlas.
uint32_t scratch_bytes
Stored-stream scratch (zero for raw).
uint32_t record_count
Record entries required.
uint32_t tile_bytes
Decoded tile-buffer bytes required.
Geometry plus anomaly counts emitted by a complete audit.
uint32_t coverage_errors
Gap/overlap/order/end mismatches.
jof_info_t info
Parsed atlas geometry.
uint32_t geometry_errors
Decoded size disagreed with tile geometry.
uint32_t decoded_tiles
Tiles decoded and hashed.
uint32_t duplicate_candidates
Matching non-uniform hash/size evidence.
Caller-owned buffers consumed by one audit.
jof_audit_record_t * records
Tile record array.
uint32_t tile_cap
Bytes available at tile.
uint32_t record_cap
Entries available at records.
uint32_t scratch_cap
Bytes available at scratch.
uint8_t * tile
Reusable decoded tile.
uint8_t * scratch
Reusable compressed staging.
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.
uint32_t index_off
Absolute byte offset of the tile index.
uint16_t tile_h
Tile height, pixels.
uint32_t tile_count
Total tiles (== cols * rows).
uint16_t tile_cols
Ceil(width / tile_w) tile columns.