linebender / linebender/color

Feature request: Statically tagged color struct

Open
#216 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
110
Forks
14
Avg merge
16h 45m
Merged PRs (30d)
1

Description

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`) 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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing AlphaColor, OpaqueColor, PremulColor, DynamicColor, ColorSpace, and ColorKind concepts mentioned in the request. Clarify the proposed API, conversion behavior, storage guarantees, and acceptance criteria before implementation; the issue does not currently define a concrete done state.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.