You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is similar to the old idea of pipelines (#197) that has gotten more relevant with the introduction of CAM16 and conversions that need additional input. It will ultimately need quite a bit of API design, but I'm writing this issue to air my ideas and keep an open discussion.
Motivation
The concept of a converter solves two problems:
Feeding parameters to the conversion process.
Pre-computing parameters, matrices, etc. to not have to repeat the process while converting a large number of values.
The first point could also be solved with an additional trait, but that doesn't solve the issue of reusability.
Design sketch
A converter would implement a trait with an input and output type. Whether they should be associated types or type parameters may change. The same with taking self as reference or by move.
traitConverter<T>{typeOutput;fnconvert(&self,input:T) -> Self::Output;}structXyzToRgb<T,S>{matrix:[T;9],rgb_standard:PhantomData<S>,}impl<T,S>Converter<Xyz<S::WhitePoint,T>>forXyzToRgb<T,S>whereS:RgbStandard,// ...{typeOutput = Rgb<S,T>;fnconvert(&self,input:Xyz<S::WhitePoint,T>) -> Self::Output{// Do what FromColorUnclamped does today}}
This would generally take the place of FromColorUnclamped as the base trait for conversion. We could then implement FromColorUnclamped as a default case for converters. By introducing another trait (let's call it DefaultConverterFrom), we can keep the current API intact.
That would double the number of conversion traits, which may be fine. It would also be nice to be able to bridge between conversions that do and those that don't require input. For example, converting from Rgb to Cam16UcsJmh would require three steps (Rgb -> Xyz -> Cam16 -> Cam16UcsJmh), but it could reasonably be expressed with a single FromColorUnclampedWith implementation. A derive macro could figure it out, as long as it's aware of the points where input is needed, and chain them in a single trait implementation.
Description
This is similar to the old idea of pipelines (#197) that has gotten more relevant with the introduction of CAM16 and conversions that need additional input. It will ultimately need quite a bit of API design, but I'm writing this issue to air my ideas and keep an open discussion.
Motivation
The concept of a converter solves two problems:
The first point could also be solved with an additional trait, but that doesn't solve the issue of reusability.
Design sketch
A converter would implement a trait with an input and output type. Whether they should be associated types or type parameters may change. The same with taking
self
as reference or by move.This would generally take the place of
FromColorUnclamped
as the base trait for conversion. We could then implementFromColorUnclamped
as a default case for converters. By introducing another trait (let's call itDefaultConverterFrom
), we can keep the current API intact.The tricky part is where additional input gets involved. One idea is to repeat the pattern above, but with an additional parameter.
That would double the number of conversion traits, which may be fine. It would also be nice to be able to bridge between conversions that do and those that don't require input. For example, converting from
Rgb
toCam16UcsJmh
would require three steps (Rgb -> Xyz -> Cam16 -> Cam16UcsJmh
), but it could reasonably be expressed with a singleFromColorUnclampedWith
implementation. A derive macro could figure it out, as long as it's aware of the points where input is needed, and chain them in a single trait implementation.This is where it would be good to make a prototype.
The text was updated successfully, but these errors were encountered: