Repository navigation
Refactor: RGBAPixel and LABAPixel to use composition with a generic AlphaPixel wrapper
#239
Closed
Ryan-Millard
started this conversation in
Ideas
Replies: 1 comment 3 replies
|
or we can always have an alpha in every color space. right now alpha is not being used so really we are just bookkeeping. |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi @Krasner, I'm not sure about how to approach this issue, so I am starting this with a discussion to find the cleanest possible way to make a reusable struct for this purpose. Below is the issue body I am proposing. Please let me know your thoughts.
During the discussion in PR #234, it was noted that
RGBAPixelandLABAPixelcurrently inherit fromRGBPixelandLABPixel. This causes two main issues:Memory layout concerns:
Conceptual clarity:
has-a) better reflects this relationship than inheritance (is-a).Proposed Refactor
1. Introduce a generic
AlphaPixelwrapperThis wrapper can wrap any pixel type and add an alpha channel. Example:
RGBAPixelbecomesusing RGBAPixel = AlphaPixel<RGBPixel<NumberT>>;LABAPixelbecomesusing LABAPixel = AlphaPixel<LABPixel<NumberT>>;This allows a single, reusable pattern for any “pixel + alpha” type.
2. Update
ImagetemplateCurrently,
Imagerequires:After refactor:
Pixelmember or satisfies a “pixel-like” trait.Or C++20 concept:
3. Update
PixelConverterusageConverter functions wrap the base pixel inside
AlphaPixel:loadFromBuffer()works unchanged.Benefits
RGBAPixelandLABAPixelhave an alpha, not are an alpha pixel).AlphaPixelstruct avoids code duplication.PixelConverterandImagesystem with minor updates.References:
All reactions