RESOLVED FIXED 212446
Extended Color: Refactor FloatComponents and ColorComponents into a single templatized ColorComponents class
https://bugs.webkit.org/show_bug.cgi?id=212446
Summary Extended Color: Refactor FloatComponents and ColorComponents into a single te...
Sam Weinig
Reported 2020-05-27 17:10:54 PDT
Extended Color: Refactor FloatComponents and ColorComponents into a single templatized ColorComponents class
Attachments
Patch (60.86 KB, patch)
2020-05-27 17:36 PDT, Sam Weinig
no flags
Patch (62.55 KB, patch)
2020-05-27 17:45 PDT, Sam Weinig
no flags
ColorComponents.h (4.20 KB, text/x-csrc)
2020-05-27 18:41 PDT, Sam Weinig
no flags
ColorUtilities.h (3.28 KB, text/x-csrc)
2020-05-27 18:41 PDT, Sam Weinig
no flags
Patch (62.16 KB, patch)
2020-05-27 18:49 PDT, Sam Weinig
no flags
Sam Weinig
Comment 1 2020-05-27 17:36:29 PDT Comment hidden (obsolete)
Sam Weinig
Comment 2 2020-05-27 17:45:40 PDT
Simon Fraser (smfr)
Comment 3 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?
Sam Weinig
Comment 4 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.
Sam Weinig
Comment 5 2020-05-27 18:41:38 PDT
Created attachment 400415 [details] ColorComponents.h
Sam Weinig
Comment 6 2020-05-27 18:41:57 PDT
Created attachment 400416 [details] ColorUtilities.h
Sam Weinig
Comment 7 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.
Sam Weinig
Comment 8 2020-05-27 18:49:23 PDT
EWS
Comment 9 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].
Radar WebKit Bug Importer
Comment 10 2020-05-27 19:31:20 PDT
Darin Adler
Comment 11 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?
Note You need to log in before you can comment on or make changes to this bug.