linebender / linebender/color

Make color generic over premul types

Open
#192 5 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

Per my comment in https://github.com/linebender/color/pull/190#issuecomment-3196190653.

Sketch:

// similar to colorspacetag
enum AlphaType {
    Alpha,
    PremultipliedAlpha,
}

struct Alpha;
struct PremultipliedAlpha;

// for const generic
// alpha trait is like colorspace trait
impl AlphaTrait for Alpha {
    const ALPHA = AlphaType::Alpha;
}

impl AlphaTrait for AlphaPremultiplied {
    const ALPHA = AlphaType::AlphaPremultiplied;
}

pub struct AlphaColor<CS, A> {
    /// The components, which may be manipulated directly.
    ///
    /// The interpretation of the first three components depends on the color
    /// space. The fourth component is separate alpha.
    pub components: [f32; 4],
    /// The color space.
    pub cs: PhantomData<CS>,
    pub alpha: PhantomData<A>,
}

pub struct DynamicColor {
    pub alpha: AlpahType,
    /// The color space.
    pub cs: ColorSpaceTag,
    /// The state of this color, tracking whether it has missing components and how it was
    /// constructed. See the documentation of [`Flags`] for more information.
    pub flags: Flags,
    /// The components.
    ///
    /// The first three components are interpreted according to the
    /// color space tag. The fourth component is alpha, interpreted
    /// as separate alpha.
    pub components: [f32; 4],
}

PremulColor would be AlphaColor<_, PremiltipliedAlpha> so we can share more impls and DynamicColor is now also dynamic over AlphaType.

Motivation:

  • This would also allow us to deduplicated (un)premultiplied interpolation/gradient stuff.
  • https://github.com/linebender/color/pull/190#issuecomment-3196190653:

    One color variant says "I have this kind of [alpha]" (you need to know that premul is an abbreviation for a word and that this word pertains to alpha).
    The other says "I have alpha".

This would be break change.

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 with the discussion in pull request 190 and the AlphaColor, PremulColor, and DynamicColor entry points described here. Compare their current color-space and alpha representations, then define the breaking generic API and shared interpolation behavior; done means the proposed alpha typing is consistent across static and dynamic colors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.