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

Module-private declarations shared by the two encoder translation units of the software JPEG codec. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_err.h"
#include "ra8_jpeg_sw_internal.h"
Include dependency graph for ra8_jpeg_sw_encode_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_enc_ctx_t
 Encoder state – buffer cursor, bit accumulator, scaled quant tables, Huffman LUTs and DC predictors. More...

Functions

void priv_jpeg_sw_enc_emit_u16 (ra8_jpeg_enc_ctx_t *e, uint16_t v)
 Append a 16-bit big-endian word to the JPEG byte stream.
void priv_jpeg_sw_enc_put_bits (ra8_jpeg_enc_ctx_t *e, uint32_t code, uint8_t n)
 Push n bits MSB-first into the entropy stream with stuffing.
void priv_jpeg_sw_enc_flush_bits (ra8_jpeg_enc_ctx_t *e)
 Flush any partial byte at the end of a scan with 1-fill.
void priv_jpeg_sw_enc_build_huff (ra8_jpeg_enc_ctx_t *e, uint16_t *total_dc_l, uint16_t *total_ac_l, uint16_t *total_dc_c, uint16_t *total_ac_c)
 Build the four Annex K.3.3 Huffman code/size LUTs.
void priv_jpeg_sw_enc_headers (ra8_jpeg_enc_ctx_t *e, uint16_t w, uint16_t h, uint16_t total_dc_l, uint16_t total_ac_l, uint16_t total_dc_c, uint16_t total_ac_c)
 Emit the SOI/APP0/DQT/SOF0/DHT/SOS header segments.

Detailed Description

Module-private declarations shared by the two encoder translation units of the software JPEG codec.

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

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

  • ra8_jpeg_sw_encode.c – pixel pipeline: RGB->YCbCr strip conversion, 4:2:0 sampling, forward DCT, quantization, per-block Huffman emission and the ra8_jpeg_sw_encode() public API.
  • ra8_jpeg_sw_encode_emit.c – byte/bit emitters, the T.81 Annex K.3.3 reference Huffman tables, the canonical code build and the JFIF header-segment writers.

Every symbol referenced by both units lives here: the encoder context struct and the ra8_jpeg_sw_priv_enc_* primitives the pixel pipeline 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_encode_internal.h.

Function Documentation

◆ priv_jpeg_sw_enc_build_huff()

void priv_jpeg_sw_enc_build_huff ( ra8_jpeg_enc_ctx_t * e,
uint16_t * total_dc_l,
uint16_t * total_ac_l,
uint16_t * total_dc_c,
uint16_t * total_ac_c )

Build the four Annex K.3.3 Huffman code/size LUTs.

Canonical-builds the luma/chroma DC/AC code and size look-up tables into the encoder context and returns each table's symbol count for the DHT emitters. Defined in ra8_jpeg_sw_encode_emit.c.

Parameters
[in,out]eEncoder context (code/size LUTs written).
[out]total_dc_lLuma DC symbol count.
[out]total_ac_lLuma AC symbol count.
[out]total_dc_cChroma DC symbol count.
[out]total_ac_cChroma AC symbol count.
Precondition
All five pointers are non-NULL (module-internal call chain).
e's LUT arrays are writable.
Postcondition
All four LUT pairs hold canonical Huffman codes.
The totals reflect the static K.3.3 BITS arrays.
Note
Internal primitive; not thread-safe.
Since
0.1.0

Build the four Annex K.3.3 Huffman code/size LUTs.

Definition at line 318 of file ra8_jpeg_sw_encode_emit.c.

References ra8_jpeg_enc_ctx_t::code_ac_c, ra8_jpeg_enc_ctx_t::code_ac_l, ra8_jpeg_enc_ctx_t::code_dc_c, ra8_jpeg_enc_ctx_t::code_dc_l, internal_enc_build_codes(), k_ra8_jpeg_huff_lengths, RA8_PRIV, s_hbits_ac_chroma, s_hbits_ac_luma, s_hbits_dc_chroma, s_hbits_dc_luma, s_hval_ac_chroma, s_hval_ac_luma, s_hval_dc_chroma, s_hval_dc_luma, ra8_jpeg_enc_ctx_t::size_ac_c, ra8_jpeg_enc_ctx_t::size_ac_l, ra8_jpeg_enc_ctx_t::size_dc_c, and ra8_jpeg_enc_ctx_t::size_dc_l.

Referenced by internal_enc_run().

◆ priv_jpeg_sw_enc_emit_u16()

void priv_jpeg_sw_enc_emit_u16 ( ra8_jpeg_enc_ctx_t * e,
uint16_t v )

Append a 16-bit big-endian word to the JPEG byte stream.

Emits the high byte then the low byte through the internal byte emitter; sets e->overflow instead of writing past e->cap. Defined in ra8_jpeg_sw_encode_emit.c.

Parameters
[in,out]eEncoder context (cursor advances).
[in]vValue to append (marker code or length field).
Precondition
e is non-NULL with dst bound (module-internal call chain).
e->pos <= e->cap.
Postcondition
e->pos advanced by 2, or e->overflow set.
No other context state is mutated.
Note
Internal primitive; not thread-safe.
Since
0.1.0

