Struct mozjpeg::Compress[][src]

pub struct Compress { /* fields omitted */ }

Create a new JPEG file from pixels

Wrapper for jpeg_compress_struct

Implementations

impl Compress[src]

pub fn new(color_space: ColorSpace) -> Compress[src]

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

pub fn new_err(err: ErrorMgr, color_space: ColorSpace) -> Compress[src]

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

pub fn start_compress(&mut self)[src]

Settings can’t be changed after this call

Panics

It may panic, like all functions of this library.

pub fn write_marker(&mut self, marker: Marker, data: &[u8])[src]

Add a marker to compressed file

Data is max 64KB

Panics

It may panic, like all functions of this library.

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

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

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

Read-only view of component information

pub fn write_scanlines(&mut self, image_src: &[u8]) -> bool[src]

Returns true if all lines in image_src (not necessarily all lines of the image) were written

Panics

It may panic, like all functions of this library.

pub fn write_raw_data(&mut self, image_src: &[&[u8]]) -> bool[src]

Advanced. Only possible after set_raw_data_in(). Write YCbCr blocks pixels instead of usual color space

See raw_data_in in libjpeg docs

Panic

Panics if raw write wasn’t enabled

pub fn set_color_space(&mut self, color_space: ColorSpace)[src]

Set color space of JPEG being written, different from input color space

See jpeg_set_colorspace in libjpeg docs

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

Image size of the input

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

👎 Deprecated:

it doesn’t do anything

libjpeg’s input_gamma = image gamma of input image

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

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

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

Set to false to make files larger for no reason

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

Specifies whether multiple scans should be considered during trellis quantization.

pub fn set_progressive_mode(&mut self)[src]

You can only turn it on

pub fn set_scan_optimization_mode(&mut self, mode: ScanMode)[src]

One scan for all components looks best. Other options may flash grayscale or green images.

pub fn set_fastest_defaults(&mut self)[src]

Reset to libjpeg v6 settings

It gives files identical with libjpeg-turbo

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

Advanced. See raw_data_in in libjpeg docs.

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

Set image quality. Values 60-80 are recommended.

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

Instead of quality setting, use a specific quantization table.

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

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

pub fn set_mem_dest(&mut self)[src]

Write to in-memory buffer

pub fn finish_compress(&mut self)[src]

Finalize compression. In case of progressive files, this may actually start processing.

Panics

It may panic, like all functions of this library.

pub fn data_as_mut_slice(&mut self) -> Result<&[u8], ()>[src]

If set_mem_dest() was enabled, this is the result

pub fn data_to_vec(&mut self) -> Result<Vec<u8>, ()>[src]

If set_mem_dest() was enabled, this is the result. Can be called once only.

Trait Implementations

impl Drop for Compress[src]

Auto Trait Implementations

impl RefUnwindSafe for Compress

impl !Send for Compress

impl !Sync for Compress

impl Unpin for Compress

impl UnwindSafe for Compress

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.