StreamingEncoder

Struct StreamingEncoder 

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

The main JPEG encoder.

Use the builder pattern to configure encoding options, then call encode_rgb() or encode_gray() to produce JPEG data.

§Presets

Use Encoder::new(preset) with a Preset to choose your settings:

§Example

use mozjpeg_rs::{Encoder, Preset};

let pixels: Vec<u8> = vec![0; 640 * 480 * 3];

let jpeg = Encoder::new(Preset::default())
    .quality(85)
    .encode_rgb(&pixels, 640, 480)?;

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 baseline_fastest() -> Self

Create a streaming encoder with fastest settings.

This matches Preset::BaselineFastest but for streaming.

Streaming mode does NOT support any optimizations that require buffering the entire image:

  • No trellis quantization (requires global context)
  • No progressive mode (requires multiple passes)
  • No Huffman optimization (requires 2-pass)
§Example
use mozjpeg_rs::StreamingEncoder;

let mut stream = StreamingEncoder::baseline_fastest()
    .quality(85)
    .start_rgb(1920, 1080, output_file)?;
Source

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

Set quality level (1-100).

Source

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

Set chroma subsampling mode.

Source

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

Set quantization table variant.

Source

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

Force baseline-compatible output.

Source

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

Set restart interval in MCUs.

Source

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

Set pixel density for the JFIF APP0 marker.

Source

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

Set EXIF data to embed.

Source

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

Set ICC color profile to embed.

Source

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

Add a custom APP marker.

Source

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

Set custom luminance quantization table.

Source

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

Set custom chrominance quantization table.

Source

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

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: Write>( self, width: u32, height: u32, writer: W, ) -> Result<EncodingStream<W>>

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

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

impl Default for StreamingEncoder

Source§

fn default() -> Self

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

Encode RGB image data to JPEG. Read more
Source§

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

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.