Skip to main content

Compress

Struct Compress 

Source
pub struct Compress { /* private fields */ }
Expand description

Create a new JPEG file from pixels

Wrapper for jpeg_compress_struct

Implementations§

Source§

impl Compress

Source

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

Source

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

Source

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

Source

pub fn components_mut(&mut self) -> &mut [CompInfo]

Expose components for modification, e.g. to set chroma subsampling

Source

pub fn components(&self) -> &[CompInfo]

Read-only view of component information

Source§

impl Compress

Source

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

Source

pub fn set_size(&mut self, width: usize, height: usize)

Image size of the input

Source

pub fn set_gamma(&mut self, gamma: f64)

👎Deprecated:

it doesn’t do anything

libjpeg’s input_gamma = image gamma of input image

Source

pub fn set_pixel_density(&mut self, density: PixelDensity)

Sets pixel density of an image in the JFIF APP0 segment1. If this method is not called, the resulting JPEG will have a default pixel aspect ratio of 1x1.


  1. This method is not related to EXIF-based intrinsic image sizing, and does not affect rendering in browsers. 

Source

pub fn set_optimize_scans(&mut self, opt: bool)

If true, it will use MozJPEG’s scan optimization. Makes progressive image files smaller.

Source

pub fn set_smoothing_factor(&mut self, smoothing_factor: u8)

If 1-100 (non-zero), it will use MozJPEG’s smoothing.

Source

pub fn set_optimize_coding(&mut self, opt: bool)

Set to false to make files larger for no reason

Source

pub fn set_use_scans_in_trellis(&mut self, opt: bool)

Specifies whether multiple scans should be considered during trellis quantization.

Source

pub fn set_progressive_mode(&mut self)

You can only turn it on

Source

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.

Source

pub fn set_fastest_defaults(&mut self)

Reset to libjpeg v6 settings

It gives files identical with libjpeg-turbo

Source

pub fn set_raw_data_in(&mut self, opt: bool)

Advanced. See raw_data_in in libjpeg docs.

Source

pub fn set_quality(&mut self, quality: f32)

Set image quality. Values 60-80 are recommended.

Source

pub fn set_luma_qtable(&mut self, qtable: &QTable)

Instead of quality setting, use a specific quantization table.

Source

pub fn set_chroma_qtable(&mut self, qtable: &QTable)

Instead of quality setting, use a specific quantization table for color.

Source

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

Trait Implementations§

Source§

impl Drop for Compress

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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

Source§

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

Source§

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.