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

Module-private declarations shared across the software JPEGcodec translation units. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_err.h"
Include dependency graph for ra8_jpeg_sw_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_jpeg_bitreader_t
 Big-endian bit reader over an entropy-coded segment. More...
struct  ra8_jpeg_htab_t
 Decoded Huffman table – 256 entries indexed by symbol order. More...
struct  ra8_jpeg_dec_ctx_t
 Decoder state shared by the whole-buffer and streaming drivers. More...

Enumerations

enum  jpeg_misc_t : uint16_t {
  k_jpeg_byte_mask = 0xFFU ,
  k_jpeg_nibble_mask = 0xFU ,
  k_jpeg_reservoir_lo = 24U ,
  k_jpeg_sof_dims_off = 5U ,
  k_jpeg_mcu_align = 15U ,
  k_jpeg_zrl_symbol = 0xF0U
}
 Misc JPEG masks / offsets. More...
enum  jpeg_dsp_shift_t : uint8_t {
  k_jpeg_idct_p1_bias_sh = 27U ,
  k_jpeg_idct_p1_sh = 28U ,
  k_jpeg_idct_p2_bias_sh = 13U ,
  k_jpeg_q14_shift = 14U ,
  k_jpeg_ycc_q15_shift = 14U
}
 Fixed-point IDCT / YCbCr shift amounts. More...
enum  jpeg_ycc_coeff_t : int16_t {
  k_cr_r_q15 = 22970 ,
  k_cb_b_q15 = 29032 ,
  k_cb_g_q15 = -5638 ,
  k_cr_g_q15 = -11700
}
 Q15 BT.601 YCbCr->RGB coefficients (== Q16 / 2). More...
enum  jpeg_marker_range_t : uint16_t {
  k_jpeg_marker_sof_lo = 0xFFC0U ,
  k_jpeg_marker_sof1 = 0xFFC1U ,
  k_jpeg_marker_sof_hi = 0xFFCFU ,
  k_jpeg_marker_jpg = 0xFFC8U ,
  k_jpeg_marker_ff00 = 0xFF00U
}
 JPEG SOF marker range and stuffing markers. More...
enum  jpeg_enc_t : uint16_t {
  k_jpeg_q_scale_low = 5000U ,
  k_jpeg_q_scale_high = 200U ,
  k_jpeg_q_round_bias = 50U ,
  k_jpeg_q_percent = 100U ,
  k_jpeg_sof_seg_len = 17U ,
  k_jpeg_sos_seg_len = 12U ,
  k_jpeg_spectral_end = 63U
}
 JPEG encoder quality scaling and segment field values. More...
enum  jpeg_enc_field_t : uint8_t {
  k_jpeg_samp_2x2 = 0x22U ,
  k_jpeg_samp_1x1 = 0x11U ,
  k_jpeg_dht_ac_chroma = 0x11U ,
  k_jpeg_sos_sel_chroma = 0x11U
}
 JPEG component sampling / table-selector bytes (positional). More...
enum  ra8_jpeg_marker_t : uint16_t {
  k_ra8_jpeg_marker_soi = 0xFFD8U ,
  k_ra8_jpeg_marker_eoi = 0xFFD9U ,
  k_ra8_jpeg_marker_sos = 0xFFDAU ,
  k_ra8_jpeg_marker_dqt = 0xFFDBU ,
  k_ra8_jpeg_marker_dht = 0xFFC4U ,
  k_ra8_jpeg_marker_dri = 0xFFDDU ,
  k_ra8_jpeg_marker_sof0 = 0xFFC0U ,
  k_ra8_jpeg_marker_sof1 = 0xFFC1U ,
  k_ra8_jpeg_marker_sof2 = 0xFFC2U ,
  k_ra8_jpeg_marker_sof3 = 0xFFC3U ,
  k_ra8_jpeg_marker_app0 = 0xFFE0U ,
  k_ra8_jpeg_marker_com = 0xFFFEU ,
  k_ra8_jpeg_marker_rst0 = 0xFFD0U ,
  k_ra8_jpeg_marker_rst7 = 0xFFD7U ,
  k_ra8_jpeg_marker_pad = 0xFF00U ,
  k_ra8_jpeg_marker_sof_lo = 0xFFC0U ,
  k_ra8_jpeg_marker_sof_hi = k_jpeg_marker_sof_hi ,
  k_ra8_jpeg_marker_dac = 0xFFC8U ,
  k_ra8_jpeg_marker_high = 0xFF00U
}
 JPEG segment marker bytes (T.81 sec B.1.1.3 "Marker assignments"). More...
enum  ra8_jpeg_const_t : uint16_t {
  k_ra8_jpeg_block_dim = 8U ,
  k_ra8_jpeg_block_size = 64U ,
  k_ra8_jpeg_max_comps = 3U ,
  k_ra8_jpeg_mcu_max_dim = 16U ,
  k_ra8_jpeg_huff_classes = 2U ,
  k_ra8_jpeg_huff_ids = 2U ,
  k_ra8_jpeg_huff_max = 256U ,
  k_ra8_jpeg_marker_byte = 0xFFU ,
  k_ra8_jpeg_quant_tabs = 2U ,
  k_ra8_jpeg_enc_max_w = 1024U ,
  k_ra8_jpeg_min_jpeg_len = 4U ,
  k_ra8_jpeg_garbage_len = 5U ,
  k_ra8_jpeg_mcu_align = 15U ,
  k_ra8_jpeg_sof0_min_len = 8U ,
  k_ra8_jpeg_dht_hdr = 1U ,
  k_ra8_jpeg_sof0_hdr_len = 17U ,
  k_ra8_jpeg_sos_len = 12U ,
  k_ra8_jpeg_app0_len = 16U ,
  k_ra8_jpeg_eob_band_max = 63U
}
 Sizes and indices used throughout the codec. More...