Append a 16-bit big-endian word to the JPEG byte stream.

Definition at line 216 of file ra8_jpeg_sw_encode_emit.c.

References internal_enc_emit_u8(), k_jpeg_byte_mask, k_ra8_jpeg_byte_shift, and RA8_PRIV.

Referenced by internal_enc_emit_app0_jfif(), internal_enc_emit_dht_one(), internal_enc_emit_dqt(), internal_enc_emit_sof0(), internal_enc_emit_sos(), and internal_enc_run().

◆ priv_jpeg_sw_enc_flush_bits()

void priv_jpeg_sw_enc_flush_bits ( ra8_jpeg_enc_ctx_t * e)

Flush any partial byte at the end of a scan with 1-fill.

Pads the residual bit_cnt bits with ones (T.81 sec F.1.2.3) so the final entropy byte is complete before the EOI marker. Defined in ra8_jpeg_sw_encode_emit.c.

Parameters
[in,out]eEncoder context (bit buffer + cursor mutate).
Precondition
e is non-NULL (module-internal call chain).
All scan data was emitted via priv_jpeg_sw_enc_put_bits().
Postcondition
e->bit_cnt == 0.
The last entropy byte, if partial, is 1-padded in dst.
Note
Internal primitive; not thread-safe.
Since
0.1.0

Flush any partial byte at the end of a scan with 1-fill.

Definition at line 238 of file ra8_jpeg_sw_encode_emit.c.

References ra8_jpeg_enc_ctx_t::bit_buf, ra8_jpeg_enc_ctx_t::bit_cnt, k_jpeg_byte_mask, k_ra8_jpeg_byte_shift, priv_jpeg_sw_enc_put_bits(), and RA8_PRIV.

Referenced by internal_enc_run().

◆ priv_jpeg_sw_enc_headers()

void priv_jpeg_sw_enc_headers ( ra8_jpeg_enc_ctx_t * e,
uint16_t w,
uint16_t h,
uint16_t total_dc_l,
uint16_t total_ac_l,
uint16_t total_dc_c,
uint16_t total_ac_c )

Emit the SOI/APP0/DQT/SOF0/DHT/SOS header segments.

Writes every byte that precedes the entropy-coded scan of a 4:2:0 YCbCr baseline stream, in JFIF 1.1 order. Defined in ra8_jpeg_sw_encode_emit.c.

Parameters
[in,out]eEncoder context (cursor advances).
[in]wImage width in pixels.
[in]hImage height in pixels.
[in]total_dc_lLuma DC symbol count (from build_huff).
[in]total_ac_lLuma AC symbol count.
[in]total_dc_cChroma DC symbol count.
[in]total_ac_cChroma AC symbol count.
Precondition
priv_jpeg_sw_enc_build_huff() populated the totals.
e->qy/e->qc hold the scaled quantization tables.
Postcondition
e->pos advanced past every header segment.
Header bytes are byte-identical to the pre-split encoder.
Note
Internal primitive; not thread-safe.
Since
0.1.0

Emit the SOI/APP0/DQT/SOF0/DHT/SOS header segments.

Definition at line 543 of file ra8_jpeg_sw_encode_emit.c.

References internal_enc_emit_app0_jfif(), internal_enc_emit_dht_one(), internal_enc_emit_dqt(), internal_enc_emit_sof0(), internal_enc_emit_sos(), k_jpeg_dht_ac_chroma, RA8_PRIV, s_hbits_ac_chroma, s_hbits_ac_luma, s_hbits_dc_chroma, s_hbits_dc_luma, s_hval_ac_chroma, s_hval_ac_luma, s_hval_dc_chroma, and s_hval_dc_luma.

Referenced by internal_enc_run().

◆ priv_jpeg_sw_enc_put_bits()

void priv_jpeg_sw_enc_put_bits ( ra8_jpeg_enc_ctx_t * e,
uint32_t code,
uint8_t n )

Push n bits MSB-first into the entropy stream with stuffing.

Accumulates bits and flushes whole bytes, inserting the T.81 sec F.1.2.3 0x00 stuffing byte after every emitted 0xFF. Defined in ra8_jpeg_sw_encode_emit.c.

Parameters
[in,out]eEncoder context (bit buffer + cursor mutate).
[in]codeRight-aligned code bits to append.
[in]nNumber of significant bits in code (0..24).
Precondition
e->bit_cnt + n fits the 32-bit accumulator (n <= 24).
e is non-NULL (module-internal call chain).
Postcondition
e->bit_cnt < 8 (all whole bytes flushed).
e->overflow set instead of any out-of-bounds write.
Note
Internal primitive; not thread-safe.
Since
0.1.0

Push n bits MSB-first into the entropy stream with stuffing.

Definition at line 223 of file ra8_jpeg_sw_encode_emit.c.

References ra8_jpeg_enc_ctx_t::bit_buf, ra8_jpeg_enc_ctx_t::bit_cnt, internal_enc_emit_u8(), k_ra8_jpeg_byte_shift, k_ra8_jpeg_marker_byte, and RA8_PRIV.

Referenced by internal_enc_block(), internal_enc_block_ac(), and priv_jpeg_sw_enc_flush_bits().