### Install colorimetry-cli Source: https://github.com/harbik/colorimetry/blob/main/cli/README.md Install the colorimetry-cli tool using Cargo. Ensure Rust and Cargo are installed first. ```bash cargo install colorimetry-cli ``` -------------------------------- ### Verify Installation and View Help Source: https://github.com/harbik/colorimetry/blob/main/cli/README.md Check if the installation was successful and view available commands and options by running the help command. ```bash color --help ``` -------------------------------- ### Install Colorimetry Source: https://context7.com/harbik/colorimetry/llms.txt Commands to add the library to a Rust project via cargo. ```bash cargo add colorimetry ``` ```toml colorimetry = "0.0.8" ``` ```bash cargo add colorimetry -F cri,munsell,cfi ``` -------------------------------- ### Match Paint Color to sRGB under Realistic Viewing Conditions Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md Requires `supplemental-observers`, and `munsell` features. This example matches a Munsell paint chip to its sRGB equivalent using the CIE 2015 10° observer and LED_B2 illuminant for realistic viewing. ```rust // requires `supplemental-observers`, and `munsell` features use colorimetry::{ cam::{ViewConditions, CIE248_HOME_SCREEN}, colorant::Munsell, illuminant::LED_B2, observer::Observer::{Cie1931, Cie2015_10}, rgb::RgbSpace::SRGB, }; let paint = Munsell::try_new("5BG5/8").unwrap(); let vc = ViewConditions::average_surround(6.0); let cam_paint = Cie2015_10.ciecam16(&LED_B2, &paint, vc); let rgb_2015 = cam_paint .rgb(SRGB, Some(CIE248_HOME_SCREEN)) .unwrap() .compress(); // Use a spectral representation of the Cie2015_10 RGB pixel, using the `Rgb`'s Light trait, // and calculate its XYZ tristimulus and RGB values for the CIE 1931 standard observer, // the // observer // required for the sRGB color space. let xyz_1931 = Cie1931.xyz(&rgb_2015, None); let rgb_1931 = xyz_1931.rgb(SRGB).compress(); let [r, g, b]: [u8; 3] = rgb_1931.into(); // (0, 113, 138) ``` -------------------------------- ### Match Paint Color to sRGB under Realistic Conditions Source: https://github.com/harbik/colorimetry/blob/main/README.md Requires `cie-illuminants`, and `munsell` features. This example matches a Munsell paint chip to its nearest sRGB equivalent under realistic viewing conditions using the CIE 2015 10° observer and LED_B2 illuminant. ```rust // requires `cie-illuminants`, and `munsell` features use colorimetry::{ cam::ViewConditions, colorant::Munsell, illuminant::LED_B2, observer::Observer::Cie2015_10, rgb::RgbSpace::SRGB, }; let paint = Munsell::try_new("5BG5/8").unwrap(); let vc = ViewConditions::average_surround(6.0); let cam_paint = Cie2015_10.ciecam16(&LED_B2, &paint, vc); let rgb_2015 = cam_paint .rgb(SRGB, None) .unwrap() .compress(); // Use a spectral representation of the Cie2015_10 RGB pixel, using the `Rgb`'s Light trait, // and calculate its XYZ tristimulus and RGB values for the CIE 1931 standard observer, the // observer // required for the sRGB color space. let xyz_1931 = Cie1931.xyz(&rgb_2015, None); let rgb_1931 = xyz_1931.rgb(SRGB).compress(); let [r, g, b]: [u8; 3] = rgb_1931.into(); // (0, 113, 138) ``` -------------------------------- ### Generate WebAssembly files with xtask Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md Use `cargo xtask wasm` to generate WebAssembly files in the `pkg` directory. This requires `wasm-pack` and `wasm-opt` to be installed. ```rust cargo xtask wasm ``` -------------------------------- ### Use CLI Tool Source: https://context7.com/harbik/colorimetry/llms.txt Commands for the colorimetry-cli tool for colorimetric calculations. ```bash # Install cargo install colorimetry-cli # View help color --help # Example usage (actual commands depend on CLI implementation) color cct D65 color cri F2 ``` -------------------------------- ### Enable features via cargo add Source: https://github.com/harbik/colorimetry/blob/main/README.md Use these commands to add the colorimetry crate with specific features enabled. ```bash cargo add colorimetry -F cri,munsell ``` ```bash cargo add colorimetry --features cri,munsell ``` -------------------------------- ### Run xtask doc Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md Use `cargo xtask doc` to build and open project documentation. This command fails on warnings. ```rust cargo xtask doc ``` -------------------------------- ### Manage Illuminants Source: https://context7.com/harbik/colorimetry/llms.txt Create and manipulate spectral power distributions for various light sources. ```rust use colorimetry::illuminant::{Illuminant, D65, D50}; use colorimetry::observer::Observer::Cie1931; // Standard illuminants let d65 = Illuminant::d65(); let d50 = Illuminant::d50(); // Create a Planckian (blackbody) illuminant at 3000K let warm_light = Illuminant::planckian(3000.0); let xyz = Cie1931.xyz(&warm_light, None); let chromaticity = xyz.chromaticity(); // chromaticity: x = 0.4369, y = 0.4041 // Create an LED illuminant (center wavelength, full-width half-maximum) let green_led = Illuminant::led(550.0, 25.0); assert_eq!(green_led.irradiance(), 1.0); // normalized to 1 W/m² // Set illuminance (lux) let bright_d65 = D65.clone().set_illuminance(Cie1931, 500.0); // Create CIE D-series illuminant by CCT let d_illuminant = Illuminant::d_illuminant(5500.0).unwrap(); // Valid for CCT range 4000K - 25000K ``` -------------------------------- ### Illuminant - Spectral Power Distribution for Light Sources Source: https://context7.com/harbik/colorimetry/llms.txt Represents spectral power distributions for various light sources. Supports standard illuminants like D65 and D50, Planckian (blackbody) radiators, and LED sources. Allows for normalization, setting illuminance, and creating CIE D-series illuminants. ```APIDOC ## Illuminant - Spectral Power Distribution for Light Sources ### Description The `Illuminant` struct represents spectral power distributions for light sources (sun, LEDs, blackbody radiators) covering 380-780nm at 1nm intervals. ### Method N/A (Struct and associated functions) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Code Examples ```rust use colorimetry::illuminant::{Illuminant, D65, D50}; use colorimetry::observer::Observer::Cie1931; // Standard illuminants let d65 = Illuminant::d65(); let d50 = Illuminant::d50(); // Create a Planckian (blackbody) illuminant at 3000K let warm_light = Illuminant::planckian(3000.0); let xyz = Cie1931.xyz(&warm_light, None); let chromaticity = xyz.chromaticity(); // chromaticity: x = 0.4369, y = 0.4041 // Create an LED illuminant (center wavelength, full-width half-maximum) let green_led = Illuminant::led(550.0, 25.0); assert_eq!(green_led.irradiance(), 1.0); // normalized to 1 W/m² // Set illuminance (lux) let bright_d65 = D65.clone().set_illuminance(Cie1931, 500.0); // Create CIE D-series illuminant by CCT let d_illuminant = Illuminant::d_illuminant(5500.0).unwrap(); // Valid for CCT range 4000K - 25000K ``` ``` -------------------------------- ### Add Colorimetry Dependency via Cargo Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md Commands to include the library in a Rust project. ```bash cargo add colorimetry ``` ```text colorimetry = "0.0.7" ``` -------------------------------- ### Add Colorimetry to Rust Project Source: https://github.com/harbik/colorimetry/blob/main/README.md Use this command to add the colorimetry library as a dependency in your Rust project. ```bash cargo add colorimetry ``` -------------------------------- ### Calculate XYZ/RGB Transformation Matrices Source: https://github.com/harbik/colorimetry/blob/main/README.md Computes conversion matrices for the DisplayP3 color space using CIE 1931 and CIE 2015 observers. ```rust use colorimetry::observer::Observer; use colorimetry::rgb::RgbSpace::DisplayP3; let xyz2rgb_31 = Observer::Cie1931.xyz2rgb_matrix(DisplayP3); // 2.4933, -0.9313, -0.4027, // -0.8298, 1.7629, 0.0236, // 0.0355, -0.076, 0.9574 let rgb2xyz_31 = Observer::Cie1931.rgb2xyz_matrix(DisplayP3); // 0.4866, 0.2656, 0.1981, // 0.2291, 0.6917, 0.0792, // 0.0001, 0.0451, 1.0433, use colorimetry::observer::Observer::Cie2015; let xyz2rgb_15 = Cie2015.xyz2rgb_matrix(DisplayP3).clone(); // 2.5258, -1.0009, -0.3649, // -0.9006, 1.8546, -0.0011, // 0.0279, -0.0574, 0.95874 ``` -------------------------------- ### Configure features in Cargo.toml Source: https://github.com/harbik/colorimetry/blob/main/README.md Manually specify features in the project's Cargo.toml file. ```toml colorimetry = { version = "0.0.7", features = ["cri", "munsell"] } ``` -------------------------------- ### Add Colorimetry to Cargo.toml Source: https://github.com/harbik/colorimetry/blob/main/README.md Alternatively, add this line to the dependencies section of your Cargo.toml file to include the colorimetry library. ```text colorimetry = "0.0.7" ``` -------------------------------- ### Add colorimetry-plot crate Source: https://github.com/harbik/colorimetry/blob/main/README.md Add the plotting module to your project dependencies. ```bash cargo add colorimetry-plot ``` -------------------------------- ### Convert Spectral Data to CIELAB Source: https://github.com/harbik/colorimetry/blob/main/cli/README.md Convert spectral data from a CSV file to CIELAB color values using the 'color' subcommand. Specify the target model with '-m lab'. The CSV should have wavelengths in the first column and spectral values in the second. ```bash color sample sample1.csv -m lab ``` -------------------------------- ### Implement CIECAM16 Color Appearance Model Source: https://context7.com/harbik/colorimetry/llms.txt Use CieCam16 to calculate perceptual color appearance under specific viewing conditions and perform UCS transformations. ```rust use colorimetry::cam::{CieCam16, ViewConditions, CamTransforms}; use colorimetry::cam::{CIE248_HOME_SCREEN, CIE248_OFFICE_SCREEN}; use colorimetry::xyz::{XYZ, RelXYZ}; use colorimetry::observer::Observer::Cie1931; use colorimetry::rgb::RgbSpace; // Define viewing conditions let vc = ViewConditions::average_surround(20.0); // 20 cd/m² adapting luminance // Or use CIE 248 presets: // CIE248_HOME_SCREEN, CIE248_OFFICE_SCREEN, CIE248_PROJECTED_DARK // Create from XYZ values let xyz = XYZ::new([60.70, 49.60, 10.29], Cie1931); let xyzn = XYZ::new([96.46, 100.0, 108.62], Cie1931); // white point let rxyz = RelXYZ::from_xyz(xyz, xyzn).unwrap(); let cam = CieCam16::from_xyz(rxyz, vc); // Get JCh appearance correlates let [j, c, h] = cam.jch(); // J = 70.44 (lightness), C = 58.60 (chroma), h = 57.91° (hue angle) // Get perceptually uniform Ja'b' coordinates (CAM16-UCS) let [jp, ap, bp] = cam.jab_prime(); // Calculate perceptual color difference (ΔE') let cam2 = CieCam16::from_xyz(rxyz, vc); let delta_e = cam.de_ucs(&cam2).unwrap(); // Inverse transform back to XYZ let rxyz_back = cam.xyz(None, None).unwrap(); // Convert to RGB with optional different viewing conditions let wide_rgb = cam.rgb(RgbSpace::SRGB, Some(CIE248_HOME_SCREEN)).unwrap(); let rgb = wide_rgb.compress(); // Create directly from JCh values let cam_direct = CieCam16::new([70.0, 50.0, 60.0], xyzn, vc); ``` -------------------------------- ### Run xtask check Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md Use `cargo xtask check` to execute clippy, fmt, check, and readme verification. ```rust cargo xtask check ``` -------------------------------- ### Handle RGB and WideRGB Colors Source: https://context7.com/harbik/colorimetry/llms.txt Use Rgb for standard [0, 1] color space and WideRgb for HDR workflows. WideRgb supports out-of-gamut values and provides clamping or compression methods. ```rust use colorimetry::rgb::{Rgb, WideRgb, RgbSpace}; use colorimetry::observer::Observer; use colorimetry::xyz::XYZ; // Create Rgb from normalized values (validates range) let rgb = Rgb::new(0.5, 0.25, 0.75, None, None).unwrap(); // Defaults: Observer::Cie1931, RgbSpace::SRGB // Create from 8-bit values (applies gamma decoding) let rgb_u8 = Rgb::from_u8(128, 64, 192, None, None); // Create from 16-bit values let rgb_u16 = Rgb::from_u16(32768, 16384, 49152, None, None); // Access channel values let r = rgb.r(); let g = rgb.g(); let b = rgb.b(); let [r, g, b] = rgb.to_array(); // Convert to XYZ let xyz = rgb.xyz(); // Convert back to 8-bit (applies gamma encoding) let [r8, g8, b8]: [u8; 3] = rgb.into(); // WideRgb for out-of-gamut colors let wide = WideRgb::new(1.5, -0.2, 0.8, None, None); // Check if in gamut let in_gamut = wide.is_in_gamut(); // false // Convert to valid Rgb let clamped = wide.clamp(); // simple clamp to [0,1] let compressed = wide.compress(); // preserve ratios, reduce chroma // Compressed: [1.0, 0.0, 0.7647] // Convert WideRgb to XYZ let xyz_wide = wide.xyz(); // Conversion from XYZ produces WideRgb let xyz = XYZ::new([50.0, 40.0, 30.0], Observer::Cie1931); let wide_from_xyz = xyz.rgb(RgbSpace::SRGB); if let Some(rgb) = wide_from_xyz.to_rgb() { // Color is in gamut } ``` -------------------------------- ### Calculate XYZ/RGB Transformation Matrices Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md Computes transformation matrices between XYZ and RGB color spaces for a specified observer and RGB color space. Supports any observer as long as both color space and data use the same one. Requires `supplemental-observers` for CIE 2015. ```rust use colorimetry::observer::Observer; use colorimetry::rgb::RgbSpace::DisplayP3; let xyz2rgb_31 = Observer::Cie1931.xyz2rgb(DisplayP3); // 2.4933, -0.9313, -0.4027, // -0.8298, 1.7629, 0.0236, // 0.0355, -0.076, 0.9574 let rgb2xyz_31 = Observer::Cie1931.rgb2xyz(DisplayP3); // 0.4866, 0.2656, 0.1981, // 0.2291, 0.6917, 0.0792, // 0.0001, 0.0451, 1.0433, // requires `supplemental-observers` use colorimetry::observer::Observer::Cie2015; let xyz2rgb_15 = Cie2015.xyz2rgb(DisplayP3); // 2.5258, -1.0009, -0.3649, // -0.9006, 1.8546, -0.0011, // 0.0279, -0.0574, 0.95874 ``` -------------------------------- ### Calculate RGB/XYZ Transformation Matrices Source: https://context7.com/harbik/colorimetry/llms.txt Computes transformation matrices between RGB and XYZ color spaces for specific observers. ```rust use colorimetry::observer::Observer; use colorimetry::rgb::RgbSpace; // Get RGB to XYZ matrix for sRGB with CIE 1931 observer let rgb2xyz = Observer::Cie1931.rgb2xyz_matrix(RgbSpace::SRGB); // [[0.4125, 0.3576, 0.1804], // [0.2127, 0.7152, 0.0722], // [0.0193, 0.1192, 0.9503]] // Get XYZ to RGB matrix let xyz2rgb = Observer::Cie1931.xyz2rgb_matrix(RgbSpace::SRGB); // [[3.2405, -1.5371, -0.4985], // [-0.9693, 1.8760, 0.0416], // [0.0556, -0.2040, 1.0572]] // Matrices for Display P3 with CIE 2015 observer let xyz2rgb_p3 = Observer::Cie2015.xyz2rgb_matrix(RgbSpace::DisplayP3); // Different matrices due to observer difference // Available RGB spaces let spaces = [ RgbSpace::SRGB, RgbSpace::Adobe, RgbSpace::DisplayP3, ]; ``` -------------------------------- ### Run xtask test Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md Use `cargo xtask test` to test various feature configurations. ```rust cargo xtask test ``` -------------------------------- ### Access Munsell Color System Source: https://context7.com/harbik/colorimetry/llms.txt Accesses the Munsell color collection for spectral reflectance samples. Requires the 'munsell' feature. ```rust use colorimetry::colorant::{Munsell, MunsellCollection, TCS}; use colorimetry::observer::Observer::{Cie1931, Cie2015_10}; use colorimetry::illuminant::D65; // Create a Munsell color by notation let munsell_red = Munsell::try_new("5R4/14").unwrap(); let munsell_teal = Munsell::try_new("5BG5/8").unwrap(); // Calculate CIELAB values let lab = munsell_red.cielab(Some(&D65), Some(Cie1931)); let [l, a, b] = lab.to_array(); // Find closest Munsell match for a colorant let test_color = &TCS[8]; // CRI test color R9 (saturated red) let (key, delta_e) = MunsellCollection::match_ciecam16( test_color, None, // illuminant (default D65) None, // view conditions Some(Cie2015_10), // observer ).unwrap(); // key = "5R4/14", delta_e ≈ 2.85 // Iterate over all Munsell colors for colorant in MunsellCollection { let xyz = Cie1931.xyz(&D65, Some(&colorant)); // Process each color... } ``` -------------------------------- ### Evaluate Color Rendering Index (CRI) Source: https://context7.com/harbik/colorimetry/llms.txt Calculate CRI for illuminants to assess color rendering quality. Requires the 'cri' feature. ```rust use colorimetry::illuminant::{Illuminant, CRI, F2, LED_B2}; // Calculate CRI for fluorescent lamp F2 let cri: CRI = (&*F2).try_into().unwrap(); // Get general color rendering index (Ra) let ra = cri.ra(); // F2: Ra ≈ 64 // Get individual R values (R1-R14) let r9 = cri[9]; // R9 (saturated red) - important for skin tones // F2: R9 ≈ -17 (poor red rendering) // CRI for LED let led_cri: CRI = (&*LED_B2).try_into().unwrap(); let ra_led = led_cri.ra(); // LED_B2: Ra ≈ 80 // CRI via method call let cri_result = F2.cri().unwrap(); let ra = cri_result.ra(); ``` -------------------------------- ### Calculate Correlated Color Temperature and Tint Source: https://github.com/harbik/colorimetry/blob/main/README.md Calculates the CCT and Duv (tint) for an illuminant. Requires the `cct` and `cie-illuminants` features. ```rust use colorimetry::illuminant::A; // Calculate CCT and Duv for the A illuminant // Requires `cct`, and `cie-illuminants` features let [cct, duv] = A.cct().unwrap().to_array(); // [2855.4977, 0.0] ``` -------------------------------- ### Match Colorant to CIE1931 using CIE2015 10° Observer Source: https://github.com/harbik/colorimetry/blob/main/README.md Requires `cri` and `munsell` features. This snippet matches a colorant to its CIE1931 equivalent using the CIE2015 10° observer. ```rust // requires `cri` and `munsell` features use colorimetry::observer::Observer::Cie2015_10; use colorimetry::colorant::{MunsellCollection, TCS}; let cri_r9 = &TCS[8]; let (key, delta_e) = MunsellCollection::match_ciecam16( cri_r9, None, None, Some(Cie2015_10), ).unwrap(); // ("5R4/14", 2.85) ``` -------------------------------- ### LED Illuminants Source: https://github.com/harbik/colorimetry/blob/main/README.md Access to standard LED illuminants (LED_B1 to LED_V1). These represent the spectral characteristics of various Light Emitting Diodes. ```APIDOC ## Accessing LED Illuminants ### Description Provides access to predefined LED illuminants. ### Endpoint `/harbik/colorimetry/illuminant/LED_X` ### Parameters #### Path Parameters - **X** (string) - Required - The identifier for the LED illuminant (e.g., B1 for LED_B1, V1 for LED_V1). ### Response #### Success Response (200) - **illuminant_data** (object) - Contains the spectral data for the requested LED illuminant. ### Request Example GET /harbik/colorimetry/illuminant/LED_B1 ### Response Example { "illuminant_data": { "wavelengths": [380, 390, ..., 780], "values": [0.05, 0.06, ..., 0.1] } } ``` -------------------------------- ### Handle XYZ Tristimulus Values Source: https://context7.com/harbik/colorimetry/llms.txt Create, manipulate, and convert CIE XYZ tristimulus values. ```rust use colorimetry::xyz::XYZ; use colorimetry::observer::Observer; use colorimetry::rgb::RgbSpace; // Create XYZ values directly let xyz = XYZ::new([95.0, 100.0, 108.0], Observer::Cie1931); // Access individual components let x = xyz.x(); // 95.0 let y = xyz.y(); // 100.0 (luminance) let z = xyz.z(); // 108.0 // Get chromaticity coordinates let chromaticity = xyz.chromaticity(); let [cx, cy] = chromaticity.to_array(); // D65: cx ≈ 0.3127, cy ≈ 0.3290 // Create from chromaticity coordinates let xyz_from_xy = XYZ::from_chromaticity( chromaticity, Some(100.0), // luminance Y Some(Observer::Cie1931) ).unwrap(); // Set illuminance (scales all values proportionally) let xyz_100 = xyz.set_illuminance(100.0); // Convert to RGB (returns WideRgb which may be out-of-gamut) let wide_rgb = xyz.rgb(RgbSpace::SRGB); let rgb_clamped = wide_rgb.clamp(); // simple clamp to [0,1] let rgb_compressed = wide_rgb.compress(); // preserve hue, reduce chroma // Get as array let [x, y, z] = xyz.to_array(); ``` -------------------------------- ### Manage Colorant Spectral Data Source: https://context7.com/harbik/colorimetry/llms.txt Use the Colorant struct to define spectral filters, perform subtractive mixing, and calculate CIELAB or XYZ values. ```rust use colorimetry::colorant::Colorant; use colorimetry::illuminant::D65; use colorimetry::observer::Observer::Cie1931; use colorimetry::traits::Filter; // Create standard colorants let white = Colorant::white(); // 100% reflectance let black = Colorant::black(); // 0% reflectance let gray = Colorant::gray(0.5); // 50% reflectance // Create band-pass filters let top_hat = Colorant::top_hat(550.0, 50.0); // center, width in nm let gaussian = Colorant::gaussian(550.0, 25.0); // center, sigma in nm // Create colorant from analytical function (domain 0.0-1.0 maps to 380-780nm) let linear_filter: Colorant = (|x: f64| x).into(); // ramp filter let parabolic: Colorant = (|x: f64| 1.0 - 4.0 * (x - 0.5).powi(2)).into(); // Calculate CIELAB values let lab = gray.cielab(Some(&D65), Some(Cie1931)); let [l, a, b] = lab.to_array(); // L* = 76.07 for 50% gray // Calculate XYZ through observer let xyz = Cie1931.xyz(&D65, Some(&linear_filter)); let chromaticity = xyz.chromaticity().to_array(); // Yellowish color due to linear ramp // Access spectrum data let spectrum = gaussian.spectrum(); let value_at_550nm = spectrum[550]; // peak value ≈ 1.0 // Subtractive mixing (multiply spectra) let combined = &white * &gray; // same as gray ``` -------------------------------- ### Match Color to CIE CAM16 with 2015 10° Observer Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md Requires `cri`, `supplemental-observers`, and `munsell` features. This snippet matches a colorant to its nearest CIE CAM16 equivalent using the specified observer. ```rust // requires `cri`, `supplemental-observers`, and `munsell` features use colorimetry::observer::Observer::Cie2015_10; use colorimetry::colorant::{MunsellCollection, TCS}; let cri_r9 = &TCS[8]; let (key, delta_e) = MunsellCollection::match_ciecam16( cri_r9, None, None, Some(Cie2015_10), ).unwrap(); // ("5R4/14", 2.85) ``` -------------------------------- ### XYZ - Tristimulus Values Source: https://context7.com/harbik/colorimetry/llms.txt Represents CIE tristimulus values (XYZ) with an associated observer tag. Supports direct creation, component access, chromaticity calculation, conversion to RGB, and scaling by illuminance. ```APIDOC ## XYZ - Tristimulus Values ### Description The `XYZ` struct represents CIE tristimulus values with an associated observer tag. ### Method N/A (Struct and associated functions) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Code Examples ```rust use colorimetry::xyz::XYZ; use colorimetry::observer::Observer; use colorimetry::rgb::RgbSpace; // Create XYZ values directly let xyz = XYZ::new([95.0, 100.0, 108.0], Observer::Cie1931); // Access individual components let x = xyz.x(); // 95.0 let y = xyz.y(); // 100.0 (luminance) let z = xyz.z(); // 108.0 // Get chromaticity coordinates let chromaticity = xyz.chromaticity(); let [cx, cy] = chromaticity.to_array(); // D65: cx ≈ 0.3127, cy ≈ 0.3290 // Create from chromaticity coordinates let xyz_from_xy = XYZ::from_chromaticity( chromaticity, Some(100.0), // luminance Y Some(Observer::Cie1931) ).unwrap(); // Set illuminance (scales all values proportionally) let xyz_100 = xyz.set_illuminance(100.0); // Convert to RGB (returns WideRgb which may be out-of-gamut) let wide_rgb = xyz.rgb(RgbSpace::SRGB); let rgb_clamped = wide_rgb.clamp(); // simple clamp to [0,1] let rgb_compressed = wide_rgb.compress(); // preserve hue, reduce chroma // Get as array let [x, y, z] = xyz.to_array(); ``` ``` -------------------------------- ### Use CIE Standard Observers Source: https://context7.com/harbik/colorimetry/llms.txt Perform tristimulus calculations and color space conversions using standard observers. ```rust use colorimetry::observer::Observer; use colorimetry::illuminant::D65; use colorimetry::colorant::Colorant; // Available observers let cie1931 = Observer::Cie1931; // 2° standard observer let cie1964 = Observer::Cie1964; // 10° standard observer let cie2015 = Observer::Cie2015; // 2° cone fundamentals let cie2015_10 = Observer::Cie2015_10; // 10° cone fundamentals // Calculate XYZ tristimulus values for an illuminant let xyz_d65 = Observer::Cie1931.xyz(&D65, None).set_illuminance(100.0); let [x, y, z] = xyz_d65.to_array(); // x = 95.04, y = 100.0, z = 108.86 // Calculate XYZ for a colorant under an illuminant let gray_patch = Colorant::gray(0.5); let xyz_gray = Observer::Cie1931.xyz(&D65, Some(&gray_patch)); // Get D65/D50 reference white points (buffered) let d65_white = Observer::Cie1931.xyz_d65(); let d50_white = Observer::Cie1931.xyz_d50(); // Calculate CIELAB values for a colorant let lab = Observer::Cie1931.lab_d65(&gray_patch); let [l, a, b] = lab.to_array(); // L* = 76.07, a* ≈ 0, b* ≈ 0 // Spectral locus wavelength range let range = Observer::Cie1931.spectral_locus_wavelength_range(); // 380..=700 nm (varies by observer) ``` -------------------------------- ### Observer - CIE Standard Observers Source: https://context7.com/harbik/colorimetry/llms.txt Provides access to different CIE standard observers for color matching functions and tristimulus calculations. Supports CIE 1931, CIE 1964, and CIE 2015 (2° and 10°) observers. ```APIDOC ## Observer - CIE Standard Observers ### Description The `Observer` enum provides access to different CIE standard observers for color matching functions and tristimulus calculations. ### Method N/A (Enum and associated functions) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Code Examples ```rust use colorimetry::observer::Observer; use colorimetry::illuminant::D65; use colorimetry::colorant::Colorant; // Available observers let cie1931 = Observer::Cie1931; // 2° standard observer let cie1964 = Observer::Cie1964; // 10° standard observer let cie2015 = Observer::Cie2015; // 2° cone fundamentals let cie2015_10 = Observer::Cie2015_10; // 10° cone fundamentals // Calculate XYZ tristimulus values for an illuminant let xyz_d65 = Observer::Cie1931.xyz(&D65, None).set_illuminance(100.0); let [x, y, z] = xyz_d65.to_array(); // x = 95.04, y = 100.0, z = 108.86 // Calculate XYZ for a colorant under an illuminant let gray_patch = Colorant::gray(0.5); let xyz_gray = Observer::Cie1931.xyz(&D65, Some(&gray_patch)); // Get D65/D50 reference white points (buffered) let d65_white = Observer::Cie1931.xyz_d65(); let d50_white = Observer::Cie1931.xyz_d50(); // Calculate CIELAB values for a colorant let lab = Observer::Cie1931.lab_d65(&gray_patch); let [l, a, b] = lab.to_array(); // L* = 76.07, a* ≈ 0, b* ≈ 0 // Spectral locus wavelength range let range = Observer::Cie1931.spectral_locus_wavelength_range(); // 380..=700 nm (varies by observer) ``` ``` -------------------------------- ### Calculate Correlated Color Temperature (CCT) Source: https://context7.com/harbik/colorimetry/llms.txt Calculate CCT for illuminants or XYZ values. Requires the 'cct' feature and is valid for duv < 0.05. ```rust use colorimetry::illuminant::{Illuminant, CCT, D65, A}; use colorimetry::observer::Observer::Cie1931; // Calculate CCT for an illuminant let cct_result = D65.cct().unwrap(); let [temperature, duv] = cct_result.to_array(); // D65: ~6504K, duv ≈ 0.0 // CCT for incandescent (Illuminant A) let cct_a = A.cct().unwrap(); let [t_a, duv_a] = cct_a.to_array(); // ~2856K, duv ≈ 0.0 // Calculate CCT from XYZ values let xyz = Cie1931.xyz(&D65, None); let cct_from_xyz: CCT = xyz.cct().unwrap(); // Create Planckian illuminant and verify CCT let planckian_5000k = Illuminant::planckian(5000.0); let cct_planck = planckian_5000k.cct().unwrap(); // Should be very close to 5000K with duv ≈ 0 // CCT is only valid when duv < 0.05 // Error returned if outside 1000-1000000K range or duv > 0.05 ``` -------------------------------- ### Standard Illuminants Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md The colorimetry library provides access to several standard illuminants used in color science. These illuminants are crucial for color calculations and simulations. ```APIDOC ## Standard Illuminants This section details the available standard illuminants within the colorimetry library. ### F3 Series Illuminants - **F3_5**: Represents a specific variant of the F3 illuminant. - **F3_6**: Represents a specific variant of the F3 illuminant. - **F3_7**: Represents a specific variant of the F3 illuminant. - **F3_8**: Represents a specific variant of the F3 illuminant. - **F3_9**: Represents a specific variant of the F3 illuminant. - **F3_10**: Represents a specific variant of the F3 illuminant. - **F3_11**: Represents a specific variant of the F3 illuminant. - **F3_12**: Represents a specific variant of the F3 illuminant. - **F3_13**: Represents a specific variant of the F3 illuminant. - **F3_14**: Represents a specific variant of the F3 illuminant. - **F3_15**: Represents a specific variant of the F3 illuminant. ### LED Series Illuminants - **LED_B1**: Represents a specific LED-based illuminant. - **LED_B2**: Represents a specific LED-based illuminant. - **LED_B3**: Represents a specific LED-based illuminant. - **LED_B4**: Represents a specific LED-based illuminant. - **LED_B5**: Represents a specific LED-based illuminant. - **LED_BH1**: Represents a specific LED-based illuminant. - **LED_RGB1**: Represents a specific LED-based illuminant. - **LED_V1**: Represents a specific LED-based illuminant. Each illuminant is linked to its detailed documentation in the Rust docs for further information on its spectral power distribution and properties. ``` -------------------------------- ### Calculate Color Fidelity Index for Illuminants Source: https://github.com/harbik/colorimetry/blob/main/README.md Computes the general Color Fidelity Index for an illuminant. Requires the `cfi` and `cie-illuminants` features. ```rust use colorimetry::illuminant::F2; // Calculate the Color Fidelity Index of the CIE F2 standard illuminant // Requires `cfi`, and `cie-illuminants` features let cf_f2 = F2.cfi().unwrap(); let cf = cf_f2.general_color_fidelity_index(); // 70.3 ``` -------------------------------- ### Calculate Tristimulus Values for Illuminants Source: https://github.com/harbik/colorimetry/blob/main/pkg/README.md Calculates XYZ tristimulus values for D65 illuminant using CIE 1931 2º and CIE 2015 10º observers. Requires the `supplemental-observers` feature for the CIE 2015 observer. ```rust use colorimetry::illuminant::D65; // D65 Tristimulus values, using the CIE1931 standard observer by default let xyz_d65 = D65.xyz(None).set_illuminance(100.0); let [x, y, z] = xyz_d65.values(); // [95.04, 100.0, 108.86] // D65 Tristimulus values using the CIE2015 10º observer // This requires the `supplemental-observers` feature (enabled by default) use colorimetry::observer::Observer::Cie2015_10; let xyz_d65_10 = D65 .xyz(Some(Cie2015_10)).set_illuminance(100.0); let [x_10, y_10, z_10] = xyz_d65_10.values(); //[94.72, 100.0, 107.143] ``` -------------------------------- ### Calculate Color Fidelity Index (CFI) Source: https://context7.com/harbik/colorimetry/llms.txt Calculates the TM-30 Color Fidelity Index for illuminants. Requires the 'cfi' feature enabled. ```rust use colorimetry::illuminant::{CFI, F2, LED_B2}; // Calculate CFI for fluorescent lamp let cfi = F2.cfi().unwrap(); // Get general color fidelity index (Rf) let rf = cfi.general_color_fidelity_index(); // F2: Rf ≈ 70 // CFI uses 99 test color samples (vs 8 for CRI) // and CIECAM02 color difference (more perceptually accurate) // CFI for LED illuminant let led_cfi = LED_B2.cfi().unwrap(); let rf_led = led_cfi.general_color_fidelity_index(); ``` -------------------------------- ### Perform CIELAB Color Space Operations Source: https://context7.com/harbik/colorimetry/llms.txt The CieLab struct handles L*a*b* color representation, color difference calculations, and conversions to/from XYZ. ```rust use colorimetry::lab::CieLab; use colorimetry::xyz::{XYZ, RelXYZ}; use colorimetry::observer::Observer::Cie1931; // Create CieLab from L*a*b* values and white point let white_point = Cie1931.xyz_d65(); let lab1 = CieLab::new([50.0, 25.0, -30.0], white_point); // Create from XYZ values let xyz = XYZ::new([36.0, 70.0, 12.0], Cie1931); let rxyz = RelXYZ::with_d65(xyz); let lab2 = CieLab::from_rxyz(rxyz); // Access L*a*b* values let l = lab2.l(); let a = lab2.a(); let b = lab2.b(); let [l, a, b] = lab2.to_array(); // Calculate color difference (Euclidean ΔE*ab) let delta_e = lab1.ciede(&lab2).unwrap(); // Simple Euclidean distance in L*a*b* space // Calculate CIEDE2000 (perceptually uniform) let delta_e_2000 = lab1.ciede2000(&lab2).unwrap(); // More accurate perceptual color difference // Convert back to XYZ let xyz_back = lab2.xyz(); // Validate L*a*b* values let is_valid = lab2.is_valid(); // Checks ranges and round-trip conversion ``` -------------------------------- ### Calculate Tristimulus Values for Illuminants Source: https://github.com/harbik/colorimetry/blob/main/README.md Calculates XYZ tristimulus values for the D65 illuminant using both the CIE 1931 2º and CIE 2015 10º observers. ```rust use colorimetry::illuminant::D65; // D65 Tristimulus values, using the CIE1931 standard observer by default let xyz_d65 = D65.xyz(None).set_illuminance(100.0); let [x, y, z] = xyz_d65.to_array(); // [95.04, 100.0, 108.86] // D65 Tristimulus values using the CIE2015 10º observer use colorimetry::observer::Observer::Cie2015_10; let xyz_d65_10 = D65 .xyz(Some(Cie2015_10)).set_illuminance(100.0); let [x_10, y_10, z_10] = xyz_d65_10.to_array(); //[94.72, 100.0, 107.143] ```