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

[deltaE] Speedup of 7th powers in DeltaE2000 #340

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/deltaE/deltaE2000.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const π = Math.PI;
const r2d = 180 / π;
const d2r = π / 180;

function pow7 (x) {
// Faster than x ** 7 or Math.pow(x, 7)

const x2 = x * x;
const x7 = x2 * x2 * x2 * x;

return x7;
}

export default function (color, sample, {kL = 1, kC = 1, kH = 1} = {}) {
// Given this color as the reference
// and the function parameter as the sample,
Expand Down Expand Up @@ -46,7 +55,7 @@ export default function (color, sample, {kL = 1, kC = 1, kH = 1} = {}) {

// calculate a-axis asymmetry factor from mean Chroma
// this turns JND ellipses for near-neutral colors back into circles
let C7 = Cbar ** 7;
let C7 = pow7(Cbar);

let G = 0.5 * (1 - Math.sqrt(C7/(C7 + Gfactor)));

Expand Down Expand Up @@ -107,7 +116,7 @@ export default function (color, sample, {kL = 1, kC = 1, kH = 1} = {}) {
// calculate mean Lightness and Chroma
let Ldash = (L1 + L2)/2;
let Cdash = (Cdash1 + Cdash2)/2;
let Cdash7 = Math.pow(Cdash, 7);
let Cdash7 = pow7(Cdash);

// Compensate for non-linearity in the blue region of Lab.
// Four possibilities for hue weighting factor,
Expand Down