From efabfd4c66b932e65fde7c07e7f50d7734b4b68a Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 5 Mar 2023 11:28:21 -0500 Subject: [PATCH] LibGfx: Fill in remaining values in built-in sRGB profile The values aren't 100% self-consistent, but it probably doesn't make a difference for u8 color data. Good enough for now. See all the links on #17714 for some more background. --- .../LibGfx/ICC/WellKnownProfiles.cpp | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.cpp b/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.cpp index 389c40c7b7..7b420b530a 100644 --- a/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.cpp +++ b/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.cpp @@ -43,7 +43,7 @@ ErrorOr> sRGB() // Returns an sRGB profile. // https://en.wikipedia.org/wiki/SRGB - // FIXME: There's a surprising amount of variety in sRGB ICC profiles in the wild. + // FIXME: There are many different sRGB ICC profiles in the wild. // Explain why, and why this picks the numbers it does. auto header = rgb_header(); @@ -61,16 +61,23 @@ ErrorOr> sRGB() TRY(tag_table.try_set(greenTRCTag, curve)); TRY(tag_table.try_set(blueTRCTag, curve)); - // Chromatic adaptation matrix, chromacities and whitepoint. - // FIXME: Actual values for chromatic adaptation matrix and chromacities. - TRY(tag_table.try_set(mediaWhitePointTag, TRY(XYZ_data(XYZ { 0, 0, 0 })))); - TRY(tag_table.try_set(redMatrixColumnTag, TRY(XYZ_data(XYZ { 0, 0, 0 })))); - TRY(tag_table.try_set(greenMatrixColumnTag, TRY(XYZ_data(XYZ { 0, 0, 0 })))); - TRY(tag_table.try_set(blueMatrixColumnTag, TRY(XYZ_data(XYZ { 0, 0, 0 })))); + // White point. + // ICC v4, 9.2.36 mediaWhitePointTag: " For displays, the values specified shall be those of the PCS illuminant as defined in 7.2.16." + TRY(tag_table.try_set(mediaWhitePointTag, TRY(XYZ_data(header.pcs_illuminant)))); - Vector chromatic_adaptation_matrix = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + // The chromatic_adaptation_matrix values are from https://www.color.org/chadtag.xalter + // That leads to exactly the S15Fixed16 values in the sRGB profiles in GIMP, Android, RawTherapee (but not in Compact-ICC-Profiles's v4 sRGB profile). + Vector chromatic_adaptation_matrix = { 1.047882, 0.022918, -0.050217, 0.029586, 0.990478, -0.017075, -0.009247, 0.015075, 0.751678 }; TRY(tag_table.try_set(chromaticAdaptationTag, TRY(try_make_ref_counted(0, 0, move(chromatic_adaptation_matrix))))); + // The chromaticity values are from https://www.color.org/srgb.pdf + // The chromatic adaptation matrix in that document is slightly different from the one on https://www.color.org/chadtag.xalter, + // so the values in our sRGB profile are currently not fully self-consistent. + // FIXME: Make values self-consistent (probably by using slightly different chromaticities). + TRY(tag_table.try_set(redMatrixColumnTag, TRY(XYZ_data(XYZ { 0.436030342570117, 0.222438466210245, 0.013897440074263 })))); + TRY(tag_table.try_set(greenMatrixColumnTag, TRY(XYZ_data(XYZ { 0.385101860087134, 0.716942745571917, 0.097076381494207 })))); + TRY(tag_table.try_set(blueMatrixColumnTag, TRY(XYZ_data(XYZ { 0.143067806654203, 0.060618777416563, 0.713926257896652 })))); + return Profile::create(header, move(tag_table)); }