-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add OkLrab and OkLrCh #511
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import ColorSpace from "../ColorSpace.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]"], | ||
}, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import ColorSpace from "../ColorSpace.js"; | ||
import OKLrab from "./oklrab.js"; | ||
import lch from "./lch.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: lch.fromBase, | ||
toBase: lch.toBase, | ||
|
||
formats: { | ||
"color": { | ||
coords: ["<percentage> | <number>", "<number> | <percentage>[0,1]", "<number> | <angle>"], | ||
}, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,22 +430,78 @@ const tests = { | |
expect: [1.0, 0.0, null], | ||
}, | ||
{ | ||
name: "sRGB red (D65) to OKlab", | ||
name: "sRGB red (D65) to OKlch", | ||
args: "red", | ||
expect: [0.6279553639214311, 0.2576833038053608, 29.23388027962784], | ||
}, | ||
{ | ||
name: "sRGB lime (D65) to OKlab", | ||
name: "sRGB lime (D65) to OKlch", | ||
args: "lime", | ||
expect: [0.8664396175234368, 0.2948272245426958, 142.4953450414439], | ||
}, | ||
{ | ||
name: "sRGB blue (D65) to OKlab", | ||
name: "sRGB blue (D65) to OKlch", | ||
args: "blue", | ||
expect: [0.45201371817442365, 0.3132143886344849, 264.0520226163699], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "OKLrab", | ||
data: { | ||
toSpace: "oklrab", | ||
}, | ||
tests: [ | ||
{ | ||
name: "sRGB white (D65) to OKlrab", | ||
args: "white", | ||
expect: [ 1.0000000000000002, -4.996003610813204e-16, 0 ], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this actually be zero and this is cumulative error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, cumulative floating point error. Oklab in Color.js currently yields that for white, so OkLrab will also yield that for white as OkLrab just applies a toe function to the lightness, and at white, there is no change. > new Color('white').to('oklab').coords
[ 1.0000000000000002, -4.996003610813204e-16, 0 ] Floating point errors can vary slightly depending on how the original matrix was generated, the exact steps and in what order. The invert matrix result can be slightly different (floating point error-wise) depending on exactly how the inversion is performed (did it use LU decomposition, some other way, what order were operations done in, etc). This isn't too different for other Lab-like spaces, especially those that employ more complicated calculations: > new Color('white').to('ictcp').coords
[ 0.5806888810416109, 1.1102230246251565e-16, 2.914335439641036e-16 ] I think my library has slightly different floating point errors. It yields an exact 1 for lightness, but non-zero results for both a and b. >>> Color('white').convert('oklab').coords()
[1.0, -4.996003610813204e-16, 1.1102230246251565e-16] But the same things happen for various other Lab-ish spaces (Y is the lightness in XYB): >>> Color('white').convert('hunter-lab').coords()
[100.0, 1.912989643463523e-14, -7.46260389005987e-15]
>>> Color('white').convert('xyb').coords()
[0.0, 0.8453085619621621, 2.220446049250313e-16] |
||
}, | ||
{ | ||
name: "sRGB red (D65) to OKlrab", | ||
args: "red", | ||
expect: [ 0.5680846563197034, 0.2248630684262744, 0.125846277330585 ], | ||
}, | ||
{ | ||
name: "sRGB lime (D65) to OKlrab", | ||
args: "lime", | ||
expect: [ 0.8445289714936317, -0.23388758093655815, 0.1794984451609376 ], | ||
}, | ||
{ | ||
name: "sRGB blue (D65) to OKlrab", | ||
args: "blue", | ||
expect: [ 0.3665653391870817, -0.03245697517079771, -0.3115281656775778 ], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "OKLrCh", | ||
data: { | ||
toSpace: "oklrch", | ||
}, | ||
tests: [ | ||
{ | ||
name: "sRGB white (D65) to OKlrch", | ||
args: "white", | ||
expect: [1.0, 0.0, null], | ||
}, | ||
{ | ||
name: "sRGB red (D65) to OKlrch", | ||
args: "red", | ||
expect: [0.5680846563197034, 0.2576833038053608, 29.23388027962784], | ||
}, | ||
{ | ||
name: "sRGB lime (D65) to OKlrch", | ||
args: "lime", | ||
expect: [0.8445289714936317, 0.2948272245426958, 142.4953450414439], | ||
}, | ||
{ | ||
name: "sRGB blue (D65) to OKlrch", | ||
args: "blue", | ||
expect: [0.3665653391870817, 0.3132143886344849, 264.0520226163699], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "Linear-light sRGB", | ||
data: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare const _default: ColorSpace; | ||
export default _default; | ||
import ColorSpace from "../ColorSpace.js"; | ||
//# sourceMappingURL=oklrab.d.ts.map |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare const _default: ColorSpace; | ||
export default _default; | ||
import ColorSpace from "../ColorSpace.js"; | ||
//# sourceMappingURL=oklrch.d.ts.map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, yes