enum  ra8_jpeg_shift_t : uint8_t {
  k_ra8_jpeg_byte_shift = 8U ,
  k_ra8_jpeg_nibble_shift = 4U ,
  k_ra8_jpeg_nibble_mask = 0x0FU ,
  k_ra8_jpeg_signbit_pos = 7U ,
  k_ra8_jpeg_signbit_pos16 = 15U ,
  k_ra8_jpeg_level_offset = 128U ,
  k_ra8_jpeg_pixel_max = 255U ,
  k_ra8_jpeg_quality_pivot = 50U ,
  k_ra8_jpeg_huff_lengths = 16U ,
  k_ra8_jpeg_zrl_runlen = 16U ,
  k_ra8_jpeg_zrl_symbol = 0xF0U ,
  k_ra8_jpeg_eob_runlen = 0xFU ,
  k_ra8_jpeg_dht_dc_class = 0U ,
  k_ra8_jpeg_dht_ac_class = 0x10U ,
  k_ra8_jpeg_y_sampling_420 = 0x22U ,
  k_ra8_jpeg_c_sampling = 0x11U ,
  k_ra8_jpeg_be_byte_mask = 0xFFU ,
  k_ra8_jpeg_yuv_shift = 16U ,
  k_ra8_jpeg_rgb_components = 3U
}
 Shift amounts and signed-cast helpers. More...
enum  ra8_jpeg_color_coef_t : int32_t {
  k_ra8_jpeg_yr = 19595 ,
  k_ra8_jpeg_yg = 38470 ,
  k_ra8_jpeg_yb = 7471 ,
  k_ra8_jpeg_cbr = -11059 ,
  k_ra8_jpeg_cbg = -21709 ,
  k_ra8_jpeg_cbb = 32768 ,
  k_ra8_jpeg_crr = 32768 ,
  k_ra8_jpeg_crg = -27439 ,
  k_ra8_jpeg_crb = -5329 ,
  k_ra8_jpeg_cr_r = 91881 ,
  k_ra8_jpeg_cb_b = 116130 ,
  k_ra8_jpeg_cr_g = -46802 ,
  k_ra8_jpeg_cb_g = -22554
}
 BT.601 RGB<->YCbCr fixed-point coefficients (Q16). More...
enum  ra8_jpeg_dec_marker_action_t : uint8_t {
  k_ra8_jpeg_dec_continue = 0U ,
  k_ra8_jpeg_dec_scan = 1U ,
  k_ra8_jpeg_dec_eoi = 2U
}
 Result of priv_jpeg_sw_dispatch(): what the driver does next. More...

Functions

static uint8_t internal_clamp_u8 (int32_t v)
 Clamp v to the unsigned 8-bit pixel range.
static uint16_t internal_read_be16 (const uint8_t *p)
 Read a 16-bit big-endian word from p.
static void internal_write_be16 (uint8_t *p, uint16_t v)
 Write a 16-bit big-endian word into p.
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_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_huff_extend (int32_t v, uint8_t n)
 Decode a signed n-bit DCT coefficient (T.81 F.1.2.1.3).
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).
ra8_err_t priv_jpeg_sw_skip_segment (ra8_jpeg_dec_ctx_t *d)
 Skip an unrecognized variable-length segment.
ra8_err_t priv_jpeg_sw_parse_dqt (ra8_jpeg_dec_ctx_t *d)
 Parse a DQT segment (T.81 sec B.2.4.1) into d->qtab.
ra8_err_t priv_jpeg_sw_parse_dht (ra8_jpeg_dec_ctx_t *d)
 Parse a DHT segment (T.81 sec B.2.4.2) and build its tables.
ra8_err_t priv_jpeg_sw_parse_sof0 (ra8_jpeg_dec_ctx_t *d)
 Parse the SOF0 frame header (T.81 sec B.2.2).
ra8_err_t priv_jpeg_sw_parse_sos (ra8_jpeg_dec_ctx_t *d)
 Parse the SOS scan header (T.81 sec B.2.3) selectors.
ra8_err_t priv_jpeg_sw_block (ra8_jpeg_dec_ctx_t *d, ra8_jpeg_bitreader_t *br, uint8_t ci, int32_t *outblk)
 Entropy-decode one 8x8 block of dequantized coefficients.
void priv_jpeg_sw_idct_into (int32_t *coeffs, uint8_t *tile)
 IDCT a coefficient block and emit level-shifted 8-bit samples.
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)
 Decode the hmax*vmax luma blocks of one MCU into the Y tile.
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)
 Decode the Cb and Cr 8x8 blocks of one MCU.
ra8_err_t priv_jpeg_sw_dispatch (ra8_jpeg_dec_ctx_t *d, bool *got_sof, ra8_jpeg_dec_marker_action_t *action)
 Dispatch one JPEG marker segment in a decode driver loop.

Variables

static const uint8_t s_zigzag [64]
 Zig-zag de-interleave order (T.81 Figure 5).
static const int32_t s_dct_cos_q14 [8][8]
 Cosine table cos((2n+1)*k*pi/16) * 2^14, k = row, n = col.
static const int32_t s_dct_w_q14 [8]
 sqrt(2/N)*C(k) DCT normalization weights, Q14.

Detailed Description

Module-private declarations shared across the software JPEG

codec translation units.

Tag
[Ring 4 / Domain] {World: NS}

The pure-software baseline JPEG codec is split across three translation units to keep each file under the maintainability line cap:

Every symbol referenced by more than one of those units lives in this header: the shared C23 typed-enum constant blocks, the two read-only DSP look-up tables, the inline byte/pixel helpers, the bit-reader and Huffman-table struct types, and the prototypes for the decode primitives that the parser unit calls into.

Spec citations are tagged T.81 sec X.Y "..." and refer to ITU-T Recommendation T.81 (1992) | ISO/IEC 10918-1.

Since
0.1.0

Definition in file ra8_jpeg_sw_internal.h.

Enumeration Type Documentation

◆ jpeg_dsp_shift_t

enum jpeg_dsp_shift_t : uint8_t

Fixed-point IDCT / YCbCr shift amounts.

Enumerator
k_jpeg_idct_p1_bias_sh 

JPEG idct p1 bias sh.

k_jpeg_idct_p1_sh 

JPEG idct p1 sh.

k_jpeg_idct_p2_bias_sh 

JPEG idct p2 bias sh.

k_jpeg_q14_shift 

JPEG q14 shift.

k_jpeg_ycc_q15_shift 

JPEG ycc q15 shift.

Definition at line 63 of file ra8_jpeg_sw_internal.h.

◆ jpeg_enc_field_t

enum jpeg_enc_field_t : uint8_t

JPEG component sampling / table-selector bytes (positional).

Enumerator
k_jpeg_samp_2x2 

JPEG samp 2x2.

k_jpeg_samp_1x1 

JPEG samp 1x1.

k_jpeg_dht_ac_chroma 

JPEG dht ac chroma.

k_jpeg_sos_sel_chroma 

JPEG sos sel chroma.

Definition at line 100 of file ra8_jpeg_sw_internal.h.

