54static const char*
s_tag =
"JPEG_SW";
56#ifdef __ARM_FEATURE_MVE
90 uint8_t b = br->
buf[br->
pos];
97 uint8_t s = br->
buf[br->
pos];
145 uint32_t v = (br->
acc >> (br->
nbits - n)) & ((1U << n) - 1U);
147 br->
acc &= (br->
nbits == 0U) ? 0U : ((1U << br->
nbits) - 1U);
180 if (h->
bits[i] == 0U) {
185 j = (uint16_t)((j + h->
bits[i]) - 1U);
198 for (uint8_t j = 0U; j < h->
bits[i]; j++) {
207 uint8_t si = (k > 0U) ? h->
huffsize[0] : 0U;
219 code = (uint16_t)(code << 1U);
253 if (br->
nbits == 0U) {
266 if (code <= h->maxcode[i]) {
267 uint16_t j = (uint16_t)(h->
valptr[i] + (uint16_t)(code - h->
mincode[i]));
271 return (int32_t)h->
vals[j];
277 code = (code << 1) | bit;
310 int32_t vt = 1 << (n - 1U);
312 v += ((int32_t)((uint32_t)-1 << n)) + 1;
343 int64_t v = (int64_t)in[k] * (int64_t)
s_dct_w_q14[k];
462 if (*i >= jpeg_len) {
465 uint8_t m = jpeg_buf[*i];
508 uint8_t precision = jpeg_buf[i + 2U];
509 if (precision != 8U) {
514 if (*out_w == 0U || *out_h == 0U) {
565 if (*i + 2U > jpeg_len) {
569 if (seglen < 2U || (uint32_t)seglen > jpeg_len - *i) {
602 while (i + 4U <= jpeg_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_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 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).
static ra8_err_t internal_dims_next_marker(const uint8_t *jpeg_buf, uint32_t jpeg_len, uint32_t *i, uint16_t *out_mk)
Advance past 0xFF pad bytes and read one marker code.
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.
ra8_err_t ra8_jpeg_sw_get_dimensions(const uint8_t *jpeg_buf, uint32_t jpeg_len, uint16_t *out_w, uint16_t *out_h)
Parse the SOF0 marker of a JPEG stream and report its image dimensions without performing entropy dec...
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).
static ra8_err_t internal_dims_step(const uint8_t *jpeg_buf, uint32_t jpeg_len, uint32_t *i, bool *done, uint16_t *out_w, uint16_t *out_h)
One step of the dimension walk: read a marker, handle it.
static ra8_err_t internal_dims_parse_sof0(const uint8_t *jpeg_buf, uint32_t i, uint16_t seglen, uint16_t *out_w, uint16_t *out_h)
Extract width/height from an SOF0 payload (T.81 sec B.2.2).
static void internal_inv_dct_1d_norm(const int32_t *in, int32_t *out)
1-D inverse DCT pass with JPEG normalization folded in.
static void internal_br_fill(ra8_jpeg_bitreader_t *br)
Refill acc until at least 16 bits are available.
static void internal_htab_build_lookup(ra8_jpeg_htab_t *h)
Build the F.2.2.3 mincode/maxcode/valptr decode tables.
Pure-software baseline JPEG (ISO/IEC 10918-1 / ITU-T T.81) codec.
Module-private declarations shared across the software JPEGcodec translation units.
@ k_ra8_jpeg_marker_dht
Define Huffman table.
@ k_ra8_jpeg_marker_eoi
End of image.
@ k_ra8_jpeg_marker_sof0
Baseline DCT, Huffman.
@ k_ra8_jpeg_marker_soi
Start of image.
@ k_ra8_jpeg_level_offset
RA8 JPEG level offset.
@ k_ra8_jpeg_byte_shift
RA8 JPEG byte shift.
@ k_ra8_jpeg_yuv_shift
BT.601 fixed-point shift.
@ 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_idct_p2_bias_sh
JPEG idct p2 bias sh.
@ k_jpeg_q14_shift
JPEG q14 shift.
@ k_jpeg_byte_mask
JPEG byte mask.
@ k_jpeg_sof_dims_off
JPEG sof dims off.
@ k_jpeg_reservoir_lo
JPEG reservoir lo.
@ k_ra8_jpeg_block_size
Coefficients per block.
@ k_ra8_jpeg_block_dim
8x8 DCT block edge.
@ k_ra8_jpeg_marker_byte
RA8 JPEG marker byte.
static const int32_t s_dct_cos_q14[8][8]
Cosine table cos((2n+1)*k*pi/16) * 2^14, k = row, n = col.
@ k_ra8_jpeg_cr_r
1.40200.
@ k_ra8_jpeg_cb_b
1.77200.
@ k_ra8_jpeg_cb_g
RA8 JPEG cb g.
@ k_ra8_jpeg_cr_g
RA8 JPEG cr g.
static uint8_t internal_clamp_u8(int32_t v)
Clamp v to the unsigned 8-bit pixel range.
@ k_jpeg_marker_jpg
JPEG marker jpg.
@ k_jpeg_marker_sof_hi
JPEG marker sof hi.
@ k_jpeg_marker_sof_lo
JPEG marker sof lo.
static const int32_t s_dct_w_q14[8]
sqrt(2/N)*C(k) DCT normalization weights, Q14.
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.
Decoded Huffman table – 256 entries indexed by symbol order.
uint16_t valptr[k_ra8_jpeg_huff_lengths]
Valptr.
uint16_t huffcode[k_ra8_jpeg_huff_max]
Code per symbol.
int32_t maxcode[k_ra8_jpeg_huff_lengths]
Maxcode.
int32_t mincode[k_ra8_jpeg_huff_lengths]
Mincode.
uint8_t vals[k_ra8_jpeg_huff_max]
Symbol order.
uint8_t bits[k_ra8_jpeg_huff_lengths]
BITS list.
uint8_t huffsize[k_ra8_jpeg_huff_max]
Code length.