31static const char*
const s_tag =
"jof";
37typedef enum : uint8_t {
51typedef enum : uint16_t {
78 return (uint16_t)((uint16_t)buf[off +
k_jof_le_b0] |
121 return (n + d - 1U) / d;
148 const ra8_err_t err = pread(pread_ctx, off, buf, len, &got);
169 if (len > (store->
cap - store->
len)) {
185 if (offset >= (uint64_t)store->
len) {
188 const size_t avail = store->
len - (size_t)offset;
189 const size_t take = (len < avail) ? len : avail;
190 (void)
memcpy(buf, &store->
buf[(
size_t)offset], take);
225 if (info->
width == 0U) {
307 const uint32_t want = cols * rows;
311 if (hdr_count != want) {
317 if (ftr_count != want) {
320 if ((uint64_t)ftr_total != total_size) {
326 const uint64_t index_end = (uint64_t)index_off + ((uint64_t)want * (uint64_t)
k_jof_index_entry) +
328 if (index_end != total_size) {
364 static const uint8_t s_magic_hdr[
k_jof_magic_len] = {
'J',
'O',
'F',
'1'};
381 static const uint8_t s_magic_ftr[
k_jof_magic_len] = {
'J',
'O',
'F',
'E'};
385 if ((total_size < min_size) || (total_size > (uint64_t)UINT32_MAX)) {
429 const uint32_t px = (uint32_t)tile_x * (uint32_t)info->
tile_w;
430 const uint32_t py = (uint32_t)tile_y * (uint32_t)info->
tile_h;
431 const uint32_t rest_w = (uint32_t)info->
width - px;
432 const uint32_t rest_h = (uint32_t)info->
height - py;
433 *out_w = (uint16_t)((rest_w < (uint32_t)info->
tile_w) ? rest_w : (uint32_t)info->
tile_w);
434 *out_h = (uint16_t)((rest_h < (uint32_t)info->
tile_h) ? rest_h : (uint32_t)info->
tile_h);
483 const uint64_t tend = (uint64_t)toff + (uint64_t)tlen;
528 uint32_t scratch_cap,
532 if (tlen != payload) {
538 if (tlen > scratch_cap) {
549 if (got != payload) {
584 uint32_t scratch_cap,
625 const uint8_t* out_px,
626 const uint16_t* out_w,
627 const uint16_t* out_h)
643 uint32_t scratch_cap,
659 const uint32_t payload = (uint32_t)tw * (uint32_t)th * (uint32_t)info->
bpp;
660 if (payload > out_cap) {
663 const uint32_t n = ((uint32_t)tile_y * (uint32_t)info->
tile_cols) + (uint32_t)tile_x;
jof_le_t
Little-endian assembly constants for the header/footer fields.
@ k_jof_le_sh16
16-bit shift.
@ k_jof_le_b1
Byte 1 offset.
@ k_jof_le_b3
Byte 3 (MSB) offset.
@ k_jof_le_sh24
24-bit shift.
@ k_jof_le_sh8
8-bit shift.
@ k_jof_le_b0
Byte 0 (LSB) offset.
@ k_jof_le_b2
Byte 2 offset.
ra8_err_t jof_memstore_pread(void *ctx, uint64_t offset, uint8_t *buf, size_t len, size_t *got)
Positioned read from a jof_memstore_t (reader seam).
static ra8_err_t internal_read_args_ok(jof_pread_fn pread, const jof_info_t *info, const uint8_t *out_px, const uint16_t *out_w, const uint16_t *out_h)
Reject any NULL jof_read_tile pointer argument.
static uint32_t internal_ceil_div(uint32_t n, uint32_t d)
Ceil-divide n by d (d > 0).
static ra8_err_t internal_fetch_decode(jof_pread_fn pread, void *pread_ctx, const jof_info_t *info, uint32_t n, uint32_t payload, uint8_t *scratch, uint32_t scratch_cap, uint8_t *out_px)
Fetch tile n's index entry, then read + decode its stream.
static ra8_err_t internal_pread_exact(jof_pread_fn pread, void *pread_ctx, uint64_t off, uint8_t *buf, size_t len)
Exact positioned read: EOF or a short read is a validation failure.
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.
static ra8_err_t internal_check_cross(jof_info_t *info, uint32_t hdr_count, const uint8_t *ftr, uint64_t total_size)
Cross-check grid, tile-count, footer and index-window invariants.
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.
static ra8_err_t internal_parse_header_region(jof_pread_fn pread, void *pread_ctx, uint8_t *hdr, jof_info_t *out_info)
Read + validate the 32-byte header region into out_info.
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.
static uint16_t internal_rd_u16(const uint8_t *buf, uint8_t off)
Read a little-endian uint16 from buf at off.
uint32_t jof_stored_bound(uint32_t raw_bytes)
Implementation of jof_stored_bound() – raw + raw/8 + 256.
static ra8_err_t internal_decode_stream(jof_pread_fn pread, void *pread_ctx, const jof_info_t *info, uint32_t toff, uint32_t tlen, uint32_t payload, uint8_t *scratch, uint32_t scratch_cap, uint8_t *out_px)
Decode a validated tile stream into out_px.
jof_bound_t
Worst-case stored-stream expansion terms (see the header contract).
@ k_jof_bound_div
Expansion denominator (raw / 8).
@ k_jof_bound_add
Fixed expansion margin, bytes.
static ra8_err_t internal_index_entry(jof_pread_fn pread, void *pread_ctx, const jof_info_t *info, uint32_t n, uint32_t *out_off, uint32_t *out_len)
Fetch + window-validate the index entry for tile n.
static uint32_t internal_rd_u32(const uint8_t *buf, uint8_t off)
Read a little-endian uint32 from buf at off.
static ra8_err_t internal_check_reserved(const uint8_t *hdr)
Reject any non-zero reserved header byte (strict, fail-closed).
static ra8_err_t internal_parse_hdr_fields(const uint8_t *hdr, jof_info_t *info)
Validate the header geometry fields into info (fail-closed).
ra8_err_t jof_memstore_sink(void *ctx, const uint8_t *buf, size_t len)
Append len bytes to a jof_memstore_t (producer sink).
JOF band-tile atlas: the display-native normalized image format (#231, shared with the longstrip scro...
@ k_jof_ofs_tile_count
Header: u32 tile count.
@ k_jof_index_entry
Bytes per tile-index entry.
@ k_jof_ofs_magic
Header: magic "JOF1".
@ k_jof_ofs_reserved
Header: first reserved byte.
@ k_jof_magic_len
Magic string length (both ends).
@ k_jof_footer_bytes
Footer length.
@ k_jof_ftr_total_size
Footer: u32 total atlas size.
@ k_jof_hdr_bytes
Header length.
@ k_jof_ftr_magic
Footer: magic "JOFE".
@ k_jof_ftr_index_off
Footer: u32 index offset.
@ k_jof_ofs_reserved2
Header: second reserved run.
@ k_jof_ofs_tile_h
Header: u16 tile height.
@ k_jof_ofs_codec
Header: u8 tile codec.
@ k_jof_idx_ofs_length
Index entry: u32 tile length.
@ k_jof_ofs_height
Header: u16 image height.
@ k_jof_ofs_tile_w
Header: u16 tile width.
@ k_jof_ofs_width
Header: u16 image width.
@ k_jof_ftr_tile_count
Footer: u32 tile count.
@ k_jof_ofs_bpp
Header: u8 bytes per pixel.
@ k_jof_idx_ofs_offset
Index entry: u32 tile offset.
@ k_jof_bpp_max
Max bytes per pixel.
@ k_jof_max_dim
Max image width/height, pixels.
@ k_jof_max_tiles
Max tiles per atlas.
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).
@ k_jof_codec_deflate
Tile stream is one raw-DEFLATE run.
@ k_jof_codec_raw
Tile stream is the packed pixels.
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
App-domain DEFLATE compress / decompress (zero-heap, firmware-safe).
ra8_err_t ra8_decompress(const uint8_t *src, uint32_t src_len, uint8_t *out, uint32_t out_cap, uint32_t *out_len)
Raw-DEFLATE decompress src into out.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
@ 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_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.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
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.
uint32_t index_off
Absolute byte offset of the tile index.
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.
Append-only memory store: the simplest atlas backing (RAM/SDRAM).
uint8_t * buf
Caller-owned backing bytes.
size_t cap
Capacity of buf.
size_t len
Bytes appended so far (see sink).