-
Notifications
You must be signed in to change notification settings - Fork 60
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
Common RGB struct #31
Comments
Something like this could be good for linear RGB. I'm not as sure when it comes to gamma encoded RGB, since it may have additional parameters (like the gamma in struct RgbColor<P: Primaries, T: Float> {
red: T,
green: T,
blue: T,
_primaries: PhantomData<P>,
}
trait Primaries {
type WhitePoint;
//Maybe also functions returning the primaries as xyY, etc.
} ...assuming that white point and primaries are connected. I'm not sure if there are any odd stuff going on in that area, so it has to be checked first. |
Simple power law gamma is a thing, but it's not an "official" specification. Just another color compression/non-linearization method and it's sometimes used as a quick-and-dirty sRGB substitute. |
Yeah, I misunderstood your comment. |
I didn't realize that currently we are assuming all the rgb types are gamma corrected. We will still need the WP trait on the RgbColor struct. It will be easier for conversions Rgb -> XYZ -> Lab using impls. Not sure how to keep track of gamma. It is defined for each color type, so we can maybe get it on the rgb variant trait
One issue is that we are not keeping track of whether the color has been corrected for gamma and relying on the end user to do it. |
That would be the |
HSV, HSL, etc. could also be made parametric in the same way as RGB, to reflect what they are based on. |
I am more inclined towards separating rgb variant and white point. It is more flexible. Consider the case of when Srgb with D50 is needed. If using primaries, this needs to be explicitly defined. However if they are separated, it will be a simple The way I see conversions working is on the RgbColor itself, rgb points from the color space and white point xy's from the whitepoint trait. Depending on how things work out, we can auto derive conversions on the RgbVariants trait ( via bradford transfrom ) and provide the optimized matrices for the defined color spaces like sRgb-d65 and adobeRgb-d50 etc. It will be good to have some implementation to see how it shapes up. |
Yes, a prototype would be good. Having the same primaries, but a different white point seems strange to me, but I guess it's mathematically possible if they are scaled differently. I'm trying to find something that explains exactly how they are connected (if they are)... |
One use case I see is that most printers, monitors, camera's etc come with an ICC color profile and these are usually defined with the D50 white point. So Srgb D50 is definitely useful |
It's still weird, because the primaries wouldn't look the same. They would intuitively be more blue, or red, or whatever. I'm currently reading section B.2 in this specification to see what they have to say about chromatic adaption. |
It's a bit cryptic. At least the last sentence. What I think it's trying to say is that primaries and white point is completely disconnected, but I'm not 100% sure. If that's the case, then we should also disconnect them, as you are suggesting. Your |
After looking at the test data, maybe a good idea to encode the gamma/linear trait in the Rgb. Looking at the options: Assume linear
Assume Gamma
Add GammaEncoding trait
|
I have some more questions:
sRGB seem to be the big one.
I'm not sure we can encode this into the types at all. Nothing will prevent anyone from just using An additional way to discourage direct use of |
It is part of the Rgb variant. The gamma values are listed here http://www.brucelindbloom.com/WorkingSpaceInfo.html#Specifications. Only Srgb has a non standard calculation. The rest all are color^gamma and its inverse. So we can enocde it directly in the RgbVariant trait.
Gamma is not a parameter as such, it just indicates whether the color is gamma corrected or not. Xyz conversions are only to the Linear Rgb Types. |
Sure, but I meant the //Encoded with standardized encodings, such as sRGB
//(maybe with a Whitepoint parameter)
struct EncodedRgb<Encoding, T> {...}
//Choose-your-own-gamma encoded RGB
struct GammaRgb<Primaries, Whitepoint, T> {...}
//Good old linear RGB
struct Rgb<Primaries, Whitepoint, T> {...}
|
You'll still have to encode gamma as part of the RgbVariant trait for conversions to and from linear. Not sure if separating them buys us anything. We'll most likely define
which will cover most of the use cases. We can discuss this more when implementing it. It will give us a much clearer picture of how the types interact. Another thing is the add, sub, mul traits and how will they work in the gamma space. I am not 100% clear on this. |
They don't, really. That's the thing with this whole library. You won't get good results in gamma space, so it's greatly discouraged. The same goes for mixing, scaling pictures, rotating, whatever. There's still the possibility to force gamma encoded values to be taken as linear, as an escape hatch, but that's it. I would really like to keep the distinction as obvious as possible, but with a small escape hatch for when the user knows what's up. Linear and encoded RGB will effectively be two different types with the same kind of content, if this same distinction is preserved, so the only duplication will more or less be the structs themselves, the constructors, and nothing else. Those things, and the custom gamma exponents, are why I'm thinking that it could be less complex to keep them separated.
Possibly, but we must think of it as a prototype, and not necessarily the final implementation. No decision has been made, so no strings attached. |
Exactly |
I'm just making sure we are on the same page 😄 |
I think this fits within the scope of 0.3.0, so I'm scheduling it, but we can always reschedule if it turns out to be problematic in any way. |
Here is how I am planning to implement this
Any thoughts? What is still unclear is whether the operations like blend, add , multiply etc should be converted into linear before applying them or apply as is for each linear and gamma encoded types. |
I'm writing up an additional proposal for the pixel encoding types. It's very similar to what you are planning and will address some of the questions. |
I think it's good to take care of what's discussed in #58 in combination with this, since they are so closely connected. It could also be done as a two step process, where the linear RGB struct is changes separately from the encoded variants, in whatever order is best.
My proposal is to not implement them for encoded types at all, and thereby prevent any accidental mixups between what's linear and what's not. |
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
Have a common rgb struct
then we can define the individual colors as
conversions will be
The text was updated successfully, but these errors were encountered: