v4 - Simplify ColorspaceConverter #2531
Unanswered
JimBobSquarePants
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Motivation
The
ColorspaceConverter
codebase is overly large, complicated, and extremely difficult to expand upon. To add a new color space requires implementing converters from that space to every single existing space which is unmaintainable.Color conversion ideally should be at most a two-step process and if we borrow the approach taken by ICC profiles, we can achieve that. ICC profiles use the concept of a Profile Connecting Space (PCS) which acts as a bridge between individual color spaces.
With C#11 we are able to implement static abstract methods in interfaces, which allows us to implement this design in a manner that allows simple expansion and ease of use.
The existing ColorSpaceConverter type only allows converting with a single set of options but with a simplified design it's possible to introduce static methods that allow conversion while passing options.
Implementation
Such an API would look like the following.
The instance implementation can use fewer generic type parameters because it's possible to overload the parameters with known PCS spaces
CieLab
,CieXyz
via extension methods.The following three interfaces would be the backbone of all color spaces.
We can implement the converter and static methods as simply as the following
Instance methods are implemented as extension methods split across multiple classes so that the compiler can handle the variation in generic type parameters.
For example...
Limitations
The static
ColorSpaceConverter
methods require all four generic type parameters to be provided and it's not possible to provide overloads for existingCieLab
,CieXyz
PCS types.Implementing a new PCS type requires implementing a new interface on the existing PCS types. For example,
CieLab
would look like this out of the box.@SixLabors/core would love to hear your thoughts here. Members of the public are invited to comment also.
Beta Was this translation helpful? Give feedback.
All reactions