Function turbojpeg::decompress

source ·
pub fn decompress(
    jpeg_data: &[u8],
    format: PixelFormat
) -> Result<Image<Vec<u8>>>
Expand description

Decompress a JPEG image.

Returns a newly allocated image with the given pixel format. If you have specific requirements regarding memory layout or allocations, please see Decompressor.

§Example

// read JPEG data from file
let jpeg_data = std::fs::read("examples/parrots.jpg")?;

// decompress the JPEG into RGB image
let image = turbojpeg::decompress(&jpeg_data, turbojpeg::PixelFormat::RGB)?;
assert_eq!(image.format, turbojpeg::PixelFormat::RGB);
assert_eq!((image.width, image.height), (384, 256));
assert_eq!(image.pixels.len(), 384 * 256 * 3);