I have a particular use case which requires a large array of colors that can be converted in-place between AlphaColor, OpaqueColor, and PremulColor. This array is homogeneous and the shared element type is known at compile time. Using DynamicColor is not a good solution, since it not only adds an overhead of 4 bytes per color (discriminants are padded to align to f32), but also ruins the oblivious cache line alignment that [f32; 4] provides, going from 16 to 20 bytes per color.
For this reason, I think it would be useful to have a statically tagged color type (Color<CS: ColorSpace, CK: ColorKind>) that internally contains an [f32; 4] and assumes a fixed alpha value of 1.0 for the opaque case. This change would not only allow in-place conversion between all the statically-sized color structs, but would also guarantee cache line alignment which would be helpful both for performance and for multi-threaded operations. The only drawback would be that storing opaque colors would waste 4 bytes per color.
Any thoughts on this?
I have a particular use case which requires a large array of colors that can be converted in-place between
AlphaColor,OpaqueColor, andPremulColor. This array is homogeneous and the shared element type is known at compile time. UsingDynamicColoris not a good solution, since it not only adds an overhead of 4 bytes per color (discriminants are padded to align tof32), but also ruins the oblivious cache line alignment that[f32; 4]provides, going from 16 to 20 bytes per color.For this reason, I think it would be useful to have a statically tagged color type (
Color<CS: ColorSpace, CK: ColorKind>) that internally contains an[f32; 4]and assumes a fixed alpha value of1.0for the opaque case. This change would not only allow in-place conversion between all the statically-sized color structs, but would also guarantee cache line alignment which would be helpful both for performance and for multi-threaded operations. The only drawback would be that storing opaque colors would waste 4 bytes per color.Any thoughts on this?