Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinction between Srgb encoding and Linear<Srgb> encoding? #133

Open
mitchmindtree opened this issue Jun 19, 2019 · 7 comments
Open

Distinction between Srgb encoding and Linear<Srgb> encoding? #133

mitchmindtree opened this issue Jun 19, 2019 · 7 comments
Labels
documentation Related to things like README or the API documentation.

Comments

@mitchmindtree
Copy link
Contributor

Hi @Ogeon! I'm (finally) updating nannou from 0.2 to 0.4 and I'm a little confused about the distinction between the Srgb and Linear<Srgb> encodings.

I'd always thought that sRGB and Linear were two distinct encodings. Specifically, I thought that Linear was a direct mapping to the hardware output, whereas sRGB was a mapping that is friendlier to the perceivable colour range. What does it mean to have Linear<Srgb>?

Sorry for the ordinary question! Feel free to point me elsewhere if there's somewhere I can read up properly on this 🙏

mitchmindtree added a commit to mitchmindtree/nannou that referenced this issue Jun 19, 2019
The biggest update to account for here was the distinction between
`RgbSpace`s. Nannou now uses the `Srgb` standard encoding as a default
throughout the crate which should more accurately represents nannou's
provided set of named colors (nannou-org#72) and likely close match users
expectations of the behaviour.

Closes nannou-org#72.
Closes nannou-org#345.

TODO:

- [ ] Decide whether or not to re-add the `Rgb` and `Rgba` types to the
  `color` module? Or should we encourage use of the `Srgb` and `Srgba`
  types instead for clarity?
- [ ] Clarify whether we should be useing `Srgb` or `Linear<Srgb>` RGB
  encoding for nannou's default draw API. I've opened up
  Ogeon/palette#133 to help clarify my understanding on this.
- [ ] Add a suite of super simple constructor functions to the color
  module (e.g. `hsl`, `hsla`, `rgb`, `rgba`, etc) that produce color
  types that are easily compatible with nannou's `Draw` API.
- [ ] Decide if we should keep the Tango based `named` colors provided
  by nannou (see [here][1]) or only use those provided [by palette][2].
  Alternatively we could keep both, but this would mean removing the
  glob palette import to fix nannou-org#345 and re-exporting `palette`'s named
  colors into our own named module.
- [ ] Decide what the most convenient type is for `named` colors. We
  should probably change them to the same type as `palette`'s named
  colors, but also ensure that these can be conveniently used within all
  areas of the `Draw` API.
- [ ] Create a `colors.rs` example that demonstrates all named colors
  within the crate. Ensure that these colors visibly match their
  references.

cc @SjorsVanGelderen.

[1]: /~https://github.com/nannou-org/nannou/blob/master/src/color.rs#L12
[2]: https://docs.rs/palette/0.4.1/palette/named/index.html
mitchmindtree added a commit to mitchmindtree/nannou that referenced this issue Jun 19, 2019
The biggest update to account for here was the distinction between
`RgbSpace`s. Nannou now uses the `Srgb` standard encoding as a default
throughout the crate which should more accurately represents nannou's
provided set of named colors (nannou-org#72) and likely close match users
expectations of the behaviour.

Closes nannou-org#72.
Closes nannou-org#345.

TODO:

- [ ] Decide whether or not to re-add the `Rgb` and `Rgba` types to the
  `color` module? Or should we encourage use of the `Srgb` and `Srgba`
  types instead for clarity?
- [ ] Clarify whether we should be useing `Srgb` or `Linear<Srgb>` RGB
  encoding for nannou's default draw API. I've opened up
  Ogeon/palette#133 to help clarify my understanding on this.
- [ ] Add a suite of super simple constructor functions to the color
  module (e.g. `hsl`, `hsla`, `rgb`, `rgba`, etc) that produce color
  types that are easily compatible with nannou's `Draw` API.
- [ ] Decide if we should keep the Tango based `named` colors provided
  by nannou (see [here][1]) or only use those provided [by palette][2].
  Alternatively we could keep both, but this would mean removing the
  glob palette import to fix nannou-org#345 and re-exporting `palette`'s named
  colors into our own named module.
- [ ] Decide what the most convenient type is for `named` colors. We
  should probably change them to the same type as `palette`'s named
  colors, but also ensure that these can be conveniently used within all
  areas of the `Draw` API.
- [ ] Create a `colors.rs` example that demonstrates all named colors
  within the crate. Ensure that these colors visibly match their
  references.

cc @SjorsVanGelderen.

[1]: /~https://github.com/nannou-org/nannou/blob/master/src/color.rs#L12
[2]: https://docs.rs/palette/0.4.1/palette/named/index.html
@Ogeon
Copy link
Owner

Ogeon commented Jun 20, 2019

Hi! Excellent question and something that should be clarified in the documentation at some point.

The short version is that sRGB is basically a storage format, where the values does not map 1:1 with the intensity they represent. So 50% is not encoded as 0.5 in sRGB, and this will affect blending operations among other things.

Linear RGB is the "normal" scale, where 50% brightness is represented by 0.5, and the same goes for the rest of the scale. It's just straight intensity values (as far as that's true for RGB in general).

sRGB stems from how old CRT displays work and does also have the benefit of a higher resolution among the darker colors. That reduces the banding effect because it also matches how we see colors. It works as a type of compression.

This video explains it in a short and nice way: https://youtu.be/LKnqECcg6Gw

I would recommend a workflow or data flow where the color is converted to linear space as soon as possible and stays like that internally. It can then be converted back when it's outputted to some media that want sRGB (image, display, etc.). I.e. a "linear workflow".

@mitchmindtree
Copy link
Contributor Author

Thanks a lot for the valuable insight, I'm glad that I asked!

Is it possible for there to be other kinds of Linear<_> encodings? E.g. something like Rgb<Linear<Foo>, T> rather than Rgb<Linear<Srgb>, T>? I guess what I'm asking is, why does the Linear encoding type require specifying a <Srgb> type parameter if it is in a linear representation rather than an sRGB one?

I'll checkout this video tonight, I love minutephysics :)

@Ogeon
Copy link
Owner

Ogeon commented Jun 20, 2019

Yes! RGB has two other parameters, beside the "transfer function" (linear v.s. nonlinear):

  • The "primaries" decide what the physical definition (wavelength and light intensity) of "red", "green" and "blue" are.

  • The "white point" decides what the physical definition of "white" is. Basically the photon output of a light source.

There are plenty of RGB standards with different values for these, but sRGB is the most common. It's all a bit of a rabbit hole and you don't have to go down there unless you want to support working with a wider gamut (wider range of perceivable colors) or doing more advanced color adaptions.

@Ogeon
Copy link
Owner

Ogeon commented Jun 20, 2019

So Linear<Srgb> uses the primaries and white point of sRGB, but replaces the sRGB transfer function with the linear transfer function. The benefit of nesting the types is that the conversion from linear will know what the original RGB standard was we don't have to make purpose made linear versions of each standard (I remembered it wrong at first), as the RGB space is still the same.

@mitchmindtree
Copy link
Contributor Author

Thanks, that clears things up for me! I'm happy for this to be closed, but will leave it open in case you'd like the reminder for the addition to the docs :)