◆ jpeg_enc_t

enum jpeg_enc_t : uint16_t

JPEG encoder quality scaling and segment field values.

Enumerator
k_jpeg_q_scale_low 

JPEG q scale low.

k_jpeg_q_scale_high 

JPEG q scale high.

k_jpeg_q_round_bias 

JPEG q round bias.

k_jpeg_q_percent 

JPEG q percent.

k_jpeg_sof_seg_len 

JPEG sof seg length.

k_jpeg_sos_seg_len 

JPEG sos seg length.

k_jpeg_spectral_end 

JPEG spectral end.

Definition at line 89 of file ra8_jpeg_sw_internal.h.

◆ jpeg_marker_range_t

enum jpeg_marker_range_t : uint16_t

JPEG SOF marker range and stuffing markers.

Enumerator
k_jpeg_marker_sof_lo 

JPEG marker sof lo.

k_jpeg_marker_sof1 

JPEG marker sof1.

k_jpeg_marker_sof_hi 

JPEG marker sof hi.

k_jpeg_marker_jpg 

JPEG marker jpg.

k_jpeg_marker_ff00 

JPEG marker ff00.

Definition at line 80 of file ra8_jpeg_sw_internal.h.

◆ jpeg_misc_t

enum jpeg_misc_t : uint16_t

Misc JPEG masks / offsets.

Enumerator
k_jpeg_byte_mask 

JPEG byte mask.

k_jpeg_nibble_mask 

JPEG nibble mask.

k_jpeg_reservoir_lo 

JPEG reservoir lo.

k_jpeg_sof_dims_off 

JPEG sof dims off.

k_jpeg_mcu_align 

JPEG mcu align.

k_jpeg_zrl_symbol 

JPEG zrl symbol.

Definition at line 53 of file ra8_jpeg_sw_internal.h.

◆ jpeg_ycc_coeff_t

enum jpeg_ycc_coeff_t : int16_t

Q15 BT.601 YCbCr->RGB coefficients (== Q16 / 2).

Enumerator
k_cr_r_q15 

1.40200 / 2 * 2^15.

k_cb_b_q15 

1.77200 / 2 * 2^15.

k_cb_g_q15 

Cb g q15.

k_cr_g_q15 

Cr g q15.

Definition at line 72 of file ra8_jpeg_sw_internal.h.

◆ ra8_jpeg_color_coef_t

enum ra8_jpeg_color_coef_t : int32_t

BT.601 RGB<->YCbCr fixed-point coefficients (Q16).

Same constants the IJG jccolor.c and jdcolor.c files use (see also T.871 / JFIF colour conversion). All values are fixed-point Q16 (multiply by 1 << 16 and round).

Enumerator
k_ra8_jpeg_yr 

0.29900 * 65536.

k_ra8_jpeg_yg 

0.58700 * 65536.

k_ra8_jpeg_yb 

0.11400 * 65536.

k_ra8_jpeg_cbr 

RA8 JPEG CBR.

k_ra8_jpeg_cbg 

RA8 JPEG cbg.

k_ra8_jpeg_cbb 

RA8 JPEG cbb.

k_ra8_jpeg_crr 

RA8 JPEG crr.

k_ra8_jpeg_crg 

RA8 JPEG crg.

k_ra8_jpeg_crb 

RA8 JPEG crb.

k_ra8_jpeg_cr_r 

1.40200.

k_ra8_jpeg_cb_b 

1.77200.

k_ra8_jpeg_cr_g 

RA8 JPEG cr g.

k_ra8_jpeg_cb_g 

RA8 JPEG cb g.

Definition at line 195 of file ra8_jpeg_sw_internal.h.

◆ ra8_jpeg_const_t

enum ra8_jpeg_const_t : uint16_t

Sizes and indices used throughout the codec.

Enumerator
k_ra8_jpeg_block_dim 

8x8 DCT block edge.

k_ra8_jpeg_block_size 

Coefficients per block.

k_ra8_jpeg_max_comps 

YCbCr or grayscale only.

k_ra8_jpeg_mcu_max_dim 

4:2:0 MCU is 16x16 luma px.

k_ra8_jpeg_huff_classes 

DC + AC.

k_ra8_jpeg_huff_ids 

Luma + chroma table id.

k_ra8_jpeg_huff_max 

Max symbols per Huffman table.

k_ra8_jpeg_marker_byte 

RA8 JPEG marker byte.

k_ra8_jpeg_quant_tabs 

One luma + one chroma table.

k_ra8_jpeg_enc_max_w 

Encoder max image width (px).

k_ra8_jpeg_min_jpeg_len 

Smallest plausible stream.

k_ra8_jpeg_garbage_len 

Garbage-input cutoff.

k_ra8_jpeg_mcu_align 

MCU alignment mask.

k_ra8_jpeg_sof0_min_len 

Min SOF0 segment length.

k_ra8_jpeg_dht_hdr 

DHT TcTh byte size.

k_ra8_jpeg_sof0_hdr_len 

SOF0 segment length we emit.

k_ra8_jpeg_sos_len 

SOS segment length we emit.

k_ra8_jpeg_app0_len 

APP0 (JFIF) segment length.

k_ra8_jpeg_eob_band_max 

Last AC zig-zag index.

Definition at line 138 of file ra8_jpeg_sw_internal.h.

◆ ra8_jpeg_dec_marker_action_t

Result of priv_jpeg_sw_dispatch(): what the driver does next.

Enumerator
k_ra8_jpeg_dec_continue 

Keep scanning markers.

k_ra8_jpeg_dec_scan 

SOS reached; the driver should run its scan loop.

k_ra8_jpeg_dec_eoi 

EOI reached; the driver should stop with an error.

Definition at line 600 of file ra8_jpeg_sw_internal.h.

◆ ra8_jpeg_marker_t

enum ra8_jpeg_marker_t : uint16_t

JPEG segment marker bytes (T.81 sec B.1.1.3 "Marker assignments").

The high byte is always 0xFF.

Enumerator
k_ra8_jpeg_marker_soi 

Start of image.

k_ra8_jpeg_marker_eoi 

End of image.

k_ra8_jpeg_marker_sos 

Start of scan.

k_ra8_jpeg_marker_dqt 

Define quantization table.

k_ra8_jpeg_marker_dht 

Define Huffman table.

k_ra8_jpeg_marker_dri 

Define restart interval.

k_ra8_jpeg_marker_sof0 

Baseline DCT, Huffman.

