Skip to content

Commit 3ec0b8a

Browse files
jxl: Extending JXL CICP support to include P3 / color primaries 12 (#5054)
I tested out the JPEG XL CICP support and noticed that color primaries 12 was not supported. This pull request is looking to extend P3 support for color primaries 12. Note: color primaries 11 uses the DCI white point and color primaries 12 uses the D65 white point. The JxlPrimaries enum only covers P3 primaries as value 11 and not 12. See, https://github.com/libjxl/libjxl/blob/main/lib/include/jxl/color_encoding.h#L55-L75 Further code is therefore required to account for this on read and write. Tests for read and write of color primaries 11 and 12 were added. Signed-off-by: Shane Smith <shane.smith@dreamworks.com>
1 parent 0ceac85 commit 3ec0b8a

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed

src/jpegxl.imageio/jxlinput.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,15 @@ JxlInput::open(const std::string& name, ImageSpec& newspec)
383383
if (have_color_encoding && color_encoding.primaries != JXL_PRIMARIES_CUSTOM
384384
&& color_encoding.white_point != JXL_WHITE_POINT_CUSTOM
385385
&& color_encoding.transfer_function != JXL_TRANSFER_FUNCTION_GAMMA) {
386-
const int cicp[4] = { color_encoding.primaries,
387-
color_encoding.transfer_function, 0 /* RGB */,
388-
1 /* Full range */ };
386+
int color_primaries = color_encoding.primaries;
387+
// JxlPrimaries enum only covers P3 primaries as value 11 and not 12
388+
// but CICP has separate code values based on white point.
389+
if (color_primaries == JXL_PRIMARIES_P3
390+
&& color_encoding.white_point == JXL_WHITE_POINT_D65) {
391+
color_primaries = 12;
392+
}
393+
const int cicp[4] = { color_primaries, color_encoding.transfer_function,
394+
0 /* RGB */, 1 /* Full range */ };
389395
m_spec.attribute("CICP", TypeDesc(TypeDesc::INT, 4), cicp);
390396
const ColorConfig& colorconfig(ColorConfig::default_colorconfig());
391397
string_view interop_id = colorconfig.get_color_interop_id(cicp);

src/jpegxl.imageio/jxloutput.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,18 @@ JxlOutput::save_image(const void* data)
571571
// primaries and white point are not currently used but could help
572572
// support more CICP codes.
573573
JxlColorEncoding color_encoding {};
574-
color_encoding.primaries = JxlPrimaries(cicp[0]);
574+
color_encoding.primaries = JxlPrimaries(cicp[0]);
575+
// CICP primaries 11 and 12 both represent P3, but with different white points.
576+
if (cicp[0] == 11) {
577+
color_encoding.white_point = JXL_WHITE_POINT_DCI;
578+
}
579+
// JxlPrimaries enum only covers P3 primaries as value 11 and not 12.
580+
else if (cicp[0] == 12) {
581+
color_encoding.primaries = JXL_PRIMARIES_P3;
582+
color_encoding.white_point = JXL_WHITE_POINT_D65;
583+
} else {
584+
color_encoding.white_point = JXL_WHITE_POINT_D65;
585+
}
575586
color_encoding.transfer_function = JxlTransferFunction(cicp[1]);
576587
color_encoding.color_space = JXL_COLOR_SPACE_RGB;
577588

@@ -581,10 +592,7 @@ JxlOutput::save_image(const void* data)
581592
switch (color_encoding.primaries) {
582593
case JXL_PRIMARIES_SRGB:
583594
case JXL_PRIMARIES_2100:
584-
case JXL_PRIMARIES_P3:
585-
supported_primaries = true;
586-
color_encoding.white_point = JXL_WHITE_POINT_D65;
587-
break;
595+
case JXL_PRIMARIES_P3: supported_primaries = true; break;
588596
case JXL_PRIMARIES_CUSTOM: // Not an actual CICP code in JXL
589597
break;
590598
}

testsuite/jxl/ref/out.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,48 @@ tahoe-cicp-pq.jxl : 128 x 96, 3 channel, uint8 jpegxl
4242
ICCProfile:profile_version: "4.4.0"
4343
ICCProfile:rendering_intent: "Perceptual"
4444
oiio:ColorSpace: "pq_rec2020_display"
45+
Reading tahoe-cicp-dcip3.jxl
46+
tahoe-cicp-dcip3.jxl : 128 x 96, 3 channel, uint8 jpegxl
47+
SHA-1: 069F1A3E5567349C2D34E535B29913029EF1B09C
48+
channel list: R, G, B
49+
CICP: 11, 17, 0, 1
50+
ICCProfile: 0, 0, 2, 24, 106, 120, 108, 32, 4, 64, 0, 0, 109, 110, 116, 114, ... [536 x uint8]
51+
ICCProfile:attributes: "Reflective, Glossy, Positive, Color"
52+
ICCProfile:cmm_type: 1786276896
53+
ICCProfile:color_space: "RGB"
54+
ICCProfile:copyright: "CC0"
55+
ICCProfile:creation_date: "2019:12:01 00:00:00"
56+
ICCProfile:creator_signature: "6a786c20"
57+
ICCProfile:device_class: "Display device profile"
58+
ICCProfile:flags: "Not Embedded, Independent"
59+
ICCProfile:manufacturer: "0"
60+
ICCProfile:model: "0"
61+
ICCProfile:platform_signature: "Apple Computer, Inc."
62+
ICCProfile:profile_connection_space: "XYZ"
63+
ICCProfile:profile_description: "RGB_DCI_DCI_Per_DCI"
64+
ICCProfile:profile_size: 536
65+
ICCProfile:profile_version: "4.4.0"
66+
ICCProfile:rendering_intent: "Perceptual"
67+
Reading tahoe-cicp-displayp3.jxl
68+
tahoe-cicp-displayp3.jxl : 128 x 96, 3 channel, uint8 jpegxl
69+
SHA-1: 069F1A3E5567349C2D34E535B29913029EF1B09C
70+
channel list: R, G, B
71+
CICP: 12, 13, 0, 1
72+
ICCProfile: 0, 0, 2, 4, 106, 120, 108, 32, 4, 64, 0, 0, 109, 110, 116, 114, ... [516 x uint8]
73+
ICCProfile:attributes: "Reflective, Glossy, Positive, Color"
74+
ICCProfile:cmm_type: 1786276896
75+
ICCProfile:color_space: "RGB"
76+
ICCProfile:copyright: "CC0"
77+
ICCProfile:creation_date: "2019:12:01 00:00:00"
78+
ICCProfile:creator_signature: "6a786c20"
79+
ICCProfile:device_class: "Display device profile"
80+
ICCProfile:flags: "Not Embedded, Independent"
81+
ICCProfile:manufacturer: "0"
82+
ICCProfile:model: "0"
83+
ICCProfile:platform_signature: "Apple Computer, Inc."
84+
ICCProfile:profile_connection_space: "XYZ"
85+
ICCProfile:profile_description: "DisplayP3"
86+
ICCProfile:profile_size: 516
87+
ICCProfile:profile_version: "4.4.0"
88+
ICCProfile:rendering_intent: "Perceptual"
89+
oiio:ColorSpace: "srgb_p3d65_scene"

testsuite/jxl/run.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
command += oiiotool ("../common/tahoe-tiny.tif --cicp \"9,16,9,1\" -o tahoe-cicp-pq.jxl")
1414
command += info_command ("tahoe-cicp-pq.jxl", safematch=True)
1515

16+
command += oiiotool ("../common/tahoe-tiny.tif --cicp \"11,17,0,1\" -o tahoe-cicp-dcip3.jxl")
17+
command += info_command ("tahoe-cicp-dcip3.jxl", safematch=True)
18+
19+
command += oiiotool ("../common/tahoe-tiny.tif --cicp \"12,13,0,1\" -o tahoe-cicp-displayp3.jxl")
20+
command += info_command ("tahoe-cicp-displayp3.jxl", safematch=True)
21+
1622
outputs = [
1723
"test-jxl.icc",
1824
"out.txt"

0 commit comments

Comments
 (0)