-
Notifications
You must be signed in to change notification settings - Fork 61
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
Generalize the RGB types over RGB standards #60
Conversation
This is a beginning. It doesn't compile, yet, because of problems with the definition of I'll write a better description later, but I decided to bundle the primaries and white point in the |
...thinking about it, something like this may work: |
☔ The latest upstream changes (presumably #61) made this pull request unmergeable. Please resolve the merge conflicts. |
src/pixel/mod.rs
Outdated
@@ -10,6 +10,15 @@ pub use self::gamma_rgb::GammaRgb; | |||
mod srgb; | |||
mod gamma_rgb; | |||
|
|||
///A transfer function to and from linear space. | |||
pub trait TransferFn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be good to add rgb_to_linear and rgb_from linear with default implementation, once the linear and gamma rgb are defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To TransferFn
or just to the pixel
module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To the TransferFn. Hsl to LinearHsl, should convert though rgb. So that is the only conversion TransferFn should care about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can also apply to Luma/Grey.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a trait to convert gamma encoded colors to linear colors (and the inverse).
let rgb = linear_rgb.from_linear()
currently does not work. If we do not want to add another trait, this is where these conversions will go for every type that can convert to and from linear.
Or we will need something similar to the From and Into traits that will leverage the transfer function to do the linear <-> non-linear conversions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit hard to generalize that in the TransferFn
trait, since there are other parameters involved. There's currently the Srgb::from_linear(color)
method, which should contain all the necessary information to convert anything to Srgb
.
let rgb = linear_rgb.from_linear()
, which I guess is the same as let rgb = linear_rgb.into_nonlinear()
, will always need extra information about the transfer function. That can't be changed by changing the TransferFn
trait.
Looks like the workaround works for now. The only problem is the occasional detour through XYZ when going from |
Anyway, it looks like it fits right into the previous model, with a few small adjustments. |
I ended up implementing a few conversions manually and modify the macros for the rest. It's now possible to freely convert The next phase will probably be the integration of the other RGB related types. I'm just not sure how they should be presented to the user. Just as plain |
The previously mentioned round trip when converting from The solution I'm using to break the recursion is to check if |
src/rgb/mod.rs
Outdated
pub type LinSrgba<T = f32> = LinRgba<standards::Srgb, T>; | ||
|
||
///An RGB space and a transfer function. | ||
pub trait RgbStandard { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the RgbStandard have the WhitePoint type as well? The use case I see for it is supporting non standard white points like ICC Srgb D50 <SrgbTranfFn, SrgbSpace, D50>.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's still possible, since RgbStandard
is implemented for (Srgb, D50, Srgb)
.
Hmm... this looks like it's close to being complete, judging from the diff. Just need to
|
I have been making an attempt to unify |
Seems like it's going to work, after all, so I'm adding some points to the checklist. |
Ok, I think I'll consider this done, at last. I skipped a couple of points from the list and decided to push them into the future. |
bors r+ |
60: [WIP] Generalize the RGB types over RGB standards r=Ogeon a=Ogeon This changes the `Rgb` type to have a type parameter that implements the `RgbStandard` trait. This trait defines a set of primaries, white point and transfer function. It does also make the RGB types more uniform and type safe. Closes #66, closes #31, closes #58
Build succeeded |
This changes the
Rgb
type to have a type parameter that implements theRgbStandard
trait. This trait defines a set of primaries, white point and transfer function. It does also make the RGB types more uniform and type safe.Closes #66, closes #31, closes #58