k_ra8_jpeg_marker_sof1 

Extended sequential DCT.

k_ra8_jpeg_marker_sof2 

Progressive DCT.

k_ra8_jpeg_marker_sof3 

Lossless.

k_ra8_jpeg_marker_app0 

JFIF APP0.

k_ra8_jpeg_marker_com 

Comment.

k_ra8_jpeg_marker_rst0 

Restart 0.

k_ra8_jpeg_marker_rst7 

Restart 7.

k_ra8_jpeg_marker_pad 

Stuffed byte (data 0xFF).

k_ra8_jpeg_marker_sof_lo 

First SOF marker code.

k_ra8_jpeg_marker_sof_hi 

Last SOF marker code.

k_ra8_jpeg_marker_dac 

DAC marker (skipped).

k_ra8_jpeg_marker_high 

Marker high-byte mask.

Definition at line 112 of file ra8_jpeg_sw_internal.h.

◆ ra8_jpeg_shift_t

enum ra8_jpeg_shift_t : uint8_t

Shift amounts and signed-cast helpers.

Enumerator
k_ra8_jpeg_byte_shift 

RA8 JPEG byte shift.

k_ra8_jpeg_nibble_shift 

RA8 JPEG nibble shift.

k_ra8_jpeg_nibble_mask 

RA8 JPEG nibble mask.

k_ra8_jpeg_signbit_pos 

RA8 JPEG signbit pos.

k_ra8_jpeg_signbit_pos16 

RA8 JPEG signbit pos16.

k_ra8_jpeg_level_offset 

RA8 JPEG level offset.

k_ra8_jpeg_pixel_max 

RA8 JPEG pixel maximum.

k_ra8_jpeg_quality_pivot 

RA8 JPEG quality pivot.

k_ra8_jpeg_huff_lengths 

16 BITS-list slots.

k_ra8_jpeg_zrl_runlen 

Zero-Run-Length symbol skip.

k_ra8_jpeg_zrl_symbol 

T.81 K.3.3 ZRL byte.

k_ra8_jpeg_eob_runlen 

F0 high-nibble RRRR mask.

k_ra8_jpeg_dht_dc_class 

RA8 JPEG dht dc class.

k_ra8_jpeg_dht_ac_class 

RA8 JPEG dht ac class.

k_ra8_jpeg_y_sampling_420 

SOF0 H/V byte for Y in 4:2:0.

k_ra8_jpeg_c_sampling 

SOF0 H/V byte for chroma.

k_ra8_jpeg_be_byte_mask 

Low-byte mask.

k_ra8_jpeg_yuv_shift 

BT.601 fixed-point shift.

k_ra8_jpeg_rgb_components 

RA8 JPEG RGB components.

Definition at line 164 of file ra8_jpeg_sw_internal.h.

Function Documentation

◆ internal_clamp_u8()

uint8_t internal_clamp_u8 ( int32_t v)
inlinestatic

Clamp v to the unsigned 8-bit pixel range.

Saturating cast used by the IDCT output stage so out-of-range coefficients map to the legal 8-bit pixel domain. Pure helper.

Parameters
[in]vSigned integer value to saturate.
Returns
Saturated 8-bit value.
Return values
0v was negative.
255v was > 255.
(u8)vv was in 0..255.
Precondition
v is a valid signed integer (no preconditions on range).
Caller is using the result for an 8-bit pixel slot.
Postcondition
Return value is in 0..255 (k_ra8_jpeg_pixel_max).
No global state is touched.
Note
Pure helper; safe from any context.
Since
0.1.0

Definition at line 294 of file ra8_jpeg_sw_internal.h.

References k_ra8_jpeg_pixel_max, and RA8_INTERNAL.

Referenced by priv_jpeg_sw_idct_into(), and priv_jpeg_sw_ycc_to_rgb().

◆ internal_read_be16()

uint16_t internal_read_be16 ( const uint8_t * p)
inlinestatic

Read a 16-bit big-endian word from p.

JPEG marker payloads use big-endian length prefixes. Inline helper keeps the parser sites free of byte-shifting noise.

Parameters
[in]pNon-NULL pointer to two readable bytes.
Returns
Decoded big-endian word.
Return values
0..65535(p[0] << 8) | p[1].
Precondition
p is non-NULL.
At least two bytes are readable starting at p.
Postcondition
No memory has been written.
Return value reflects the bytes at the call site.
Note
Pure helper; safe from any context.
Since
0.1.0

Definition at line 325 of file ra8_jpeg_sw_internal.h.

References k_ra8_jpeg_byte_shift, and RA8_INTERNAL.

Referenced by internal_dims_parse_sof0(), internal_dims_step(), internal_js_begin(), priv_jpeg_sw_parse_dht(), priv_jpeg_sw_parse_dqt(), priv_jpeg_sw_parse_sof0(), priv_jpeg_sw_parse_sos(), priv_jpeg_sw_skip_segment(), ra8_jpeg_sw_decode(), and ra8_jpeg_sw_get_dimensions().

◆ internal_write_be16()

void internal_write_be16 ( uint8_t * p,
uint16_t v )
inlinestatic

Write a 16-bit big-endian word into p.

Encoder helper for emitting JPEG marker payloads (length prefixes, SOFn / DHT / DQT field counts).

Parameters
[out]pNon-NULL pointer to two writable bytes.
[in]vValue to encode.
Precondition
p is non-NULL.
At least two bytes are writable starting at p.
Postcondition
p[0] holds the high byte of v, p[1] the low byte.
No global state is touched.
Note
Pure helper; safe from any context.
Since
0.1.0

Definition at line 348 of file ra8_jpeg_sw_internal.h.

References k_jpeg_byte_mask, k_ra8_jpeg_byte_shift, and RA8_INTERNAL.

◆ priv_jpeg_sw_block()

ra8_err_t priv_jpeg_sw_block ( ra8_jpeg_dec_ctx_t * d,
ra8_jpeg_bitreader_t * br,
uint8_t ci,
int32_t * outblk )

Entropy-decode one 8x8 block of dequantized coefficients.

T.81 sec F.2.2: DC difference + AC run-length decode against the component's Huffman tables, dequantized through its quant table, de-zigzagged into row-major order.

