Skip to main content

JpegImage

Struct JpegImage 

Source
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

Source

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.

Source

pub fn to_bytes(&self) -> Result<Vec<u8>>

Encode the (possibly modified) image back to JPEG bytes.

Source

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.

Source

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).

Source

pub fn dct_grid_mut(&mut self, component: usize) -> &mut DctGrid

Get a mutable reference to the DCT coefficient grid for a component.

Source

pub fn frame_info(&self) -> &FrameInfo

Get the frame information.

Source

pub fn quant_table(&self, id: usize) -> Option<&QuantTable>

Get a quantization table by ID.

Source

pub fn num_components(&self) -> usize

Number of components in the scan.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for JpegImage

Source§

fn clone(&self) -> JpegImage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V