evilmartians/oklch-picker

Enquiry of Functionality for Luminance Range Calculation

Closed this issue · 3 comments

First, I want to express my appreciation for the OKLCH tool—it's incredibly useful, and I'm a big fan of its capabilities. I am particularly interested in the functionality that shows the possible luminance range, as illustrated in the figure below.

Request:

I need to utilize this functionality at the backend and would like to understand the method you use to calculate the possible range of luminance for given a and b values in the LAB color space.

Specific Questions:

What is the algorithm or method used to determine the possible luminance range given specific a and b values?
Are there any existing functions or API endpoints in the project that I can leverage for this purpose?
If not, could you provide guidance or reference materials on how I might implement this?

Figure:
image

ai commented

luminance range given specific a and b values

Just convert LAB colors to LCH and do the labToLCH(a).l - labToLCH(b).l

Just convert LAB colors to LCH

Many thanks for your prompt response. I appreciate the guidance on converting LAB to LCH. I have a follow-up question: After converting a color from LAB to LCH and fixing the chroma (C) and hue (H) channels, how can we estimate the valid luminance range for these fixed C and H values?

ai commented

Do you mean, you need min and max L for specific C and H (for sRGB gamma)?

Unfortunately there is no algorithm for that. You need to walk through all colors and create a map.

There is an optimization hack. You can walk through all RGB colors with 100% in one of the channels.

https://github.com/evilmartians/oklch-picker/blob/main/lib/model.ts#L39