jxl_oxide::integration

Struct JxlDecoder

Source
pub struct JxlDecoder<R> { /* private fields */ }
Available on crate feature image only.
Expand description

JPEG XL decoder which implements ImageDecoder.

§Supported features

Currently JxlDecoder supports following features:

  • Returning images of 8-bit, 16-bit integer and 32-bit float samples
  • RGB or luma-only images, with or without alpha
  • Returning ICC profiles via icc_profile
  • Setting decoder limits (caveat: memory limits are not strict)
  • Cropped decoding with ImageDecoderRect
  • (When lcms2 feature is enabled) Converting CMYK images to sRGB color space

Some features are planned but not implemented yet:

  • Decoding animations

§Note about color management

JxlDecoder doesn’t do color management by itself (except for CMYK images, which will be converted to sRGB color space if lcms2 is available). Consumers should apply appropriate color transforms using ICC profile returned by icc_profile(), otherwise colors may be inaccurate.

§Examples

Converting JPEG XL image to PNG:

use image::{DynamicImage, ImageDecoder};
use jxl_oxide::integration::JxlDecoder;

// Read and decode a JPEG XL image.
let file = std::fs::File::open("image.jxl")?;
let mut decoder = JxlDecoder::new(file)?;
let icc = decoder.icc_profile()?;
let mut image = DynamicImage::from_decoder(decoder)?;

// Perform color transform using the ICC profile.
// Note that ICC profile will be always available for images decoded by `JxlDecoder`.
if let Some(icc) = icc {
    do_color_transform(&mut image, icc)?;
}

// Save decoded image to PNG.
image.save("image.png")?;

Implementations§

Source§

impl<R: Read> JxlDecoder<R>

Source

pub fn new(reader: R) -> ImageResult<Self>

Initializes a decoder which reads from given image stream.

Decoder will be initialized with default thread pool.

Source

pub fn with_thread_pool(reader: R, pool: JxlThreadPool) -> ImageResult<Self>

Initializes a decoder which reads from given image stream, with custom thread pool.

Trait Implementations§

Source§

impl<R: Read> ImageDecoder for JxlDecoder<R>

Source§

fn dimensions(&self) -> (u32, u32)

Returns a tuple containing the width and height of the image
Source§

fn color_type(&self) -> ColorType

Returns the color type of the image data produced by this decoder
Source§

fn read_image(self, buf: &mut [u8]) -> ImageResult<()>
where Self: Sized,

Returns all the bytes in the image. Read more
Source§

fn read_image_boxed(self: Box<Self>, buf: &mut [u8]) -> ImageResult<()>

Use read_image instead; this method is an implementation detail needed so the trait can be object safe. Read more
Source§

fn icc_profile(&mut self) -> ImageResult<Option<Vec<u8>>>

Returns the ICC color profile embedded in the image, or Ok(None) if the image does not have one. Read more
Source§

fn set_limits(&mut self, limits: Limits) -> ImageResult<()>

Set the decoder to have the specified limits. See Limits for the different kinds of limits that is possible to set. Read more
Source§

fn original_color_type(&self) -> ExtendedColorType

Returns the color type of the image file before decoding
Source§

fn exif_metadata(&mut self) -> Result<Option<Vec<u8>>, ImageError>

Returns the raw Exif chunk, if it is present. A third-party crate such as kamadak-exif is required to actually parse it. Read more
Source§

fn orientation(&mut self) -> Result<Orientation, ImageError>

Returns the orientation of the image. Read more
Source§

fn total_bytes(&self) -> u64

Returns the total number of bytes in the decoded image. Read more
Source§

impl<R: Read> ImageDecoderRect for JxlDecoder<R>

Source§

fn read_rect( &mut self, x: u32, y: u32, width: u32, height: u32, buf: &mut [u8], row_pitch: usize, ) -> ImageResult<()>

Decode a rectangular section of the image. Read more

Auto Trait Implementations§

§

impl<R> !Freeze for JxlDecoder<R>

§

impl<R> !RefUnwindSafe for JxlDecoder<R>

§

impl<R> Send for JxlDecoder<R>
where R: Send,

§

impl<R> Sync for JxlDecoder<R>
where R: Sync,

§

impl<R> Unpin for JxlDecoder<R>
where R: Unpin,

§

impl<R> !UnwindSafe for JxlDecoder<R>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more