Parameters
[in,out]dDecoder context (DC predictor mutates).
[in,out]brBit reader over the entropy-coded segment.
[in]ciComponent index (0 = luma).
[out]outblk64-entry coefficient block.
Returns
ra8_err_t Error code.
Return values
k_ra8_okBlock decoded.
k_ra8_err_protocol_errorStream underflow / illegal symbol.
Precondition
d tables for component ci were parsed.
outblk holds 64 writable int32 slots.
Postcondition
On success outblk holds dequantized row-major coefficients.
On error the scan aborts.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

Entropy-decode one 8x8 block of dequantized coefficients.

Definition at line 392 of file ra8_jpeg_sw_decode.c.

References ra8_jpeg_dec_ctx_t::comp_dc_id, ra8_jpeg_dec_ctx_t::comp_dc_pred, ra8_jpeg_dec_ctx_t::comp_qid, ra8_jpeg_dec_ctx_t::hdc, internal_dec_block_ac(), k_ra8_err_protocol_error, k_ra8_jpeg_block_size, priv_jpeg_sw_br_get_bits(), priv_jpeg_sw_htab_decode(), priv_jpeg_sw_huff_extend(), ra8_jpeg_dec_ctx_t::qtab, and RA8_PRIV.

Referenced by priv_jpeg_sw_mcu_chroma(), and priv_jpeg_sw_mcu_y().

◆ priv_jpeg_sw_br_get_bits()

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.

Tops off the accumulator from the entropy stream, then drains n MSBs as a non-negative integer. Defined in ra8_jpeg_sw.c; the parser unit calls it while decoding DC/AC magnitude bits.

Parameters
[in,out]brBit reader (state mutated in place).
[in]nNumber of bits to consume (0..16).
Returns
Decoded bit pattern, or -1 on stream underflow.
Return values
>=0n-bit unsigned value drained from the accumulator.
-1Underflow / EOI before n bits were available.
Precondition
br is non-NULL.
n <= 16 (caller-enforced).
Postcondition
br->nbits decreases by n on success.
Accumulator is masked to its remaining bits.
Note
Internal helper; not thread-safe.
Since
0.1.0

Calls internal_br_fill to top off the accumulator, then drains n MSBs as a non-negative integer.

Parameters
[in,out]brBit reader (state mutated in place).
[in]nNumber of bits to consume (0..16).
Returns
Decoded bit pattern, or -1 on stream underflow.
Return values
>=0n-bit unsigned value drained from the accumulator.
-1Underflow / EOI before n bits were available.
Precondition
br is non-NULL.
n <= 16 (caller-enforced).
Postcondition
br->nbits decreases by n on success.
Accumulator is masked to its remaining bits.
Note
Internal helper; not thread-safe.
Since
0.1.0

Definition at line 134 of file ra8_jpeg_sw.c.

References ra8_jpeg_bitreader_t::acc, internal_br_fill(), ra8_jpeg_bitreader_t::nbits, and RA8_PRIV.

Referenced by internal_dec_block_ac(), priv_jpeg_sw_block(), and priv_jpeg_sw_htab_decode().

◆ priv_jpeg_sw_dispatch()

ra8_err_t priv_jpeg_sw_dispatch ( ra8_jpeg_dec_ctx_t * d,
bool * got_sof,
ra8_jpeg_dec_marker_action_t * action )

Dispatch one JPEG marker segment in a decode driver loop.

Parses one marker following the 0xFF prefix at d->cursor and updates the decoder context. Unknown APPn/COM payloads are skipped; RST markers are consumed as standalone bytes.

Parameters
[in,out]dDecoder context (cursor advances).
[in,out]got_sofTracks whether SOF0 has been parsed yet.
[out]actionWhat the driver should do next.
Returns
ra8_err_t Error code.
Return values
k_ra8_okMarker handled (see *action).
k_ra8_err_protocol_errorMalformed marker / truncated stream / SOS before SOF.
k_ra8_err_not_supportedUnsupported SOFn (progressive, ...).
Precondition
d->cursor < d->src_len (caller checks).
The whole next segment is inside d->src (window drivers ensure).
Postcondition
d->cursor advanced past the marker and any sized payload.
*action is a ra8_jpeg_dec_marker_action_t value.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

Dispatch one JPEG marker segment in a decode driver loop.

Definition at line 810 of file ra8_jpeg_sw_decode.c.

References ra8_jpeg_dec_ctx_t::cursor, internal_dec_dispatch_tail(), k_jpeg_marker_ff00, k_jpeg_marker_jpg, k_jpeg_marker_sof1, k_jpeg_marker_sof_hi, k_ra8_err_not_supported, k_ra8_err_protocol_error, k_ra8_jpeg_dec_continue, k_ra8_jpeg_marker_byte, k_ra8_jpeg_marker_dht, k_ra8_jpeg_marker_sof0, k_ra8_ok, priv_jpeg_sw_parse_sof0(), RA8_PRIV, ra8_jpeg_dec_ctx_t::src, and ra8_jpeg_dec_ctx_t::src_len.

Referenced by internal_dec_run(), and internal_js_parse_markers().

◆ priv_jpeg_sw_htab_build()

void priv_jpeg_sw_htab_build ( ra8_jpeg_htab_t * h)

Build canonical code/size and mincode/maxcode tables.

Implements T.81 Annex C "Generation of size table" + "Generation of code table" plus the Annex F.2.2.3 mincode/maxcode/valptr tables used by the symbol decoder. Defined in ra8_jpeg_sw.c; the parser unit calls it from dec_parse_dht().

Parameters
[in,out]hHuffman table (BITS / VALS in, derived tables out).
Precondition
h is non-NULL.
h->bits and h->vals populated from the JPEG DHT marker.
Postcondition
h->huffcode, h->huffsize, h->mincode, h->maxcode and h->valptr are populated.
h->total reflects the symbol count.
Note
Internal helper; not thread-safe.
Since
0.1.0

Definition at line 192 of file ra8_jpeg_sw.c.

References ra8_jpeg_htab_t::bits, ra8_jpeg_htab_t::huffcode, ra8_jpeg_htab_t::huffsize, internal_htab_build_lookup(), k_ra8_jpeg_huff_lengths, RA8_PRIV, and ra8_jpeg_htab_t::total.

Referenced by internal_dec_parse_dht_one().

◆ priv_jpeg_sw_htab_decode()

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.

Single-bit greedy lookup per T.81 F.2.2.3 "Decoder code-length algorithm". Returns -1 on stream underflow or table miss. Defined in ra8_jpeg_sw.c; the parser unit calls it from dec_block().

