|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Software JPEG encoder: byte/bit emitters, Annex K.3.3 tables and JFIF header-segment writers. More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_err.h"#include "ra8_jpeg_sw.h"#include "ra8_jpeg_sw_encode_internal.h"#include "ra8_jpeg_sw_internal.h"Go to the source code of this file.
Functions | |
| static void | internal_enc_emit_u8 (ra8_jpeg_enc_ctx_t *e, uint8_t b) |
| Append one byte; sets overflow on capacity exhaustion. | |
| void | priv_jpeg_sw_enc_emit_u16 (ra8_jpeg_enc_ctx_t *e, uint16_t v) |
| Implementation of priv_jpeg_sw_enc_emit_u16() – big-endian byte pair. | |
| void | priv_jpeg_sw_enc_put_bits (ra8_jpeg_enc_ctx_t *e, uint32_t code, uint8_t n) |
| Implementation of priv_jpeg_sw_enc_put_bits() – T.81 F.1.2.3 stuffing. | |
| void | priv_jpeg_sw_enc_flush_bits (ra8_jpeg_enc_ctx_t *e) |
| Implementation of priv_jpeg_sw_enc_flush_bits() – 1-fill pad. | |
| static void | internal_enc_build_codes (const uint8_t *bits, const uint8_t *vals, uint16_t *codes, uint8_t *sizes, uint16_t total) |
| Build the canonical-code table from BITS+HUFFVAL. | |
| 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) |
| Implementation of priv_jpeg_sw_enc_build_huff() – four K.3.3 LUT builds. | |
| static void | internal_enc_emit_dqt (ra8_jpeg_enc_ctx_t *e) |
| Emit the DQT segment for both luma and chroma tables. | |
| static void | internal_enc_emit_dht_one (ra8_jpeg_enc_ctx_t *e, uint8_t tc_th, const uint8_t *bits, const uint8_t *vals, uint16_t total) |
| Emit one DHT segment (T.81 sec B.2.4.2). | |
| static void | internal_enc_emit_app0_jfif (ra8_jpeg_enc_ctx_t *e) |
| Emit the SOI marker plus the 16-byte APP0 JFIF header. | |
| static void | internal_enc_emit_sof0 (ra8_jpeg_enc_ctx_t *e, uint16_t w, uint16_t h) |
| Emit the SOF0 frame header for a 3-component 4:2:0 stream. | |
| static void | internal_enc_emit_sos (ra8_jpeg_enc_ctx_t *e) |
| Emit the SOS scan header (T.81 sec B.2.3). | |
| 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) |
| Implementation of priv_jpeg_sw_enc_headers() – JFIF 1.1 segment order. | |
Variables | |
| static const uint8_t | s_hbits_dc_luma [16] |
| K.3.3 luma DC BITS (number of codes of each length 1..16). | |
| static const uint8_t | s_hval_dc_luma [12] |
| K.3.3 luma DC HUFFVAL (12 symbols). | |
| static const uint8_t | s_hbits_dc_chroma [16] |
| K.3.3 chroma DC BITS. | |
| static const uint8_t | s_hval_dc_chroma [12] |
| K.3.3 chroma DC HUFFVAL. | |
| static const uint8_t | s_hbits_ac_luma [16] |
| K.3.3 luma AC BITS. | |
| static const uint8_t | s_hval_ac_luma [162] |
| K.3.3 luma AC HUFFVAL (162 symbols). | |
| static const uint8_t | s_hbits_ac_chroma [16] |
| K.3.3 chroma AC BITS. | |
| static const uint8_t | s_hval_ac_chroma [162] |
| K.3.3 chroma AC HUFFVAL. | |
Software JPEG encoder: byte/bit emitters, Annex K.3.3 tables and JFIF header-segment writers.
Emitter half of the software JPEG encoder: the bounds-checked byte emitter, the MSB-first bit packer with T.81 sec F.1.2.3 stuffing, the canonical Huffman code build over the T.81 Annex K.3.3 reference tables, and the SOI/APP0/DQT/SOF0/DHT/SOS header-segment writers. The pixel pipeline (RGB->YCbCr conversion, sampling, forward DCT, quantization, per-block emission) and the ra8_jpeg_sw_encode() public API live in ra8_jpeg_sw_encode.c; the symbols shared between the two units are declared in ra8_jpeg_sw_encode_internal.h.
The Huffman BITS/HUFFVAL tables in this file are taken verbatim from ITU-T T.81 / ISO 10918-1 Annex K.3.3.
Spec citations are tagged T.81 sec X.Y "..." and refer to ITU-T Recommendation T.81 (1992) | ISO/IEC 10918-1.
Definition in file ra8_jpeg_sw_encode_emit.c.
|
static |
Build the canonical-code table from BITS+HUFFVAL.
T.81 Annex C "Generation of size table" + "Generation of code table": expands the BITS list into per-symbol code lengths, assigns consecutive canonical codes within each length, and scatters both into symbol-indexed LUTs so the block encoder can look codes up by symbol value directly.
| [in] | bits | 16-entry BITS list (codes per length 1..16). |
| [in] | vals | HUFFVAL symbol list (total entries). |
| [out] | codes | 256-entry code LUT indexed by symbol value. |
| [out] | sizes | 256-entry code-length LUT indexed by symbol value. |
| [in] | total | Number of symbols in vals. |
Definition at line 277 of file ra8_jpeg_sw_encode_emit.c.
References k_ra8_jpeg_huff_lengths, k_ra8_jpeg_huff_max, and RA8_INTERNAL.
Referenced by priv_jpeg_sw_enc_build_huff().
|
static |
Emit the SOI marker plus the 16-byte APP0 JFIF header.
Writes the JFIF 1.1 APP0 segment with units=0, aspect ratio 1:1, no embedded thumbnail. The byte sequence is identical to what the pre-split monolithic encoder produced.
| [in,out] | e | Encoder context (cursor advances). |
Definition at line 446 of file ra8_jpeg_sw_encode_emit.c.
References internal_enc_emit_u8(), k_ra8_jpeg_marker_app0, k_ra8_jpeg_marker_soi, priv_jpeg_sw_enc_emit_u16(), and RA8_INTERNAL.
Referenced by priv_jpeg_sw_enc_headers().
|
static |
Emit one DHT segment (T.81 sec B.2.4.2).
Serialises the TcTh selector, the 16-entry BITS list and the HUFFVAL symbol list of one reference Huffman table.
| [in,out] | e | Encoder context (cursor advances). |
| [in] | tc_th | Table class/id byte (0x00/0x10/0x01/0x11). |
| [in] | bits | 16-entry BITS list. |
| [in] | vals | HUFFVAL list (total entries). |
| [in] | total | Symbol count for the segment length field. |
Definition at line 411 of file ra8_jpeg_sw_encode_emit.c.
References internal_enc_emit_u8(), k_ra8_jpeg_huff_lengths, k_ra8_jpeg_marker_dht, priv_jpeg_sw_enc_emit_u16(), and RA8_INTERNAL.
Referenced by priv_jpeg_sw_enc_headers().
|
static |
Emit the DQT segment for both luma and chroma tables.
One DQT marker carrying two 8-bit-precision tables (PqTq 0,0 then 0,1), each serialised in zig-zag order per T.81 sec B.2.4.1.
| [in,out] | e | Encoder context (cursor advances). |
Definition at line 377 of file ra8_jpeg_sw_encode_emit.c.
References internal_enc_emit_u8(), k_ra8_jpeg_block_size, k_ra8_jpeg_marker_dqt, priv_jpeg_sw_enc_emit_u16(), ra8_jpeg_enc_ctx_t::qc, ra8_jpeg_enc_ctx_t::qy, RA8_INTERNAL, and s_zigzag.
Referenced by priv_jpeg_sw_enc_headers().
|
static |
Emit the SOF0 frame header for a 3-component 4:2:0 stream.
T.81 sec B.2.2: 8-bit precision, the image dimensions, and the three component records (Y 2x2 sampling on quant table 0; Cb/Cr 1x1 on quant table 1).
| [in,out] | e | Encoder context (cursor advances). |
| [in] | w | Image width in pixels. |
| [in] | h | Image height in pixels. |
Definition at line 487 of file ra8_jpeg_sw_encode_emit.c.
References internal_enc_emit_u8(), k_jpeg_samp_1x1, k_jpeg_samp_2x2, k_jpeg_sof_seg_len, k_ra8_jpeg_marker_sof0, priv_jpeg_sw_enc_emit_u16(), and RA8_INTERNAL.
Referenced by priv_jpeg_sw_enc_headers().
|
static |
Emit the SOS scan header (T.81 sec B.2.3).
Binds the three scan components to their Huffman selectors (Y dc=0/ac=0, Cb/Cr dc=1/ac=1) and writes the baseline spectral-range bytes (Ss=0, Se=63, AhAl=0).
| [in,out] | e | Encoder context (cursor advances). |
Definition at line 526 of file ra8_jpeg_sw_encode_emit.c.
References internal_enc_emit_u8(), k_jpeg_sos_seg_len, k_jpeg_sos_sel_chroma, k_jpeg_spectral_end, k_ra8_jpeg_marker_sos, priv_jpeg_sw_enc_emit_u16(), and RA8_INTERNAL.
Referenced by priv_jpeg_sw_enc_headers().
|
static |
Append one byte; sets overflow on capacity exhaustion.
Single choke point for every byte that reaches the output buffer: once e->pos hits e->cap the byte is dropped and e->overflow latches so the driver can fail the encode with k_ra8_err_invalid_size after the fact.
| [in,out] | e | Encoder context (cursor advances). |
| [in] | b | Byte to append. |
Definition at line 205 of file ra8_jpeg_sw_encode_emit.c.
References ra8_jpeg_enc_ctx_t::cap, ra8_jpeg_enc_ctx_t::dst, ra8_jpeg_enc_ctx_t::overflow, ra8_jpeg_enc_ctx_t::pos, and RA8_INTERNAL.
Referenced by internal_enc_emit_app0_jfif(), internal_enc_emit_dht_one(), internal_enc_emit_dqt(), internal_enc_emit_sof0(), internal_enc_emit_sos(), priv_jpeg_sw_enc_emit_u16(), and priv_jpeg_sw_enc_put_bits().
| 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 ) |
Implementation of priv_jpeg_sw_enc_build_huff() – four K.3.3 LUT builds.
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().
| void priv_jpeg_sw_enc_emit_u16 | ( | ra8_jpeg_enc_ctx_t * | e, |
| uint16_t | v ) |
Implementation of priv_jpeg_sw_enc_emit_u16() – big-endian byte pair.
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().
| void priv_jpeg_sw_enc_flush_bits | ( | ra8_jpeg_enc_ctx_t * | e | ) |
Implementation of priv_jpeg_sw_enc_flush_bits() – 1-fill pad.
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().
| 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 ) |
Implementation of priv_jpeg_sw_enc_headers() – JFIF 1.1 segment order.
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().
| void priv_jpeg_sw_enc_put_bits | ( | ra8_jpeg_enc_ctx_t * | e, |
| uint32_t | code, | ||
| uint8_t | n ) |
Implementation of priv_jpeg_sw_enc_put_bits() – T.81 F.1.2.3 stuffing.
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().
|
static |
K.3.3 chroma AC BITS.
Definition at line 148 of file ra8_jpeg_sw_encode_emit.c.
Referenced by priv_jpeg_sw_enc_build_huff(), and priv_jpeg_sw_enc_headers().
|
static |
K.3.3 luma AC BITS.
Definition at line 114 of file ra8_jpeg_sw_encode_emit.c.
Referenced by priv_jpeg_sw_enc_build_huff(), and priv_jpeg_sw_enc_headers().
|
static |
K.3.3 chroma DC BITS.
Definition at line 79 of file ra8_jpeg_sw_encode_emit.c.
Referenced by priv_jpeg_sw_enc_build_huff(), and priv_jpeg_sw_enc_headers().
|
static |
K.3.3 luma DC BITS (number of codes of each length 1..16).
Definition at line 44 of file ra8_jpeg_sw_encode_emit.c.
Referenced by priv_jpeg_sw_enc_build_huff(), and priv_jpeg_sw_enc_headers().
|
static |
K.3.3 chroma AC HUFFVAL.
Definition at line 167 of file ra8_jpeg_sw_encode_emit.c.
Referenced by priv_jpeg_sw_enc_build_huff(), and priv_jpeg_sw_enc_headers().
|
static |
K.3.3 luma AC HUFFVAL (162 symbols).
Definition at line 133 of file ra8_jpeg_sw_encode_emit.c.
Referenced by priv_jpeg_sw_enc_build_huff(), and priv_jpeg_sw_enc_headers().
|
static |
K.3.3 chroma DC HUFFVAL.
Definition at line 98 of file ra8_jpeg_sw_encode_emit.c.
Referenced by priv_jpeg_sw_enc_build_huff(), and priv_jpeg_sw_enc_headers().
|
static |
K.3.3 luma DC HUFFVAL (12 symbols).
Definition at line 63 of file ra8_jpeg_sw_encode_emit.c.
Referenced by priv_jpeg_sw_enc_build_huff(), and priv_jpeg_sw_enc_headers().