question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Color Spaces: Units in color channels

See original GitHub issue

The current definition of colors says that channel values are floating-point—that is, they’re stored without reference to a unit. However, there’s no explicit conversion from Sass numbers (which may have units) to floating-point numbers (which may not) either in Parsing Color Components or color().

This raises a few questions:

  • CSS Colors 5 only allows raw numbers or percentages for custom colors. Should we do the same for unknown color spaces? Or is the risk of forwards-incompatibility with potential new predefined polar color spaces too great?

  • If we do allow unknown color spaces to specify channels with circular units, do we have to store that fact? Can we just serialize those colors with a unitless value for that channel? Is there a risk of a new predefiend color space with a polar channel that defaults to turns instead of degrees?

  • If we allow unknown color spaces to specify channels with circular units, do we allow any units, or just unitless/percent/circular?

  • The existing channel-access functions color.hue(), color.saturation(), color.lightness(), color.whiteness(), and color.blackness() return values with units. However, color.channel() is specified never to do so—so color.channel($color, 'hue') isn’t a drop-in replacement for color.hue($color). Is this a problem?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nex3commented, Oct 31, 2022

What’s the best way to capture that final part? I’m not familiar with the term ‘raw double’. Is it fair to keep channel values as floating-point numbers, and then make sure we have guidance for adding/removing units as appropriate?

Yes, that’s what I mean. The term “double” (in a Sass context) is defined in the Number spec and basically just means “a 64-bit floating point number”. We should try to use “double” in the spec rather than “floating-point number” because it’s more explicit about the size and gamut of the number in question.

The channel normalization/validation processes (which could technically be combined) already now convert all values into unitless values where possible, or use % or deg in a few cases. Appending them where appropriate is simple enough. I think we would ideally want to remove them as part of ‘creating a color’ - maybe we can note that in the definition of the color object, that units are removed on creation? Or do we need to build that into various processes?

I think generally it’s a good idea to try to avoid having logic in definitions, so if it’s feasible to keep that in processes that would be ideal. It shouldn’t require too much verbosity—just saying “hue’s value” is enough to make it clear that you mean the double it contains.

0reactions
mirisuzannecommented, Nov 15, 2022
  • add units in: channels() and serialization
  • remove units in normalization
Read more comments on GitHub >

github_iconTop Results From Across the Web

Color space - Wikipedia
A color space is a specific organization of colors. In combination with color profiling supported by various physical devices, it supports reproducible ...
Read more >
Introduction to Color Spaces in Video - Matrox
This guide aims to explain the representation of color in a video setting while outlining the differences between common color models.
Read more >
Color
The CIE RGB color space is one of many RGB color spaces, disunguished by a parucular set of monochromauc primary colors. The RGB...
Read more >
Color Basics and Channels -- IM v6 Examples - ImageMagick
RGB Color Space, and Channels​​ Each of the three arrays of values are known as a channel, which is simply a gray-scale image...
Read more >
Color Spaces - Photopea
While Grams (unit of weight) consist of one number (e.g. 150 grams), CIELAB (unit of color) consists of three numbers (e.g. CIELAB 0.5,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found