41static const char*
s_tag =
"JPEG_SW";
47typedef enum : uint16_t {
177 uint8_t* stripe =
nullptr;
178 uint32_t stripe_cap = 0U;
185 const uint32_t need = (uint32_t)d->
width * (uint32_t)st->
mcu_h * (uint32_t)st->
channels;
186 if (stripe_cap < need) {
218 uint32_t* out_scan_pos)
220 bool got_sof =
false;
221 bool geom_done =
false;
234 if (got_sof && !geom_done) {
276 const uint8_t* y_tile,
277 const uint8_t* cb_tile,
278 const uint8_t* cr_tile,
283 const uint32_t stride = (uint32_t)d->
width * (uint32_t)st->
channels;
284 for (uint16_t r = 0U; r < rows; r++) {
285 for (uint16_t c = 0U; c < st->
mcu_w; c++) {
286 const uint32_t px = ((uint32_t)mx * (uint32_t)st->
mcu_w) + (uint32_t)c;
287 if (px >= (uint32_t)d->
width) {
290 const int32_t y = (int32_t)y_tile[((uint32_t)r * (uint32_t)st->
mcu_w) + (uint32_t)c];
292 st->
stripe[((uint32_t)r * stride) + px] = (uint8_t)y;
295 const uint16_t cx = (uint16_t)(c / d->
hmax);
296 const uint16_t cy = (uint16_t)(r / d->
vmax);
299 const uint32_t idx = ((uint32_t)r * stride) + (px * (uint32_t)st->
channels);
332 const uint32_t shift = br->
pos;
427 for (uint16_t my = 0U; my < st->
mcus_y; my++) {
428 const uint32_t y0 = (uint32_t)my * (uint32_t)st->
mcu_h;
429 const uint32_t left = (uint32_t)d->
height - y0;
430 const uint16_t rows = (uint16_t)((left < (uint32_t)st->
mcu_h) ? left : (uint32_t)st->
mcu_h);
431 for (uint16_t mx = 0U; mx < st->
mcus_x; mx++) {
477 (void)
memset(st, 0,
sizeof(*st));
517 uint32_t scan_pos = 0U;
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.
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ 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.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
void * memmove(void *dst, const void *src, size_t n)
Copy memory area between potentially overlapping regions.
void priv_jpeg_sw_ycc_to_rgb(int32_t y, int32_t cb, int32_t cr, uint8_t *out_r, uint8_t *out_g, uint8_t *out_b)
Convert a YCbCr triple to RGB (BT.601, fixed-point).
Pure-software baseline JPEG (ISO/IEC 10918-1 / ITU-T T.81) codec.
@ k_ra8_jpeg_sw_stream_scan_margin
Refill trigger, bytes.
@ k_ra8_jpeg_sw_stream_min_window
Minimum window bytes.
ra8_err_t(* ra8_jpeg_sw_pull_fn)(void *ctx, uint8_t *buf, size_t cap, size_t *got)
Forward byte source for the streaming decoder (DIP seam).
ra8_err_t(* ra8_jpeg_sw_rows_fn)(void *ctx, const uint8_t *px, uint16_t width, uint16_t y0, uint16_t nrows, uint8_t channels)
Stripe sink: receives each completed run of decoded pixel rows.
ra8_err_t(* ra8_jpeg_sw_geom_fn)(void *ctx, uint16_t width, uint16_t height, uint8_t channels, uint16_t stripe_rows, uint8_t **out_stripe, uint32_t *out_stripe_cap)
Geometry callback: fires once, right after SOF0 parses.
ra8_err_t priv_jpeg_sw_dispatch(ra8_jpeg_dec_ctx_t *d, bool *got_sof, ra8_jpeg_dec_marker_action_t *action)
Implementation of priv_jpeg_sw_dispatch() – marker extraction + routing.
ra8_err_t priv_jpeg_sw_mcu_y(ra8_jpeg_dec_ctx_t *d, ra8_jpeg_bitreader_t *br, uint8_t *y_tile, uint16_t mcu_w_px)
Implementation of priv_jpeg_sw_mcu_y() – hmax*vmax luma block loop.
ra8_err_t priv_jpeg_sw_mcu_chroma(ra8_jpeg_dec_ctx_t *d, ra8_jpeg_bitreader_t *br, uint8_t *cb_tile, uint8_t *cr_tile)
Implementation of priv_jpeg_sw_mcu_chroma() – one Cb then one Cr block.
Module-private declarations shared across the software JPEGcodec translation units.
@ k_ra8_jpeg_marker_soi
Start of image.
static uint16_t internal_read_be16(const uint8_t *p)
Read a 16-bit big-endian word from p.
@ k_ra8_jpeg_mcu_max_dim
4:2:0 MCU is 16x16 luma px.
@ k_ra8_jpeg_block_size
Coefficients per block.
@ k_ra8_jpeg_block_dim
8x8 DCT block edge.
@ k_ra8_jpeg_max_comps
YCbCr or grayscale only.
ra8_jpeg_dec_marker_action_t
Result of priv_jpeg_sw_dispatch(): what the driver does next.
@ k_ra8_jpeg_dec_eoi
EOI reached; the driver should stop with an error.
@ k_ra8_jpeg_dec_continue
Keep scanning markers.
@ k_ra8_jpeg_dec_scan
SOS reached; the driver should run its scan loop.
static ra8_err_t internal_js_scan(ra8_jpeg_stream_state_t *st, uint32_t scan_pos)
Decode the whole entropy-coded scan, one MCU row per stripe.
ra8_jpeg_stream_const_t
Streaming-driver bounds (loop caps and phase sizes).
@ k_ra8_jpeg_stream_soi_bytes
SOI marker size.
@ k_ra8_jpeg_stream_max_markers
Marker-segment dispatch cap.
@ k_ra8_jpeg_stream_rgb_ch
Colour output channels.
@ k_ra8_jpeg_stream_gray_ch
Grayscale output channels.
static ra8_err_t internal_js_begin(ra8_jpeg_stream_state_t *st, ra8_jpeg_sw_pull_fn pull, void *pull_ctx, uint8_t *window, uint32_t window_cap, ra8_jpeg_sw_rows_fn on_rows, void *cb_ctx)
Bind the source, prime the window and consume the SOI marker.
ra8_err_t ra8_jpeg_sw_decode_stripes(ra8_jpeg_sw_pull_fn pull, void *pull_ctx, uint8_t *window, uint32_t window_cap, ra8_jpeg_sw_geom_fn on_geom, ra8_jpeg_sw_rows_fn on_rows, void *cb_ctx)
Decode a baseline JPEG in bounded RAM, one MCU-row stripe at a time.
static ra8_err_t internal_js_slide(ra8_jpeg_stream_state_t *st, uint32_t consumed)
Discard consumed leading window bytes and refill.
static ra8_err_t internal_js_parse_markers(ra8_jpeg_stream_state_t *st, ra8_jpeg_sw_geom_fn on_geom, uint32_t *out_scan_pos)
Walk marker segments until SOS, firing the geometry callback.
static void internal_js_emit_mcu(const ra8_jpeg_stream_state_t *st, const uint8_t *y_tile, const uint8_t *cb_tile, const uint8_t *cr_tile, uint16_t mx, uint16_t rows)
Emit one decoded MCU's visible pixels into the stripe buffer.
static ra8_err_t internal_js_refill(ra8_jpeg_stream_state_t *st)
Top the window up from the pull source until full or EOF.
static ra8_err_t internal_js_scan_margin(ra8_jpeg_stream_state_t *st, ra8_jpeg_bitreader_t *br)
Keep the entropy window topped up ahead of the bit reader.
static ra8_err_t internal_js_bind_geometry(ra8_jpeg_stream_state_t *st, ra8_jpeg_sw_geom_fn on_geom)
Validate the SOF0 geometry and fire the consumer geometry callback.
static ra8_jpeg_stream_state_t s_js
Module-static streaming state (codec documented not thread-safe).
static ra8_err_t internal_js_decode_mcu(ra8_jpeg_stream_state_t *st, ra8_jpeg_bitreader_t *br, uint8_t *y_tile, uint8_t *cb_tile, uint8_t *cr_tile, uint16_t mx, uint16_t rows)
Decode + emit one MCU: margin slide, luma, chroma, stripe write.
Lightweight Logging Interface for ra8-firmware.
Big-endian bit reader over an entropy-coded segment.
Decoder state shared by the whole-buffer and streaming drivers.
int32_t comp_dc_pred[k_ra8_jpeg_max_comps]
DC predictors (scan state).
uint16_t height
Image height from SOF0, pixels.
uint8_t vmax
Max vertical sampling factor.
uint32_t src_len
Length of src in bytes.
uint32_t cursor
Parse cursor into src.
uint8_t ncomp
1 grayscale, 3 YCbCr.
uint16_t width
Image width from SOF0, pixels.
uint8_t hmax
Max horizontal sampling factor.
const uint8_t * src
Byte slice the parsers read from.
Whole streaming-decode state: source window + geometry + stripe.
uint32_t win_len
Valid bytes currently in the window.
uint8_t eof
1 once the source reported EOF.
ra8_jpeg_sw_rows_fn on_rows
Stripe sink.
uint32_t win_cap
Window capacity, bytes.
ra8_jpeg_sw_pull_fn pull
Sequential byte source.
uint8_t * win
Sliding window base.
uint32_t stripe_cap
Stripe buffer capacity, bytes.
void * cb_ctx
Consumer context for both callbacks.
uint8_t * stripe
Consumer stripe buffer (geometry cb).
uint8_t channels
Output channels (1 or 3).
ra8_jpeg_dec_ctx_t dec
Shared decoder tables + parse state.
uint16_t mcus_x
MCU columns.
uint16_t mcu_w
MCU width, pixels.
uint16_t mcu_h
MCU height, pixels (== stripe rows).
void * pull_ctx
Context for pull.