pub struct JpegImage { /* private fields */ }Expand description
A decoded JPEG image providing access to quantized DCT coefficients.
Created by parsing a JPEG byte stream with JpegImage::from_bytes.
After modifying DCT coefficients (e.g., for steganographic embedding),
call JpegImage::to_bytes to re-encode. If coefficient modifications
introduce symbols not present in the original Huffman tables, call
JpegImage::rebuild_huffman_tables first.
Implementations§
Source§impl JpegImage
impl JpegImage
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self>
pub fn from_bytes(data: &[u8]) -> Result<Self>
Parse a JPEG file from bytes.
Supports both baseline (SOF0) and progressive (SOF2) JPEG.
Progressive images are decoded by accumulating all scans, then the
coefficients are stored exactly as in baseline — to_bytes() always
writes baseline output.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>>
pub fn to_bytes(&self) -> Result<Vec<u8>>
Encode the (possibly modified) image back to JPEG bytes.
Sourcepub fn to_bytes_with_progress(
&self,
on_progress: Option<&dyn Fn()>,
) -> Result<Vec<u8>>
pub fn to_bytes_with_progress( &self, on_progress: Option<&dyn Fn()>, ) -> Result<Vec<u8>>
Serialize this JPEG image to bytes, with an optional progress callback
that fires approximately scan::JPEG_WRITE_STEPS times during scan
encoding.
Sourcepub fn dct_grid(&self, component: usize) -> &DctGrid
pub fn dct_grid(&self, component: usize) -> &DctGrid
Get a reference to the DCT coefficient grid for a component. Component index is in scan order (typically 0=Y, 1=Cb, 2=Cr).
Sourcepub fn dct_grid_mut(&mut self, component: usize) -> &mut DctGrid
pub fn dct_grid_mut(&mut self, component: usize) -> &mut DctGrid
Get a mutable reference to the DCT coefficient grid for a component.
Sourcepub fn frame_info(&self) -> &FrameInfo
pub fn frame_info(&self) -> &FrameInfo
Get the frame information.
Sourcepub fn quant_table(&self, id: usize) -> Option<&QuantTable>
pub fn quant_table(&self, id: usize) -> Option<&QuantTable>
Get a quantization table by ID.
Sourcepub fn num_components(&self) -> usize
pub fn num_components(&self) -> usize
Number of components in the scan.
Sourcepub fn rebuild_huffman_tables(&mut self)
pub fn rebuild_huffman_tables(&mut self)
Rebuild Huffman tables from the current coefficient data.
Call this after modifying DCT coefficients to ensure the Huffman tables
can encode all symbols present in the modified data. This replaces the
DHT segments in raw_segments and updates dc_huff_specs/ac_huff_specs.
Sourcepub fn set_quant_table(&mut self, id: usize, qt: QuantTable)
pub fn set_quant_table(&mut self, id: usize, qt: QuantTable)
Replace a quantization table by ID and rebuild the DQT marker segments.
Call this after modifying DCT coefficients to reflect new quantization
(e.g., for recompression simulation). Updates both the internal table
and the raw DQT segments so that to_bytes() produces correct output.