Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calc more accurate inverse matrices for cat and pre-calc D50 <-> D65 #354

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 89 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"core-js": "^3.30.1",
"eslint": "latest",
"htest.dev": "^0.0.8",
"mathjs": "^12.1.0",
"postcss": "latest",
"postcss-cli": "latest",
"postcss-nesting": "latest",
Expand Down
50 changes: 50 additions & 0 deletions scripts/cat-mat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { create, all } from 'mathjs'
const config = {}
const math = create(all, config)

const d50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585]
const d65 = [0.3127 / 0.3290, 1.00000, (1.0 - 0.3127 - 0.3290) / 0.3290]

const bradford = [
[0.8951000, 0.2664000, -0.1614000],
[-0.7502000, 1.7135000, 0.0367000],
[0.0389000, -0.0685000, 1.0296000]
]

const von_kries = [
[0.4002400, 0.7076000, -0.0808100],
[-0.2263000, 1.1653200, 0.0457000],
[0.0000000, 0.0000000, 0.9182200]
]

const cat02 = [
[0.7328000, 0.4296000, -0.1624000],
[-0.7036000, 1.6975000, 0.0061000],
[0.0030000, 0.0136000, 0.9834000]
]

const cat16 = [
[ 0.401288, 0.650173, -0.051461 ],
[ -0.250268, 1.204414, 0.045854 ],
[ -0.002079, 0.048952, 0.953127 ]
]

console.log('===== bradford =====')
console.log(bradford)
console.log('===== bradford inverse =====')
console.log(math.inv(bradford))

console.log('===== von kries =====')
console.log(von_kries)
console.log('===== von kries inverse =====')
console.log(math.inv(von_kries))

console.log('===== cat02 =====')
console.log(cat02)
console.log('===== cat02 inverse =====')
console.log(math.inv(cat02))

console.log('===== cat16 =====')
console.log(cat16)
console.log('===== cat16 inverse =====')
console.log(math.inv(cat16))
24 changes: 12 additions & 12 deletions src/CATs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ defineCAT({
[ 0.0000000, 0.0000000, 0.9182200 ]
],
fromCone_M: [
[ 1.8599364, -1.1293816, 0.2198974 ],
[ 0.3611914, 0.6388125, -0.0000064 ],
[ 0.0000000, 0.0000000, 1.0890636 ]
[ 1.8599363874558397, -1.1293816185800916, 0.21989740959619328 ],
[ 0.3611914362417676, 0.6388124632850422, -0.000006370596838649899 ],
[ 0, 0, 1.0890636230968613 ]
]
});

Expand All @@ -70,9 +70,9 @@ defineCAT({
],
// and back
fromCone_M: [
[ 0.9869929, -0.1470543, 0.1599627 ],
[ 0.4323053, 0.5183603, 0.0492912 ],
[ -0.0085287, 0.0400428, 0.9684867 ]
[ 0.9869929054667121, -0.14705425642099013, 0.15996265166373122 ],
[ 0.4323052697233945, 0.5183602715367774, 0.049291228212855594 ],
[ -0.00852866457517732, 0.04004282165408486, 0.96848669578755 ]
]
});

Expand All @@ -85,9 +85,9 @@ defineCAT({
[ 0.0030000, 0.0136000, 0.9834000 ]
],
fromCone_M: [
[ 1.0961238, -0.2788690, 0.1827452 ],
[ 0.4543690, 0.4735332, 0.0720978 ],
[ -0.0096276, -0.0056980, 1.0153256 ]
[ 1.0961238208355142, -0.27886900021828726, 0.18274517938277307 ],
[ 0.4543690419753592, 0.4735331543074117, 0.07209780371722911 ],
[ -0.009627608738429355, -0.00569803121611342, 1.0153256399545427 ]
]
});

Expand All @@ -100,9 +100,9 @@ defineCAT({
],
// the extra precision is needed to avoid roundtripping errors
fromCone_M: [
[ 1.862067855087233e+0, -1.011254630531685e+0, 1.491867754444518e-1 ],
[ 3.875265432361372e-1, 6.214474419314753e-1, -8.973985167612518e-3 ],
[ -1.584149884933386e-2, -3.412293802851557e-2, 1.049964436877850e+0 ]
[ 1.862067855087233, -1.0112546305316845, 0.14918677544445172 ],
[ 0.3875265432361372, 0.6214474419314753, -0.008973985167612521 ],
[ -0.01584149884933386, -0.03412293802851557, 1.0499644368778496 ]
]
});

Expand Down
12 changes: 6 additions & 6 deletions src/adapt.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ export default function adapt (W1, W2, XYZ, options = {}) {
if (!env.M) {
if (env.W1 === WHITES.D65 && env.W2 === WHITES.D50) {
env.M = [
[ 1.0479298208405488, 0.022946793341019088, -0.05019222954313557 ],
[ 0.029627815688159344, 0.990434484573249, -0.01707382502938514 ],
[ -0.009243058152591178, 0.015055144896577895, 0.7518742899580008 ]
[ 1.0479297925449969, 0.022946870601609652, -0.05019226628920524 ],
[ 0.02962780877005599, 0.9904344267538799, -0.017073799063418826 ],
[ -0.009243040646204504, 0.015055191490298152, 0.7518742814281371 ]
];
}
else if (env.W1 === WHITES.D50 && env.W2 === WHITES.D65) {

env.M = [
[ 0.9554734527042182, -0.023098536874261423, 0.0632593086610217 ],
[ -0.028369706963208136, 1.0099954580058226, 0.021041398966943008 ],
[ 0.012314001688319899, -0.020507696433477912, 1.3303659366080753 ]
[ 0.947386632323667, 0.28196156725620036, -0.1708280666484637 ],
[ -0.7357288996314816, 1.6804471734451398, 0.035992069603406264 ],
[ 0.029218329379919382, -0.05145129980782719, 0.7733468362356041 ]
Comment on lines -47 to +49

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are very different values.

The other changes seem to be the same value at higher precision, but this one is completely different.

Is this correct?

When we use these values in postcss-preset-env it dramatically changes the color results.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romainmenke great catch! Accidentally copied in the adapted M cone response as the inverse. I have a fix here: #360. This one copies the correct matrix, directly calculated by color.js when a D50 <-> D65 conversion occurs.

];
}
}
Expand Down