Parameters
[in,out]brBit reader (state mutated in place).
[in]hPre-built canonical Huffman table.
Returns
Decoded symbol or -1 on error.
Return values
>=0Symbol value from h->vals.
-1Stream underflow or table miss.
Precondition
br and h non-NULL.
h was previously populated by priv_jpeg_sw_htab_build.
Postcondition
br advances by the consumed code length on success.
No table state is mutated.
Note
Internal helper; not thread-safe.
Since
0.1.0

Single-bit greedy lookup per T.81 F.2.2.3 "Decoder code-length algorithm". Returns -1 on stream underflow or table miss.

Parameters
[in,out]brBit reader (state mutated in place).
[in]hPre-built canonical Huffman table.
Returns
Decoded symbol or -1 on error.
Return values
>=0Symbol value from h->vals.
-1Stream underflow or table miss.
Precondition
br and h non-NULL.
h was previously populated by priv_jpeg_sw_htab_build.
Postcondition
br advances by the consumed code length on success.
No table state is mutated.
Note
Internal helper; not thread-safe.
Since
0.1.0

Definition at line 250 of file ra8_jpeg_sw.c.

References internal_br_fill(), k_ra8_jpeg_huff_lengths, ra8_jpeg_htab_t::mincode, ra8_jpeg_bitreader_t::nbits, priv_jpeg_sw_br_get_bits(), RA8_PRIV, ra8_jpeg_htab_t::total, ra8_jpeg_htab_t::valptr, and ra8_jpeg_htab_t::vals.

Referenced by internal_dec_block_ac(), and priv_jpeg_sw_block().

◆ priv_jpeg_sw_huff_extend()

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).

Extends a non-negative n-bit pattern into the signed range documented at T.81 Figure F.12 "EXTEND". A leading-zero pattern is treated as the negative of the symmetric positive value. Defined in ra8_jpeg_sw.c; the parser unit calls it from dec_block().

Parameters
[in]vNon-negative bit pattern from the bit reader.
[in]nNumber of significant bits.
Returns
Signed coefficient.
Return values
0..(1<<n)-1v had its high bit set (positive value).
-(1<<n)+1..0v had its high bit clear (negative value).
Precondition
v is in 0..(1 << n) - 1.
n <= 16 (caller-enforced from JPEG stream).
Postcondition
Return value is in (-(1<<n))+1 .. (1<<n)-1.
No global state is mutated.
Note
Pure helper; safe from any context.
Since
0.1.0

Extends a non-negative n-bit pattern into the signed range documented at T.81 Figure F.12 "EXTEND". A leading-zero pattern is treated as the negative of the symmetric positive value.

Parameters
[in]vNon-negative bit pattern from the bit reader.
[in]nNumber of significant bits.
Returns
Signed coefficient.
Return values
0..(1<<n)-1v had its high bit set (positive value).
-(1<<n)+1..0v had its high bit clear (negative value).
Precondition
v is in 0..(1 << n) - 1.
n <= 16 (caller-enforced from JPEG stream).
Postcondition
Return value is in (-(1<<n))+1 .. (1<<n)-1.
No global state is mutated.
Note
Pure helper; safe from any context.
Since
0.1.0

Definition at line 305 of file ra8_jpeg_sw.c.

References RA8_PRIV.

Referenced by internal_dec_block_ac(), and priv_jpeg_sw_block().

◆ priv_jpeg_sw_idct8x8()

void priv_jpeg_sw_idct8x8 ( int32_t * block)

Full 8x8 inverse DCT, in place.

Two-pass separable IDCT (rows then columns) using the shared Q14 cosine basis. Defined in ra8_jpeg_sw.c; the parser unit calls it from dec_idct_into().

Parameters
[in,out]block64-entry row-major coefficient block, IDCTed in place.
Precondition
block is non-NULL with at least 64 writable int32 slots.
block holds dequantized DCT coefficients.
Postcondition
block holds the reconstructed spatial samples.
No global state is touched.
Note
Internal helper; not thread-safe.
Since
0.1.0

Definition at line 352 of file ra8_jpeg_sw.c.

References internal_inv_dct_1d_norm(), k_ra8_jpeg_block_dim, k_ra8_jpeg_block_size, and RA8_PRIV.

Referenced by priv_jpeg_sw_idct_into().

◆ priv_jpeg_sw_idct_into()

void priv_jpeg_sw_idct_into ( int32_t * coeffs,
uint8_t * tile )

IDCT a coefficient block and emit level-shifted 8-bit samples.

Runs the shared 8x8 IDCT, then level-shifts and clamps each sample.

Parameters
[in,out]coeffs64-entry coefficient block (IDCTed in place).
[out]tile64-byte destination sample tile.
Precondition
coeffs holds dequantized coefficients.
tile holds 64 writable bytes.
Postcondition
tile holds clamped 8-bit spatial samples.
coeffs content is clobbered by the in-place IDCT.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

IDCT a coefficient block and emit level-shifted 8-bit samples.

Definition at line 425 of file ra8_jpeg_sw_decode.c.

References internal_clamp_u8(), k_ra8_jpeg_block_size, k_ra8_jpeg_level_offset, priv_jpeg_sw_idct8x8(), and RA8_PRIV.

Referenced by priv_jpeg_sw_mcu_chroma(), and priv_jpeg_sw_mcu_y().

◆ priv_jpeg_sw_mcu_chroma()

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 )

Decode the Cb and Cr 8x8 blocks of one MCU.

Consumes one Cb block then one Cr block, IDCTing each into its tile.

Parameters
[in,out]dDecoder context (DC predictors mutate).
[in,out]brBit-reader positioned at the next chroma block.
[out]cb_tile64-byte buffer for reconstructed Cb pixels.
[out]cr_tile64-byte buffer for reconstructed Cr pixels.
Returns
ra8_err_t Error code.
Return values
k_ra8_okBoth chroma blocks decoded.
k_ra8_err_protocol_errorUnderlying block decode failed.
Precondition
d->ncomp == 3 (caller verifies).
Both tiles hold 64 writable bytes.
Postcondition
On success both tiles are fully populated.
On error the scan aborts.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

Decode the Cb and Cr 8x8 blocks of one MCU.

Definition at line 493 of file ra8_jpeg_sw_decode.c.

References k_ra8_jpeg_block_size, k_ra8_ok, priv_jpeg_sw_block(), priv_jpeg_sw_idct_into(), and RA8_PRIV.

Referenced by internal_dec_decode_mcu(), and internal_js_decode_mcu().

◆ priv_jpeg_sw_mcu_y()

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 )

