Skip to content

Exposing ColorSpaceWhitePoint is too heavyweight, and doesn't actually fix equality #30

@LeaVerou

Description

@LeaVerou

Right now, the API defines a ColorSpaceWhitePoint class, with static predefined values ColorSpaceWhitePoint.D50 and ColorSpaceWhitePoint.D65 that authors are supposed to reference in creating ColorSpace objects.

This means that in the case where the white point is something else, code would need to do things like if (c.white.x === ACES.x && c.white.y === ACES.y) to compare with it, not to mention that things like if (c.white === ColorSpaceWhitePoint.D65) do not account for creating ColorSpaceWhitePoint objects with the same x and y values as the predefined ones (which should really be identified as D50/D65).

Also, exposing a whole other interface just for this seems pointlessly heavyweight.

I would propose a different design:

  • A private map of white point names to their x/y coords, pre-populated with D50 and D65, possibly a few more too.
  • A static method on ColorSpace to register a custom white point, which does not allow registration of duplicate values
  • A static method on ColorSpace to look up white point chromaticity values by their name
  • ColorSpaceOptions.white would be a string, referencing a registered whitepoint

This would allow handling white points as plain strings making equality checks easy.

Thoughts @svgeesus @tabatkins ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-designIssues related to API shape

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions