Skip to content

Commit 0634dbd

Browse files
committed
Revert: faster to do as separate operations
1 parent 0ab458b commit 0634dbd

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

coloraide/spaces/cam16_jmh.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,12 @@
2222
M16 = CAT16.MATRIX
2323
MI6_INV = alg.inv(M16)
2424

25-
# Calculate `[Ra', Ga', Ba']` from `[P2', a, b]`
2625
M1 = [
2726
[460.0, 451.0, 288.0],
2827
[460.0, -891.0, -261.0],
2928
[460.0, -220.0, -6300.0]
3029
]
3130

32-
# Calculate `[P2' a, b, u]` from `[Ra', Ga', Ba']`
33-
M2 = [
34-
[2.0, 1.0, 1 / 20],
35-
[1.0, -12 / 11, 1 / 11],
36-
[1.0 / 9, 1/9, -2 / 9],
37-
[1.0, 1.0, 21 / 20]
38-
]
39-
4031
ADAPTED_COEF = 0.42
4132
ADAPTED_COEF_INV = 1 / ADAPTED_COEF
4233

@@ -270,7 +261,7 @@ def cam16_to_xyz_d65(
270261
# Calculate red-green and yellow-blue components
271262
p1 = 5e4 / 13 * env.nc * env.ncb * et
272263
p2 = A / env.nbb
273-
r = alg.zdiv(23 * (p2 + 0.305) * t, 23 * p1 + t * (11 * cos_h + 108 * sin_h))
264+
r = 23 * (p2 + 0.305) * alg.zdiv(t, 23 * p1 + t * (11 * cos_h + 108 * sin_h))
274265
a = r * cos_h
275266
b = r * sin_h
276267

@@ -292,19 +283,22 @@ def xyz_d65_to_cam16(xyzd65: Vector, env: Environment, calc_hue_quadrature: bool
292283
env.fl
293284
)
294285

295-
p1, a, b, u = alg.matmul(M2, rgb_a, dims=alg.D2_D1)
296-
297286
# Calculate hue from red-green and yellow-blue components
287+
a = rgb_a[0] + (-12 * rgb_a[1] + rgb_a[2]) / 11
288+
b = (rgb_a[0] + rgb_a[1] - 2 * rgb_a[2]) / 9
298289
h_rad = math.atan2(b, a) % math.tau
299290

300291
# Eccentricity
301292
et = 0.25 * (math.cos(h_rad + 2) + 3.8)
302293

303-
t = 5e4 / 13 * env.nc * env.ncb * alg.zdiv(et * math.hypot(a, b), u + 0.305)
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+
)
304298
alpha = alg.spow(t, 0.9) * math.pow(1.64 - math.pow(0.29, env.n), 0.73)
305299

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

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

0 commit comments

Comments
 (0)