From bdd2404453d1ac9093568c94b89ea2d6ea93d750 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 31 Oct 2023 21:03:19 -0400 Subject: [PATCH] LibPDF: Ignore input whitepoint in convert_to_d65() CalRGBColorSpace::color() converts into a flat xyz space, which already takes input whitepoint into account. It shouldn't be taken into account again when converting from the flat color space to D65. --- Userland/Libraries/LibPDF/ColorSpace.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibPDF/ColorSpace.cpp b/Userland/Libraries/LibPDF/ColorSpace.cpp index 6db02ac7e2..3d18e281ff 100644 --- a/Userland/Libraries/LibPDF/ColorSpace.cpp +++ b/Userland/Libraries/LibPDF/ColorSpace.cpp @@ -293,17 +293,13 @@ constexpr Array scale_black_point(Array blackpoint, Array convert_to_d65(Array whitepoint, Array xyz) +constexpr Array convert_to_d65(Array xyz) { constexpr float d65x = 0.95047f; constexpr float d65y = 1.0f; constexpr float d65z = 1.08883f; - return { - (xyz[0] * d65x) / whitepoint[0], - (xyz[1] * d65y) / whitepoint[1], - (xyz[2] * d65z) / whitepoint[2], - }; + return { xyz[0] * d65x, xyz[1] * d65y, xyz[2] * d65z }; } // https://en.wikipedia.org/wiki/SRGB @@ -343,7 +339,7 @@ PDFErrorOr CalRGBColorSpace::color(ReadonlySpan arguments) const auto flattened_xyz = flatten_and_normalize_whitepoint(m_whitepoint, { x, y, z }); auto scaled_black_point_xyz = scale_black_point(m_blackpoint, flattened_xyz); - auto d65_normalized = convert_to_d65(m_whitepoint, scaled_black_point_xyz); + auto d65_normalized = convert_to_d65(scaled_black_point_xyz); auto srgb = convert_to_srgb(d65_normalized); auto red = static_cast(srgb[0] * 255.0f);