Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jxl-oxide: Add more docs around the image integration #383

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/jxl-oxide/src/integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
//! Various integrations to other library crates.
//!
//! # Available integrations
//!
//! Integrations are enabled with feature flags.
//! - `JxlDecoder`, which implements `image::ImageDecoder` (`image` feature)

#[cfg(feature = "image")]
mod image;

#[cfg(feature = "image")]
pub use image::*;
52 changes: 51 additions & 1 deletion crates/jxl-oxide/src/integration/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,57 @@ use jxl_grid::AllocTracker;

use crate::{CropInfo, InitializeResult, JxlImage};

/// JPEG XL decoder which implements `image::ImageDecoder`.
/// JPEG XL decoder which implements [`ImageDecoder`][image::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`][image::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:
///
/// ```no_run
/// use image::{DynamicImage, ImageDecoder};
/// use jxl_oxide::integration::JxlDecoder;
///
/// # type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
/// # fn do_color_transform(_: &mut DynamicImage, _: Vec<u8>) -> Result<()> { Ok(()) }
/// # fn main() -> Result<()> {
/// // 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")?;
/// # Ok(()) }
/// ```
///
/// [`icc_profile()`]: image::ImageDecoder::icc_profile
pub struct JxlDecoder<R> {
reader: R,
image: JxlImage,
Expand Down
1 change: 0 additions & 1 deletion crates/jxl-oxide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ pub use jxl_image::{ExtraChannelType, ImageHeader};
pub use jxl_threadpool::JxlThreadPool;

mod fb;
#[cfg(feature = "image")]
pub mod integration;
#[cfg(feature = "lcms2")]
mod lcms2;
Expand Down