30typedef enum : uint64_t {
37typedef enum : uint8_t {
85 const ssize_t got = read(fd, buf + done, len - done);
124 const ssize_t wrote =
write(s->
fd, buf + done, len - done);
130 if (errno == EINTR) {
136 done += (size_t)wrote;
162 size_t n = s->
len - s->
pos;
253 const int in_fd = open(in_path, O_RDONLY);
258 if (fstat(in_fd, &st) != 0) {
266 const size_t src_len = (size_t)st.st_size;
267 uint8_t* src = (uint8_t*)malloc(src_len);
268 if (src ==
nullptr) {
310 uint8_t** out_webp_work,
311 size_t* out_webp_cap)
313 *out_webp_work =
nullptr;
318 if (src_len > UINT32_MAX) {
322 if (webp_need == 0U) {
326 (uint8_t*)malloc(webp_need);
327 if (webp_work ==
nullptr) {
330 *out_webp_work = webp_work;
331 *out_webp_cap = (size_t)webp_need;
373 size_t webp_work_cap)
375 const int out_fd = open(out_path, O_WRONLY | O_CREAT | O_TRUNC, (mode_t)
k_worker_out_mode);
379 worker_pull_t pull = {.data = src, .len = src_len, .pos = 0U};
392 .work_cap = work_cap,
393 .webp_work = webp_work,
394 .webp_work_cap = webp_work_cap,
398 const int close_rc = close(out_fd);
400 if ((close_rc != 0) || sink.
failed) {
409RA8_NASA_RULE_3_OK(
"host-only single-image transcode: three bounded arenas sized by probe")
412 if ((in_path ==
nullptr) || (out_path ==
nullptr)) {
415 uint8_t* src =
nullptr;
429 if (work_cap == 0U) {
433 uint8_t* work = (uint8_t*)malloc(work_cap);
434 if (work ==
nullptr) {
438 uint8_t* webp_work =
nullptr;
439 size_t webp_work_cap = 0U;
457 (void)unlink(out_path);
@ 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_probe_dims(const uint8_t *data, size_t len, uint16_t *out_w, uint16_t *out_h)
Read a source image's pixel dimensions without decoding its body.
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).
static const uint8_t s_worker_webp[k_worker_webp_tag_len]
WebP form-type fourCC (source head bytes 8..11).
static bool worker_is_webp(const uint8_t *data, size_t len)
Test whether source bytes carry the WebP RIFF container head.
static jof_worker_result_t worker_read_source(const char *in_path, uint8_t **out_src, size_t *out_len)
Read encoded source file into an allocated RAM buffer.
static jof_worker_result_t worker_alloc_webp(const uint8_t *src, size_t src_len, uint16_t w, uint16_t h, uint8_t **out_webp_work, size_t *out_webp_cap)
Allocate the WebP frame arena if the source format requires one.
worker_limit_t
Named resource limits for the worker.
@ k_worker_out_mode
File mode: rw-r–r–.
@ k_worker_tile_h
Band-tile height cap, pixels.
@ k_worker_max_input
Largest accepted input, bytes.
static bool worker_read_all(int fd, uint8_t *buf, size_t len)
Read exactly len bytes unless the descriptor fails or ends early.
worker_webp_t
WebP container-head offsets for the whole-frame-arena decision.
@ k_worker_webp_form_ofs
Offset of the "WEBP" fourCC.
@ k_worker_webp_head_len
Bytes needed to sniff both tags.
@ k_worker_webp_riff_ofs
Offset of the "RIFF" fourCC.
@ k_worker_webp_tag_len
Length of one fourCC tag.
static ra8_err_t worker_pull(void *ctx, uint8_t *buf, size_t cap, size_t *got)
Copy the next encoded source span into a producer buffer.
static jof_worker_result_t worker_produce_to_file(const char *out_path, const uint8_t *src, size_t src_len, uint16_t w, uint16_t h, uint16_t tile_h, uint8_t *work, size_t work_cap, uint8_t *webp_work, size_t webp_work_cap)
Stream JOF producer output into the destination atlas file.
static ra8_err_t worker_sink(void *ctx, const uint8_t *buf, size_t len)
Append producer output bytes to the output descriptor.
static const uint8_t s_worker_riff[k_worker_webp_tag_len]
WebP RIFF container tag (source head bytes 0..3).
static jof_worker_result_t worker_map_producer(ra8_err_t err)
Map a producer return code to the worker result contract.
Single-image to JOF worker: the per-page transcode the cbz2jof Go driver shells out to.
jof_worker_result_t
Process exit code contract between the worker and its Go driver.
@ k_jof_worker_ok
Atlas fully written to the output path.
@ k_jof_worker_output
Output open/write/close failed.
@ k_jof_worker_geometry
Source dimensions unusable or unproduceable.
@ k_jof_worker_input
Input open/stat/read failed or was refused.
@ k_jof_worker_usage
Wrong argument count or null path.
@ k_jof_worker_decode
Source is hostile or an unsupported variant.
@ k_jof_worker_memory
A bounded work arena could not be allocated.
jof_worker_result_t jof_worker_convert(const char *in_path, const char *out_path)
Transcode one encoded image file into one JOF atlas file.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_NASA_RULE_3_OK(reason)
Documented exception to NASA Power-of-10 Rule 3 (no dynamic alloc).
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_fail
Generic unspecified failure.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ 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.
Producer configuration: source, sink, tile geometry and work arena.
Pull cursor over the in-RAM encoded source.
const uint8_t * data
Encoded bytes.
Sink state over the raw output descriptor.
int fd
Open output descriptor.
bool failed
Latched true on any write failure.