Bug 212446 - Extended Color: Refactor FloatComponents and ColorComponents into a single templatized ColorComponents class
Summary: Extended Color: Refactor FloatComponents and ColorComponents into a single te...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sam Weinig
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-05-27 17:10 PDT by Sam Weinig
Modified: 2020-05-27 20:33 PDT (History)
11 users (show)

See Also:


Attachments
Patch (60.86 KB, patch)
2020-05-27 17:36 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (62.55 KB, patch)
2020-05-27 17:45 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
ColorComponents.h (4.20 KB, text/x-csrc)
2020-05-27 18:41 PDT, Sam Weinig
no flags Details
ColorUtilities.h (3.28 KB, text/x-csrc)
2020-05-27 18:41 PDT, Sam Weinig
no flags Details
Patch (62.16 KB, patch)
2020-05-27 18:49 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2020-05-27 17:10:54 PDT
Extended Color: Refactor FloatComponents and ColorComponents into a single templatized ColorComponents class
Comment 1 Sam Weinig 2020-05-27 17:36:29 PDT Comment hidden (obsolete)
Comment 2 Sam Weinig 2020-05-27 17:45:40 PDT
Created attachment 400410 [details]
Patch
Comment 3 Simon Fraser (smfr) 2020-05-27 18:10:56 PDT
Comment on attachment 400410 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=400410&action=review

> Source/WebCore/platform/graphics/ColorComponents.h:48
> +        components[0] = values[0];
> +        components[1] = values[1];
> +        components[2] = values[2];
> +        components[3] = values[3];

Can this just be one assignment?

> Source/WebCore/platform/graphics/ColorComponents.h:175
> +inline unsigned byteOffsetOfPixel(unsigned x, unsigned y, unsigned rowBytes)
> +{
> +    const unsigned bytesPerPixel = 4;
> +    return x * bytesPerPixel + y * rowBytes;
> +}

Seems like an odd thing to be here, particularly as it assumes 4 bpp which is also baked into rowBytes.

> Source/WebCore/platform/graphics/ColorComponents.h:192
> +float contrastRatio(const FloatComponents&, const FloatComponents&);

Are the arguments assumed to be sRGB?

> Source/WebCore/platform/graphics/ColorUtilities.h:46
> +ColorComponents<float> rgbToLinearComponents(const ColorComponents<float>&);
> +ColorComponents<float> linearToRGBComponents(const ColorComponents<float>&);
> +
> +ColorComponents<float> p3ToSRGB(const ColorComponents<float>&);
> +ColorComponents<float> sRGBToP3(const ColorComponents<float>&);
> +
> +WEBCORE_EXPORT ColorComponents<float> sRGBToHSL(const ColorComponents<float>&);
> +WEBCORE_EXPORT ColorComponents<float> hslToSRGB(const ColorComponents<float>&);

Sucks to have all these in two places. Don't like.

> Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp:93
> +static inline unsigned byteOffsetOfPixel(unsigned x, unsigned y, unsigned rowBytes)
> +{
> +    const unsigned bytesPerPixel = 4;
> +    return x * bytesPerPixel + y * rowBytes;
> +}

Ohai.

> Source/WebCore/platform/graphics/filters/FEMorphology.cpp:94
> +inline ColorComponents<uint8_t> makeColorComponentsfromPixelValue(unsigned pixel)
> +{
> +    return ColorComponents<uint8_t>((pixel >> 24) & 0xFF, (pixel >> 16) & 0xFF, (pixel >> 8) & 0xFF, pixel & 0xFF);
> +}

This looks just like ColorComponents fromRGBA(unsigned pixel)

> Source/WebCore/platform/graphics/filters/FEMorphology.cpp:100
> +inline unsigned makePixelValueFromColorComponents(const ColorComponents<uint8_t>& components)
> +{
> +    auto [r, g, b, a] = components;
> +    return r << 24 | g << 16 | b << 8 | a;
> +}

