22typedef enum : uint32_t {
48typedef enum : uint8_t {
56typedef enum : uint8_t {
89 if ((offset > source->
size) || ((uint64_t)len > (source->
size - offset))) {
96 source->
read_at(source->
ctx, offset + done, &bytes[done], len - done, &got);
100 if ((got == 0U) || (got > (len - done))) {
124 return (uint16_t)(((uint16_t)bytes[0] << 8U) | bytes[1]);
144 ((uint32_t)bytes[2] << 8U) | bytes[3];
164 const bool in_range =
231 uint16_t segment_len,
236 if (segment_len < 8U) {
248 if ((width == 0U) || (height == 0U) || ((uint32_t)width > (uint32_t)
k_jof_max_dim) ||
277 uint64_t offset = 2U;
278 while (offset < source->size) {
284 const bool standalone =
293 uint8_t length_bytes[2U];
299 if (segment_len < 2U) {
307 offset += segment_len;
308 if (offset > source->
size) {
337 if ((width == 0U) || (height == 0U) || (width > (uint32_t)
k_jof_max_dim) ||
341 *out_w = (uint16_t)width;
342 *out_h = (uint16_t)height;
378 size_t count =
sizeof(prefix);
379 if (source->
size < (uint64_t)count) {
380 count = (size_t)source->
size;
393 if (
memcmp(prefix, png_magic,
sizeof(png_magic)) == 0) {
400 if ((
memcmp(prefix,
"RIFF", 4U) == 0) && (
memcmp(&prefix[8],
"WEBP", 4U) == 0)) {
402 uint32_t height = 0U;
407 if ((width == 0U) || (height == 0U) || (width > (uint32_t)
k_jof_max_dim) ||
412 *out_w = (uint16_t)width;
413 *out_h = (uint16_t)height;
440 if ((pull ==
nullptr) || (got ==
nullptr) || ((bytes ==
nullptr) && (cap != 0U))) {
448 if ((uint64_t)cap > remain) {
449 cap = (size_t)remain;
452 if ((rc ==
k_ra8_ok) && (*got <= cap)) {
480 return transaction->
ops->
append(transaction->
ctx, bytes, len);
497 if ((transaction !=
nullptr) && (transaction->
ops !=
nullptr) &&
498 (transaction->
ops->
abort !=
nullptr)) {
520 return report->write(report->ctx, (
const uint8_t*)text,
strlen(text));
545 }
while (value != 0U);
547 for (
size_t i = 0U; i < count; ++i) {
548 text[i] = reverse[count - i - 1U];
550 return report->write(report->ctx, (
const uint8_t*)text, count);
618 if ((source ==
nullptr) || (source->
read_at ==
nullptr) || (out ==
nullptr)) {
635 if (source->
size > (uint64_t)UINT32_MAX) {
651 const char* output_name)
653 if ((source ==
nullptr) || (source->
read_at ==
nullptr) || (requirements ==
nullptr) ||
654 (workspace ==
nullptr) || (transaction ==
nullptr) || (transaction->
ops ==
nullptr) ||
656 (transaction->
ops->
abort ==
nullptr) || (report ==
nullptr) || (report->write ==
nullptr) ||
657 (output_name ==
nullptr)) {
664 if ((workspace->work ==
nullptr) || (workspace->
work_cap < requirements->
work_bytes) ||
674 .sink_ctx = transaction,
678 .max_width = requirements->
width,
679 .max_height = requirements->
height,
680 .work = workspace->work,
@ k_jof_max_dim
Max image width/height, pixels.
@ 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,...
uint32_t jof_webp_work_bytes(uint16_t max_width, uint16_t max_height, uint32_t max_src_bytes)
Compute the whole-frame webp_work arena a WebP source needs (#290).
uint32_t jof_work_bytes(uint16_t max_width, uint16_t max_height, uint16_t tile_w, uint16_t tile_h)
Compute the work-arena size the producer needs for given caps.
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_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ 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 uint16_t internal_be16(const uint8_t bytes[2])
Decode one big-endian uint16 field.
static void internal_abort(ra8_fmt_transaction_t *transaction)
Abort an active transaction after any pre-publication error.
ra8_err_t ra8_fmt_jof_convert_requirements(const ra8_fmt_source_t *source, ra8_fmt_jof_convert_requirements_t *out)
Derive source geometry and exact JOF conversion workspace needs.
static ra8_err_t internal_u64(const ra8_fmt_sink_t *report, uint64_t value)
Append one unsigned decimal to a report sink.
static bool internal_is_sof(uint8_t marker)
Classify JPEG SOF-range markers without mistaking table markers.
static ra8_err_t internal_append(void *ctx, const uint8_t *bytes, size_t len)
Producer sink adapter over the durable transaction append operation.
ra8_err_t ra8_fmt_jof_convert_stream(const ra8_fmt_source_t *source, const ra8_fmt_jof_convert_requirements_t *requirements, const ra8_fmt_jof_convert_workspace_t *workspace, ra8_fmt_transaction_t *transaction, const ra8_fmt_sink_t *report, const char *output_name)
Stream one encoded image into a durably published JOF artifact.
static uint32_t internal_be32(const uint8_t bytes[4])
Decode one big-endian uint32 field.
convert_kind_t
Accepted source encoding selected by the header probe.
@ k_convert_kind_jpeg
Baseline JPEG.
@ k_convert_kind_webp
WebP accepted by the firmware facade.
@ k_convert_kind_png
Non-interlaced PNG (producer validates body).
static ra8_err_t internal_jpeg_marker(const ra8_fmt_source_t *source, uint64_t *offset, uint8_t *marker)
Find the next non-fill JPEG marker code.
static ra8_err_t internal_jpeg_sof0(const ra8_fmt_source_t *source, uint64_t payload, uint16_t segment_len, uint16_t *out_w, uint16_t *out_h)
Parse and validate one baseline JPEG SOF0 segment.
convert_const_t
Image-probe and report constants.
@ k_convert_png_h
PNG IHDR height offset.
@ k_convert_jpeg_soi
JPEG start-of-image marker.
@ k_convert_u32_high_shift
Shift of a big-endian uint32 high byte.
@ k_convert_jpeg_eoi
JPEG end-of-image marker.
@ k_convert_jpeg_sof0
Baseline sequential frame marker.
@ k_convert_jpeg_dac
Arithmetic table non-frame marker.
@ k_convert_jpeg_tem
Standalone TEM marker.
@ k_convert_jpeg_sof_last
Last JPEG SOF-range marker.
@ k_convert_band_height
Established media-downloader band height.
@ k_convert_jpeg_rst_hi
Last restart marker.
@ k_convert_marker
JPEG marker introducer.
@ k_convert_jpeg_8bit
Supported JPEG sample precision.
@ k_convert_probe_min
Smallest supported image prefix.
@ k_convert_decimal_base
Report integer radix.
@ k_convert_png_dims_end
PNG prefix through IHDR dimensions.
@ k_convert_probe_bytes
WebP metadata prefix capacity.
@ k_convert_jpeg_sos
JPEG start-of-scan marker.
@ k_convert_jpeg_dht
Non-frame marker inside SOF number range.
@ k_convert_jpeg_jpg
Reserved non-frame marker.
@ k_convert_png_w
PNG IHDR width offset.
@ k_convert_decimal_max
Decimal digits in uint64_t.
@ k_convert_jpeg_rst_lo
First restart marker.
static ra8_err_t internal_jpeg_dims(const ra8_fmt_source_t *source, uint16_t *out_w, uint16_t *out_h)
Walk a JPEG marker chain to its baseline SOF0 dimensions.
static ra8_err_t internal_report(const ra8_fmt_sink_t *report, const jof_info_t *info, const char *output_name)
Emit the established successful-conversion report line.
static void internal_field(const ra8_fmt_sink_t *report, uint64_t value, const char *suffix, ra8_err_t *status)
Append one numeric report field and its suffix fail-fast.
convert_png_signature_t
Fixed non-ASCII bytes in the PNG signature.
@ k_convert_png_sig_cr
Carriage return byte.
@ k_convert_png_sig_high
High-bit signature byte.
@ k_convert_png_sig_sub
DOS EOF byte.
@ k_convert_png_sig_lf
Line feed byte.
static ra8_err_t internal_probe(const ra8_fmt_source_t *source, convert_kind_t *kind, uint16_t *out_w, uint16_t *out_h)
Probe the exact source kind and dimensions through positioned reads.
static ra8_err_t internal_read_exact(const ra8_fmt_source_t *source, uint64_t offset, uint8_t *bytes, size_t len)
Read an exact positioned source window.
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_png_dims(const uint8_t prefix[k_convert_png_dims_end], uint16_t *out_w, uint16_t *out_h)
Probe PNG dimensions from the fixed IHDR prefix.
static ra8_err_t internal_text(const ra8_fmt_sink_t *report, const char *text)
Append a NUL-terminated text fragment to a report sink.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
size_t strlen(const char *s)
Calculate string length.
static void internal_append(ra8_kbd_text_t *t, char ch)
Append character ch to the text buffer if capacity allows.
Zero-heap WebP (VP8 / VP8L) decode facade over the vendored libwebp.
ra8_err_t ra8_webp_get_info(const uint8_t *data, size_t size, uint32_t *out_w, uint32_t *out_h)
Read a WebP header's pixel dimensions without decoding the body.
Sequential cursor over one positioned source callback.
uint64_t offset
Next absolute byte offset.
const ra8_fmt_source_t * source
Borrowed immutable source.
Parsed + validated geometry of one JOF atlas.
uint8_t bpp
Bytes per pixel (1, 3 or 4).
uint16_t width
Image width, pixels.
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).
Producer configuration: source, sink, tile geometry and work arena.
Source geometry and exact arenas required by one JOF conversion.
uint16_t width
Declared source width in pixels.
uint32_t webp_work_bytes
Exact WebP whole-frame bytes, or zero.
uint16_t height
Declared source height in pixels.
uint16_t tile_height
Height selected for emitted tiles.
uint32_t work_bytes
Exact streaming-producer arena bytes.
uint16_t tile_width
Width selected for emitted tiles.
Caller-owned arenas supplied to the streaming JOF converter.
uint32_t work_cap
Bytes available at work.
uint8_t * webp_work
Optional WebP decode arena.
uint32_t webp_work_cap
Bytes at webp_work.
Injected append-only sink.
Immutable, randomly readable input object.
uint64_t size
Exact object byte length.
void * ctx
Backend-owned context.
jof_pread_fn read_at
Positioned-read callback.
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.