-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Introduce color interpolation based on the LAB color-space #6782
base: main
Are you sure you want to change the base?
Conversation
@tjzel @piaskowyk would appreciate a go/no-go on this |
Hey @d4vidi, thanks for your contribution! This looks interesting and I see no reason not to add this to Reanimated. We'll circle back to it once we start preparing 3.17.0 release. |
Super, thanks. I'm @d4vidi, BTW 😅 |
Haha, sorry, I'm used to doing @ and the first letter to get the OPs name, no idea where devjs1000 came from 🤭 |
What do you mean by include the culori library? We don't want to add any external dependencies to Reanimated if that's what you meant. |
It's cool, I often make the same mistake
I technically ripped code off the culori library in order to convert between the LAB <--> sRGB color spaces. Ideally, I'd like to be able to use the actual library itself, as a node module. |
Unfortunately we don't have any production-ready methods to workletize full libraries. |
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.
Hi! Firstly, thanks for your contribution, it's really nice and a pretty interesting feature c:
Moving on to the review, I'd be grateful if you'd comment code in the documentation related to this feature. Please mark it with a - preferably TODO - comment explaining that it would be uncommented when Reanimated including this feature comes out. I'll take care of upgrading Reanimated version in the docs and uncommenting this portion when it'll be available.
As of culori
being a dependency - I strongly support what @tjzel said, we are not able to workletize full libraries yet, and culori
adding and maintaining workletization of their important functions is probably a no-go. As I checked, your approach to rewriting needed functions to worklets is fine - they seem easy to maintain and we focus only on portions of the library that we require. Please include culori
MIT license requests in the code as I mentioned in a review comment.
...cs-reanimated/src/components/InteractivePlayground/useInterpolateColorPlayground/Example.tsx
Outdated
Show resolved
Hide resolved
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.
Few more adjustments ✨
.../InteractivePlayground/useInterpolateColorPlayground/ColorProgressBar/ProgressBarSection.tsx
Outdated
Show resolved
Hide resolved
...cs-reanimated/src/components/InteractivePlayground/useInterpolateColorPlayground/Example.tsx
Show resolved
Hide resolved
...docs-reanimated/src/components/InteractivePlayground/useInterpolateColorPlayground/index.tsx
Outdated
Show resolved
Hide resolved
@patrycjakalinska So you can say I've pretty much eradicated all mentioning of OKLAB on the docs side; Replaced everything with instructional comments that start with Thanks a lot for all your time and patience! |
Hope to get more comments from you guys/gals 🙏🏻 |
Hi, thanks and sorry for the wait! One thing I noticed that's happening is that when I try to use docs with your react-native-reanimated package with culori, the Docusaurus throws an error. As far as I know and worked with Docusaurus, it could be bug on my side not related to your package as well as full blown bug. Does docs on your side work with reanimated extended with culori package installed? |
All good, it's new years and therefore well understood! |
No, the error rises when you check if your Reanimated package is working with documentation. To check you need to Try to replace
|
@patrycjakalinska ok I think I got it, will test that out. I've previously checked (developed) by replacing the |
Hi @d4vidi, good to hear that, as I suspected Docusaurus is randomly not working on my side c': |
// | ||
// import { converter } from 'culori'; | ||
// | ||
// export default { | ||
// convert: { | ||
// fromRgb: (rgbColor: RgbColor) => converter('oklab')({ | ||
// mode: 'rgb', | ||
// ...rgbColor, | ||
// }), | ||
// toRgb: (labColor: LabColor) => converter('rgb')({ | ||
// mode: 'oklab', | ||
// ...labColor, | ||
// }), | ||
// }, | ||
// }; |
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.
Do we need this portion of code?
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.
Hey, no - we don't. This was meant to explain how to integrate the same functionality assuming culori
could one day be workletized. I can remove it if you consider it unnecessary noise.
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.
I think we can remove it for now c: You can also merge main into your branch and I think we are good to go!
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 news! Should I remove these TODO's altogether or just the code snippet part?
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.
How does this sound as a replacement of the TODO after the code snippet is removed? -
// TODO Once we have the option to workletize external dependencies, we can replace most of the code below with
// a simple implementation based on their converter utils (see
// https://github.com/software-mansion/react-native-reanimated/pull/6782#pullrequestreview-2488830278).
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.
perfect!
Summary
In this PR, I've introduced color interpolation based on the OKLAB color space.
(image credit: ColorAide)
Details
OKLAB is derived from CIELAB - both considered improvements compared to RGB and HSV/L in terms of color gradient computation, as the linear interpolations over their channels results in a smoother experience. That's for 2 reasons:
L*a*b* does often yield results very similar to RGB w/ gamma correction, as in the case of the default colors on the web-site:
Nevertheless, there are some cases where the result can be considered better. Going from red to blue, for example, LAB shows a smoother transition with less intermediate coloring (purple in this case):
Also, in yellow-to-blue, LAB better preserves lightness:
Things to notice
culori
, but had to rip their code off from it (all-the-while keeping the credit). I couldn't use it as-is, because I had no way to specify it's meant for off-loaded execution (i.e. using theworklet
notation). I could definitely use some advice with that by the maintainers ❗LAB
(alongisdeRGB
andHSV
), hiding the implementation details (i.e. the underlying selection of oklab, in particular). I believe that any future offering of other LAB spaces (e.g. CIELAB) could be introduced by allowing for LAB-specificoptions
.Motivation
There are potential screens in the apps we're working on where a smooth color transition could improve the user experience. We're avid users of
reanimated
and would love to be able to incorporate the best experience though it.Test plan
TBD