Skip to content

Request: Add oklch output format #97

@rmunn

Description

@rmunn

Background

Now that oklch is available in most browsers, it would be nice to be able to have oklch as an output format option for hyprpicker.

In case you're not familiar with oklch and oklab, they are color definition methods recently added to CSS whose intent is better perceptual fidelity; i.e., when you change the lightness of blue, it should stay blue and not look purplish. The existing lch function doesn't actually match how the human eye perceives color very well, which is why it ends up changing the color of a blue-white gradiant. See https://atmos.style/blog/lch-vs-oklch for a good illustration (the "Hue in LCH vs OKLCH" section is about halfway down the page).

Desired result

What I'd like is an output format that prints the following: oklch(59.246% 33.42% 180) or, if there's an alpha component, oklch(59.246% 33.42% 180 / 0.5). I.e., the same format as accepted in CSS. The lightness and chroma values are percentages from 0 to 100 and written with a % sign after the number, and the hue is a number in degrees (between 0 and 360). Finally, if the alpha is 1 then it's omitted, otherwise the alpha is a number between 0 and 1 written after a / (slash) character. That way the output from hypicker in oklch mode could be pasted directly into a CSS file.

The number of decimal points for all three (or four if the alpha isn't 1) values is arbitrary, but three decimal points (rounding 59.245502194 to 59.246) is probably a good mix between precision and human-readability. Values with a 0 at the end could be printed with fewer decimals, e.g. 33.42% instead of 33.420%.

NOTE: Three decimal points is more precision than would be needed normally (even the most color-sensitive people would be unable to distinguish between 59.246% luminosity and 59.240% luminosity), but since CSS also allows colors to be used as a basis for calculating other colors (with the oklch(from var(--othercolor) calc(l * 0.9) c h / a) format to, for example, reduce brightness by 10%), rounding error could add up after multiple calculations, so an output with three decimal points is probably a good idea. (I haven't measured this, this is just my rough estimate).

Additional information

Björn Ottoson (the creator of the oklab/oklch color spaces) has posted MIT-licensed C code at https://bottosson.github.io/posts/colorpicker/ to convert between the sRPG and Okhsl color spaces (scroll down to the bottom of the page for the source code, though the entire page is worth reading). This might be useful as a starting point for implementing this feature request. Mr. Ottoson has more posts at https://bottosson.github.io/ explaining why he created the oklab and oklch color spaces, which are great background reading if you haven't encountered them before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions