Crate zune_jpeg

source ·
Expand description

This crate provides a library for decoding valid ITU-T Rec. T.851 (09/2005) ITU-T T.81 (JPEG-1) or JPEG images.

§Features

  • SSE and AVX accelerated functions to speed up certain decoding operations
  • FAST and accurate 32 bit IDCT algorithm
  • Fast color convert functions
  • RGBA and RGBX (4-Channel) color conversion functions
  • YCbCr to Luma(Grayscale) conversion.

§Usage

Add zune-jpeg to the dependencies in the project Cargo.toml

[dependencies]
zune_jpeg = "0.3"

§Examples

§Decode a JPEG file with default arguments.

 use std::fs::read;
 use zune_jpeg::JpegDecoder;
 let file_contents = read("a_jpeg.file").unwrap();
 let mut decoder = JpegDecoder::new(&file_contents);
 let mut pixels = decoder.decode().unwrap();

§Decode a JPEG file to RGBA format

  • Other (limited) supported formats are and BGR, BGRA
 use zune_core::colorspace::ColorSpace;
 use zune_core::options::DecoderOptions;
 use zune_jpeg::JpegDecoder;

 let mut options = DecoderOptions::default().jpeg_set_out_colorspace(ColorSpace::RGBA);

 let mut decoder = JpegDecoder::new_with_options(&[],options);
 let pixels = decoder.decode().unwrap();

§Decode an image and get it’s width and height.

 use zune_jpeg::JpegDecoder;

 let mut decoder = JpegDecoder::new(&[]);
 decoder.decode_headers().unwrap();
 let image_info = decoder.info().unwrap();
 println!("{},{}",image_info.width,image_info.height)

§Crate features.

This crate tries to be as minimal as possible while being extensible enough to handle the complexities arising from parsing different types of jpeg images.

Safety is a top concern that is why we provide both static ways to disable unsafe code, disabling x86 feature, and dynamic ,by using DecoderOptions::set_use_unsafe(false), both of these disable platform specific optimizations, which reduce the speed of decompression.

Please do note that careful consideration has been taken to ensure that the unsafe paths are only unsafe because they depend on platform specific intrinsics, hence no need to disable them

The crate tries to decode as many images as possible, as a best effort, even those violating the standard , this means a lot of images may get silent warnings and wrong output, but if you are sure you will be handling images that follow the spec, set ZuneJpegOptions::set_strict to true.

Re-exports§

Modules§

  • Contains most common errors that may be encountered in decoding a Decoder image

Structs§