Skip to content

Commit 0d08cb4

Browse files
committed
Refactor so we remember we are already doing the p, a, b, u optimization
1 parent 0634dbd commit 0d08cb4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

coloraide/spaces/cam16_jmh.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,22 @@ def xyz_d65_to_cam16(xyzd65: Vector, env: Environment, calc_hue_quadrature: bool
283283
env.fl
284284
)
285285

286-
# Calculate hue from red-green and yellow-blue components
286+
p1 = 2 * rgb_a[0] + rgb_a[1] + 0.05 * rgb_a[2]
287287
a = rgb_a[0] + (-12 * rgb_a[1] + rgb_a[2]) / 11
288288
b = (rgb_a[0] + rgb_a[1] - 2 * rgb_a[2]) / 9
289+
u = rgb_a[0] + rgb_a[1] + 1.05 * rgb_a[2]
290+
291+
# Calculate hue from red-green and yellow-blue components
289292
h_rad = math.atan2(b, a) % math.tau
290293

291294
# Eccentricity
292295
et = 0.25 * (math.cos(h_rad + 2) + 3.8)
293296

294-
t = (
295-
5e4 / 13 * env.nc * env.ncb *
296-
alg.zdiv(et * math.sqrt(a ** 2 + b ** 2), rgb_a[0] + rgb_a[1] + 1.05 * rgb_a[2] + 0.305)
297-
)
297+
t = 5e4 / 13 * env.nc * env.ncb * alg.zdiv(et * math.hypot(a, b), u + 0.305)
298298
alpha = alg.spow(t, 0.9) * math.pow(1.64 - math.pow(0.29, env.n), 0.73)
299299

300300
# Achromatic response
301-
A = env.nbb * (2 * rgb_a[0] + rgb_a[1] + 0.05 * rgb_a[2])
301+
A = env.nbb * p1
302302

303303
J_root = alg.spow(A / env.a_w, 0.5 * env.c * env.z)
304304

0 commit comments

Comments
 (0)