use proper colorspace for color operations
cannot lighten black
0 * (1 + y) == 0
https://github.com/david-vanderson/dvui/blob/811e8d93f9f55c0a16d18d45e61a2db646198b52/src/Color.zig#L28-L35
Yep you are right. Do you know what we should be doing here? My guess is that we need some colorspace conversion functions (cielab?) so that lighten/darken use that. Do you know which we should use?
CIELUV.
https://www.hsluv.org/ https://www.kuon.ch/post/2020-03-08-hsluv/ https://gist.github.com/denis-bz/ec601823dc52666812a3e27b88772a84
I vaguely remember porting the conversion code between sRGB and HSLuv from d3.js (Javascript) to Rust or C, but I cannot find the code. I can port the code again when I have time.
What rendering API do we even use? OpenGL? We need control over colorspace so the color displayed is accurate.
Excellent - thanks for that. As for rendering API, for the SDL backend we use SDL_RenderGeometryRaw and I haven't dug into it to figure out what's going on with colorspaces. For the mach backend (which I will make work again at some point), it uses webgpu with some shaders I wrote, but again I haven't thought about colorspaces yet.
I think a great step would be to have conversion code so that we have nicer darken/lighten functions. Thank you!
I have ported ok_color.h to C. -> branch ok_color
This branch can't build because the color space conversion code is used at compile time. Can't call into C code at compile time. Build this branch and you will understand.
I have also attempted to translate it to Zig, but it's difficult so I gave up. -> branch ok_color_zig
I think eventually zig translate-c will get good enough that this becomes automatic.
right now i give up
Thanks very much. I really appreciate you taking the time to dig into this. I will pick up where you left off soon and see if I can make progress.
One idea is to generate the palette at the start of run-time instead of at compile-time. You can do this in dvui.init().
Edit: I forgot to push the ok_color branch to this repo... I have done it now.
I can't #68. Either zig c-translate produced invalid code, or the original algorithm is buggy.
Hopefully dvui won't need Okhsl, ever.
I was finally able to hand-convert hsluv.c to zig. The adwaita theme code is specifying colors using it, and the demo window (under styling) has HSLuv sliders.
This is just a start and I'm unsure what the path forward is, but being able to convert to HSLuv and back (HPLuv is also implemented) is a big improvement from where we were.
Thanks for the help here!
~~Where did you get hsluv.c? If it's the ok_color branch, that's by me (I ported it from C++ to C).~~
It seems to be from https://github.com/hsluv/hsluv-c/blob/master/src/hsluv.c.
That's right. It looked the easiest to port and had test data.
Is this issue done now?
I think so. Likely there will be follow-on stuff regarding more colorspace stuff, but this is a good start. Thanks!