pub struct Compress { /* private fields */ }Expand description
Create a new JPEG file from pixels
Wrapper for jpeg_compress_struct
Implementations§
Source§impl Compress
impl Compress
Sourcepub fn new(color_space: ColorSpace) -> Self
pub fn new(color_space: ColorSpace) -> Self
Compress image using input in this colorspace.
§Panics
You need to wrap all use of this library in std::panic::catch_unwind()
By default errors cause unwind (panic) and unwind through the C code, which strictly speaking is not guaranteed to work in Rust (but seems to work fine, at least on x86-64 and ARM).
Sourcepub fn new_err(err: Box<ErrorMgr>, color_space: ColorSpace) -> Self
pub fn new_err(err: Box<ErrorMgr>, color_space: ColorSpace) -> Self
Use a specific error handler instead of the default unwinding one.
Note that the error handler must either abort the process or unwind, it can’t gracefully return due to the design of libjpeg.
color_space refers to input color space
Sourcepub fn start_compress<W: Write>(self, writer: W) -> Result<CompressStarted<W>>
pub fn start_compress<W: Write>(self, writer: W) -> Result<CompressStarted<W>>
Settings can’t be changed after this call. Returns a CompressStarted struct that will handle the rest of the writing.
§Panics
It may panic, like all functions of this library.
Source§impl Compress
impl Compress
Sourcepub fn components_mut(&mut self) -> &mut [CompInfo]
pub fn components_mut(&mut self) -> &mut [CompInfo]
Expose components for modification, e.g. to set chroma subsampling
Sourcepub fn components(&self) -> &[CompInfo]
pub fn components(&self) -> &[CompInfo]
Read-only view of component information
Source§impl Compress
impl Compress
Sourcepub fn set_color_space(&mut self, color_space: ColorSpace)
pub fn set_color_space(&mut self, color_space: ColorSpace)
Set color space of JPEG being written, different from input color space
See jpeg_set_colorspace in libjpeg docs
Sourcepub fn set_gamma(&mut self, gamma: f64)
👎Deprecated: it doesn’t do anything
pub fn set_gamma(&mut self, gamma: f64)
it doesn’t do anything
libjpeg’s input_gamma = image gamma of input image
Sourcepub fn set_pixel_density(&mut self, density: PixelDensity)
pub fn set_pixel_density(&mut self, density: PixelDensity)
Sourcepub fn set_optimize_scans(&mut self, opt: bool)
pub fn set_optimize_scans(&mut self, opt: bool)
If true, it will use MozJPEG’s scan optimization. Makes progressive image files smaller.
Sourcepub fn set_smoothing_factor(&mut self, smoothing_factor: u8)
pub fn set_smoothing_factor(&mut self, smoothing_factor: u8)
If 1-100 (non-zero), it will use MozJPEG’s smoothing.
Sourcepub fn set_optimize_coding(&mut self, opt: bool)
pub fn set_optimize_coding(&mut self, opt: bool)
Set to false to make files larger for no reason
Sourcepub fn set_use_scans_in_trellis(&mut self, opt: bool)
pub fn set_use_scans_in_trellis(&mut self, opt: bool)
Specifies whether multiple scans should be considered during trellis quantization.
Sourcepub fn set_progressive_mode(&mut self)
pub fn set_progressive_mode(&mut self)
You can only turn it on
Sourcepub fn set_scan_optimization_mode(&mut self, mode: ScanMode)
pub fn set_scan_optimization_mode(&mut self, mode: ScanMode)
One scan for all components looks best. Other options may flash grayscale or green images.
Sourcepub fn set_fastest_defaults(&mut self)
pub fn set_fastest_defaults(&mut self)
Reset to libjpeg v6 settings
It gives files identical with libjpeg-turbo
Sourcepub fn set_raw_data_in(&mut self, opt: bool)
pub fn set_raw_data_in(&mut self, opt: bool)
Advanced. See raw_data_in in libjpeg docs.
Sourcepub fn set_quality(&mut self, quality: f32)
pub fn set_quality(&mut self, quality: f32)
Set image quality. Values 60-80 are recommended.
Sourcepub fn set_luma_qtable(&mut self, qtable: &QTable)
pub fn set_luma_qtable(&mut self, qtable: &QTable)
Instead of quality setting, use a specific quantization table.
Sourcepub fn set_chroma_qtable(&mut self, qtable: &QTable)
pub fn set_chroma_qtable(&mut self, qtable: &QTable)
Instead of quality setting, use a specific quantization table for color.
Sourcepub fn set_chroma_sampling_pixel_sizes(&mut self, cb: (u8, u8), cr: (u8, u8))
pub fn set_chroma_sampling_pixel_sizes(&mut self, cb: (u8, u8), cr: (u8, u8))
Sets chroma subsampling, separately for Cb and Cr channels.
Instead of setting samples per pixel, like in cinfo’s x_samp_factor,
it sets size of chroma “pixels” per luma pixel.
(1,1), (1,1)== 4:4:4(2,1), (2,1)== 4:2:2(2,2), (2,2)== 4:2:0