Struct jpeg_encoder::Encoder

source ·
pub struct Encoder<W: JfifWrite> { /* private fields */ }
Expand description

Implementations§

source§

impl<W: JfifWrite> Encoder<W>

source

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

source

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

source

pub fn density(&self) -> Density

Return pixel density

source

pub fn set_sampling_factor(&mut self, sampling: SamplingFactor)

Set chroma subsampling factor

source

pub fn sampling_factor(&self) -> SamplingFactor

Get chroma subsampling factor

source

pub fn set_quantization_tables( &mut self, luma: QuantizationTableType, chroma: QuantizationTableType )

Set quantization tables for luma and chroma components

source

pub fn quantization_tables(&self) -> &[QuantizationTableType; 2]

Get configured quantization tables

source

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

source

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

source

pub fn progressive_scans(&self) -> Option<u8>

Return number of progressive scans if progressive encoding is enabled

source

pub fn set_restart_interval(&mut self, interval: u16)

Set restart interval

Set numbers of MCUs between restart markers.

source

pub fn restart_interval(&self) -> Option<u16>

Return the restart interval

source

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.

source

pub fn optimized_huffman_tables(&self) -> bool

Returns if optimized huffman table should be generated

source

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

source

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

source

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.

source

pub fn encode_image<I: ImageBuffer>(self, image: I) -> Result<(), EncodingError>

Encode an image

source§

impl Encoder<BufWriter<File>>

source

pub fn new_file<P: AsRef<Path>>( path: P, quality: u8 ) -> Result<Encoder<BufWriter<File>>, EncodingError>

Create a new decoder that writes into a file

See new for further information.

Errors

Returns an IoError(std::io::Error) if the file can’t be created

Auto Trait Implementations§

§

impl<W> RefUnwindSafe for Encoder<W>
where W: RefUnwindSafe,

§

impl<W> Send for Encoder<W>
where W: Send,

§

impl<W> Sync for Encoder<W>
where W: Sync,

§

impl<W> Unpin for Encoder<W>
where W: Unpin,

§

impl<W> UnwindSafe for Encoder<W>
where W: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.