-
Notifications
You must be signed in to change notification settings - Fork 7
Add OKLAB and OKLCH color spaces. #21
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
base: master
Are you sure you want to change the base?
Conversation
Values were taken from the most recent conversion specification packaged with the css color specification level 4.
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.
This is awesome! Thank you for creating this PR!
Could I please also ask you to apply the basic tests that are already implemented in the test suite. You can use the ones defined for CIELab as an example:
- Lab:
Color/Color/tests/Graphics/Color/Space/CIE1976/LABSpec.hs
Lines 17 to 24 in b48f0e0
instance (Elevator e, Random e, Illuminant i) => Arbitrary (Color (LAB (i :: k)) e) where arbitrary = ColorLAB <$> arbitraryElevator <*> arbitraryElevator <*> arbitraryElevator spec :: Spec spec = describe "LAB" $ do colorModelSpec @(LAB 'D65) @Word "LAB" colorSpaceLenientSpec @(LAB 'D65) @Double 1e-10 - And LCH that also checks Lab <-> LCH conversion roundtripping: https://github.com/lehins/Color/blob/master/Color/tests/Graphics/Color/Space/CIE1976/LAB/LCHSpec.hs
Also could you please bump up the version to 0.4.1 and add a changelog entry for this very nice addition?
!l' = 1.0000000000000000 * ll + 0.3963377773761749 * a + 0.2158037573099136 * b | ||
!m' = 1.0000000000000000 * ll - 0.1055613458156586 * a - 0.0638541728258133 * b | ||
!s' = 1.0000000000000000 * ll - 0.0894841775298119 * a - 1.2914855480194092 * b |
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.
Ditto
!l' = 1.0000000000000000 * ll + 0.3963377773761749 * a + 0.2158037573099136 * b | |
!m' = 1.0000000000000000 * ll - 0.1055613458156586 * a - 0.0638541728258133 * b | |
!s' = 1.0000000000000000 * ll - 0.0894841775298119 * a - 1.2914855480194092 * b | |
!l' = ll + 0.3963377773761749 * a + 0.2158037573099136 * b | |
!m' = ll - 0.1055613458156586 * a - 0.0638541728258133 * b | |
!s' = ll - 0.0894841775298119 * a - 1.2914855480194092 * b |
!l' = 1.0000000000000000 * ll + 0.3963377773761749 * a + 0.2158037573099136 * b | ||
!m' = 1.0000000000000000 * ll - 0.1055613458156586 * a - 0.0638541728258133 * b | ||
!s' = 1.0000000000000000 * ll - 0.0894841775298119 * a - 1.2914855480194092 * b |
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.
Multiplication by 1 is superfluous.
!l' = 1.0000000000000000 * ll + 0.3963377773761749 * a + 0.2158037573099136 * b | |
!m' = 1.0000000000000000 * ll - 0.1055613458156586 * a - 0.0638541728258133 * b | |
!s' = 1.0000000000000000 * ll - 0.0894841775298119 * a - 1.2914855480194092 * b | |
!l' = ll + 0.3963377773761749 * a + 0.2158037573099136 * b | |
!m' = ll - 0.1055613458156586 * a - 0.0638541728258133 * b | |
!s' = ll - 0.0894841775298119 * a - 1.2914855480194092 * b |
The only reason why multiplication by 1 is done in the css color spec, is because they define the matrix and then use matrix multiplication functionality.
if x < 0 | ||
then -((-x) ** (1 / 3)) | ||
else x ** (1 / 3) | ||
|
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.
It is important to inline such function, otherwise it will destroy the performance if GHC fails to inline it.
{-# INLINE signedCubeRoot #-} | |
-------------- | ||
|
||
-- | [OK L*a*b*](https://bottosson.github.io/posts/oklab/) color space | ||
data OKLAB |
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.
data OKLAB | |
-- | |
-- Values for matrices used in conversion to and from @CIEXYZ@ where taken from [W3 CSS specification](https://www.w3.org/TR/css-color-4/#color-conversion-code) instead of the original blogpost about the OKLab color space. | |
data OKLAB |
Values were taken from the most recent conversion specification packaged with the css color specification level 4.
Resolves #15