Decode the hmax*vmax luma blocks of one MCU into the Y tile.

Decodes hmax*vmax successive luma blocks into their tile sub-rectangles.

Parameters
[in,out]dDecoder context (DC predictors mutate).
[in,out]brBit-reader positioned at the next luma block.
[out]y_tileOutput tile of (mcu_w_px x mcu_h_px) luma px.
[in]mcu_w_pxMCU width in pixels.
Returns
ra8_err_t Error code.
Return values
k_ra8_okAll luma blocks consumed.
k_ra8_err_protocol_errorUnderlying block decode failed.
Precondition
d->hmax and d->vmax are non-zero (SOF0-enforced).
y_tile covers mcu_w_px * (8 * vmax) bytes.
Postcondition
On success y_tile is fully populated.
On error the scan aborts.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

Decode the hmax*vmax luma blocks of one MCU into the Y tile.

Definition at line 472 of file ra8_jpeg_sw_decode.c.

References ra8_jpeg_dec_ctx_t::hmax, internal_dec_copy_block_to_tile(), k_ra8_jpeg_block_size, k_ra8_ok, priv_jpeg_sw_block(), priv_jpeg_sw_idct_into(), RA8_PRIV, and ra8_jpeg_dec_ctx_t::vmax.

Referenced by internal_dec_decode_mcu(), and internal_js_decode_mcu().

◆ priv_jpeg_sw_parse_dht()

ra8_err_t priv_jpeg_sw_parse_dht ( ra8_jpeg_dec_ctx_t * d)

Parse a DHT segment (T.81 sec B.2.4.2) and build its tables.

T.81 sec B.2.4.2: reads the BITS/VALS lists and canonical-builds the table.

Parameters
[in,out]dDecoder context (cursor advances; tables written).
Returns
ra8_err_t Error code.
Return values
k_ra8_okTable(s) parsed and built.
k_ra8_err_protocol_errorTruncated / malformed segment.
k_ra8_err_not_supportedTable class / id out of range.
Precondition
d->cursor points at the DHT length field.
d->src covers d->src_len readable bytes.
Postcondition
On success the referenced Huffman tables are canonical-built.
On error the decode aborts; table state is partial.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

Parse a DHT segment (T.81 sec B.2.4.2) and build its tables.

Definition at line 158 of file ra8_jpeg_sw_decode.c.

References ra8_jpeg_dec_ctx_t::cursor, internal_dec_parse_dht_one(), internal_read_be16(), k_ra8_err_protocol_error, k_ra8_ok, RA8_PRIV, ra8_jpeg_dec_ctx_t::src, and ra8_jpeg_dec_ctx_t::src_len.

Referenced by internal_dec_dispatch_tail().

◆ priv_jpeg_sw_parse_dqt()

ra8_err_t priv_jpeg_sw_parse_dqt ( ra8_jpeg_dec_ctx_t * d)

Parse a DQT segment (T.81 sec B.2.4.1) into d->qtab.

T.81 sec B.2.4.1: de-zigzags each 8-bit table into d->qtab.

Parameters
[in,out]dDecoder context (cursor advances; tables written).
Returns
ra8_err_t Error code.
Return values
k_ra8_okTable(s) parsed.
k_ra8_err_protocol_errorTruncated / malformed segment.
k_ra8_err_not_supported16-bit precision table.
Precondition
d->cursor points at the DQT length field.
d->src covers d->src_len readable bytes.
Postcondition
On success the referenced quant tables are de-zigzagged in place.
On error the decode aborts; table state is partial.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

Parse a DQT segment (T.81 sec B.2.4.1) into d->qtab.

Definition at line 68 of file ra8_jpeg_sw_decode.c.

References ra8_jpeg_dec_ctx_t::cursor, internal_read_be16(), k_ra8_err_not_supported, k_ra8_err_protocol_error, k_ra8_jpeg_block_size, k_ra8_jpeg_nibble_mask, k_ra8_jpeg_nibble_shift, k_ra8_jpeg_quant_tabs, k_ra8_ok, ra8_jpeg_dec_ctx_t::qtab, RA8_PRIV, s_zigzag, ra8_jpeg_dec_ctx_t::src, and ra8_jpeg_dec_ctx_t::src_len.

Referenced by internal_dec_dispatch_tail().

◆ priv_jpeg_sw_parse_sof0()

ra8_err_t priv_jpeg_sw_parse_sof0 ( ra8_jpeg_dec_ctx_t * d)

Parse the SOF0 frame header (T.81 sec B.2.2).

T.81 sec B.2.2: reads precision, dimensions and per-component sampling.

Parameters
[in,out]dDecoder context (dims/sampling written).
Returns
ra8_err_t Error code.
Return values
k_ra8_okBaseline frame accepted.
k_ra8_err_protocol_errorTruncated / malformed segment.
k_ra8_err_not_supportedNon-8-bit precision, component count not 1/3, or a chroma layout other than 4:4:4 / 4:2:0.
Precondition
d->cursor points at the SOF0 length field.
d->src covers d->src_len readable bytes.
Postcondition
On success width/height/ncomp/hmax/vmax are set non-zero.
On error the decode aborts.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

Parse the SOF0 frame header (T.81 sec B.2.2).

Definition at line 258 of file ra8_jpeg_sw_decode.c.

References ra8_jpeg_dec_ctx_t::cursor, ra8_jpeg_dec_ctx_t::height, internal_dec_check_chroma_layout(), internal_dec_parse_sof0_components(), internal_read_be16(), k_ra8_err_not_supported, k_ra8_err_protocol_error, ra8_jpeg_dec_ctx_t::ncomp, RA8_PRIV, ra8_jpeg_dec_ctx_t::src, ra8_jpeg_dec_ctx_t::src_len, and ra8_jpeg_dec_ctx_t::width.

Referenced by priv_jpeg_sw_dispatch().

◆ priv_jpeg_sw_parse_sos()

ra8_err_t priv_jpeg_sw_parse_sos ( ra8_jpeg_dec_ctx_t * d)

Parse the SOS scan header (T.81 sec B.2.3) selectors.

T.81 sec B.2.3: binds each scan component to its DC/AC table selectors.

Parameters
[in,out]dDecoder context (per-component table ids written).
Returns
ra8_err_t Error code.
Return values
k_ra8_okScan header accepted.
k_ra8_err_protocol_errorTruncated / malformed segment.
k_ra8_err_not_supportedComponent count mismatch or selector out of range.
Precondition
d->cursor points at the SOS length field.
A successful SOF0 parse preceded this call.
Postcondition
On success d->cursor sits at the entropy-coded data.
On error the decode aborts.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

