41static const char*
s_tag =
"JPEG_SW";
77 uint32_t end = d->
cursor + len;
141 total = (uint16_t)(total + h->
bits[i]);
146 if (d->
cursor + total > end) {
149 for (uint16_t i = 0U; i < total; i++) {
167 uint32_t end = d->
cursor + len;
202 for (uint8_t i = 0U; i < d->
ncomp; i++) {
205 uint8_t hv = d->
src[*s];
246 if (d->
ncomp == 3U) {
247 bool is_444 = (d->
hmax == 1U && d->
vmax == 1U);
250 if (!is_444 && !is_420) {
267 uint32_t s = d->
cursor + 2U;
268 uint8_t precision = d->
src[s];
270 if (precision != 8U) {
282 if (((uint32_t)d->
ncomp * 3U) + (s - d->
cursor) > (uint32_t)len) {
300 uint32_t s = d->
cursor + 2U;
301 uint8_t ns = d->
src[s];
303 if (ns != d->
ncomp) {
306 for (uint8_t i = 0U; i < ns; i++) {
307 uint8_t cs = d->
src[s];
309 uint8_t tdta = d->
src[s];
312 for (uint8_t j = 0U; j < d->
ncomp; j++) {
371 k = (uint8_t)(k + 16U);
376 k = (uint8_t)(k + rrrr);
409 if (r < 0 && t != 0) {
478 for (uint8_t by = 0U; by < d->
vmax; by++) {
479 for (uint8_t bx = 0U; bx < d->
hmax; bx++) {
543 const uint8_t* y_tile,
544 const uint8_t* cb_tile,
545 const uint8_t* cr_tile,
552 for (uint16_t r = 0U; r < mcu_h_px; r++) {
553 uint16_t py = (uint16_t)((my * mcu_h_px) + r);
557 for (uint16_t c = 0U; c < mcu_w_px; c++) {
558 uint16_t px = (uint16_t)((mx * mcu_w_px) + c);
559 if (px >= d->
width) {
562 int32_t y = (int32_t)y_tile[(r * mcu_w_px) + c];
565 if (d->
ncomp == 3U) {
566 uint16_t cr_x = (uint16_t)(c / d->
hmax);
567 uint16_t cr_y = (uint16_t)(r / d->
vmax);
628 if (d->
ncomp == 3U) {
700 if (out_buf_len < need) {
721 uint16_t mcus_x = (uint16_t)(((d->
width + mcu_w_px) - 1U) / mcu_w_px);
722 uint16_t mcus_y = (uint16_t)(((d->
height + mcu_h_px) - 1U) / mcu_h_px);
728 for (uint16_t my = 0U; my < mcus_y; my++) {
729 for (uint16_t mx = 0U; mx < mcus_x; mx++) {
873 uint32_t out_buf_len,
877 bool got_sof =
false;
899 uint32_t out_buf_len,
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_ASSERT(condition, message)
Runtime invariant check.
#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_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_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 priv_jpeg_sw_idct8x8(int32_t *block)
Full 8x8 inverse DCT, in place.
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).
int32_t priv_jpeg_sw_htab_decode(ra8_jpeg_bitreader_t *br, const ra8_jpeg_htab_t *h)
Decode one Huffman symbol from br using table h.
int32_t priv_jpeg_sw_br_get_bits(ra8_jpeg_bitreader_t *br, uint8_t n)
Pop n bits MSB-first; returns -1 on underflow.
void priv_jpeg_sw_htab_build(ra8_jpeg_htab_t *h)
Build canonical code/size and mincode/maxcode tables.
int32_t priv_jpeg_sw_huff_extend(int32_t v, uint8_t n)
Decode a signed n-bit DCT coefficient (T.81 F.1.2.1.3).
Pure-software baseline JPEG (ISO/IEC 10918-1 / ITU-T T.81) codec.
static void internal_dec_scan_begin(ra8_jpeg_dec_ctx_t *d, ra8_jpeg_bitreader_t *br)
Prime the bit reader and reset the DC predictors for a scan.
ra8_err_t priv_jpeg_sw_parse_sof0(ra8_jpeg_dec_ctx_t *d)
Implementation of priv_jpeg_sw_parse_sof0() – T.81 B.2.2 frame header.
static ra8_err_t internal_dec_decode_scan(ra8_jpeg_dec_ctx_t *d, uint8_t *out_buf, uint32_t out_buf_len)
Decode the whole entropy-coded segment, MCU by MCU.
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.
static ra8_err_t internal_dec_parse_dht_one(ra8_jpeg_dec_ctx_t *d, uint32_t end)
Parse one (TcTh, BITS, HUFFVAL) table out of a DHT segment.
static ra8_err_t internal_dec_dispatch_tail(ra8_jpeg_dec_ctx_t *d, uint16_t mk, bool got_sof, ra8_jpeg_dec_marker_action_t *action)
Handle a non-SOF marker in the decode dispatch chain.
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.
static ra8_err_t internal_dec_run(ra8_jpeg_dec_ctx_t *d, uint8_t *out_buf, uint32_t out_buf_len, uint16_t *out_w, uint16_t *out_h)
Marker-walk driver for the whole-buffer decode.
static void internal_dec_parse_sof0_components(ra8_jpeg_dec_ctx_t *d, uint32_t *s)
Read the per-component id/sampling/quant fields of an SOF0.
static void internal_dec_emit_mcu_rgb(const ra8_jpeg_dec_ctx_t *d, const uint8_t *y_tile, const uint8_t *cb_tile, const uint8_t *cr_tile, uint16_t mx, uint16_t my, uint16_t mcu_w_px, uint16_t mcu_h_px, uint8_t *out_buf)
Convert one MCU's reconstructed YCbCr tiles into output RGB pixels.
static ra8_err_t internal_dec_block_ac(ra8_jpeg_dec_ctx_t *d, ra8_jpeg_bitreader_t *br, uint8_t ci, int32_t *outblk)
Run-length decode the 63 AC coefficients of one block.
static void internal_dec_copy_block_to_tile(const uint8_t *blk, uint8_t *y_tile, uint8_t bx, uint8_t by, uint16_t mcu_w_px)
Copy one reconstructed 8x8 luma block into its Y-tile slot.
ra8_err_t priv_jpeg_sw_parse_dht(ra8_jpeg_dec_ctx_t *d)
Implementation of priv_jpeg_sw_parse_dht() – T.81 B.2.4.2 record loop.
static ra8_err_t internal_dec_decode_mcu(ra8_jpeg_dec_ctx_t *d, ra8_jpeg_bitreader_t *br, uint8_t *y_tile, uint8_t *cb_tile, uint8_t *cr_tile, uint16_t mx, uint16_t my, uint16_t mcu_w_px, uint16_t mcu_h_px, uint8_t *out_buf)
Decode one MCU (luma + optional chroma) and emit its RGB pixels.
ra8_err_t ra8_jpeg_sw_decode(const uint8_t *jpeg_buf, uint32_t jpeg_len, uint8_t *out_buf, uint32_t out_buf_len, uint16_t *out_w, uint16_t *out_h)
Decode a baseline JPEG stream into packed RGB888.
void priv_jpeg_sw_idct_into(int32_t *coeffs, uint8_t *tile)
Implementation of priv_jpeg_sw_idct_into() – IDCT + level shift + clamp.
ra8_err_t priv_jpeg_sw_block(ra8_jpeg_dec_ctx_t *d, ra8_jpeg_bitreader_t *br, uint8_t ci, int32_t *outblk)
Implementation of priv_jpeg_sw_block() – T.81 F.2.2 DC diff + AC run-length.
ra8_err_t priv_jpeg_sw_skip_segment(ra8_jpeg_dec_ctx_t *d)
Implementation of priv_jpeg_sw_skip_segment() – bounds-checked cursor hop.
ra8_err_t priv_jpeg_sw_parse_dqt(ra8_jpeg_dec_ctx_t *d)
Implementation of priv_jpeg_sw_parse_dqt() – T.81 B.2.4.1 de-zigzag parse.
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.
ra8_err_t priv_jpeg_sw_parse_sos(ra8_jpeg_dec_ctx_t *d)
Implementation of priv_jpeg_sw_parse_sos() – T.81 B.2.3 selector binding.
static ra8_err_t internal_dec_check_chroma_layout(const ra8_jpeg_dec_ctx_t *d)
Accept only the 4:4:4 and 4:2:0 3-component chroma layouts.
Module-private declarations shared across the software JPEGcodec translation units.
@ k_ra8_jpeg_marker_dht
Define Huffman table.
@ k_ra8_jpeg_marker_rst7
Restart 7.
@ k_ra8_jpeg_marker_eoi
End of image.
@ k_ra8_jpeg_marker_sof0
Baseline DCT, Huffman.
@ k_ra8_jpeg_marker_rst0
Restart 0.
@ k_ra8_jpeg_marker_soi
Start of image.
@ k_ra8_jpeg_marker_dqt
Define quantization table.
@ k_ra8_jpeg_marker_sos
Start of scan.
@ k_ra8_jpeg_level_offset
RA8 JPEG level offset.
@ k_ra8_jpeg_nibble_shift
RA8 JPEG nibble shift.
@ k_ra8_jpeg_nibble_mask
RA8 JPEG nibble mask.
@ k_ra8_jpeg_rgb_components
RA8 JPEG RGB components.
@ k_ra8_jpeg_huff_lengths
16 BITS-list slots.
static uint16_t internal_read_be16(const uint8_t *p)
Read a 16-bit big-endian word from p.
@ k_jpeg_nibble_mask
JPEG nibble mask.
@ k_ra8_jpeg_huff_ids
Luma + chroma table id.
@ 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_huff_classes
DC + AC.
@ k_ra8_jpeg_marker_byte
RA8 JPEG marker byte.
@ k_ra8_jpeg_max_comps
YCbCr or grayscale only.
@ k_ra8_jpeg_quant_tabs
One luma + one chroma table.
@ k_ra8_jpeg_huff_max
Max symbols per Huffman table.
static const uint8_t s_zigzag[64]
Zig-zag de-interleave order (T.81 Figure 5).
static uint8_t internal_clamp_u8(int32_t v)
Clamp v to the unsigned 8-bit pixel range.
@ k_jpeg_marker_ff00
JPEG marker ff00.
@ k_jpeg_marker_jpg
JPEG marker jpg.
@ k_jpeg_marker_sof1
JPEG marker sof1.
@ k_jpeg_marker_sof_hi
JPEG marker sof hi.
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.
Big-endian bit reader over an entropy-coded segment.
uint32_t acc
Bit accumulator.
uint8_t nbits
Bits valid in acc (0..32).
const uint8_t * buf
Byte stream.
uint8_t had_eoi
Set when an end marker is consumed.
Decoder state shared by the whole-buffer and streaming drivers.
int32_t comp_dc_pred[k_ra8_jpeg_max_comps]
DC predictors (scan state).
ra8_jpeg_htab_t hac[k_ra8_jpeg_huff_ids]
AC Huffman tables.
uint16_t qtab[k_ra8_jpeg_quant_tabs][k_ra8_jpeg_block_size]
Dequant tables.
uint8_t comp_qid[k_ra8_jpeg_max_comps]
Quant-table selector.
uint8_t comp_dc_id[k_ra8_jpeg_max_comps]
DC Huffman selector.
uint16_t height
Image height from SOF0, pixels.
uint8_t vmax
Max vertical sampling factor.
uint32_t src_len
Length of src in bytes.
uint8_t comp_v[k_ra8_jpeg_max_comps]
Vertical sampling.
uint32_t cursor
Parse cursor into src.
uint8_t ncomp
1 grayscale, 3 YCbCr.
ra8_jpeg_htab_t hdc[k_ra8_jpeg_huff_ids]
DC Huffman tables.
uint16_t width
Image width from SOF0, pixels.
uint8_t comp_h[k_ra8_jpeg_max_comps]
Horizontal sampling.
uint8_t comp_id[k_ra8_jpeg_max_comps]
Component identifiers.
uint8_t comp_ac_id[k_ra8_jpeg_max_comps]
AC Huffman selector.
uint8_t hmax
Max horizontal sampling factor.
const uint8_t * src
Byte slice the parsers read from.
Decoded Huffman table – 256 entries indexed by symbol order.
uint8_t vals[k_ra8_jpeg_huff_max]
Symbol order.
uint8_t bits[k_ra8_jpeg_huff_lengths]
BITS list.