StreamingEncoder

Struct StreamingEncoder 

Source
pub struct StreamingEncoder { /* private fields */ }
Expand description

Streaming JPEG encoder configuration.

This encoder supports scanline-by-scanline encoding, which is memory-efficient for large images. It does NOT support trellis quantization, progressive mode, or Huffman optimization (these require buffering the entire image).

Use Encoder for full-featured batch encoding with optimizations.

§Example

use mozjpeg_rs::Encoder;

// Create streaming encoder
let mut stream = Encoder::streaming()
    .quality(85)
    .start_rgb(1920, 1080, output_file)?;

// Write scanlines (must be in multiples of 8 or 16 depending on subsampling)
for chunk in rgb_scanlines.chunks(16 * 1920 * 3) {
    stream.write_scanlines(chunk)?;
}

// Finalize the JPEG
stream.finish()?;

Implementations§

Source§

impl StreamingEncoder

Source

pub fn new() -> StreamingEncoder

Create a new streaming encoder with default settings.

Unlike [Encoder::new()], this uses settings optimized for streaming:

  • No trellis quantization (requires global context)
  • No progressive mode (requires buffering entire image)
  • No Huffman optimization (requires 2-pass)
Source

pub fn quality(self, quality: u8) -> StreamingEncoder

Set quality level (1-100).

Source

pub fn subsampling(self, mode: Subsampling) -> StreamingEncoder

Set chroma subsampling mode.

Source

pub fn quant_tables(self, idx: QuantTableIdx) -> StreamingEncoder

Set quantization table variant.

Source

pub fn force_baseline(self, enable: bool) -> StreamingEncoder

Force baseline-compatible output.

Source

pub fn restart_interval(self, interval: u16) -> StreamingEncoder

Set restart interval in MCUs.

Source

pub fn pixel_density(self, density: PixelDensity) -> StreamingEncoder

Set pixel density for the JFIF APP0 marker.

Source

pub fn exif_data(self, data: Vec<u8>) -> StreamingEncoder

Set EXIF data to embed.

Source

pub fn icc_profile(self, profile: Vec<u8>) -> StreamingEncoder

Set ICC color profile to embed.

Source

pub fn add_marker(self, app_num: u8, data: Vec<u8>) -> StreamingEncoder

Add a custom APP marker.

Source

pub fn custom_luma_qtable(self, table: [u16; 64]) -> StreamingEncoder

Set custom luminance quantization table.

Source

pub fn custom_chroma_qtable(self, table: [u16; 64]) -> StreamingEncoder

Set custom chrominance quantization table.

Source

pub fn start_rgb<W>( self, width: u32, height: u32, writer: W, ) -> Result<EncodingStream<W>, Error>
where W: Write,

Start streaming RGB encoding to a writer.

§Arguments
  • width - Image width in pixels
  • height - Image height in pixels
  • writer - Output writer
§Returns

An EncodingStream that accepts scanlines.

Source

pub fn start_gray<W>( self, width: u32, height: u32, writer: W, ) -> Result<EncodingStream<W>, Error>
where W: Write,

Start streaming grayscale encoding to a writer.

§Arguments
  • width - Image width in pixels
  • height - Image height in pixels
  • writer - Output writer
§Returns

An EncodingStream that accepts scanlines.

Trait Implementations§

Source§

impl Clone for StreamingEncoder

Source§

fn clone(&self) -> StreamingEncoder

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
Source§

impl Debug for StreamingEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for StreamingEncoder

Source§

fn default() -> StreamingEncoder

Returns the “default value” for a type. Read more
Source§

impl Encode for StreamingEncoder

Implement batch encoding for StreamingEncoder (without optimizations).

Source§

fn encode_rgb( &self, rgb_data: &[u8], width: u32, height: u32, ) -> Result<Vec<u8>, Error>

Encode RGB image data to JPEG. Read more
Source§

fn encode_gray( &self, gray_data: &[u8], width: u32, height: u32, ) -> Result<Vec<u8>, Error>

Encode grayscale image data to JPEG. 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> 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.