-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import ColorSpace from "../space.js"; | ||
import OKLab from "./oklab.js"; | ||
import {toe, toeInv} from "./okhsl.js"; | ||
|
||
export default new ColorSpace({ | ||
id: "oklrab", | ||
name: "Oklrab", | ||
coords: { | ||
l: { | ||
refRange: [0, 1], | ||
name: "Lightness", | ||
}, | ||
a: { | ||
refRange: [-0.4, 0.4], | ||
}, | ||
b: { | ||
refRange: [-0.4, 0.4], | ||
}, | ||
}, | ||
|
||
// Note that XYZ is relative to D65 | ||
white: "D65", | ||
base: OKLab, | ||
fromBase (oklab) { | ||
return [toe(oklab[0]), oklab[1], oklab[2]]; | ||
}, | ||
toBase (oklrab) { | ||
return [toeInv(oklrab[0]), oklrab[1], oklrab[2]]; | ||
}, | ||
|
||
formats: { | ||
"color": { | ||
coords: ["<percentage> | <number>", "<number> | <percentage>[-1,1]", "<number> | <percentage>[-1,1]"], | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import ColorSpace from "../space.js"; | ||
import OKLrab from "./oklrab.js"; | ||
import {toe, toeInv} from "./okhsl.js"; | ||
import {constrain as constrainAngle} from "../angles.js"; | ||
import {isNone} from "../util.js"; | ||
|
||
export default new ColorSpace({ | ||
id: "oklrch", | ||
name: "Oklrch", | ||
coords: { | ||
l: { | ||
refRange: [0, 1], | ||
name: "Lightness", | ||
}, | ||
c: { | ||
refRange: [0, 0.4], | ||
name: "Chroma", | ||
}, | ||
h: { | ||
refRange: [0, 360], | ||
type: "angle", | ||
name: "Hue", | ||
}, | ||
}, | ||
white: "D65", | ||
|
||
base: OKLrab, | ||
fromBase (oklab) { | ||
// Convert to polar form | ||
let [L, a, b] = oklab; | ||
let h; | ||
const ε = 0.0002; // chromatic components much smaller than a,b | ||
|
||
if (Math.abs(a) < ε && Math.abs(b) < ε) { | ||
h = NaN; | ||
} | ||
else { | ||
h = Math.atan2(b, a) * 180 / Math.PI; | ||
} | ||
|
||
return [ | ||
L, // OKLab L is still L | ||
Math.sqrt(a ** 2 + b ** 2), // Chroma | ||
constrainAngle(h), // Hue, in degrees [0 to 360) | ||
]; | ||
}, | ||
// Convert from polar form | ||
toBase (oklch) { | ||
let [L, C, h] = oklch; | ||
let a, b; | ||
|
||
// check for NaN hue | ||
if (isNone(h)) { | ||
a = 0; | ||
b = 0; | ||
} | ||
else { | ||
a = C * Math.cos(h * Math.PI / 180); | ||
b = C * Math.sin(h * Math.PI / 180); | ||
} | ||
|
||
return [ L, a, b ]; | ||
}, | ||
|
||
formats: { | ||
"color": { | ||
coords: ["<percentage> | <number>", "<number> | <percentage>[0,1]", "<number> | <angle>"], | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ColorSpace from "../space.js"; | ||
declare const _default: ColorSpace; | ||
export default _default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ColorSpace from "../space.js"; | ||
declare const _default: ColorSpace; | ||
export default _default; |