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>
impl<R: Read> JxlDecoder<R>
Sourcepub fn new(reader: R) -> ImageResult<Self>
pub fn new(reader: R) -> ImageResult<Self>
Initializes a decoder which reads from given image stream.
Decoder will be initialized with default thread pool.
Sourcepub fn with_thread_pool(reader: R, pool: JxlThreadPool) -> ImageResult<Self>
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>
impl<R: Read> ImageDecoder for JxlDecoder<R>
Source§fn dimensions(&self) -> (u32, u32)
fn dimensions(&self) -> (u32, u32)
Returns a tuple containing the width and height of the image
Source§fn color_type(&self) -> ColorType
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,
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<()>
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 moreSource§fn icc_profile(&mut self) -> ImageResult<Option<Vec<u8>>>
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 moreSource§fn set_limits(&mut self, limits: Limits) -> ImageResult<()>
fn set_limits(&mut self, limits: Limits) -> ImageResult<()>
Source§fn original_color_type(&self) -> ExtendedColorType
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>
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 moreSource§fn orientation(&mut self) -> Result<Orientation, ImageError>
fn orientation(&mut self) -> Result<Orientation, ImageError>
Returns the orientation of the image. Read more
Source§fn total_bytes(&self) -> u64
fn total_bytes(&self) -> u64
Returns the total number of bytes in the decoded 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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