Skip to content

Commit

Permalink
Fix JzAzBz to XYZ conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
danburzo committed Aug 16, 2020
1 parent 0d37e2c commit 0c38577
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/jab/convertJabToXyz65.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ const rel = v => v / 203;
export default ({ j, a, b, alpha }) => {
let i = (j + d0) / (0.44 + 0.56 * (j + d0));

let l = pq_inv(i + 0.138605 * a + 0.0580473 * b);
let m = pq_inv(i - 0.138605 * a - 0.0580473 * b);
let s = pq_inv(i - 0.0960192 * a - 0.811892 * b);

let xp = 1.92423 * l - 1.00479 * m + 0.0376514 * s;
let yp = 0.350317 * l + 0.726481 * m - 0.0653844 * s;
let z = -0.0909828 * l - 0.312728 * m + 1.52277 * s;
let l = pq_inv(i + 0.13860504 * a + 0.058047316 * b);
let m = pq_inv(i - 0.13860504 * a - 0.058047316 * b);
let s = pq_inv(i - 0.096019242 * a - 0.8118919 * b);

let res = {
mode: 'xyz65',
x: rel((xp + 0.15 * z) / 1.15),
y: rel((yp - 0.34 * x) / 0.66),
z: rel(z)
x: rel(
1.661373024652174 * l -
0.914523081304348 * m +
0.23136208173913045 * s
),
y: rel(
-0.3250758611844533 * l +
1.571847026732543 * m -
0.21825383453227928 * s
),
z: rel(-0.090982811 * l - 0.31272829 * m + 1.5227666 * s)
};

if (alpha !== undefined) {
Expand Down
7 changes: 6 additions & 1 deletion test/jab.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tape from 'tape';
import { jab, xyz, xyz65, mapper } from '../src/index';
import { jab, formatHex } from '../src/index';

tape('jab', t => {
t.deepEqual(
Expand All @@ -26,3 +26,8 @@ tape('jab', t => {
);
t.end();
});

tape('rgb -> jab -> rgb', t => {
t.equal(formatHex(jab('#cc3302')), '#cc3302', '#cc3302');
t.end();
});

0 comments on commit 0c38577

Please sign in to comment.