Chapter 22: Zero-Dependency Codecs, ORB, Sparse BCSR4 & ONNX
"Owning every bit from disk bitstream to compute register eliminates dependency rot forever."
22.1 Raster Codecs in Pure C23: DEFLATE/PNG & 8x8 DCT JPEG (rcre_codec)
Rather than linking libpng or libjpeg-turbo, RCRE implements raster compression directly (src/cv/codec.c):
- PNG (RFC 1950 / 1951): pairs CRC-32 chunk integrity and Adler-32 checksums with DEFLATE decompression (stored, fixed Huffman, and dynamic Huffman prefix tables) plus all 5 scanline predictors (
None,Sub,Up,Avg,Paeth). - Baseline JPEG: parses
DQT,SOF0,DHT, and byte-stuffedSOSentropy streams, reconstructing RGB channels via separable 8x8 Inverse Discrete Cosine Transform (IDCT) and ITU-R BT.601 YCbCr rotation.
22.2 Binary Vision Features: FAST-9 & Rotated BRIEF (ORB)
Float patch descriptors compare slowly in SLAM and panorama loops. rcre_cv_fast_detect() evaluates the 16-pixel Bresenham radius-3 ring around candidate corners (using the FAST-9 2-of-4 cardinal pre-filter) and extracts intensity-centroid orientation \(\theta = \text{atan2}(m_{01}, m_{10})\). rcre_cv_orb_extract() then rotates 256 intensity test pairs into a 32-byte binary signature compared in single-cycle POPCNT instructions (rcre_cv_orb_match()).
22.3 Register-Blocked Sparse Compute (BCSR4) & ONNX Protobuf Subset
For pruned CNN/MLP weights at \(\ge 75\%\) sparsity (src/core/sparse.c), arbitrary irregular CSR lookups break SIMD continuity. Grouping non-zeros into dense \(4 \times 4\) register blocks (BCSR4) lets NEON compute 4 dot-products simultaneously, hitting 28.78x speedup (\(1.56\;\mu\text{s}\) per MobileNet head pass). Notice carefully: when column count is not divisible by 4, trailing block loads must clamp reads inside [0, cols) so sanitizers never observe out-of-bounds vector loads.
Complementing raw weights, src/cv/onnx_subset.c parses standard Google Protobuf wire primitives (varint, length-delimited bytes, fixed32) to execute exported Relu, Gemm, MatMul, Add, Softmax, Conv, and GlobalAveragePool computational graphs without libprotobuf.
22.4 Chapter Project: CRC-32, PNG Paeth Predictor & Popcount Hamming Matcher
Companion code in examples/ch22/main.c (make ch22) implements IEEE 802.3 CRC-32, PNG Paeth scanline filtering/unfiltering, and 256-bit Hamming matching verified under ASan and UBSan.