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
impl StreamingEncoder
Sourcepub fn new() -> StreamingEncoder
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)
Sourcepub fn quality(self, quality: u8) -> StreamingEncoder
pub fn quality(self, quality: u8) -> StreamingEncoder
Set quality level (1-100).
Sourcepub fn subsampling(self, mode: Subsampling) -> StreamingEncoder
pub fn subsampling(self, mode: Subsampling) -> StreamingEncoder
Set chroma subsampling mode.
Sourcepub fn quant_tables(self, idx: QuantTableIdx) -> StreamingEncoder
pub fn quant_tables(self, idx: QuantTableIdx) -> StreamingEncoder
Set quantization table variant.
Sourcepub fn force_baseline(self, enable: bool) -> StreamingEncoder
pub fn force_baseline(self, enable: bool) -> StreamingEncoder
Force baseline-compatible output.
Sourcepub fn restart_interval(self, interval: u16) -> StreamingEncoder
pub fn restart_interval(self, interval: u16) -> StreamingEncoder
Set restart interval in MCUs.
Sourcepub fn pixel_density(self, density: PixelDensity) -> StreamingEncoder
pub fn pixel_density(self, density: PixelDensity) -> StreamingEncoder
Set pixel density for the JFIF APP0 marker.
Sourcepub fn exif_data(self, data: Vec<u8>) -> StreamingEncoder
pub fn exif_data(self, data: Vec<u8>) -> StreamingEncoder
Set EXIF data to embed.
Sourcepub fn icc_profile(self, profile: Vec<u8>) -> StreamingEncoder
pub fn icc_profile(self, profile: Vec<u8>) -> StreamingEncoder
Set ICC color profile to embed.
Sourcepub fn add_marker(self, app_num: u8, data: Vec<u8>) -> StreamingEncoder
pub fn add_marker(self, app_num: u8, data: Vec<u8>) -> StreamingEncoder
Add a custom APP marker.
Sourcepub fn custom_luma_qtable(self, table: [u16; 64]) -> StreamingEncoder
pub fn custom_luma_qtable(self, table: [u16; 64]) -> StreamingEncoder
Set custom luminance quantization table.
Sourcepub fn custom_chroma_qtable(self, table: [u16; 64]) -> StreamingEncoder
pub fn custom_chroma_qtable(self, table: [u16; 64]) -> StreamingEncoder
Set custom chrominance quantization table.
Sourcepub fn start_rgb<W>(
self,
width: u32,
height: u32,
writer: W,
) -> Result<EncodingStream<W>, Error>where
W: Write,
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 pixelsheight- Image height in pixelswriter- Output writer
§Returns
An EncodingStream that accepts scanlines.
Sourcepub fn start_gray<W>(
self,
width: u32,
height: u32,
writer: W,
) -> Result<EncodingStream<W>, Error>where
W: Write,
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 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§fn default() -> StreamingEncoder
fn default() -> StreamingEncoder
Source§impl Encode for StreamingEncoder
Implement batch encoding for StreamingEncoder (without optimizations).
impl Encode for StreamingEncoder
Implement batch encoding for StreamingEncoder (without optimizations).