### Install jxl-oxide Command Line Tool Source: https://github.com/tirr-c/jxl-oxide/blob/main/README.md This command installs the `jxl-oxide-cli` package using Cargo, which provides a command-line interface for interacting with the JPEG XL decoder. The installed binary will be named `jxl-oxide`. ```bash cargo install jxl-oxide-cli ``` -------------------------------- ### Install jxl-oxide Command-Line Tool Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Installs the jxl-oxide command-line tool using Cargo, Rust's package manager. This command fetches the latest version of the jxl-oxide-cli crate from the official repository and compiles it, making the `jxl-oxide` executable available in the system's PATH. ```bash cargo install jxl-oxide-cli ``` -------------------------------- ### Initialize and Use JxlImage in JavaScript Source: https://github.com/tirr-c/jxl-oxide/blob/main/crates/jxl-oxide-wasm/README.md This snippet demonstrates how to initialize the jxl-oxide-wasm module and subsequently create an instance of JxlImage. Ensure the 'init' function is awaited before using any JxlImage functionalities. This is crucial for proper setup of the WebAssembly module. ```javascript import init, { JxlImage } from 'jxl-oxide-wasm'; await init(); // Use `JxlImage` after initialization. const image = new JxlImage(); ``` -------------------------------- ### Reconstruct JPEG Bitstream with jxl-oxide Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Demonstrates reconstructing the original JPEG file from a JPEG XL image if the necessary reconstruction data is present. The example checks for availability, reconstructs the JPEG, and handles different status codes. ```rust use jxl_oxide::{JxlImage, JpegReconstructionStatus}; use std::fs::File; fn main() -> jxl_oxide::Result<()> { let image = JxlImage::builder().open("input.jxl")?; // Check if JPEG reconstruction is available match image.jpeg_reconstruction_status() { JpegReconstructionStatus::Available => { println!("JPEG reconstruction available"); // Reconstruct original JPEG let output = File::create("output.jpg")?; image.reconstruct_jpeg(output)?; println!("JPEG reconstructed successfully"); } JpegReconstructionStatus::Unavailable => { println!("Not a transcoded JPEG image"); } JpegReconstructionStatus::Invalid => { println!("Reconstruction data is invalid"); } JpegReconstructionStatus::NeedMoreData => { println!("Need more data for reconstruction"); } } Ok(()) } ``` -------------------------------- ### Integrate jxl-oxide with image Crate Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Shows how to use jxl-oxide as a decoder with the popular `image` crate, enabling seamless integration. This example demonstrates obtaining ICC profiles and Exif metadata, and decoding the image into a `DynamicImage` for further processing or saving. ```rust #[cfg(feature = "image")] use image::{DynamicImage, ImageDecoder}; #[cfg(feature = "image")] use jxl_oxide::integration::JxlDecoder; #[cfg(feature = "image")] fn main() -> Result<(), Box> { let file = std::fs::File::open("input.jxl")?; let decoder = JxlDecoder::new(file)?; // Get ICC profile let icc_profile = decoder.icc_profile()?; // Get Exif metadata if let Some(exif) = decoder.exif_metadata()? { println!("Exif data: {} bytes", exif.len()); } // Decode to DynamicImage let image = DynamicImage::from_decoder(decoder)?; // Save as PNG image.save("output.png")?; Ok(()) } #[cfg(not(feature = "image"))] fn main() { println!("Enable image feature to use this example"); } ``` -------------------------------- ### Crop Image Regions with jxl-oxide Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Demonstrates how to specify a cropping region of interest for decoding a JPEG XL image. This is useful for reducing memory usage when only a part of a large image is needed. The example sets the crop and verifies the decoded stream dimensions. ```rust use jxl_oxide::{JxlImage, CropInfo}; fn main() -> jxl_oxide::Result<()> { let mut image = JxlImage::builder().open("input.jxl")?; // Define crop region (left, top, width, height) let crop = CropInfo { left: 100, top: 100, width: 400, height: 300, }; image.set_image_region(crop); // Render only the cropped region let render = image.render_frame(0)?; let stream = render.stream(); assert_eq!(stream.width(), 400); assert_eq!(stream.height(), 300); Ok(()) } ``` -------------------------------- ### Access Extra Image Channels with jxl-oxide Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Provides an example of how to access and process extra channels in a JPEG XL image, such as alpha channels or spot colors. It retrieves metadata and buffers for these channels, allowing for separate manipulation. ```rust use jxl_oxide::JxlImage; fn main() -> jxl_oxide::Result<()> { let image = JxlImage::builder().open("input.jxl")?; let render = image.render_frame(0)?; // Get extra channel metadata and buffers let (extra_channel_info, extra_buffers) = render.extra_channels(); for (idx, channel) in extra_channel_info.iter().enumerate() { println!("Extra channel {}: {} (type: {:?})", idx, channel.name(), channel.ty()); if channel.is_alpha() { println!(" -> This is an alpha channel"); // Access the buffer: extra_buffers[idx] } if channel.is_spot_colour() { println!(" -> This is a spot colour channel"); } } Ok(()) } ``` -------------------------------- ### Get JPEG XL Image Information using CLI Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Displays metadata and technical information about a JPEG XL image file using the jxl-oxide command-line tool. This command is useful for inspecting image properties without performing a full decode. ```bash jxl-oxide info input.jxl ``` -------------------------------- ### Decode JPEG XL with Custom Options using CLI Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Demonstrates advanced decoding options for the jxl-oxide CLI tool. It shows how to specify the number of threads for decoding, control colored terminal output, and enable verbose logging. These options allow users to fine-tune performance and output verbosity. ```bash # Use 8 threads for decoding jxl-oxide decode --num-threads 8 input.jxl output.png # Disable colored terminal output jxl-oxide decode --color never input.jxl output.png # Verbose output jxl-oxide -v decode input.jxl output.png ``` -------------------------------- ### Add jxl-oxide Library Dependency Source: https://github.com/tirr-c/jxl-oxide/blob/main/README.md This snippet shows how to add the `jxl-oxide` crate as a dependency to your Rust project's `Cargo.toml` file. This is the primary way to integrate the JPEG XL decoding functionality into your application. ```toml [dependencies] jxl-oxide = "0.12.5" ``` -------------------------------- ### Run libfuzzer-decode Fuzz Target with Cargo Fuzz Source: https://github.com/tirr-c/jxl-oxide/blob/main/fuzz/README.md This snippet demonstrates how to execute the `libfuzzer-decode` fuzz target using the `cargo fuzz` command. Ensure you are in the repository root. This command initiates the fuzzing process, which may benefit from an initial corpus for improved results. ```bash cargo +nightly fuzz run libfuzzer-decode ``` -------------------------------- ### Configure Multithreading with jxl-oxide Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Shows how to configure a custom thread pool for parallel decoding operations in jxl-oxide. This allows control over the number of threads used, potentially improving performance on multi-core systems. ```rust use jxl_oxide::{JxlImage, JxlThreadPool}; fn main() -> jxl_oxide::Result<()> { // Create custom thread pool with 4 threads let pool = JxlThreadPool::rayon(4); let image = JxlImage::builder() .pool(pool) .open("input.jxl")?; // Decoding will use the custom thread pool let render = image.render_frame(0)?; Ok(()) } ``` -------------------------------- ### Accessing JPEG XL Auxiliary Metadata in Rust Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Retrieves Exif and XMP metadata boxes from a JPEG XL container using the jxl-oxide library. This function demonstrates how to open a JXL image, finalize its loading, and then access the auxiliary boxes, specifically looking for Exif and XML (XMP) data. It requires the jxl-oxide crate and handles potential errors during file operations and data extraction. ```rust use jxl_oxide::JxlImage; fn main() -> jxl_oxide::Result<()> { let mut image = JxlImage::builder().open("input.jxl")?; image.finalize()?; let aux_boxes = image.aux_boxes(); // Access Exif data if let Ok(Some(exif)) = aux_boxes.first_exif() { println!("Exif metadata: {} bytes", exif.payload().len()); } // Access XMP data if let Some(xmp) = aux_boxes.first_xml() { println!("XMP metadata: {} bytes", xmp.len()); } Ok(()) } ``` -------------------------------- ### Use External Color Management System with jxl-oxide Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Demonstrates integrating an external color management system, specifically Little CMS 2, for advanced ICC profile handling in JPEG XL images. This requires enabling the `lcms2` feature. It shows how to set the CMS, request specific color encodings, and render frames. ```rust #[cfg(feature = "lcms2")] use jxl_oxide::{JxlImage, Lcms2, EnumColourEncoding, RenderingIntent}; #[cfg(feature = "lcms2")] fn main() -> jxl_oxide::Result<()> { let mut image = JxlImage::builder().open("input.jxl")?; // Set external CMS (enabled by default with lcms2 feature) image.set_cms(Lcms2); // Request Display P3 output let display_p3 = EnumColourEncoding::display_p3(RenderingIntent::Perceptual); image.request_color_encoding(display_p3); let render = image.render_frame(0)?; Ok(()) } #[cfg(not(feature = "lcms2"))] fn main() { println!("Enable lcms2 feature to use this example"); } ``` -------------------------------- ### Async/Incremental JPEG XL Decoding Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Enables progressive image loading by feeding data incrementally, suitable for asynchronous contexts. It uses `JxlImage::builder().build_uninit()` and `feed_bytes()` to process data in chunks, handling `InitializeResult::NeedMoreData` until the image is initialized and fully loaded. ```rust use jxl_oxide::{JxlImage, InitializeResult}; use std::fs::File; use std::io::Read; fn main() -> jxl_oxide::Result<()> { let mut file = File::open("input.jxl")?; let mut uninit_image = JxlImage::builder().build_uninit(); let mut buf = vec![0u8; 4096]; // Feed data until image header is parsed let mut image = loop { let bytes_read = file.read(&mut buf)?; if bytes_read == 0 { return Err("Unexpected EOF".into()); } uninit_image.feed_bytes(&buf[..bytes_read])?; match uninit_image.try_init()? { InitializeResult::NeedMoreData(uninit) => { uninit_image = uninit; } InitializeResult::Initialized(img) => { break img; } } }; // Continue feeding data for frame data while !image.is_loading_done() { let bytes_read = file.read(&mut buf)?; if bytes_read == 0 { break; } image.feed_bytes(&buf[..bytes_read])?; } image.finalize()?; println!("Loaded {} frames", image.num_loaded_keyframes()); Ok(()) } ``` -------------------------------- ### Decode JPEG XL Image to PNG using CLI Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Decodes a JPEG XL image file to PNG format using the jxl-oxide command-line tool. This is a basic usage command that takes the input JXL file path and the desired output PNG file path as arguments. ```bash jxl-oxide decode input.jxl output.png ``` -------------------------------- ### Decode JPEG XL Image from File Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Opens and fully decodes a JPEG XL image file, loading all frames and metadata. It utilizes the `JxlImage::builder().open()` method and provides access to image dimensions, frame count, and pixel format. Basic error handling is included via `jxl_oxide::Result`. ```rust use jxl_oxide::JxlImage; fn main() -> jxl_oxide::Result<()> { // Open and decode image file let image = JxlImage::builder().open("input.jxl")?; // Access image metadata println!("Image dimensions: {}x{}", image.width(), image.height()); println!("Number of frames: {}", image.num_loaded_keyframes()); println!("Pixel format: {:?}", image.pixel_format()); // Check if image has ICC profile if let Some(icc) = image.original_icc() { println!("ICC profile size: {} bytes", icc.len()); } Ok(()) } ``` -------------------------------- ### Reconstruct JPEG from Transcoded JPEG XL using CLI Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Reconstructs the original JPEG file from a transcoded JPEG XL image using the jxl-oxide CLI. This option is only applicable if the JPEG XL image was originally created from a JPEG file. It attempts to extract the embedded JPEG data. ```bash # This will fail if the image wasn't created from JPEG jxl-oxide decode --jpeg input.jxl output.jpg ``` -------------------------------- ### Render JPEG XL Frames to Pixel Buffers Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Renders decoded keyframes from a JPEG XL image into pixel buffers, applying color management. It iterates through available keyframes, obtains rendering streams, and writes pixel data to a provided buffer. The output pixels are typically in the range [0.0, 1.0]. ```rust use jxl_oxide::JxlImage; fn main() -> jxl_oxide::Result<()> { let image = JxlImage::builder().open("input.jxl")?; // Render all keyframes for keyframe_idx in 0..image.num_loaded_keyframes() { let render = image.render_frame(keyframe_idx)?; println!("Frame {}: {}x{}", keyframe_idx, render.stream().width(), render.stream().height() ); // Get interleaved pixel data as f32 let stream = render.stream(); let width = stream.width(); let height = stream.height(); let channels = stream.channels(); let mut pixels = vec![0.0f32; width * height * channels]; stream.write_to_buffer(&mut pixels)?; // Process pixels (values in range [0.0, 1.0]) println!("First pixel: {:?}", &pixels[..channels]); } Ok(()) } ``` -------------------------------- ### Request Custom Color Encoding for Rendering Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Allows requesting a specific color encoding for the rendered output, performing conversions from the embedded profile. It uses `request_color_encoding()` to specify the desired output format (e.g., sRGB) and `RenderingIntent`. The `rendered_icc()` method can then retrieve the ICC profile of the output. ```rust use jxl_oxide::{JxlImage, EnumColourEncoding, RenderingIntent}; fn main() -> jxl_oxide::Result<()> { let mut image = JxlImage::builder().open("input.jxl")?; // Request sRGB output let srgb = EnumColourEncoding::srgb(RenderingIntent::Relative); image.request_color_encoding(srgb); // Get ICC profile of rendered output let rendered_icc = image.rendered_icc(); println!("Output ICC profile: {} bytes", rendered_icc.len()); // Render with color conversion applied let render = image.render_frame(0)?; let stream = render.stream(); Ok(()) } ``` -------------------------------- ### Decode JPEG XL Image from Reader Source: https://context7.com/tirr-c/jxl-oxide/llms.txt Reads and decodes a JPEG XL image from any `std::io::Read` implementation, such as a file stream. This method is useful for decoding images from sources other than direct file paths. It uses `JxlImage::builder().read()` and provides access to the image header. ```rust use jxl_oxide::JxlImage; use std::fs::File; fn main() -> jxl_oxide::Result<()> { let file = File::open("input.jxl")?; let image = JxlImage::builder().read(file)?; println!("Image header: {:?}", image.image_header()); Ok(()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.