### jxl_cli Command-Line Tool Usage Source: https://context7.com/libjxl/jxl-rs/llms.txt Provides examples of using the jxl_cli command-line tool for decoding JXL images. It shows basic decoding to PNG and how to override the bit depth for output. ```bash # Basic decode to PNG jxl_cli input.jxl output.png # Decode to 16-bit PNG jxl_cli input.jxl output.png --override-bitdepth 16 ``` -------------------------------- ### Decode JPEG XL Image Incrementally with JxlDecoder Source: https://context7.com/libjxl/jxl-rs/llms.txt Demonstrates the incremental decoding process of a JPEG XL image using the `JxlDecoder` struct. It shows how to handle `NeedsMoreInput` and `Complete` results, access image and frame information, prepare output buffers, and retrieve decoded pixels. This example utilizes the typestate pattern to ensure correct API usage. ```rust use jxl::api::{JxlDecoder, JxlDecoderOptions, ProcessingResult, states}; use jxl::image::{Image, Rect, JxlOutputBuffer}; // Read JXL file into memory let file_data = std::fs::read("image.jxl").unwrap(); let mut input: &[u8] = &file_data; // Create decoder with default options let options = JxlDecoderOptions::default(); let decoder = JxlDecoder::::new(options); // Process until we have image info let mut decoder = decoder; let decoder_with_info = loop { match decoder.process(&mut input).unwrap() { ProcessingResult::Complete { result } => break result, ProcessingResult::NeedsMoreInput { fallback, size_hint } => { // For streaming: fetch more data, here we just continue decoder = fallback; } } }; // Access basic info (dimensions, bit depth, animation info, etc.) let info = decoder_with_info.basic_info(); let (width, height) = info.size; println!("Image: {}x{}, bit_depth: {:?}", width, height, info.bit_depth); // Process to get frame info let mut decoder = decoder_with_info; let decoder_with_frame = loop { match decoder.process(&mut input).unwrap() { ProcessingResult::Complete { result } => break result, ProcessingResult::NeedsMoreInput { fallback, .. } => decoder = fallback, } }; // Prepare output buffer (RGB interleaved, 3 channels) let num_channels = 3; let mut color_buffer = Image::::new((width * num_channels, height)).unwrap(); let mut buffers = vec![JxlOutputBuffer::from_image_rect_mut( color_buffer.get_rect_mut(Rect { origin: (0, 0), size: (width * num_channels, height), }).into_raw(), )]; // Decode frame pixels let mut decoder = decoder_with_frame; loop { match decoder.process(&mut input, &mut buffers).unwrap() { ProcessingResult::Complete { result } => { // result is decoder back in WithImageInfo state // Check result.has_more_frames() for animations break; } ProcessingResult::NeedsMoreInput { fallback, .. } => decoder = fallback, } } // Access decoded pixels for y in 0..height { let row = color_buffer.row(y); for x in 0..width { let r = row[x * 3]; let g = row[x * 3 + 1]; let b = row[x * 3 + 2]; } } ``` -------------------------------- ### Implement JXL Streaming Input with JxlBitstreamInput Trait in Rust Source: https://context7.com/libjxl/jxl-rs/llms.txt Explains the `JxlBitstreamInput` trait for flexible JXL data input, supporting byte slices and `BufReader`. It outlines the trait's methods (`available_bytes`, `read`, `skip`, `unconsume`) and provides a custom `NetworkInput` example for network streaming. This requires the `jxl` crate and standard I/O modules. ```rust use jxl::api::JxlBitstreamInput; use std::io::{BufReader, IoSliceMut}; use std::fs::File; // Using a byte slice (simplest case) let data = std::fs::read("image.jxl").unwrap(); let mut input: &[u8] = &data; // Using a BufReader for file streaming (lower memory usage) let file = File::open("large_image.jxl").unwrap(); let mut reader = BufReader::new(file); // Both implement JxlBitstreamInput: // - available_bytes() -> estimated remaining bytes // - read(bufs) -> fill buffers with data // - skip(bytes) -> skip ahead in stream // - unconsume(count) -> un-read bytes (for cleanup) // Custom implementation example (for network streaming): struct NetworkInput { buffer: Vec, position: usize, } impl JxlBitstreamInput for NetworkInput { fn available_bytes(&mut self) -> Result { Ok(self.buffer.len() - self.position) } fn read(&mut self, bufs: &mut [IoSliceMut]) -> Result { let mut total = 0; for buf in bufs { let remaining = &self.buffer[self.position..]; let to_copy = remaining.len().min(buf.len()); buf[..to_copy].copy_from_slice(&remaining[..to_copy]); self.position += to_copy; total += to_copy; if to_copy < buf.len() { break; } } Ok(total) } } ``` -------------------------------- ### JxlOutputBuffer Management in Rust Source: https://context7.com/libjxl/jxl-rs/llms.txt Demonstrates various methods to create and manage JxlOutputBuffer for writing pixel data, including from byte slices, Image types, uninitialized memory, and raw pointers. It also shows how to extract sub-regions. ```rust use jxl::api::JxlOutputBuffer; use jxl::image::{Image, Rect}; use std::mem::MaybeUninit; let width = 1920; let height = 1080; let channels = 4; // RGBA let bytes_per_sample = 4; // f32 // Method 1: From a flat byte slice let mut buffer = vec![0u8; width * height * channels * bytes_per_sample]; let output = JxlOutputBuffer::new( &mut buffer, height, // num_rows width * channels * bytes_per_sample, // bytes_per_row ); // Method 2: From Image type (recommended) let mut image = Image::::new((width * channels, height)).unwrap(); let output = JxlOutputBuffer::from_image_rect_mut( image.get_rect_mut(Rect { origin: (0, 0), size: (width * channels, height), }).into_raw(), ); // Method 3: From uninitialized memory (for performance) let mut uninit_buffer: Vec> = vec![MaybeUninit::uninit(); width * height * channels * bytes_per_sample]; let output = JxlOutputBuffer::new_uninit( &mut uninit_buffer, height, width * channels * bytes_per_sample, ); // Method 4: From raw pointer (unsafe, for FFI) let mut raw_buffer = vec![0u8; width * height * channels * bytes_per_sample]; let output = unsafe { JxlOutputBuffer::new_from_ptr( raw_buffer.as_mut_ptr() as *mut MaybeUninit, height, // num_rows width * channels * bytes_per_sample, // bytes_per_row width * channels * bytes_per_sample, // bytes_between_rows (stride) ) }; // Extracting a sub-region let mut full_output = JxlOutputBuffer::new(&mut buffer, height, width * channels * bytes_per_sample); let sub_rect = full_output.rect(Rect { origin: (100 * channels * bytes_per_sample, 100), // byte offset for origin size: (640 * channels * bytes_per_sample, 480), }); ``` -------------------------------- ### Animated JXL Decoding Frame-by-Frame in Rust Source: https://context7.com/libjxl/jxl-rs/llms.txt Illustrates how to decode animated JXL images by processing each frame individually. It covers initializing the decoder, setting pixel formats, extracting frame information, and preparing output buffers for each frame. ```rust use jxl::api::{ JxlDecoder, JxlDecoderOptions, JxlPixelFormat, JxlDataFormat, JxlColorType, ProcessingResult, JxlOutputBuffer, states }; use jxl::image::{Image, Rect}; let file_data = std::fs::read("animation.jxl").unwrap(); let mut input: &[u8] = &file_data; let options = JxlDecoderOptions::default(); let decoder = JxlDecoder::::new(options); // Get to image info state let mut decoder = decoder; let mut decoder = loop { match decoder.process(&mut input).unwrap() { ProcessingResult::Complete { result } => break result, ProcessingResult::NeedsMoreInput { fallback, .. } => decoder = fallback, } }; let info = decoder.basic_info().clone(); let (width, height) = info.size; // Set pixel format decoder.set_pixel_format(JxlPixelFormat { color_type: JxlColorType::Rgba, color_data_format: Some(JxlDataFormat::f32()), extra_channel_format: vec![None], // Alpha is included in RGBA }); let mut frames: Vec> = Vec::new(); let mut frame_durations: Vec = Vec::new(); loop { // Get frame info let mut decoder_frame = loop { match decoder.process(&mut input).unwrap() { ProcessingResult::Complete { result } => break result, ProcessingResult::NeedsMoreInput { fallback, .. } => decoder = fallback, } }; // Get frame header (name, duration, size) let frame_header = decoder_frame.frame_header(); if let Some(duration) = frame_header.duration { frame_durations.push(duration); } // Prepare output buffer let mut frame_buffer = Image::::new((width * 4, height)).unwrap(); let mut buffers = vec![JxlOutputBuffer::from_image_rect_mut( frame_buffer.get_rect_mut(Rect { origin: (0, 0), size: (width * 4, height), }).into_raw(), )]; // Decode frame decoder = loop { match decoder_frame.process(&mut input, &mut buffers).unwrap() { ProcessingResult::Complete { result } => break result, ProcessingResult::NeedsMoreInput { fallback, .. } => decoder_frame = fallback, } }; frames.push(frame_buffer); // Check for more frames if !decoder.has_more_frames() { break; } } println!("Decoded {} frames", frames.len()); for (i, duration) in frame_durations.iter().enumerate() { println!("Frame {}: {} seconds", i, duration); } ``` -------------------------------- ### Access JXL Image Metadata with JxlBasicInfo in Rust Source: https://context7.com/libjxl/jxl-rs/llms.txt Demonstrates how to use `JxlBasicInfo` to retrieve image metadata from a JXL file. This includes image dimensions, bit depth, orientation, animation information, extra channels, and tone mapping parameters. It requires the `jxl` crate and standard file I/O. ```rust use jxl::api::{JxlDecoder, JxlDecoderOptions, ProcessingResult, states}; let file_data = std::fs::read("animated.jxl").unwrap(); let mut input: &[u8] = &file_data; let decoder = JxlDecoder::::new(JxlDecoderOptions::default()); let mut decoder = decoder; let decoder = loop { match decoder.process(&mut input).unwrap() { ProcessingResult::Complete { result } => break result, ProcessingResult::NeedsMoreInput { fallback, .. } => decoder = fallback, } }; let info = decoder.basic_info(); // Image dimensions (after any upsampling) let (width, height) = info.size; // Bit depth information match &info.bit_depth { jxl::api::JxlBitDepth::Int { bits_per_sample } => { println!("Integer format: {} bits", bits_per_sample); } jxl::api::JxlBitDepth::Float { bits_per_sample, exponent_bits_per_sample } => { println!("Float format: {} bits ({} exponent)", bits_per_sample, exponent_bits_per_sample); } } // EXIF orientation println!("Orientation: {:?}", info.orientation); // Extra channels (alpha, depth, etc.) for (i, ec) in info.extra_channels.iter().enumerate() { println!("Extra channel {}: type={:?}, alpha_associated={}", i, ec.ec_type, ec.alpha_associated); } // Animation information (if present) if let Some(anim) = &info.animation { let fps = anim.tps_numerator as f64 / anim.tps_denominator as f64; println!("Animation: {:.2} FPS, {} loops, timecodes={}", fps, anim.num_loops, anim.have_timecodes); } // Preview frame size (if present) if let Some((pw, ph)) = info.preview_size { println!("Preview: {}x{}", pw, ph); } // Tone mapping info let tm = &info.tone_mapping; println!("Intensity target: {} nits", tm.intensity_target); ``` -------------------------------- ### JxlDecoderOptions - Configuration Options Source: https://context7.com/libjxl/jxl-rs/llms.txt Configure decoder behavior including orientation adjustment, spot color rendering, animation coalescing, pixel limits, precision mode, and optional CMS integration. ```APIDOC ## JxlDecoderOptions - Configuration Options ### Description `JxlDecoderOptions` configures decoder behavior including orientation adjustment, spot color rendering, animation coalescing, pixel limits, precision mode, and optional CMS (Color Management System) integration. ### Method N/A (Struct Configuration) ### Endpoint N/A ### Parameters #### Struct Fields - **adjust_orientation** (bool) - Optional - Auto-rotate image based on EXIF orientation (default: true) - **render_spot_colors** (bool) - Optional - Render spot colors into output (default: true) - **coalescing** (bool) - Optional - Coalesce animation frames (default: true) - **skip_preview** (bool) - Optional - Skip preview frame decoding (default: true) - **desired_intensity_target** (Option) - Optional - Target intensity for HDR->SDR conversion - **progressive_mode** (JxlProgressiveMode) - Optional - Progressive decoding mode - **cms** (Option>) - Optional - Optional Color Management System - **pixel_limit** (Option) - Optional - Memory limit: max pixels * channels (e.g., 100 megapixels) - **high_precision** (bool) - Optional - High precision decoding (slower but more accurate) (default: false) - **premultiply_output** (bool) - Optional - Premultiply RGB by alpha in output (default: false) ### Request Example ```rust use jxl::api::{JxlDecoderOptions, JxlProgressiveMode}; let options = JxlDecoderOptions { adjust_orientation: true, render_spot_colors: true, coalescing: true, skip_preview: true, desired_intensity_target: Some(250.0), progressive_mode: JxlProgressiveMode::Pass, cms: None, pixel_limit: Some(1024 * 1024 * 100), high_precision: false, premultiply_output: false, }; ``` ### Response N/A (Struct Configuration) #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Handle Color Profiles with JxlColorProfile Source: https://context7.com/libjxl/jxl-rs/llms.txt JxlColorProfile manages color profiles, supporting embedded ICC profiles and simple color encodings like sRGB and Display P3. It allows retrieving, setting, and comparing color profiles, and converting them to ICC byte representations. ```rust use jxl::api::{ JxlColorProfile, JxlColorEncoding, JxlWhitePoint, JxlPrimaries, JxlTransferFunction, JxlDecoder, JxlDecoderOptions, ProcessingResult, states }; use jxl::headers::color_encoding::RenderingIntent; // After getting image info from decoder: let file_data = std::fs::read("image.jxl").unwrap(); let mut input: &[u8] = &file_data; let decoder = JxlDecoder::::new(JxlDecoderOptions::default()); let mut decoder = decoder; let decoder = loop { match decoder.process(&mut input).unwrap() { ProcessingResult::Complete { result } => break result, ProcessingResult::NeedsMoreInput { fallback, .. } => decoder = fallback, } }; // Get the embedded color profile (what the image was encoded with) let embedded_profile = decoder.embedded_color_profile(); // Get the current output color profile let output_profile = decoder.output_color_profile(); // Convert to ICC bytes (for saving or passing to other libraries) let icc_bytes = output_profile.as_icc(); // Create standard sRGB profile let srgb_profile = JxlColorProfile::Simple(JxlColorEncoding::srgb(false)); // Create linear sRGB profile (for compositing/rendering) let linear_srgb = JxlColorProfile::Simple(JxlColorEncoding::linear_srgb(false)); // Create Display P3 profile let display_p3 = JxlColorProfile::Simple(JxlColorEncoding::RgbColorSpace { white_point: JxlWhitePoint::D65, primaries: JxlPrimaries::P3, transfer_function: JxlTransferFunction::SRGB, rendering_intent: RenderingIntent::Perceptual, }); // Create BT.2100 PQ (HDR) profile let bt2100_pq = JxlColorProfile::Simple(JxlColorEncoding::RgbColorSpace { white_point: JxlWhitePoint::D65, primaries: JxlPrimaries::BT2100, transfer_function: JxlTransferFunction::PQ, rendering_intent: RenderingIntent::Relative, }); // Check if decoder can output to a profile without CMS let can_convert = srgb_profile.can_output_to(); // true for simple profiles // Compare color encodings (ignoring rendering intent) let same = srgb_profile.same_color_encoding(&linear_srgb); // false (different TF) ``` -------------------------------- ### Generate IDCT and Reinterpreting DCT Files using Python Scripts Source: https://github.com/libjxl/jxl-rs/blob/main/jxl_transforms/implementation_details.md This bash script iterates through various sizes (2, 4, 8, 16, 32) to generate Rust files for IDCT and reinterpreting DCT using Python scripts. It also generates 2D versions and formats the code using 'cargo fmt'. ```bash for i in 2 4 8 16 32 do python3 gen_idct.py $i > src/idct$i.rs done for i in 2 4 8 16 32 do python3 gen_reinterpreting_dct.py $i > src/reinterpreting_dct$i.rs done python3 gen_idct2d.py > src/idct2d.rs python3 gen_reinterpreting_dct2d.py > src/reinterpreting_dct2d.rs cargo fmt ``` -------------------------------- ### Configure JXL Decoder Behavior with JxlDecoderOptions Source: https://context7.com/libjxl/jxl-rs/llms.txt JxlDecoderOptions allows customization of decoder behavior such as orientation adjustment, spot color rendering, animation coalescing, pixel limits, and precision. It supports default settings and custom configurations for various image properties and processing modes. ```rust use jxl::api::{JxlDecoderOptions, JxlProgressiveMode}; // Default options let default_options = JxlDecoderOptions::default(); // Custom options for HDR content with CMS let options = JxlDecoderOptions { // Auto-rotate image based on EXIF orientation (default: true) adjust_orientation: true, // Render spot colors into output (default: true) render_spot_colors: true, // Coalesce animation frames (default: true) coalescing: true, // Skip preview frame decoding (default: true) skip_preview: true, // Target intensity for HDR->SDR conversion desired_intensity_target: Some(250.0), // Progressive decoding mode progressive_mode: JxlProgressiveMode::Pass, // Optional Color Management System cms: None, // Or Some(Box::new(your_cms_implementation)) // Memory limit: max pixels * channels pixel_limit: Some(1024 * 1024 * 100), // 100 megapixels // High precision decoding (slower but more accurate) high_precision: false, // Premultiply RGB by alpha in output premultiply_output: false, }; ``` -------------------------------- ### Specify Output Pixel Format with JxlPixelFormat Source: https://context7.com/libjxl/jxl-rs/llms.txt JxlPixelFormat defines the desired output pixel format, including color type (e.g., RGB, RGBA), data format (e.g., u8, u16, f16), and bit depth. It provides convenient constructors for common formats like RGBA 8-bit and 16-bit, and allows custom configurations. ```rust use jxl::api::{JxlPixelFormat, JxlColorType, JxlDataFormat, Endianness}; // RGBA 8-bit format (common for display) let rgba8 = JxlPixelFormat::rgba8(0); // 0 extra channels beyond alpha // RGBA 16-bit format (for high bit-depth output) let rgba16 = JxlPixelFormat::rgba16(0); // RGBA float16 format (for HDR workflows) let rgba_f16 = JxlPixelFormat::rgba_f16(0); // RGBA float32 format (highest precision) let rgba_f32 = JxlPixelFormat::rgba_f32(0); // Custom format: BGR 8-bit (for some display systems) let bgr8 = JxlPixelFormat { color_type: JxlColorType::Bgr, color_data_format: Some(JxlDataFormat::U8 { bit_depth: 8 }), extra_channel_format: vec![], }; // Grayscale with alpha, 16-bit let gray_alpha_16 = JxlPixelFormat { color_type: JxlColorType::GrayscaleAlpha, color_data_format: Some(JxlDataFormat::U16 { endianness: Endianness::native(), bit_depth: 16, }), extra_channel_format: vec![], }; // Set format on decoder after getting image info // decoder_with_info.set_pixel_format(rgba8); ``` -------------------------------- ### JxlPixelFormat - Output Pixel Format Configuration Source: https://context7.com/libjxl/jxl-rs/llms.txt Specifies the desired output format including color type, data format, and extra channel handling. ```APIDOC ## JxlPixelFormat - Output Pixel Format Configuration ### Description `JxlPixelFormat` specifies the desired output format including color type (RGB, RGBA, Grayscale, etc.), data format (u8, u16, f16, f32), and extra channel handling. ### Method N/A (Struct Configuration) ### Endpoint N/A ### Parameters #### Struct Fields - **color_type** (JxlColorType) - Required - The color type of the output pixels (e.g., RGB, RGBA, Grayscale). - **color_data_format** (Option) - Optional - The data format for the color channels (e.g., U8, U16, F16, F32). - **extra_channel_format** (Vec) - Optional - Data formats for any extra channels. ### Request Example ```rust use jxl::api::{JxlPixelFormat, JxlColorType, JxlDataFormat, Endianness}; // RGBA 8-bit format let rgba8 = JxlPixelFormat::rgba8(0); // RGBA 16-bit format let rgba16 = JxlPixelFormat::rgba16(0); // RGBA float16 format let rgba_f16 = JxlPixelFormat::rgba_f16(0); // RGBA float32 format let rgba_f32 = JxlPixelFormat::rgba_f32(0); // Custom format: BGR 8-bit let bgr8 = JxlPixelFormat { color_type: JxlColorType::Bgr, color_data_format: Some(JxlDataFormat::U8 { bit_depth: 8 }), extra_channel_format: vec![], }; // Grayscale with alpha, 16-bit let gray_alpha_16 = JxlPixelFormat { color_type: JxlColorType::GrayscaleAlpha, color_data_format: Some(JxlDataFormat::U16 { endianness: Endianness::native(), bit_depth: 16, }), extra_channel_format: vec![], }; ``` ### Response N/A (Struct Configuration) #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### JxlBasicInfo - Image Metadata Access Source: https://context7.com/libjxl/jxl-rs/llms.txt Access image metadata such as dimensions, bit depth, orientation, animation information, extra channels, and tone mapping parameters using the JxlBasicInfo struct. ```APIDOC ## JxlBasicInfo - Image Metadata Access ### Description `JxlBasicInfo` contains image metadata including dimensions, bit depth, orientation, animation info, extra channels, and tone mapping parameters. ### Method GET (Implicit, accessed via decoder object) ### Endpoint N/A (This is a struct/data access pattern within the library) ### Parameters None ### Request Example ```rust use jxl::api::{JxlDecoder, JxlDecoderOptions, ProcessingResult, states}; let file_data = std::fs::read("animated.jxl").unwrap(); let mut input: &[u8] = &file_data; let decoder = JxlDecoder::::new(JxlDecoderOptions::default()); let mut decoder = decoder; let decoder = loop { match decoder.process(&mut input).unwrap() { ProcessingResult::Complete { result } => break result, ProcessingResult::NeedsMoreInput { fallback, .. } => decoder = fallback, } }; let info = decoder.basic_info(); // Image dimensions (after any upsampling) let (width, height) = info.size; // Bit depth information match &info.bit_depth { jxl::api::JxlBitDepth::Int { bits_per_sample } => { println!("Integer format: {} bits", bits_per_sample); } jxl::api::JxlBitDepth::Float { bits_per_sample, exponent_bits_per_sample } => { println!("Float format: {} bits ({} exponent)", bits_per_sample, exponent_bits_per_sample); } } // EXIF orientation println!("Orientation: {:?}", info.orientation); // Extra channels (alpha, depth, etc.) for (i, ec) in info.extra_channels.iter().enumerate() { println!("Extra channel {}: type={{:?}}, alpha_associated={}", i, ec.ec_type, ec.alpha_associated); } // Animation information (if present) if let Some(anim) = &info.animation { let fps = anim.tps_numerator as f64 / anim.tps_denominator as f64; println!("Animation: {:.2} FPS, {} loops, timecodes={}", fps, anim.num_loops, anim.have_timecodes); } // Preview frame size (if present) if let Some((pw, ph)) = info.preview_size { println!("Preview: {}x{}", pw, ph); } // Tone mapping info let tm = &info.tone_mapping; println!("Intensity target: {} nits", tm.intensity_target); ``` ### Response #### Success Response (200) - **size** (tuple) - Image dimensions (width, height). - **bit_depth** (enum) - Bit depth information (Integer or Float). - **orientation** (enum) - EXIF orientation. - **extra_channels** (array of structs) - Details of extra channels. - **animation** (optional struct) - Animation parameters if the image is animated. - **preview_size** (optional tuple) - Dimensions of the preview frame if present. - **tone_mapping** (struct) - Tone mapping parameters. #### Response Example ```json { "size": [1920, 1080], "bit_depth": {"type": "Int", "bits_per_sample": 8}, "orientation": "Normal", "extra_channels": [ {"ec_type": "Alpha", "alpha_associated": true} ], "animation": { "tps_numerator": 30, "tps_denominator": 1, "num_loops": 0, "have_timecodes": true }, "preview_size": [256, 144], "tone_mapping": { "intensity_target": 1000, "max_display_brightness": 1000, "min_nits": 0, "max_nits": 0, "num_tone_mapping_passes": 0 } } ``` ``` -------------------------------- ### JxlColorProfile - Color Profile Handling Source: https://context7.com/libjxl/jxl-rs/llms.txt Represents either an ICC profile or a simple color encoding. The decoder can retrieve embedded profiles, set output profiles, and generate ICC profiles from simple encodings. ```APIDOC ## JxlColorProfile - Color Profile Handling ### Description `JxlColorProfile` represents either an ICC profile or a simple color encoding. The decoder can retrieve embedded profiles, set output profiles, and generate ICC profiles from simple encodings. ### Method N/A (Struct Configuration & Decoder Methods) ### Endpoint N/A ### Parameters #### Struct Fields (JxlColorProfile) - **Simple(JxlColorEncoding)**: Represents a simple color encoding (e.g., sRGB, linear sRGB, Display P3, BT.2100 PQ). - **Icc(Vec)**: Represents an ICC profile as a byte vector. #### Decoder Methods (after initialization) - **embedded_color_profile()**: Returns the `JxlColorProfile` embedded in the JXL file. - **output_color_profile()**: Returns the current output `JxlColorProfile`. - **as_icc()**: Converts a `JxlColorProfile` to ICC bytes. - **can_output_to()**: Checks if the profile can be converted to a target profile. - **same_color_encoding()**: Compares two `JxlColorProfile` instances for the same color encoding (ignoring rendering intent). ### Request Example ```rust use jxl::api::{ JxlColorProfile, JxlColorEncoding, JxlWhitePoint, JxlPrimaries, JxlTransferFunction, JxlDecoder, JxlDecoderOptions, ProcessingResult, states }; use jxl::headers::color_encoding::RenderingIntent; // Assume decoder is initialized and processed // let mut decoder = ...; // Get embedded profile let embedded_profile = decoder.embedded_color_profile(); // Get output profile let output_profile = decoder.output_color_profile(); // Convert to ICC bytes let icc_bytes = output_profile.as_icc(); // Create standard sRGB profile let srgb_profile = JxlColorProfile::Simple(JxlColorEncoding::srgb(false)); // Create linear sRGB profile let linear_srgb = JxlColorProfile::Simple(JxlColorEncoding::linear_srgb(false)); // Create Display P3 profile let display_p3 = JxlColorProfile::Simple(JxlColorEncoding::RgbColorSpace { white_point: JxlWhitePoint::D65, primaries: JxlPrimaries::P3, transfer_function: JxlTransferFunction::SRGB, rendering_intent: RenderingIntent::Perceptual, }); // Create BT.2100 PQ (HDR) profile let bt2100_pq = JxlColorProfile::Simple(JxlColorEncoding::RgbColorSpace { white_point: JxlWhitePoint::D65, primaries: JxlPrimaries::BT2100, transfer_function: JxlTransferFunction::PQ, rendering_intent: RenderingIntent::Relative, }); // Check conversion capability let can_convert = srgb_profile.can_output_to(); // Compare color encodings let same = srgb_profile.same_color_encoding(&linear_srgb); ``` ### Response N/A (Struct Configuration & Decoder Methods) #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### JxlBitstreamInput - Streaming Input Trait Source: https://context7.com/libjxl/jxl-rs/llms.txt The `JxlBitstreamInput` trait enables the JXL decoder to process data from various input sources, including byte slices and buffered readers, facilitating efficient streaming. ```APIDOC ## JxlBitstreamInput - Streaming Input Trait ### Description The `JxlBitstreamInput` trait allows the decoder to work with various input sources. It's implemented for byte slices and `BufReader` where R implements `Read + Seek`. ### Method N/A (This is a trait definition for input handling) ### Endpoint N/A ### Parameters None ### Request Example ```rust use jxl::api::JxlBitstreamInput; use std::io::{BufReader, IoSliceMut}; use std::fs::File; // Using a byte slice (simplest case) let data = std::fs::read("image.jxl").unwrap(); let mut input: &[u8] = &data; // Using a BufReader for file streaming (lower memory usage) let file = File::open("large_image.jxl").unwrap(); let mut reader = BufReader::new(file); // Both implement JxlBitstreamInput: // - available_bytes() -> estimated remaining bytes // - read(bufs) -> fill buffers with data // - skip(bytes) -> skip ahead in stream // - unconsume(count) -> un-read bytes (for cleanup) // Custom implementation example (for network streaming): struct NetworkInput { buffer: Vec, position: usize, } impl JxlBitstreamInput for NetworkInput { fn available_bytes(&mut self) -> Result { Ok(self.buffer.len() - self.position) } fn read(&mut self, bufs: &mut [IoSliceMut]) -> Result { let mut total = 0; for buf in bufs { let remaining = &self.buffer[self.position..]; let to_copy = remaining.len().min(buf.len()); buf[..to_copy].copy_from_slice(&remaining[..to_copy]); self.position += to_copy; total += to_copy; if to_copy < buf.len() { break; } } Ok(total) } } ``` ### Response #### Success Response (200) - **available_bytes()** (method) - Returns the estimated number of available bytes. - **read(bufs)** (method) - Fills provided buffers with data from the input stream. - **skip(bytes)** (method) - Advances the stream position by the specified number of bytes. - **unconsume(count)** (method) - Allows un-reading a specified number of bytes from the stream. #### Response Example N/A (This describes trait methods, not a typical request/response) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.