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:
Preset::ProgressiveBalanced- Progressive with all optimizations (default)Preset::BaselineBalanced- Baseline with all optimizationsPreset::BaselineFastest- No optimizations, maximum speedPreset::ProgressiveSmallest- Maximum compression (matches C mozjpeg)
§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
impl StreamingEncoder
Sourcepub fn baseline_fastest() -> Self
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)?;Sourcepub fn subsampling(self, mode: Subsampling) -> Self
pub fn subsampling(self, mode: Subsampling) -> Self
Set chroma subsampling mode.
Sourcepub fn quant_tables(self, idx: QuantTableIdx) -> Self
pub fn quant_tables(self, idx: QuantTableIdx) -> Self
Set quantization table variant.
Sourcepub fn force_baseline(self, enable: bool) -> Self
pub fn force_baseline(self, enable: bool) -> Self
Force baseline-compatible output.
Sourcepub fn restart_interval(self, interval: u16) -> Self
pub fn restart_interval(self, interval: u16) -> Self
Set restart interval in MCUs.
Sourcepub fn pixel_density(self, density: PixelDensity) -> Self
pub fn pixel_density(self, density: PixelDensity) -> Self
Set pixel density for the JFIF APP0 marker.
Sourcepub fn icc_profile(self, profile: Vec<u8>) -> Self
pub fn icc_profile(self, profile: Vec<u8>) -> Self
Set ICC color profile to embed.
Sourcepub fn add_marker(self, app_num: u8, data: Vec<u8>) -> Self
pub fn add_marker(self, app_num: u8, data: Vec<u8>) -> Self
Add a custom APP marker.
Sourcepub fn custom_luma_qtable(self, table: [u16; 64]) -> Self
pub fn custom_luma_qtable(self, table: [u16; 64]) -> Self
Set custom luminance quantization table.
Sourcepub fn custom_chroma_qtable(self, table: [u16; 64]) -> Self
pub fn custom_chroma_qtable(self, table: [u16; 64]) -> Self
Set custom chrominance quantization table.
Sourcepub fn start_rgb<W: Write>(
self,
width: u32,
height: u32,
writer: W,
) -> Result<EncodingStream<W>>
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 pixelsheight- Image height in pixelswriter- Output writer
§Returns
An EncodingStream that accepts scanlines.
Sourcepub fn start_gray<W: Write>(
self,
width: u32,
height: u32,
writer: W,
) -> Result<EncodingStream<W>>
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 pixelsheight- Image height in pixelswriter- Output writer
§Returns
An EncodingStream that accepts scanlines.
Trait Implementations§
Source§impl Clone for StreamingEncoder
impl Clone for StreamingEncoder
Source§fn clone(&self) -> StreamingEncoder
fn clone(&self) -> StreamingEncoder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StreamingEncoder
impl Debug for StreamingEncoder
Source§impl Default for StreamingEncoder
impl Default for StreamingEncoder
Source§impl Encode for StreamingEncoder
Implement batch encoding for StreamingEncoder (without optimizations).
impl Encode for StreamingEncoder
Implement batch encoding for StreamingEncoder (without optimizations).