@Ogeon
Copy link
Owner

Ogeon commented Jun 20, 2019

It can stay open for now. 🙂 Feel free to come back and ask more if there are any more road blocks!

@Ogeon
Copy link
Owner

Ogeon commented Jun 20, 2019

Oh I should probably clarify that any shader code should also be considered being within the linear part of the pipeline, so don't convert to sRGB until just before it ends up on the monitor for the best results. That is unless the shader itself expect sRGB as input, or unless the graphics backed is set to convert it for you. I don't know how your current pipeline looks, so that may already be taken care of, but I'm mentioning it just in case...

mitchmindtree added a commit to mitchmindtree/nannou that referenced this issue Jul 20, 2019
The biggest update to account for here was the distinction between
`RgbSpace`s. Nannou now uses the `Srgb` standard encoding as a default
throughout the crate which should more accurately represents nannou's
provided set of named colors (nannou-org#72) and likely close match users
expectations of the behaviour.

Closes nannou-org#72.
Closes nannou-org#345.

TODO:

- [ ] Decide whether or not to re-add the `Rgb` and `Rgba` types to the
  `color` module? Or should we encourage use of the `Srgb` and `Srgba`
  types instead for clarity?
- [ ] Clarify whether we should be useing `Srgb` or `Linear<Srgb>` RGB
  encoding for nannou's default draw API. I've opened up
  Ogeon/palette#133 to help clarify my understanding on this.
- [ ] Add a suite of super simple constructor functions to the color
  module (e.g. `hsl`, `hsla`, `rgb`, `rgba`, etc) that produce color
  types that are easily compatible with nannou's `Draw` API.
- [ ] Decide if we should keep the Tango based `named` colors provided
  by nannou (see [here][1]) or only use those provided [by palette][2].
  Alternatively we could keep both, but this would mean removing the
  glob palette import to fix nannou-org#345 and re-exporting `palette`'s named
  colors into our own named module.
- [ ] Decide what the most convenient type is for `named` colors. We
  should probably change them to the same type as `palette`'s named
  colors, but also ensure that these can be conveniently used within all
  areas of the `Draw` API.
- [ ] Create a `colors.rs` example that demonstrates all named colors
  within the crate. Ensure that these colors visibly match their
  references.

cc @SjorsVanGelderen.

[1]: /~https://github.com/nannou-org/nannou/blob/master/src/color.rs#L12
[2]: https://docs.rs/palette/0.4.1/palette/named/index.html
mitchmindtree added a commit to mitchmindtree/nannou that referenced this issue Jul 21, 2019
The biggest update to account for here was the distinction between
`RgbSpace`s. Nannou now uses the `Srgb` standard encoding as a default
throughout the crate which should more accurately represents nannou's
provided set of named colors (nannou-org#72) and likely close match users
expectations of the behaviour.

Closes nannou-org#72.
Closes nannou-org#345.

TODO:

- [ ] Decide whether or not to re-add the `Rgb` and `Rgba` types to the
  `color` module? Or should we encourage use of the `Srgb` and `Srgba`
  types instead for clarity?
- [ ] Clarify whether we should be useing `Srgb` or `Linear<Srgb>` RGB
  encoding for nannou's default draw API. I've opened up
  Ogeon/palette#133 to help clarify my understanding on this.
- [ ] Add a suite of super simple constructor functions to the color
  module (e.g. `hsl`, `hsla`, `rgb`, `rgba`, etc) that produce color
  types that are easily compatible with nannou's `Draw` API.
- [ ] Decide if we should keep the Tango based `named` colors provided
  by nannou (see [here][1]) or only use those provided [by palette][2].
  Alternatively we could keep both, but this would mean removing the
  glob palette import to fix nannou-org#345 and re-exporting `palette`'s named
  colors into our own named module.
- [ ] Decide what the most convenient type is for `named` colors. We
  should probably change them to the same type as `palette`'s named
  colors, but also ensure that these can be conveniently used within all
  areas of the `Draw` API.
- [ ] Create a `colors.rs` example that demonstrates all named colors
  within the crate. Ensure that these colors visibly match their
  references.

cc @SjorsVanGelderen.

[1]: /~https://github.com/nannou-org/nannou/blob/master/src/color.rs#L12
[2]: https://docs.rs/palette/0.4.1/palette/named/index.html
@Ogeon Ogeon added the documentation Related to things like README or the API documentation. label Aug 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Related to things like README or the API documentation.
Projects
None yet
Development

No branches or pull requests

2 participants