-
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
Converting from a wider gamut to a smaller one should return an option #41
Comments
Yeah the output of the conversion needs to be clamped. The example prints:
|
The reason for having unchecked conversion is to keep it lossless in situations where imaginary or otherwise invalid colors are acceptable for pure mathematical reasons, but I do see why this can be problematic. A simple alternative to forcing valid colors could be to provide additional conversion methods. Something like: fn try_convert<T: From<Self> + Limited>(self) -> Option<T>;
fn convert_clamped<T: From<Self> + Limited>(self) -> T; If we, on the other hand, would turn the table and force A possible middle ground could be to only clamp values that are definitely invalid in almost every case, like negative RGB. That would still allow brighter than white and such, which is important in applications like 3D rendering. |
Still a bit fuzzy. Adding it to the wish list for now. |
FYI, Rust nightly now has a |
Yes, that would be perfect for this. There is still a use case for converting without clamping (in 3D rendering engines, for example), but that could perhaps get the same treatment as wrapping arithmetics and be available through some kind of |
Seems like I'll add more specific issues when I figure work tasks, but other than that it's free to come with input. |
106: Add Extended Conversion Trait r=Ogeon a=Veykril This commit tries to implement a conversion trait similar to the one mentioned in #41 mimicking the `From`/`Into` traits of the `std` library. `convert_*` clamps the resulting color to its color space limitations. `convert_unclamped_*` simply converts the color. `try_convert_*` converts the color and returns it in a `Result` depending on it being valid or not. Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
If it means or changes anything, |
That's great! I'm just not sure if it (and From/Into) are the right thing to use for this, after all. Or maybe they are, in combination with something else. The problem is that they will not be consistent when converting to a variation of the same color space. Like one RGB to another. This is because |
Just for the record, I have been working a bit on this, now and then when I haven't had other things going on. It has been tricky to get it right, but I think I have something acceptable on its way. The idea is to have three kinds of traits (naming may change); It's still a bit unclear where |
There will be options, similar to what's described above, to convert with or without clamping in version 0.6. Including the |
This is real confusing:
I assumed it was a bug in the conversion routine, but it's just that Lab* is wider than sRGB. Returning an option type,
assert!
ing when the input is outside the target color space, or clamping the output value would all be preferable to the current situation.The text was updated successfully, but these errors were encountered: