ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
jof_produce_webp.c File Reference

Transcode producer: whole-frame WebP arm (#290 normalize-on-import). More...

#include <stddef.h>
#include <stdint.h>
#include "jof_internal.h"
#include "jof_produce.h"
#include "ra8_attributes.h"
#include "ra8_err.h"
#include "ra8_webp.h"
#include "ra8_webp_arena.h"
Include dependency graph for jof_produce_webp.c:

Go to the source code of this file.

Enumerations

enum  jof_webp_const_t : uint32_t {
  k_jof_webp_bpp = 4U ,
  k_jof_webp_scratch_mult = 2U ,
  k_jof_webp_scratch_slack = 1U * 1024U * 1024U
}
 WebP whole-frame arena sizing constants (webp_work layout). More...

Functions

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).
static ra8_err_t internal_webp_pull_all (jof_prefix_pull_t *pfx, uint8_t *dst, size_t cap, size_t *out_len)
 Pull the whole compressed WebP source into the webp_work arena.
static ra8_err_t internal_webp_feed (jof_prod_state_t *st, const uint8_t *frame, uint16_t w, uint16_t h)
 Band a decoded RGBA frame through the shared tile path.
ra8_err_t priv_jof_webp_transcode (jof_prod_state_t *st, jof_prefix_pull_t *pfx)
 Transcode a WebP source into the JOF tile path (whole-frame, #290).

Detailed Description

Transcode producer: whole-frame WebP arm (#290 normalize-on-import).

The producer normalises WebP manifest images to the one on-device JOF band-tile format alongside JPEG and PNG, so the reader consumes a single format regardless of source. WebP is not stripe-decodable (its lossless VP8L mode back-references the whole frame), so – unlike the streaming JPEG/PNG arms – it carries an honest whole-frame memory cost isolated in the caller's separate webp_work arena: the compressed source, the decoded RGBA frame and libwebp's scratch are all resident at once, fail-closed on any shortfall, no downscaling. Once decoded the frame is banded out through the shared band accumulator (priv_jof_on_rows()), so the emitted atlas bytes are identical to the streaming arms for the same pixels. This arm is dispatched from jof_produce.c and shares the producer state and geometry / rows / prefix-pull seams through jof_internal.h; it allocates nothing on the heap (libwebp scratch is drawn from webp_work through the ra8_webp bump arena).

[Ring 4 / Domain] {World: NS}

Definition in file jof_produce_webp.c.

Enumeration Type Documentation

◆ jof_webp_const_t

enum jof_webp_const_t : uint32_t

WebP whole-frame arena sizing constants (webp_work layout).

The WebP decode holds the compressed source, the decoded RGBA frame and libwebp's scratch simultaneously; the scratch bound is a whole- frame-scale over-estimate (libwebp's VP8L path reconstructs the full image internally) plus a fixed slack. Under-sizing merely fails the decode closed – it can never overrun.

Enumerator
k_jof_webp_bpp 

WebP decodes to RGBA8888.

k_jof_webp_scratch_mult 

Scratch >= this * frame bytes.

k_jof_webp_scratch_slack 

Fixed scratch slack (bytes).

Definition at line 48 of file jof_produce_webp.c.

Function Documentation

◆ internal_webp_feed()

ra8_err_t internal_webp_feed ( jof_prod_state_t * st,
const uint8_t * frame,
uint16_t w,
uint16_t h )
static

Band a decoded RGBA frame through the shared tile path.

Feeds the whole-frame RGBA buffer to priv_jof_on_rows in tile_h slices, so the WebP path reuses the identical band/cut/encode/sink machinery as the streaming decoders (byte-identical output).

Parameters
[in,out]stProducer state (geometry already bound).
[in]frameDecoded RGBA8888 pixels, h rows of w * 4 bytes.
[in]wFrame width, pixels.
[in]hFrame height, pixels.
Returns
Result code.
Return values
k_ra8_okEvery row was fed; bands flushed as they filled.
otherPropagated from priv_jof_on_rows.
Precondition
priv_jof_on_geom() has fired (geom_done == 1) with these w/h/4bpp.
frame holds h * w * 4 readable bytes.
Postcondition
On success rows_seen == h; the last partial band is left for the epilogue to flush.
On error the transcode aborts.
Note
Not thread-safe.
Since
0.1.0

Definition at line 137 of file jof_produce_webp.c.

References jof_prod_state_t::cfg, k_jof_webp_bpp, k_ra8_ok, priv_jof_on_rows(), and jof_produce_cfg_t::tile_h.

Referenced by priv_jof_webp_transcode().

◆ internal_webp_pull_all()

ra8_err_t internal_webp_pull_all ( jof_prefix_pull_t * pfx,
uint8_t * dst,
size_t cap,
size_t * out_len )
static

Pull the whole compressed WebP source into the webp_work arena.

WebP is not stripe-decodable (its lossless mode back-references the whole frame), so libwebp needs the entire compressed source contiguous. Fills dst front to back; a source longer than the arena affords fails closed (k_ra8_err_invalid_size).

Parameters
[in]pfxPrefix-replay pull adapter over the source.
[out]dstArena front (receives the source bytes).
[in]capBytes available at dst.
[out]out_lenReceives the source byte count.
Returns
Result code.
Return values
k_ra8_okWhole source resident in dst.
k_ra8_err_invalid_sizeThe source exceeds cap (fail-closed).
otherPropagated from the pull callback.
Precondition
dst holds cap writable bytes.
pfx replays the sniffed head before the live source.
Postcondition
On success *out_len <= cap bytes are resident from dst[0].
On error the transcode aborts.
Note
Not thread-safe.
Since
0.1.0

Definition at line 94 of file jof_produce_webp.c.

References k_ra8_err_invalid_size, k_ra8_ok, and priv_jof_prefix_pull().

Referenced by priv_jof_webp_transcode().

◆ jof_webp_work_bytes()

uint32_t jof_webp_work_bytes ( uint16_t max_width,
uint16_t max_height,
uint32_t max_src_bytes )
nodiscard

Compute the whole-frame webp_work arena a WebP source needs (#290).

A WebP transcode cannot stream (its lossless mode back-references the whole frame), so it holds three regions at once, all carved from webp_work: the compressed source (up to max_src_bytes), the decoded RGBA8888 frame (max_width * max_height * 4) and libwebp's decode scratch (a further whole-frame-scale allocation plus slack). Sizing with the same caps used in the produce config guarantees jof_produce() never fails on WebP arena exhaustion for an in-cap WebP source. This is separate from jof_work_bytes(): that arena stays small (the streaming tile path); only WebP-capable callers pay the whole-frame cost here.

Parameters
[in]max_widthLargest WebP source width to support (>= 1).
[in]max_heightLargest WebP source height to support (>= 1).
[in]max_src_bytesLargest compressed WebP byte length to support (>= 1).
Returns
Required webp_work size in bytes, or 0 on nonsense / out-of-cap inputs.
Return values
0A dimension is zero or exceeds the WebP per-axis cap (8192), the source-byte cap is zero, or the total exceeds the u32 arena cap.
>0Byte size to allocate for webp_work.
Precondition
Arguments describe the caller's real WebP budget caps.
The same max_width/max_height bound the produce config caps.
Postcondition
No state mutated.
A webp_work_cap of the returned size never exhausts mid-decode for an in-cap WebP source of at most max_src_bytes compressed bytes.
Note
Thread-safe (pure).
See also
jof_produce()
Since
0.1.0

Definition at line 54 of file jof_produce_webp.c.

References k_jof_carve_slack, k_jof_webp_bpp, k_jof_webp_scratch_mult, k_jof_webp_scratch_slack, and k_ra8_webp_max_dim.

Referenced by internal_jof_carve_webp(), ra8_fmt_jof_convert_requirements(), and worker_alloc_webp().

◆ priv_jof_webp_transcode()

ra8_err_t priv_jof_webp_transcode ( jof_prod_state_t * st,
jof_prefix_pull_t * pfx )

Transcode a WebP source into the JOF tile path (whole-frame, #290).

Pulls the whole compressed source into cfg->webp_work, reads its geometry, binds it as a 4-bpp source through priv_jof_on_geom, carves the decoded RGBA frame and libwebp scratch after the source bytes, decodes heap-free through the ra8_webp facade, and bands the frame out through priv_jof_on_rows. Every carve is bounds-checked; any shortfall fails closed. WebP is not stripe-decodable (its lossless mode back-references the whole frame), so it carries an honest whole-frame memory cost isolated in webp_work; the emitted atlas bytes are identical to the streaming arms for the same pixels.

Parameters
[in,out]stProducer state (priv_init_state() succeeded).
[in,out]pfxPrefix-replay pull adapter over the source.
Returns
Result code.
Return values
k_ra8_okWhole WebP decoded and accumulated.
k_ra8_err_not_supportedNo webp_work arena, or an axis over cap.
k_ra8_err_invalid_sizeThe arena cannot fit source + frame + scratch.
k_ra8_err_validation_failedCorrupt WebP or the scratch exhausted.
otherPropagated from the pull / facade / rows.
Precondition
priv_jof_prefix_pull replays the sniffed head before the source.
The dispatcher confirmed the RIFF+WEBP head.
Postcondition
On success every source row reached the band accumulator.
On error the transcode aborts.
Note
Not thread-safe.
Since
0.1.0

Definition at line 158 of file jof_produce_webp.c.

References jof_prod_state_t::cfg, internal_webp_feed(), internal_webp_pull_all(), k_jof_bump_align, k_jof_webp_bpp, k_ra8_err_invalid_size, k_ra8_err_not_supported, k_ra8_ok, priv_jof_on_geom(), RA8_PRIV, ra8_webp_decode_rgba(), ra8_webp_get_info(), jof_produce_cfg_t::webp_work, and jof_produce_cfg_t::webp_work_cap.

Referenced by internal_dispatch().