### Create Professional RGB Profiles Source: https://context7.com/awxkee/moxcms/llms.txt Initializes Adobe RGB, ProPhoto RGB, or DCI P3 profiles. ```rust use moxcms::ColorProfile; // Adobe RGB (1998) - gamma 2.2 let adobe_rgb = ColorProfile::new_adobe_rgb(); // ProPhoto RGB - gamma 1.8 let prophoto = ColorProfile::new_pro_photo_rgb(); // DCI P3 - gamma 2.6 let dci_p3 = ColorProfile::new_dci_p3(); ``` -------------------------------- ### Create Display P3 Profiles Source: https://context7.com/awxkee/moxcms/llms.txt Initializes Display P3 profiles with either sRGB or PQ transfer curves. ```rust use moxcms::ColorProfile; // Display P3 with sRGB transfer curve let display_p3 = ColorProfile::new_display_p3(); // Display P3 with PQ (Perceptual Quantizer) for HDR let display_p3_pq = ColorProfile::new_display_p3_pq(); ``` -------------------------------- ### Create Grayscale Profiles Source: https://context7.com/awxkee/moxcms/llms.txt Initializes monochrome grayscale profiles with a specified gamma. ```rust use moxcms::ColorProfile; // Grayscale with gamma 2.2 let gray_profile = ColorProfile::new_gray_with_gamma(2.2f32); // Grayscale with gamma 1.8 let gray_18 = ColorProfile::new_gray_with_gamma(1.8f32); ``` -------------------------------- ### Create ACES Profiles Source: https://context7.com/awxkee/moxcms/llms.txt Initializes ACES 2065-1 or ACEScg linear profiles. ```rust use moxcms::ColorProfile; // ACES 2065-1 (AP0) - linear let aces_2065 = ColorProfile::new_aces_aces_2065_1_linear(); // ACEScg (AP1) - linear let aces_cg = ColorProfile::new_aces_cg_linear(); ``` -------------------------------- ### Create Built-in sRGB Profile Source: https://context7.com/awxkee/moxcms/llms.txt Initializes a standard sRGB (IEC 61966-2.1) profile. ```rust use moxcms::ColorProfile; // Create sRGB profile (IEC 61966-2.1) let srgb = ColorProfile::new_srgb(); // Access profile properties assert_eq!(srgb.color_space, moxcms::DataColorSpace::Rgb); assert!(srgb.red_trc.is_some()); assert!(srgb.green_trc.is_some()); assert!(srgb.blue_trc.is_some()); ``` -------------------------------- ### Configure Color Transform Options Source: https://context7.com/awxkee/moxcms/llms.txt Customize color transformation behavior using rendering intent and optimization settings. Ensure necessary imports are included. ```rust use moxcms::{ColorProfile, Layout, TransformOptions, RenderingIntent}; let source = ColorProfile::new_display_p3(); let dest = ColorProfile::new_srgb(); let options = TransformOptions { // Rendering intent: Perceptual, RelativeColorimetric, Saturation, AbsoluteColorimetric rendering_intent: RenderingIntent::Perceptual, // Use CICP transfer characteristics when available (faster) allow_use_cicp_transfer: true, // Prefer fixed-point math (faster, slightly less precise) prefer_fixed_point: true, // Interpolation method for LUT transforms interpolation_method: moxcms::InterpolationMethod::Linear, ..Default::default() }; let transform = source .create_transform_8bit(Layout::Rgb, &dest, Layout::Rgb, options) .unwrap(); ``` -------------------------------- ### Create BT.2020 Profiles Source: https://context7.com/awxkee/moxcms/llms.txt Initializes BT.2020 profiles for HDR and wide-gamut workflows using Rec.709, PQ, or HLG transfer curves. ```rust use moxcms::ColorProfile; // BT.2020 with Rec.709 transfer curve let bt2020 = ColorProfile::new_bt2020(); // BT.2020 with PQ transfer (HDR10) let bt2020_pq = ColorProfile::new_bt2020_pq(); // BT.2020 with HLG transfer (broadcast HDR) let bt2020_hlg = ColorProfile::new_bt2020_hlg(); ``` -------------------------------- ### Perform ICC Profile Transformation in Rust Source: https://github.com/awxkee/moxcms/blob/master/README.md Demonstrates loading an ICC profile from a JPEG file and applying a color transform to convert the image to sRGB. ```rust let f_str = "./assets/dci_p3_profile.jpeg"; let file = File::open(f_str).expect("Failed to open file"); let img = image::ImageReader::open(f_str).unwrap().decode().unwrap(); let rgb = img.to_rgb8(); let mut decoder = JpegDecoder::new(BufReader::new(file)).unwrap(); let icc = decoder.icc_profile().unwrap().unwrap(); let color_profile = ColorProfile::new_from_slice(&icc).unwrap(); let dest_profile = ColorProfile::new_srgb(); let transform = color_profile .create_transform_8bit(&dest_profile, Layout::Rgb8, TransformOptions::default()) .unwrap(); let mut dst = vec![0u8; rgb.len()]; for (src, dst) in rgb .chunks_exact(img.width() as usize * 3) .zip(dst.chunks_exact_mut(img.dimensions().0 as usize * 3)) { transform .transform( &src[..img.dimensions().0 as usize * 3], &mut dst[..img.dimensions().0 as usize * 3], ) .unwrap(); } image::save_buffer( "v1.jpg", &dst, img.dimensions().0, img.dimensions().1, image::ExtendedColorType::Rgb8, ) .unwrap(); ``` -------------------------------- ### Load ICC Profile from File Source: https://context7.com/awxkee/moxcms/llms.txt Parses ICC profile data from a file path into a ColorProfile instance. ```rust use moxcms::{ColorProfile, CmsError}; use std::fs; fn load_profile_from_file(path: &str) -> Result { let icc_data = fs::read(path).expect("Failed to read ICC file"); let profile = ColorProfile::new_from_slice(&icc_data)?; // Access profile metadata println!("Color space: {:?}", profile.color_space); println!("Profile class: {:?}", profile.profile_class); println!("PCS: {:?}", profile.pcs); Ok(profile) } // Example usage let profile = load_profile_from_file("./assets/Display P3.icc").unwrap(); ``` -------------------------------- ### Oklab Color Space Conversion and Distance Source: https://context7.com/awxkee/moxcms/llms.txt Convert between linear RGB and the Oklab perceptual color space. Also provides functions to calculate Euclidean and hybrid perceptual color distances between Oklab values. ```rust use moxcms::{Oklab, Rgb}; // Linear RGB to Oklab let linear_rgb = Rgb::new(0.5f32, 0.3f32, 0.7f32); let oklab = Oklab::from_linear_rgb(linear_rgb); println!("Oklab: L={}, a={}, b={}", oklab.l, oklab.a, oklab.b); // Oklab to Linear RGB let rgb_back = oklab.to_linear_rgb(); // Calculate perceptual color distance let oklab2 = Oklab::new(0.6, 0.1, -0.1); let distance = oklab.euclidean_distance(oklab2); let hybrid_dist = oklab.hybrid_distance(oklab2); ``` -------------------------------- ### RGB to Gray Transform Source: https://context7.com/awxkee/moxcms/llms.txt Converts RGB image data to grayscale using perceptual luminance. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; let rgb_profile = ColorProfile::new_srgb(); let gray_profile = ColorProfile::new_gray_with_gamma(2.2); let transform = rgb_profile .create_transform_8bit( Layout::Rgb, &gray_profile, Layout::Gray, TransformOptions::default(), ) .unwrap(); let src: Vec = vec![255, 128, 64]; // RGB pixel let mut dst: Vec = vec![0; 1]; // Gray output transform.transform(&src, &mut dst).unwrap(); ``` -------------------------------- ### 10-bit and 12-bit Color Transforms Source: https://context7.com/awxkee/moxcms/llms.txt Handles professional video workflow color transformations for 10-bit and 12-bit data. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; let source = ColorProfile::new_bt2020(); let dest = ColorProfile::new_srgb(); // 10-bit transform (values 0-1023) let transform_10bit = source .create_transform_10bit(Layout::Rgb, &dest, Layout::Rgb, TransformOptions::default()) .unwrap(); let src_10: Vec = vec![512, 256, 768]; let mut dst_10: Vec = vec![0; 3]; transform_10bit.transform(&src_10, &mut dst_10).unwrap(); // 12-bit transform (values 0-4095) let transform_12bit = source .create_transform_12bit(Layout::Rgb, &dest, Layout::Rgb, TransformOptions::default()) .unwrap(); let src_12: Vec = vec![2048, 1024, 3072]; let mut dst_12: Vec = vec![0; 3]; transform_12bit.transform(&src_12, &mut dst_12).unwrap(); ``` -------------------------------- ### Gray to RGB Transform Source: https://context7.com/awxkee/moxcms/llms.txt Converts grayscale image data into the RGB color space. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; let gray_profile = ColorProfile::new_gray_with_gamma(2.2); let rgb_profile = ColorProfile::new_srgb(); let transform = gray_profile .create_transform_8bit( Layout::Gray, &rgb_profile, Layout::Rgb, TransformOptions::default(), ) .unwrap(); // Single channel grayscale input let src: Vec = vec![128, 64, 192]; // Three channel RGB output let mut dst: Vec = vec![0; 9]; transform.transform(&src, &mut dst).unwrap(); ``` -------------------------------- ### Compute Color Profile Transformation Matrices Source: https://context7.com/awxkee/moxcms/llms.txt Access and compute various transformation matrices from color profiles, including RGB to XYZ matrices and direct transform matrices between two profiles. Also retrieves the colorant matrix and profile gamut volume. ```rust use moxcms::ColorProfile; let srgb = ColorProfile::new_srgb(); let display_p3 = ColorProfile::new_display_p3(); // Get RGB to XYZ matrix (colorant matrix) let rgb_to_xyz = srgb.rgb_to_xyz_matrix(); println!("sRGB to XYZ matrix: {:?}", rgb_to_xyz); // Compute direct transform matrix between profiles let transform_matrix = srgb.transform_matrix(&display_p3); println!("sRGB to Display P3 matrix: {:?}", transform_matrix); // Get colorant matrix directly let colorants = srgb.colorant_matrix(); // Compute profile gamut volume if let Some(volume) = srgb.profile_volume() { println!("Profile gamut volume: {}", volume); } ``` -------------------------------- ### Create Color Profile from CICP Source: https://context7.com/awxkee/moxcms/llms.txt Generate a color profile directly from Coding Independent Code Points (CICP) metadata. This is useful for profiles defined by standards like BT.2020. ```rust use moxcms::{ColorProfile, CicpProfile, CicpColorPrimaries, TransferCharacteristics, MatrixCoefficients}; let cicp = CicpProfile { color_primaries: CicpColorPrimaries::Bt2020, transfer_characteristics: TransferCharacteristics::Smpte2084, // PQ matrix_coefficients: MatrixCoefficients::Bt709, full_range: true, }; let profile = ColorProfile::new_from_cicp(cicp); ``` -------------------------------- ### CIE Lab Color Space Conversion Source: https://context7.com/awxkee/moxcms/llms.txt Perform conversions between CIE XYZ and CIE Lab color spaces. Includes methods for both XYZ to Lab and Lab to XYZ, as well as Profile Connection Space (PCS) encoding. ```rust use moxcms::{Lab, Xyz}; // XYZ to Lab conversion let xyz = Xyz::new(0.1, 0.2, 0.3); let lab = Lab::from_xyz(xyz); println!("Lab: L={}, a={}, b={}", lab.l, lab.a, lab.b); // Lab to XYZ conversion let xyz_back = lab.to_xyz(); // PCS (Profile Connection Space) encoding let lab_pcs = Lab::from_pcs_xyz(xyz); let xyz_pcs = lab_pcs.to_pcs_xyz(); ``` -------------------------------- ### Parse ICC Profiles with Custom Options Source: https://context7.com/awxkee/moxcms/llms.txt Load ICC profiles with custom parsing options to set size limits for the profile and its components. This is useful for handling potentially large or malformed profile data. ```rust use moxcms::{ColorProfile, ParsingOptions}; use std::fs; let icc_data = fs::read("./assets/Display P3.icc").expect("ICC file"); let options = ParsingOptions { max_profile_size: 10 * 1024 * 1024, // 10 MB max max_allowed_clut_size: 10_000_000, // CLUT size limit max_allowed_trc_size: 40_000, // TRC curve size limit }; let profile = ColorProfile::new_from_slice_with_options(&icc_data, options) .expect("Failed to parse profile"); ``` -------------------------------- ### Floating-Point f64 Color Transform Source: https://context7.com/awxkee/moxcms/llms.txt Transforms f64 floating-point data for high-precision color workflows. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; let source = ColorProfile::new_bt2020(); let dest = ColorProfile::new_srgb(); let transform = source .create_transform_f64( Layout::Rgb, &dest, Layout::Rgb, TransformOptions::default(), ) .unwrap(); let src: Vec = vec![0.5, 0.25, 0.75]; let mut dst: Vec = vec![0.0; 3]; transform.transform(&src, &mut dst).unwrap(); ``` -------------------------------- ### Update Profile RGB Colorimetry Source: https://context7.com/awxkee/moxcms/llms.txt Modify a profile's RGB primaries and white point. Use this to update an existing color profile with new colorimetry standards like BT.2020. ```rust use moxcms::{ColorProfile, ColorPrimaries, XyY}; let mut profile = ColorProfile::new_srgb(); // Update with new primaries (BT.2020) let white_point = XyY { x: 0.3127, y: 0.3290, yb: 1.0 }; // D65 profile.update_rgb_colorimetry(white_point, ColorPrimaries::BT_2020); ``` -------------------------------- ### Perform 8-bit RGB Color Transform Source: https://context7.com/awxkee/moxcms/llms.txt Transforms 8-bit RGB data between two profiles using a created transform object. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; let source_profile = ColorProfile::new_display_p3(); let dest_profile = ColorProfile::new_srgb(); // Create 8-bit transform let transform = source_profile .create_transform_8bit( Layout::Rgb, &dest_profile, Layout::Rgb, TransformOptions::default(), ) .expect("Failed to create transform"); // Transform image data (width * height * 3 channels) let src: Vec = vec![128, 64, 192]; // One pixel let mut dst: Vec = vec![0; 3]; transform.transform(&src, &mut dst).expect("Transform failed"); println!("Transformed: {:?}", dst); ``` -------------------------------- ### Encode Color Profile to ICC Data Source: https://context7.com/awxkee/moxcms/llms.txt Serialize a ColorProfile object into ICC binary format for storage or transmission. This allows saving custom or standard profiles to files. ```rust use moxcms::ColorProfile; use std::fs; let profile = ColorProfile::new_srgb(); // Encode to ICC binary data let icc_data = profile.encode().expect("Failed to encode profile"); // Write to file fs::write("output.icc", &icc_data).expect("Failed to write ICC file"); ``` -------------------------------- ### 16-bit Color Transform Source: https://context7.com/awxkee/moxcms/llms.txt Performs color transformation on 16-bit image data for high bit-depth workflows. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; let source = ColorProfile::new_srgb(); let dest = ColorProfile::new_bt2020(); let transform = source .create_transform_16bit( Layout::Rgb, &dest, Layout::Rgb, TransformOptions::default(), ) .unwrap(); // 16-bit values (0-65535) let src: Vec = vec![32768, 16384, 49152]; let mut dst: Vec = vec![0; 3]; transform.transform(&src, &mut dst).unwrap(); ``` -------------------------------- ### Process Image Rows with Color Transform Source: https://context7.com/awxkee/moxcms/llms.txt Transform image data row-by-row for memory-efficient processing. This method is suitable for large images where loading the entire image into memory is not feasible. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; let source = ColorProfile::new_display_p3(); let dest = ColorProfile::new_srgb(); let transform = source .create_transform_8bit(Layout::Rgb, &dest, Layout::Rgb, TransformOptions::default()) .unwrap(); let width = 1920; let height = 1080; // Allocate source and destination row buffers let mut src_row = vec![0u8; width * 3]; let mut dst_row = vec![0u8; width * 3]; // Process image row by row for y in 0..height { // Fill src_row with source image data for row y // ... // Transform the row transform.transform(&src_row, &mut dst_row).unwrap(); // Write dst_row to destination image at row y // ... ``` -------------------------------- ### Safe Color Transform with Error Handling Source: https://context7.com/awxkee/moxcms/llms.txt Perform color transformations with robust error handling for common issues like incompatible layouts or unsupported profile connections. This function returns a Result to manage potential CmsError variants. ```rust use moxcms::{ColorProfile, Layout, TransformOptions, CmsError}; fn safe_transform( src_profile: &ColorProfile, dst_profile: &ColorProfile, src: &[u8], ) -> Result, CmsError> { let transform = src_profile.create_transform_8bit( Layout::Rgb, dst_profile, Layout::Rgb, TransformOptions::default(), )?; let mut dst = vec![0u8; src.len()]; transform.transform(src, &mut dst)?; Ok(dst) } // Example error handling let srgb = ColorProfile::new_srgb(); let gray = ColorProfile::new_gray_with_gamma(2.2); // This will fail: incompatible layouts match srgb.create_transform_8bit(Layout::Rgb, &gray, Layout::Gray, TransformOptions::default()) { Ok(_) => println!("Transform created"), Err(CmsError::InvalidLayout) => println!("Invalid layout combination"), Err(CmsError::UnsupportedProfileConnection) => println!("Unsupported profile connection"), Err(e) => println!("Error: {}", e), } ``` -------------------------------- ### CMYK Color Transform to RGB Source: https://context7.com/awxkee/moxcms/llms.txt Transform CMYK image data to RGB using ICC profiles with LUT support. Load CMYK profiles from files and specify correct layouts for CMYK (Rgba) and RGB. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; use std::fs; // Load CMYK profile (e.g., US Web Coated SWOP) let cmyk_icc = fs::read("./assets/us_swop_coated.icc").expect("CMYK profile"); let cmyk_profile = ColorProfile::new_from_slice(&cmyk_icc).unwrap(); let rgb_profile = ColorProfile::new_srgb(); // CMYK uses Layout::Rgba (4 channels: C, M, Y, K) let transform = cmyk_profile .create_transform_8bit( Layout::Rgba, &rgb_profile, Layout::Rgb, TransformOptions::default(), ) .unwrap(); // CMYK values (0-255 for each channel) let cmyk: Vec = vec![0, 100, 100, 0]; // Cyan 0%, Magenta ~40%, Yellow ~40%, Key 0% let mut rgb: Vec = vec![0; 3]; transform.transform(&cmyk, &mut rgb).unwrap(); ``` -------------------------------- ### Floating-Point f32 Color Transform Source: https://context7.com/awxkee/moxcms/llms.txt Transforms normalized f32 floating-point data, suitable for HDR and extended range workflows. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; let source = ColorProfile::new_srgb(); let dest = ColorProfile::new_display_p3(); let transform = source .create_transform_f32( Layout::Rgba, &dest, Layout::Rgba, TransformOptions::default(), ) .unwrap(); // Normalized values [0.0, 1.0] - extended range may produce values outside this range let src: Vec = vec![0.5, 0.25, 0.75, 1.0]; let mut dst: Vec = vec![0.0; 4]; transform.transform(&src, &mut dst).unwrap(); println!("Result: {:?}", dst); ``` -------------------------------- ### 8-bit RGBA Color Transform Source: https://context7.com/awxkee/moxcms/llms.txt Transforms 8-bit RGBA image data while preserving the alpha channel. ```rust use moxcms::{ColorProfile, Layout, TransformOptions}; let bt2020 = ColorProfile::new_bt2020(); let srgb = ColorProfile::new_srgb(); let transform = bt2020 .create_transform_8bit( Layout::Rgba, &srgb, Layout::Rgba, TransformOptions::default(), ) .unwrap(); // Source pixels with alpha channel let src: Vec = vec![ 255, 128, 64, 255, // Pixel 1, opaque 100, 150, 200, 128, // Pixel 2, semi-transparent ]; let mut dst: Vec = vec![0; 8]; transform.transform(&src, &mut dst).unwrap(); // Alpha channel is preserved assert_eq!(dst[3], 255); assert_eq!(dst[7], 128); ``` -------------------------------- ### Check if Profile is Matrix Shaper Source: https://context7.com/awxkee/moxcms/llms.txt Determine if a color profile utilizes a matrix-shaper (TRC + colorant) approach instead of a Look-Up Table (LUT). This is useful for understanding profile complexity and performance characteristics. ```rust use moxcms::ColorProfile; use std::fs; let srgb = ColorProfile::new_srgb(); assert!(srgb.is_matrix_shaper()); // LUT-based profiles (like CMYK) return false let cmyk_icc = fs::read("./assets/us_swop_coated.icc").expect("CMYK profile"); let cmyk = ColorProfile::new_from_slice(&cmyk_icc).unwrap(); assert!(!cmyk.is_matrix_shaper()); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.