Crate tjpgdec_rs

Crate tjpgdec_rs 

Source
Expand description

§TJpgDec-rs - Tiny JPEG Decompressor

A lightweight JPEG decoder optimized for embedded systems.

Based on TJpgDec R0.03 (C)ChaN, 2021

§Key Features

  • Memory pool allocation - Predictable memory usage
  • Small decoder struct - Only ~120 bytes
  • no_std compatible - Works in embedded environments
  • Three optimization levels - Balance speed vs memory (fast-decode-0/1/2)
  • No heap allocation - All memory from user-provided pool

§Example Usage

use tjpgdec_rs::{JpegDecoder, MemoryPool, RECOMMENDED_POOL_SIZE, Result};
 
fn decode_jpeg(jpeg_data: &[u8]) -> Result<()> {
    // Allocate memory pool
    let mut pool_buffer = vec![0u8; RECOMMENDED_POOL_SIZE];
    let mut pool = MemoryPool::new(&mut pool_buffer);
     
    // Create decoder
    let mut decoder = JpegDecoder::new();
     
    // Prepare decoder
    decoder.prepare(jpeg_data, &mut pool)?;
     
    // Get image info
    let width = decoder.width();
    let height = decoder.height();
     
    // Decode image...
    Ok(())
}

Structs§

BitStream
Bit stream reader
HuffmanTable
Huffman coding table
JpegDecoder
JPEG decoder
MemoryPool
Memory pool for workspace allocation
Rectangle
Rectangular region in the output image

Enums§

Error
Error codes for JPEG decompression
OutputFormat
Output pixel format

Constants§

BUFFER_SIZE
Size of stream input buffer
MINIMUM_POOL_SIZE
Minimum workspace size
MIN_WORKSPACE_SIZE
RECOMMENDED_POOL_SIZE
Recommended workspace size

Functions§

calculate_pool_size
Calculate required workspace memory pool size
fastdecode_level
Query the current optimization level

Type Aliases§

OutputCallback
Output callback function
Result
Result type for JPEG operations