Struct jpeg_encoder::Encoder
source · pub struct Encoder<W: JfifWrite> { /* private fields */ }
Expand description
Implementations§
source§impl<W: JfifWrite> Encoder<W>
impl<W: JfifWrite> Encoder<W>
sourcepub fn new(w: W, quality: u8) -> Encoder<W>
pub fn new(w: W, quality: u8) -> Encoder<W>
Create a new encoder with the given quality
The quality must be between 1 and 100 where 100 is the highest image quality.
By default, quality settings below 90 use a chroma subsampling (2x2 / 4:2:0) which can
be changed with set_sampling_factor
sourcepub fn set_density(&mut self, density: Density)
pub fn set_density(&mut self, density: Density)
Set pixel density for the image
By default, this value is None which is equal to “1 pixel per pixel”.
sourcepub fn set_sampling_factor(&mut self, sampling: SamplingFactor)
pub fn set_sampling_factor(&mut self, sampling: SamplingFactor)
Set chroma subsampling factor
sourcepub fn sampling_factor(&self) -> SamplingFactor
pub fn sampling_factor(&self) -> SamplingFactor
Get chroma subsampling factor
sourcepub fn set_quantization_tables(
&mut self,
luma: QuantizationTableType,
chroma: QuantizationTableType
)
pub fn set_quantization_tables( &mut self, luma: QuantizationTableType, chroma: QuantizationTableType )
Set quantization tables for luma and chroma components
sourcepub fn quantization_tables(&self) -> &[QuantizationTableType; 2]
pub fn quantization_tables(&self) -> &[QuantizationTableType; 2]
Get configured quantization tables
sourcepub fn set_progressive(&mut self, progressive: bool)
pub fn set_progressive(&mut self, progressive: bool)
Controls if progressive encoding is used.
By default, progressive encoding uses 4 scans.
Use set_progressive_scans to use a different number of scans
sourcepub fn set_progressive_scans(&mut self, scans: u8)
pub fn set_progressive_scans(&mut self, scans: u8)
Set number of scans per component for progressive encoding
Number of scans must be between 2 and 64. There is at least one scan for the DC coefficients and one for the remaining 63 AC coefficients.
Panics
If number of scans is not within valid range
sourcepub fn progressive_scans(&self) -> Option<u8>
pub fn progressive_scans(&self) -> Option<u8>
Return number of progressive scans if progressive encoding is enabled
sourcepub fn set_restart_interval(&mut self, interval: u16)
pub fn set_restart_interval(&mut self, interval: u16)
Set restart interval
Set numbers of MCUs between restart markers.
sourcepub fn restart_interval(&self) -> Option<u16>
pub fn restart_interval(&self) -> Option<u16>
Return the restart interval
sourcepub fn set_optimized_huffman_tables(&mut self, optimize_huffman_table: bool)
pub fn set_optimized_huffman_tables(&mut self, optimize_huffman_table: bool)
Set if optimized huffman table should be created
Optimized tables result in slightly smaller file sizes but decrease encoding performance.
sourcepub fn optimized_huffman_tables(&self) -> bool
pub fn optimized_huffman_tables(&self) -> bool
Returns if optimized huffman table should be generated
sourcepub fn add_app_segment(
&mut self,
segment_nr: u8,
data: &[u8]
) -> Result<(), EncodingError>
pub fn add_app_segment( &mut self, segment_nr: u8, data: &[u8] ) -> Result<(), EncodingError>
Appends a custom app segment to the JFIF file
Segment numbers need to be in the range between 1 and 15
The maximum allowed data length is 2^16 - 2 bytes.
Errors
Returns an error if the segment number is invalid or data exceeds the allowed size
sourcepub fn add_icc_profile(&mut self, data: &[u8]) -> Result<(), EncodingError>
pub fn add_icc_profile(&mut self, data: &[u8]) -> Result<(), EncodingError>
Add an ICC profile
The maximum allowed data length is 16,707,345 bytes.
Errors
Returns an Error if the data exceeds the maximum size for the ICC profile
sourcepub fn encode(
self,
data: &[u8],
width: u16,
height: u16,
color_type: ColorType
) -> Result<(), EncodingError>
pub fn encode( self, data: &[u8], width: u16, height: u16, color_type: ColorType ) -> Result<(), EncodingError>
Encode an image
Data format and length must conform to specified width, height and color type.
sourcepub fn encode_image<I: ImageBuffer>(self, image: I) -> Result<(), EncodingError>
pub fn encode_image<I: ImageBuffer>(self, image: I) -> Result<(), EncodingError>
Encode an image