Skip to content

Feature request: Statically tagged color struct #216

Description

@leonardohn

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions