From 84e67c3f00cc4861141b566b6943917c59e116db Mon Sep 17 00:00:00 2001 From: facelessuser Date: Tue, 12 Sep 2023 07:10:02 -0600 Subject: [PATCH] Update some links and clean up comments Also, bring back appendix D math shortcut `fy ** 3 if l > KE else l / KAPPA` is functionally equivalent to `fy ** 3 if fy > EPSILON3 else (116 * fy - 16) / KAPPA`, it just saves us from doing redundant math and is what is recommended in appendix D and the example used by Bruce Lindbloom. I admit the second approach is less confusing, but the first is more efficient. We briefly considered the more intuitive approach over the efficient approach and have decided we will stick with efficient. --- coloraide/spaces/lab/__init__.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/coloraide/spaces/lab/__init__.py b/coloraide/spaces/lab/__init__.py index b15ec9d5a..e78c2834a 100644 --- a/coloraide/spaces/lab/__init__.py +++ b/coloraide/spaces/lab/__init__.py @@ -1,4 +1,9 @@ -"""Lab class.""" +""" +Lab class. + +https://ia802802.us.archive.org/23/items/gov.law.cie.15.2004/cie.15.2004.pdf +http://www.brucelindbloom.com/Eqn_Lab_to_XYZ.html +""" from __future__ import annotations from ...spaces import Space, Labish from ...cat import WHITES @@ -15,14 +20,7 @@ def lab_to_xyz(lab: Vector, white: VectorLike) -> Vector: - """ - Convert Lab to D50-adapted XYZ. - - http://www.brucelindbloom.com/Eqn_Lab_to_XYZ.html - - While the derivation is different than the specification, the results are the same as Appendix D: - https://www.cdvplus.cz/file/3-publikace-cie15-2004/ - """ + """Convert CIE Lab to XYZ using the reference white.""" l, a, b = lab @@ -34,7 +32,7 @@ def lab_to_xyz(lab: Vector, white: VectorLike) -> Vector: # compute `xyz` xyz = [ fx ** 3 if fx > EPSILON3 else (116 * fx - 16) / KAPPA, - fy ** 3 if fy > EPSILON3 else (116 * fy - 16) / KAPPA, + fy ** 3 if l > KE else l / KAPPA, fz ** 3 if fz > EPSILON3 else (116 * fz - 16) / KAPPA ] @@ -43,14 +41,7 @@ def lab_to_xyz(lab: Vector, white: VectorLike) -> Vector: def xyz_to_lab(xyz: Vector, white: VectorLike) -> Vector: - """ - Assuming XYZ is relative to D50, convert to CIELab from CIE standard. - - http://www.brucelindbloom.com/Eqn_XYZ_to_Lab.html - - While the derivation is different than the specification, the results are the same: - https://www.cdvplus.cz/file/3-publikace-cie15-2004/ - """ + """Convert XYZ to CIE Lab using the reference white.""" # compute `xyz`, which is XYZ scaled relative to reference white xyz = alg.divide(xyz, white, dims=alg.D1)