moxcms 0.8.1

Simple Color Management in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
/*
 * // Copyright (c) Radzivon Bartoshyk 3/2025. All rights reserved.
 * //
 * // Redistribution and use in source and binary forms, with or without modification,
 * // are permitted provided that the following conditions are met:
 * //
 * // 1.  Redistributions of source code must retain the above copyright notice, this
 * // list of conditions and the following disclaimer.
 * //
 * // 2.  Redistributions in binary form must reproduce the above copyright notice,
 * // this list of conditions and the following disclaimer in the documentation
 * // and/or other materials provided with the distribution.
 * //
 * // 3.  Neither the name of the copyright holder nor the names of its
 * // contributors may be used to endorse or promote products derived from
 * // this software without specific prior written permission.
 * //
 * // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
use crate::chad::BRADFORD_D;
use crate::cicp::create_rec709_parametric;
use crate::trc::{ToneReprCurve, curve_from_gamma};
use crate::{
    CicpColorPrimaries, CicpProfile, ColorPrimaries, ColorProfile, DataColorSpace,
    LocalizableString, LutMultidimensionalType, LutWarehouse, Matrix3d, MatrixCoefficients,
    ProfileClass, ProfileText, RenderingIntent, TransferCharacteristics, Vector3, XyY,
};
use pxfm::{copysignk, exp, floor, pow};

/// From lcms: `cmsWhitePointFromTemp`
/// tempK must be >= 4000. and <= 25000.
/// Invalid values of tempK will return
/// (x,y,Y) = (-1.0, -1.0, -1.0)
/// similar to argyll: `icx_DTEMP2XYZ()`
const fn white_point_from_temperature(temp_k: i32) -> XyY {
    let mut white_point = XyY {
        x: 0.,
        y: 0.,
        yb: 0.,
    };
    // No optimization provided.
    let temp_k = temp_k as f64; // Square
    let temp_k2 = temp_k * temp_k; // Cube
    let temp_k3 = temp_k2 * temp_k;
    // For correlated color temperature (T) between 4000K and 7000K:
    let x = if temp_k > 4000.0 && temp_k <= 7000.0 {
        -4.6070 * (1E9 / temp_k3) + 2.9678 * (1E6 / temp_k2) + 0.09911 * (1E3 / temp_k) + 0.244063
    } else if temp_k > 7000.0 && temp_k <= 25000.0 {
        -2.0064 * (1E9 / temp_k3) + 1.9018 * (1E6 / temp_k2) + 0.24748 * (1E3 / temp_k) + 0.237040
    } else {
        // or for correlated color temperature (T) between 7000K and 25000K:
        // Invalid tempK
        white_point.x = -1.0;
        white_point.y = -1.0;
        white_point.yb = -1.0;
        debug_assert!(false, "invalid temp");
        return white_point;
    };
    // Obtain y(x)
    let y = -3.000 * (x * x) + 2.870 * x - 0.275;
    // wave factors (not used, but here for futures extensions)
    // let M1 = (-1.3515 - 1.7703*x + 5.9114 *y)/(0.0241 + 0.2562*x - 0.7341*y);
    // let M2 = (0.0300 - 31.4424*x + 30.0717*y)/(0.0241 + 0.2562*x - 0.7341*y);
    // Fill white_point struct
    white_point.x = x;
    white_point.y = y;
    white_point.yb = 1.0;
    white_point
}

pub const WHITE_POINT_D50: XyY = white_point_from_temperature(5003);
pub const WHITE_POINT_D60: XyY = white_point_from_temperature(6000);
pub const WHITE_POINT_D65: XyY = white_point_from_temperature(6504);
pub const WHITE_POINT_DCI_P3: XyY = white_point_from_temperature(6300);

// https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-F.pdf
// Perceptual Quantization / SMPTE standard ST.2084
#[inline]
const fn pq_curve(x: f64) -> f64 {
    const M1: f64 = 2610.0 / 16384.0;
    const M2: f64 = (2523.0 / 4096.0) * 128.0;
    const C1: f64 = 3424.0 / 4096.0;
    const C2: f64 = (2413.0 / 4096.0) * 32.0;
    const C3: f64 = (2392.0 / 4096.0) * 32.0;

    if x == 0.0 {
        return 0.0;
    }
    let sign = x;
    let x = x.abs();

    let xpo = pow(x, 1.0 / M2);
    let num = (xpo - C1).max(0.0);
    let den = C2 - C3 * xpo;
    let res = pow(num / den, 1.0 / M1);

    copysignk(res, sign)
}

pub(crate) const fn build_trc_table_pq() -> [u16; 4096] {
    let mut table = [0u16; 4096];

    const NUM_ENTRIES: usize = 4096;
    let mut i = 0usize;
    while i < NUM_ENTRIES {
        let x: f64 = i as f64 / (NUM_ENTRIES - 1) as f64;
        let y: f64 = pq_curve(x);
        let mut output: f64;
        output = y * 65535.0 + 0.5;
        if output > 65535.0 {
            output = 65535.0
        }
        if output < 0.0 {
            output = 0.0
        }
        table[i] = floor(output) as u16;
        i += 1;
    }
    table
}

pub(crate) const fn build_trc_table_hlg() -> [u16; 4096] {
    let mut table = [0u16; 4096];

    const NUM_ENTRIES: usize = 4096;
    let mut i = 0usize;
    while i < NUM_ENTRIES {
        let x: f64 = i as f64 / (NUM_ENTRIES - 1) as f64;
        let y: f64 = hlg_curve(x);
        let mut output: f64;
        output = y * 65535.0 + 0.5;
        if output > 65535.0 {
            output = 65535.0
        }
        if output < 0.0 {
            output = 0.0
        }
        table[i] = floor(output) as u16;
        i += 1;
    }
    table
}

// https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-F.pdf
// Hybrid Log-Gamma
const fn hlg_curve(x: f64) -> f64 {
    const BETA: f64 = 0.04;
    const RA: f64 = 5.591816309728916; // 1.0 / A where A = 0.17883277
    const B: f64 = 0.28466892; // 1.0 - 4.0 * A
    const C: f64 = 0.5599107295; // 0,5 –aln(4a)

    let e = (x * (1.0 - BETA) + BETA).max(0.0);

    if e == 0.0 {
        return 0.0;
    }

    let sign = e.abs();

    let res = if e <= 0.5 {
        e * e / 3.0
    } else {
        (exp((e - C) * RA) + B) / 12.0
    };

    copysignk(res, sign)
}

/// Perceptual Quantizer Lookup table
pub const PQ_LUT_TABLE: [u16; 4096] = build_trc_table_pq();
/// Hybrid Log Gamma Lookup table
pub const HLG_LUT_TABLE: [u16; 4096] = build_trc_table_hlg();

impl ColorProfile {
    const SRGB_COLORANTS: Matrix3d =
        ColorProfile::colorants_matrix(WHITE_POINT_D65, ColorPrimaries::BT_709);

    const DISPLAY_P3_COLORANTS: Matrix3d =
        ColorProfile::colorants_matrix(WHITE_POINT_D65, ColorPrimaries::SMPTE_432);

    const ADOBE_RGB_COLORANTS: Matrix3d =
        ColorProfile::colorants_matrix(WHITE_POINT_D65, ColorPrimaries::ADOBE_RGB);

    const DCI_P3_COLORANTS: Matrix3d =
        ColorProfile::colorants_matrix(WHITE_POINT_DCI_P3, ColorPrimaries::DCI_P3);

    const PRO_PHOTO_RGB_COLORANTS: Matrix3d =
        ColorProfile::colorants_matrix(WHITE_POINT_D50, ColorPrimaries::PRO_PHOTO_RGB);

    const BT2020_COLORANTS: Matrix3d =
        ColorProfile::colorants_matrix(WHITE_POINT_D65, ColorPrimaries::BT_2020);

    const ACES_2065_1_COLORANTS: Matrix3d =
        ColorProfile::colorants_matrix(WHITE_POINT_D60, ColorPrimaries::ACES_2065_1);

    const ACES_CG_COLORANTS: Matrix3d =
        ColorProfile::colorants_matrix(WHITE_POINT_D60, ColorPrimaries::ACES_CG);

    #[inline]
    fn basic_rgb_profile() -> ColorProfile {
        ColorProfile {
            profile_class: ProfileClass::DisplayDevice,
            rendering_intent: RenderingIntent::Perceptual,
            color_space: DataColorSpace::Rgb,
            pcs: DataColorSpace::Xyz,
            chromatic_adaptation: Some(BRADFORD_D),
            white_point: WHITE_POINT_D50.to_xyzd(),
            ..Default::default()
        }
    }

    /// Creates new profile from CICP
    pub fn new_from_cicp(cicp_color_primaries: CicpProfile) -> ColorProfile {
        let mut basic = ColorProfile::basic_rgb_profile();
        basic.update_rgb_colorimetry_from_cicp(cicp_color_primaries);
        basic
    }

    /// Creates new sRGB profile
    pub fn new_srgb() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::SRGB_COLORANTS);

        let curve =
            ToneReprCurve::Parametric(vec![2.4, 1. / 1.055, 0.055 / 1.055, 1. / 12.92, 0.04045]);
        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D65.to_xyzd());
        profile.cicp = Some(CicpProfile {
            color_primaries: CicpColorPrimaries::Bt709,
            transfer_characteristics: TransferCharacteristics::Srgb,
            matrix_coefficients: MatrixCoefficients::Bt709,
            full_range: false,
        });
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "sRGB IEC61966-2.1".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new Adobe RGB profile
    pub fn new_adobe_rgb() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::ADOBE_RGB_COLORANTS);

        let curve = curve_from_gamma(2.19921875f32);
        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D65.to_xyzd());
        profile.white_point = WHITE_POINT_D50.to_xyzd();
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Adobe RGB 1998".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new Display P3 profile
    pub fn new_display_p3() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::DISPLAY_P3_COLORANTS);

        let curve =
            ToneReprCurve::Parametric(vec![2.4, 1. / 1.055, 0.055 / 1.055, 1. / 12.92, 0.04045]);
        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D65.to_xyzd());
        profile.cicp = Some(CicpProfile {
            color_primaries: CicpColorPrimaries::Smpte431,
            transfer_characteristics: TransferCharacteristics::Srgb,
            matrix_coefficients: MatrixCoefficients::Bt709,
            full_range: false,
        });
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Display P3".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new Display P3 PQ profile
    pub fn new_display_p3_pq() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::DISPLAY_P3_COLORANTS);

        let curve = ToneReprCurve::Lut(PQ_LUT_TABLE.to_vec());

        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D65.to_xyzd());
        profile.cicp = Some(CicpProfile {
            color_primaries: CicpColorPrimaries::Smpte431,
            transfer_characteristics: TransferCharacteristics::Smpte2084,
            matrix_coefficients: MatrixCoefficients::Bt709,
            full_range: false,
        });
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Display P3 PQ".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new DCI P3 profile
    pub fn new_dci_p3() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::DCI_P3_COLORANTS);

        let curve = curve_from_gamma(2.6f32);
        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_DCI_P3.to_xyzd());
        profile.cicp = Some(CicpProfile {
            color_primaries: CicpColorPrimaries::Smpte432,
            transfer_characteristics: TransferCharacteristics::Srgb,
            matrix_coefficients: MatrixCoefficients::Bt709,
            full_range: false,
        });
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "DCI P3".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new ProPhoto RGB profile
    pub fn new_pro_photo_rgb() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::PRO_PHOTO_RGB_COLORANTS);

        let curve = curve_from_gamma(1.8f32);
        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D50.to_xyzd());
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "ProPhoto RGB".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new Bt.2020 profile
    pub fn new_bt2020() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::BT2020_COLORANTS);

        let curve = ToneReprCurve::Parametric(create_rec709_parametric().to_vec());
        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D65.to_xyzd());
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Rec.2020".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new Bt.2020 PQ profile
    pub fn new_bt2020_pq() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::BT2020_COLORANTS);

        let curve = ToneReprCurve::Lut(PQ_LUT_TABLE.to_vec());

        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D65.to_xyzd());
        profile.cicp = Some(CicpProfile {
            color_primaries: CicpColorPrimaries::Bt2020,
            transfer_characteristics: TransferCharacteristics::Smpte2084,
            matrix_coefficients: MatrixCoefficients::Bt709,
            full_range: false,
        });
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Rec.2020 PQ".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new Bt.2020 HLG profile
    pub fn new_bt2020_hlg() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::BT2020_COLORANTS);

        let curve = ToneReprCurve::Lut(HLG_LUT_TABLE.to_vec());

        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D65.to_xyzd());
        profile.cicp = Some(CicpProfile {
            color_primaries: CicpColorPrimaries::Bt2020,
            transfer_characteristics: TransferCharacteristics::Hlg,
            matrix_coefficients: MatrixCoefficients::Bt709,
            full_range: false,
        });
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Rec.2020 HLG".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new Monochrome profile
    pub fn new_gray_with_gamma(gamma: f32) -> ColorProfile {
        ColorProfile {
            gray_trc: Some(curve_from_gamma(gamma)),
            profile_class: ProfileClass::DisplayDevice,
            rendering_intent: RenderingIntent::Perceptual,
            color_space: DataColorSpace::Gray,
            media_white_point: Some(WHITE_POINT_D65.to_xyzd()),
            white_point: WHITE_POINT_D50.to_xyzd(),
            chromatic_adaptation: Some(BRADFORD_D),
            copyright: Some(ProfileText::Localizable(vec![LocalizableString::new(
                "en".to_string(),
                "US".to_string(),
                "Public Domain".to_string(),
            )])),
            ..Default::default()
        }
    }

    /// Creates new ACES 2065-1/AP0 profile
    pub fn new_aces_aces_2065_1_linear() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::ACES_2065_1_COLORANTS);

        let curve = ToneReprCurve::Lut(vec![]);
        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D60.to_xyzd());
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "ACES 2065-1".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new ACEScg profile
    pub fn new_aces_cg_linear() -> ColorProfile {
        let mut profile = ColorProfile::basic_rgb_profile();
        profile.update_colorants(ColorProfile::ACES_CG_COLORANTS);

        let curve = ToneReprCurve::Lut(vec![]);
        profile.red_trc = Some(curve.clone());
        profile.blue_trc = Some(curve.clone());
        profile.green_trc = Some(curve);
        profile.media_white_point = Some(WHITE_POINT_D60.to_xyzd());
        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "ACEScg/AP1".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));
        profile
    }

    /// Creates new Generic CIE LAB profile
    pub fn new_lab() -> ColorProfile {
        let mut profile = ColorProfile {
            profile_class: ProfileClass::DisplayDevice,
            rendering_intent: RenderingIntent::Perceptual,
            color_space: DataColorSpace::Lab,
            pcs: DataColorSpace::Xyz,
            chromatic_adaptation: Some(BRADFORD_D),
            white_point: WHITE_POINT_D50.to_xyzd(),
            media_white_point: Some(WHITE_POINT_D65.to_xyzd()),
            ..Default::default()
        };

        let b_to_a_lut = LutWarehouse::Multidimensional(LutMultidimensionalType {
            num_input_channels: 3,
            num_output_channels: 3,
            grid_points: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            clut: None,
            b_curves: vec![
                ToneReprCurve::Lut(vec![]),
                ToneReprCurve::Lut(vec![]),
                ToneReprCurve::Lut(vec![]),
            ],
            matrix: Matrix3d::IDENTITY,
            a_curves: vec![],
            m_curves: vec![],
            bias: Vector3::default(),
        });
        profile.lut_b_to_a_perceptual = Some(b_to_a_lut.clone());
        profile.lut_b_to_a_colorimetric = Some(b_to_a_lut);

        let a_to_b = LutWarehouse::Multidimensional(LutMultidimensionalType {
            num_input_channels: 3,
            num_output_channels: 3,
            grid_points: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            clut: None,
            b_curves: vec![
                ToneReprCurve::Lut(vec![]),
                ToneReprCurve::Lut(vec![]),
                ToneReprCurve::Lut(vec![]),
            ],
            matrix: Matrix3d::IDENTITY,
            a_curves: vec![],
            m_curves: vec![],
            bias: Vector3::default(),
        });
        profile.lut_a_to_b_colorimetric = Some(a_to_b.clone());
        profile.lut_a_to_b_perceptual = Some(a_to_b);

        profile.description = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Generic L*a*b* Profile".to_string(),
        )]));
        profile.copyright = Some(ProfileText::Localizable(vec![LocalizableString::new(
            "en".to_string(),
            "US".to_string(),
            "Public Domain".to_string(),
        )]));

        profile
    }
}