Browse Source

LibGfx/ICC: Improve XYZ coordinates of gray colors

In XYZ space, gray doesn't have three equal values. Instead, it is
a line through the whitepoint.

(Multiplying by the whitepoint has the same effect as multiplying
the sRGB matrix with a (g, g, g) vector, since the numbers on
the matrix's rows add up to the whitepoint.)

Fixes the very slight red tint on all the figures in chapter 4
of the PDF 1.7 spec.
Nico Weber 1 year ago
parent
commit
bcb1e548f1
1 changed files with 2 additions and 1 deletions
  1. 2 1
      Userland/Libraries/LibGfx/ICC/Profile.cpp

+ 2 - 1
Userland/Libraries/LibGfx/ICC/Profile.cpp

@@ -1287,7 +1287,8 @@ ErrorOr<FloatVector3> Profile::to_pcs(ReadonlyBytes color) const
             // ICC v4, F.2 grayTRCTag
             // ICC v4, F.2 grayTRCTag
             // "connection = grayTRC[device]"
             // "connection = grayTRC[device]"
             float gray = evaluate_curve(grayTRCTag, color[0] / 255.f);
             float gray = evaluate_curve(grayTRCTag, color[0] / 255.f);
-            return FloatVector3 { gray, gray, gray };
+            FloatVector3 white { pcs_illuminant().X, pcs_illuminant().Y, pcs_illuminant().Z };
+            return white * gray;
         }
         }
 
 
         // FIXME: Per ICC v4, A.1 General, this should also handle HLS, HSV, YCbCr.
         // FIXME: Per ICC v4, A.1 General, this should also handle HLS, HSV, YCbCr.