Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 973

Utilities and Tools • Lua for Oklch

$
0
0
Yincognito, thank you for your comment.

It is me who was surprised. Your code is very short! Just looking at HSV-RGB and HSL-RGB conversions, yours is much more compact than mine. It seems that you made use of the results of other conversions in a clever way. To be honest though, it is too sophisticated for me to imitate. :lol:

As you said, Oklch conversion looks rather simple in terms of the algorithm. But it's not, because there is a thing which is not written in the Wikipedia, which we cannot dance around to manipulate Oklch colors.

Let me explain it. Oklch color space has a complex shape which resembles that of the Munsell color system.

20250326 15010301.png
Source

Therefore, colors often fall out of the gamut when you shift their hue while keeping their chroma and lightness constant like the color circle in my skin does. The same applies when you change chorma or lightness. The RGB values of those "out-of-gamut" colors go below zero or exceed 255. Simply clipping the values at zero or 255 is not a good way, which usually results in too vivid colors. You can experience that in this web page or this page.

One of the solution is decreasing chroma of out-of-gamut colors so that they fit within the gamut. The reason why chroma, not hue or lightness, is changed is that human eyes are the most insensitive to chroma.

20250326 16392101.jpg
Source

Note 1: In this figure, the vertical and horizontal axes indicate lightness and chroma respectively.

Note 2: Lightness is also changed slightly in the script I wrote.

This method is called "gamut clipping" and this is the most difficult and complicated part of the conversion. The interface or edge of the gamut cannot be derived mathematically. In general, an asymptotic method or binary search is needed to find it out. I ported Ottosson's C++ code because it is beyond my ability to write the code from scratch.

The gamut clipping code occupies about half the amount of my Oklch manipulation script. Probably, that is the reason my script is long. In addition to that, error handling when incorrect values are passed to the functions contributes to my lengthy code. Having said that, you could have made the code much shorter if you had written the script. :bow:

Thank you for reading my long writing to the end.

Statistics: Posted by PineYellow — Today, 10:00 am — Replies 2 — Views 61



Viewing all articles
Browse latest Browse all 973

Trending Articles