Share this too?
Comment 4 Sam Weinig 2020-05-27 18:36:30 PDT
All those things aren’t really in ColorComponents.h, it’s just the patch showing it being copied. Then below you will see them being removed.
Comment 5 Sam Weinig 2020-05-27 18:41:38 PDT
Created attachment 400415 [details]
ColorComponents.h
Comment 6 Sam Weinig 2020-05-27 18:41:57 PDT
Created attachment 400416 [details]
ColorUtilities.h
Comment 7 Sam Weinig 2020-05-27 18:44:57 PDT
(In reply to Simon Fraser (smfr) from comment #3)
> Comment on attachment 400410 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=400410&action=review
> 
> > Source/WebCore/platform/graphics/ColorComponents.h:48
> > +        components[0] = values[0];
> > +        components[1] = values[1];
> > +        components[2] = values[2];
> > +        components[3] = values[3];
> 
> Can this just be one assignment?

It is in the patch. This is the initial copy the diff has. See later in the patch for this real version.

> 
> > Source/WebCore/platform/graphics/ColorComponents.h:175
> > +inline unsigned byteOffsetOfPixel(unsigned x, unsigned y, unsigned rowBytes)
> > +{
> > +    const unsigned bytesPerPixel = 4;
> > +    return x * bytesPerPixel + y * rowBytes;
> > +}
> 
> Seems like an odd thing to be here, particularly as it assumes 4 bpp which
> is also baked into rowBytes.

In the patch it is moved to FEDisplacementMap.cpp

> 
> > Source/WebCore/platform/graphics/ColorComponents.h:192
> > +float contrastRatio(const FloatComponents&, const FloatComponents&);
> 
> Are the arguments assumed to be sRGB?

Later in the patch you can see it was updated to:

float contrastRatio(const ColorComponents<float>& sRGBCompontentsA, const ColorComponents<float>& sRGBCompontentsB);

> 
> > Source/WebCore/platform/graphics/ColorUtilities.h:46
> > +ColorComponents<float> rgbToLinearComponents(const ColorComponents<float>&);
> > +ColorComponents<float> linearToRGBComponents(const ColorComponents<float>&);
> > +
> > +ColorComponents<float> p3ToSRGB(const ColorComponents<float>&);
> > +ColorComponents<float> sRGBToP3(const ColorComponents<float>&);
> > +
> > +WEBCORE_EXPORT ColorComponents<float> sRGBToHSL(const ColorComponents<float>&);
> > +WEBCORE_EXPORT ColorComponents<float> hslToSRGB(const ColorComponents<float>&);
> 
> Sucks to have all these in two places. Don't like.

Not duplicated. Just weird diff.

> 
> > Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp:93
> > +static inline unsigned byteOffsetOfPixel(unsigned x, unsigned y, unsigned rowBytes)
> > +{
> > +    const unsigned bytesPerPixel = 4;
> > +    return x * bytesPerPixel + y * rowBytes;
> > +}
> 
> Ohai.
> 
> > Source/WebCore/platform/graphics/filters/FEMorphology.cpp:94
> > +inline ColorComponents<uint8_t> makeColorComponentsfromPixelValue(unsigned pixel)
> > +{
> > +    return ColorComponents<uint8_t>((pixel >> 24) & 0xFF, (pixel >> 16) & 0xFF, (pixel >> 8) & 0xFF, pixel & 0xFF);
> > +}
> 
> This looks just like ColorComponents fromRGBA(unsigned pixel)
> 
> > Source/WebCore/platform/graphics/filters/FEMorphology.cpp:100
> > +inline unsigned makePixelValueFromColorComponents(const ColorComponents<uint8_t>& components)
> > +{
> > +    auto [r, g, b, a] = components;
> > +    return r << 24 | g << 16 | b << 8 | a;
> > +}
> 
> Share this too?

These both only exist in FEMorphology.cpp now.
Comment 8 Sam Weinig 2020-05-27 18:49:23 PDT
Created attachment 400417 [details]
Patch
Comment 9 EWS 2020-05-27 19:30:42 PDT
Committed r262232: <https://trac.webkit.org/changeset/262232>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 400417 [details].
Comment 10 Radar WebKit Bug Importer 2020-05-27 19:31:20 PDT
<rdar://problem/63701108>
Comment 11 Darin Adler 2020-05-27 20:33:51 PDT
Comment on attachment 400417 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=400417&action=review

> Source/WebCore/platform/graphics/ColorComponents.h:96
> +        result.components[0] = fabs(components[0]);
> +        result.components[1] = fabs(components[1]);
> +        result.components[2] = fabs(components[2]);
> +        result.components[3] = fabs(components[3]);

std::abs?

> Source/WebCore/platform/graphics/ColorUtilities.h:33
> +template<typename T> struct ColorComponents;

Take out the "T"?

> Source/WebCore/platform/graphics/ColorUtilities.h:71
> +inline uint16_t fastDivideBy255(uint16_t value)

constexpr

> Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp:89
> +static inline unsigned byteOffsetOfPixel(unsigned x, unsigned y, unsigned rowBytes)

constexpr

> Source/WebCore/platform/graphics/filters/FEMorphology.cpp:91
> +inline ColorComponents<uint8_t> makeColorComponentsfromPixelValue(unsigned pixel)

constexpr?

> Source/WebCore/platform/graphics/filters/FEMorphology.cpp:96
> +inline unsigned makePixelValueFromColorComponents(const ColorComponents<uint8_t>& components)

constexpr?