Parse the SOS scan header (T.81 sec B.2.3) selectors.

Definition at line 291 of file ra8_jpeg_sw_decode.c.

References ra8_jpeg_dec_ctx_t::comp_ac_id, ra8_jpeg_dec_ctx_t::comp_dc_id, ra8_jpeg_dec_ctx_t::comp_id, ra8_jpeg_dec_ctx_t::cursor, internal_read_be16(), k_ra8_err_not_supported, k_ra8_err_protocol_error, k_ra8_jpeg_huff_ids, k_ra8_jpeg_nibble_mask, k_ra8_jpeg_nibble_shift, k_ra8_ok, ra8_jpeg_dec_ctx_t::ncomp, RA8_PRIV, ra8_jpeg_dec_ctx_t::src, and ra8_jpeg_dec_ctx_t::src_len.

Referenced by internal_dec_dispatch_tail().

◆ priv_jpeg_sw_skip_segment()

ra8_err_t priv_jpeg_sw_skip_segment ( ra8_jpeg_dec_ctx_t * d)

Skip an unrecognized variable-length segment.

Reads the 16-bit big-endian segment length at d->cursor and advances past the payload, bounds-checked against d->src_len.

Parameters
[in,out]dDecoder context (cursor advances).
Returns
ra8_err_t Error code.
Return values
k_ra8_okSegment skipped.
k_ra8_err_protocol_errorTruncated / malformed length field.
Precondition
d is non-NULL with src/src_len set.
d->cursor points at a segment length field.
Postcondition
On success d->cursor advanced past the whole segment.
On error d->cursor is unspecified; the decode aborts.
Note
Not thread-safe; caller serializes via decoder context.
Since
0.1.0

Skip an unrecognized variable-length segment.

Definition at line 54 of file ra8_jpeg_sw_decode.c.

References ra8_jpeg_dec_ctx_t::cursor, internal_read_be16(), k_ra8_err_protocol_error, k_ra8_ok, RA8_PRIV, ra8_jpeg_dec_ctx_t::src, and ra8_jpeg_dec_ctx_t::src_len.

Referenced by internal_dec_dispatch_tail().

◆ priv_jpeg_sw_ycc_to_rgb()

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).

Defined in ra8_jpeg_sw.c; the parser unit calls it from the MCU pixel-emit loop. The MVE-accelerated row helper is enabled when __ARM_FEATURE_MVE is defined; the scalar path is what host tests exercise.

Parameters
[in]yLuma sample.
[in]cbCb chroma sample (level-offset removed inside).
[in]crCr chroma sample (level-offset removed inside).
[out]out_rReceives the red channel byte.
[out]out_gReceives the green channel byte.
[out]out_bReceives the blue channel byte.
Precondition
out_r, out_g, out_b are non-NULL.
y/cb/cr are valid reconstructed samples.
Postcondition
Each output byte is in 0..255.
No global state is touched.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

MVE-accelerated path is enabled when __ARM_FEATURE_MVE is defined (Cortex-M85 target). Host tests run the scalar path.

Parameters
[in,out]cbSee function signature.
[in,out]crSee function signature.
[in,out]out_bSee function signature.
[in,out]out_gSee function signature.
[in,out]out_rSee function signature.
[in,out]ySee function signature.
Precondition
Module has been initialized.
Caller has validated arguments.
Postcondition
Side effects bounded to documented state.
State reflects operation result.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 402 of file ra8_jpeg_sw.c.

References internal_clamp_u8(), k_ra8_jpeg_cb_b, k_ra8_jpeg_cb_g, k_ra8_jpeg_cr_g, k_ra8_jpeg_cr_r, k_ra8_jpeg_level_offset, k_ra8_jpeg_yuv_shift, and RA8_PRIV.

Referenced by internal_dec_emit_mcu_rgb(), and internal_js_emit_mcu().

Variable Documentation

◆ s_dct_cos_q14

const int32_t s_dct_cos_q14[8][8]
static
Initial value:
= {
{16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384},
{16069, 13623, 9102, 3196, -3196, -9102, -13623, -16069},
{15137, 6270, -6270, -15137, -15137, -6270, 6270, 15137},
{13623, -3196, -16069, -9102, 9102, 16069, 3196, -13623},
{11585, -11585, -11585, 11585, 11585, -11585, -11585, 11585},
{9102, -16069, 3196, 13623, -13623, -3196, 16069, -9102},
{6270, -15137, 15137, -6270, -6270, 15137, -15137, 6270},
{3196, -9102, 13623, -16069, 16069, -13623, 9102, -3196},
}

Cosine table cos((2n+1)*k*pi/16) * 2^14, k = row, n = col.

Shared by both forward and inverse 1-D DCT so the encoder and decoder are guaranteed to use a numerically identical basis. Q14 picks the largest scale that lets a row sum fit in int32_t for 16-bit pre-normalized inputs. Read-only; each translation unit holds its own copy.

Definition at line 235 of file ra8_jpeg_sw_internal.h.

Referenced by internal_fwd_dct_1d_norm(), and internal_inv_dct_1d_norm().

◆ s_dct_w_q14

const int32_t s_dct_w_q14[8]
static
Initial value:
= {
5793,
8192,
8192,
8192,
8192,
8192,
8192,
8192,
}

sqrt(2/N)*C(k) DCT normalization weights, Q14.

The cosine table is Q14; this sqrt(2/N)*C(k) weight is also Q14 so the inner accumulator is Q28, which the DCT row loops shift back to Q0 with a >>14 round on emit. Read-only; each translation unit holds its own copy.

Definition at line 255 of file ra8_jpeg_sw_internal.h.

Referenced by internal_fwd_dct_1d_norm(), and internal_inv_dct_1d_norm().

◆ s_zigzag

const uint8_t s_zigzag[64]
static
Initial value:
= {
0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48,
41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23,
30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63,
}

Zig-zag de-interleave order (T.81 Figure 5).

s_zigzag[i] returns the row-major 0..63 position that the i-th transmitted coefficient lives at inside an 8x8 block. Read-only; each translation unit holds its own copy.

Definition at line 219 of file ra8_jpeg_sw_internal.h.

Referenced by internal_dec_block_ac(), internal_enc_block(), internal_enc_emit_dqt(), and priv_jpeg_sw_parse_dqt().