Title: [263941] trunk
Revision
263941
Author
[email protected]
Date
2020-07-04 12:20:50 -0700 (Sat, 04 Jul 2020)

Log Message

Part 1 of SimpleColor and SRGBA<uint8_t> are essentially the same - let's converge them
https://bugs.webkit.org/show_bug.cgi?id=213948

Reviewed by Darin Adler.

Source/WebCore:

Begin converging SimpleColor and SRGBA<uint8_t>, starting with removing usages that
were getting SimpleColors to access or operate on the color's components.

- Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>
- Replace toSRGBALossy() with toSRGBALossy<float>().
- Remove direct color component accessors from SimpleColor.
- Add new ARGB type to support explicit conversion from packed ARGB bits to a color type.
- Update premulitplication functions to operate on SRGBA<uint8_t> and rename them to
  match existing function operating on SRGBA<float>.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
Removes SimpleColor.cpp

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::colorValue const):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* accessibility/atk/WebKitAccessibleInterfaceText.cpp:
(getAttributeSetForAccessibilityObject):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::colorValue const):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* css/DeprecatedCSSOMRGBColor.h:
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* editing/cocoa/DataDetection.mm:
(WebCore::DataDetection::detectContentInRange):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/Color.cpp:
(WebCore::Color::lightened const):
(WebCore::Color::darkened const):
(WebCore::Color::lightness const):
(WebCore::Color::luminance const):
(WebCore::Color::semanticColor const):
(WebCore::Color::toSRGBASimpleColorLossy const): Deleted.
(WebCore::Color::toSRGBALossy const): Deleted.
* platform/graphics/Color.h:
Remove toSRGBASimpleColorLossy() and templatize toSRGBALossy() to support both
lossy conversion to byte based components as well.

* platform/graphics/ColorBlending.cpp:
(WebCore::blendSourceOver):
(WebCore::blendWithWhite):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

(WebCore::blend):
(WebCore::blendWithoutPremultiply):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>. Adopt new premultipliedCeiling
and unpremultiplied functions that operate on SRGBA<uint8_t> (rather than SimpleColor) and
clamping conversion to SRGBA<uint8_t> via convertToComponentBytes<SRGBA>. premultipliedCeiling
now works correctly for 0 alpha, so no workaround is needed anymore.

* platform/graphics/ColorTypes.h:
(WebCore::asARGB):
(WebCore::asSRGBA):
Add new type of color struct representing a format packing. The initial one is ARGB to support
the few places using SimpleColor to manipulate ARGB pixel data.

* platform/graphics/ColorUtilities.cpp:
(WebCore::unpremultiplied):
(WebCore::premultipliedFlooring):
(WebCore::premultipliedCeiling):
(WebCore::unpremultipliedComponentByte):
* platform/graphics/ColorUtilities.h:
(WebCore::convertToComponentBytes):
(WebCore::convertToComponentFloats):
Move remaining premultiplication functions here (from SimpleColor.h/cpp) and reimplement
to operate on SRGBA<uint8_t>. Also slightly rename, premultiply -> premultiplied, to
match existing premultiplied functions. While moving them, also fix the premultiplied
functions to better support 0 alpha to avoid workarounds in callers.

Additional, this adds convertToComponentBytes/convertToComponentFloats helper functions
which convert to/from uint8_t/float based color types, and support creating color types
from values potentially outside of their supported value range. Right now, that value
range is always considerer to be 0-255 for uint8_t and 0-1 for float, but that can be
chnaged in the future by allowing color type structs to indicate their supported ranges.

* platform/graphics/ExtendedColor.cpp:
(WebCore::ExtendedColor::toSRGBAFloatComponentsLossy const):
(WebCore::ExtendedColor::toSRGBALossy const): Deleted.
* platform/graphics/ExtendedColor.h:
(WebCore::ExtendedColor::toSRGBALossy const):
Rename existing toSRGBALossy() to toSRGBAFloatComponentsLossy() and replace templatize
toSRGBALossy(), with the uint8_t case just down converting via new convertToComponentBytes.

* platform/graphics/ImageBackingStore.h:
(WebCore::ImageBackingStore::fillRect):
(WebCore::ImageBackingStore::setPixel):
(WebCore::ImageBackingStore::blendPixel):
(WebCore::ImageBackingStore::pixelValue const):
Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
Update to use new premulitplication functions. Also, update the interface to take pixel
components as uint8_t, rather than unsigned, as that is what the callers are passing anyway,
and it avoids us having to clamp/cast manually all over the case.

* platform/graphics/SimpleColor.cpp: Removed.
* platform/graphics/SimpleColor.h:
(WebCore::SimpleColor::alphaComponent const):
(WebCore::SimpleColor::asSRGBA const):
(WebCore::SimpleColor::redComponent const):
(WebCore::SimpleColor::greenComponent const):
(WebCore::SimpleColor::blueComponent const):
(WebCore::operator==):
(WebCore::makeSimpleColor):
Simplify interface, making red, green and blue component accessors private and having
callers all use SRGBA directly. Remove premultiplication functions in favor of new ones
in ColorUtilities.

* platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm:
(WebCore::PlatformCAAnimationCocoa::setFromValue):
(WebCore::PlatformCAAnimationCocoa::setToValue):
(WebCore::PlatformCAAnimationCocoa::setValues):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* platform/graphics/ca/win/PlatformCAAnimationWin.cpp:
(PlatformCAAnimationWin::setFromValue):
(PlatformCAAnimationWin::setToValue):
(PlatformCAAnimationWin::setValues):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* platform/graphics/cairo/CairoUtilities.cpp:
(WebCore::setSourceRGBAFromColor):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/cairo/GradientCairo.cpp:
(WebCore::addColorStopRGBA):
(WebCore::setCornerColorRGBA):
(WebCore::interpolateColorStop):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp:
(WebCore::ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace):
Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
Update to use new premulitplication functions.

* platform/graphics/cairo/NativeImageCairo.cpp:
(WebCore::nativeImageSinglePixelSolidColor):
Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
Update to use new premulitplication functions.

* platform/graphics/cpu/arm/filters/FELightingNEON.h:
(WebCore::FELighting::platformApplyNeon):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* platform/graphics/filters/FELighting.cpp:
(WebCore::FELighting::drawLighting):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/filters/FilterOperations.cpp:
(WebCore::FilterOperations::transformColor const):
(WebCore::FilterOperations::inverseTransformColor const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/gtk/ColorGtk.cpp:
(WebCore::Color::operator GdkRGBA const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGL::drawBorder):
(WebCore::TextureMapperGL::drawNumber):
(WebCore::prepareFilterProgram):
(WebCore::TextureMapperGL::drawSolidColor):
(WebCore::TextureMapperGL::clearColor):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/win/ColorDirect2D.cpp:
(WebCore::Color::operator D2D1_COLOR_F const):
(WebCore::Color::operator D2D1_VECTOR_4F const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/win/GradientDirect2D.cpp:
(WebCore::Gradient::generateGradient):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/win/GraphicsContextCGWin.cpp:
(WebCore::GraphicsContext::drawDotsForDocumentMarker):
Replace direct usage component access from SimpleColor with usage of accessed SRGBA<uint8_t>.

* platform/graphics/win/GraphicsContextDirect2D.cpp:
(WebCore::GraphicsContext::colorWithGlobalAlpha const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::disabledTextColor const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* rendering/RenderThemeIOS.mm:
(WebCore::shouldUseConvexGradient):
Replace toSRGBALossy() with toSRGBALossy<float>().

* rendering/TextPaintStyle.cpp:
(WebCore::textColorIsLegibleAgainstBackgroundColor):
Replace toSRGBALossy() with toSRGBALossy<float>().

* svg/properties/SVGAnimationAdditiveValueFunctionImpl.h:
(WebCore::SVGAnimationColorFunction::animate):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

Source/WebKit:

* UIProcess/API/wpe/WebKitColor.cpp:
(webkitColorFillFromWebCoreColor):
* UIProcess/gtk/ViewGestureControllerGtk.cpp:
(WebKit::ViewGestureController::beginSwipeGesture):
* WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:
(WebKit::animationValueFromKeyframeValue):
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::getDocumentBackgroundColor):
Adapt to use templatized toSRGBALossy<float/uint8_t>.

Tools:

* TestWebKitAPI/Tests/WebCore/ColorTests.cpp:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp:
(TestWebKitAPI::TEST):
Adapt tests to use templatized toSRGBALossy<float/uint8_t>.

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (263940 => 263941)


--- trunk/Source/WebCore/ChangeLog	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/ChangeLog	2020-07-04 19:20:50 UTC (rev 263941)
@@ -1,3 +1,213 @@
+2020-07-04  Sam Weinig  <[email protected]>
+
+        Part 1 of SimpleColor and SRGBA<uint8_t> are essentially the same - let's converge them
+        https://bugs.webkit.org/show_bug.cgi?id=213948
+
+        Reviewed by Darin Adler.
+
+        Begin converging SimpleColor and SRGBA<uint8_t>, starting with removing usages that
+        were getting SimpleColors to access or operate on the color's components.
+
+        - Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>
+        - Replace toSRGBALossy() with toSRGBALossy<float>().
+        - Remove direct color component accessors from SimpleColor. 
+        - Add new ARGB type to support explicit conversion from packed ARGB bits to a color type.
+        - Update premulitplication functions to operate on SRGBA<uint8_t> and rename them to
+          match existing function operating on SRGBA<float>.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        Removes SimpleColor.cpp
+
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::AccessibilityNodeObject::colorValue const):
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.
+
+        * accessibility/atk/WebKitAccessibleInterfaceText.cpp:
+        (getAttributeSetForAccessibilityObject):
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.
+
+        * accessibility/isolatedtree/AXIsolatedObject.cpp:
+        (WebCore::AXIsolatedObject::colorValue const):
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.
+
+        * css/DeprecatedCSSOMRGBColor.h:
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.
+        
+        * editing/cocoa/DataDetection.mm:
+        (WebCore::DataDetection::detectContentInRange):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * platform/graphics/Color.cpp:
+        (WebCore::Color::lightened const):
+        (WebCore::Color::darkened const):
+        (WebCore::Color::lightness const):
+        (WebCore::Color::luminance const):
+        (WebCore::Color::semanticColor const):
+        (WebCore::Color::toSRGBASimpleColorLossy const): Deleted.
+        (WebCore::Color::toSRGBALossy const): Deleted.
+        * platform/graphics/Color.h:
+        Remove toSRGBASimpleColorLossy() and templatize toSRGBALossy() to support both
+        lossy conversion to byte based components as well.
+
+        * platform/graphics/ColorBlending.cpp:
+        (WebCore::blendSourceOver):
+        (WebCore::blendWithWhite):
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.
+
+        (WebCore::blend):
+        (WebCore::blendWithoutPremultiply):
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>. Adopt new premultipliedCeiling
+        and unpremultiplied functions that operate on SRGBA<uint8_t> (rather than SimpleColor) and 
+        clamping conversion to SRGBA<uint8_t> via convertToComponentBytes<SRGBA>. premultipliedCeiling 
+        now works correctly for 0 alpha, so no workaround is needed anymore.
+
+        * platform/graphics/ColorTypes.h:
+        (WebCore::asARGB):
+        (WebCore::asSRGBA):
+        Add new type of color struct representing a format packing. The initial one is ARGB to support
+        the few places using SimpleColor to manipulate ARGB pixel data. 
+
+        * platform/graphics/ColorUtilities.cpp:
+        (WebCore::unpremultiplied):
+        (WebCore::premultipliedFlooring):
+        (WebCore::premultipliedCeiling):
+        (WebCore::unpremultipliedComponentByte):
+        * platform/graphics/ColorUtilities.h:
+        (WebCore::convertToComponentBytes):
+        (WebCore::convertToComponentFloats):
+        Move remaining premultiplication functions here (from SimpleColor.h/cpp) and reimplement
+        to operate on SRGBA<uint8_t>. Also slightly rename, premultiply -> premultiplied, to 
+        match existing premultiplied functions. While moving them, also fix the premultiplied
+        functions to better support 0 alpha to avoid workarounds in callers.
+        
+        Additional, this adds convertToComponentBytes/convertToComponentFloats helper functions
+        which convert to/from uint8_t/float based color types, and support creating color types
+        from values potentially outside of their supported value range. Right now, that value
+        range is always considerer to be 0-255 for uint8_t and 0-1 for float, but that can be
+        chnaged in the future by allowing color type structs to indicate their supported ranges.
+
+        * platform/graphics/ExtendedColor.cpp:
+        (WebCore::ExtendedColor::toSRGBAFloatComponentsLossy const):
+        (WebCore::ExtendedColor::toSRGBALossy const): Deleted.
+        * platform/graphics/ExtendedColor.h:
+        (WebCore::ExtendedColor::toSRGBALossy const):
+        Rename existing toSRGBALossy() to toSRGBAFloatComponentsLossy() and replace templatize
+        toSRGBALossy(), with the uint8_t case just down converting via new convertToComponentBytes.
+        
+        * platform/graphics/ImageBackingStore.h:
+        (WebCore::ImageBackingStore::fillRect):
+        (WebCore::ImageBackingStore::setPixel):
+        (WebCore::ImageBackingStore::blendPixel):
+        (WebCore::ImageBackingStore::pixelValue const):
+        Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
+        Update to use new premulitplication functions. Also, update the interface to take pixel 
+        components as uint8_t, rather than unsigned, as that is what the callers are passing anyway,
+        and it avoids us having to clamp/cast manually all over the case.
+
+        * platform/graphics/SimpleColor.cpp: Removed.
+        * platform/graphics/SimpleColor.h:
+        (WebCore::SimpleColor::alphaComponent const):
+        (WebCore::SimpleColor::asSRGBA const):
+        (WebCore::SimpleColor::redComponent const):
+        (WebCore::SimpleColor::greenComponent const):
+        (WebCore::SimpleColor::blueComponent const):
+        (WebCore::operator==):
+        (WebCore::makeSimpleColor):
+        Simplify interface, making red, green and blue component accessors private and having 
+        callers all use SRGBA directly. Remove premultiplication functions in favor of new ones  
+        in ColorUtilities.
+
+        * platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm:
+        (WebCore::PlatformCAAnimationCocoa::setFromValue):
+        (WebCore::PlatformCAAnimationCocoa::setToValue):
+        (WebCore::PlatformCAAnimationCocoa::setValues):
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.
+
+        * platform/graphics/ca/win/PlatformCAAnimationWin.cpp:
+        (PlatformCAAnimationWin::setFromValue):
+        (PlatformCAAnimationWin::setToValue):
+        (PlatformCAAnimationWin::setValues):
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.
+
+        * platform/graphics/cairo/CairoUtilities.cpp:
+        (WebCore::setSourceRGBAFromColor):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * platform/graphics/cairo/GradientCairo.cpp:
+        (WebCore::addColorStopRGBA):
+        (WebCore::setCornerColorRGBA):
+        (WebCore::interpolateColorStop):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp:
+        (WebCore::ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace):
+        Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
+        Update to use new premulitplication functions.
+
+        * platform/graphics/cairo/NativeImageCairo.cpp:
+        (WebCore::nativeImageSinglePixelSolidColor):
+        Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
+        Update to use new premulitplication functions. 
+
+        * platform/graphics/cpu/arm/filters/FELightingNEON.h:
+        (WebCore::FELighting::platformApplyNeon):
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.
+
+        * platform/graphics/filters/FELighting.cpp:
+        (WebCore::FELighting::drawLighting):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * platform/graphics/filters/FilterOperations.cpp:
+        (WebCore::FilterOperations::transformColor const):
+        (WebCore::FilterOperations::inverseTransformColor const):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * platform/graphics/gtk/ColorGtk.cpp:
+        (WebCore::Color::operator GdkRGBA const):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore::TextureMapperGL::drawBorder):
+        (WebCore::TextureMapperGL::drawNumber):
+        (WebCore::prepareFilterProgram):
+        (WebCore::TextureMapperGL::drawSolidColor):
+        (WebCore::TextureMapperGL::clearColor):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * platform/graphics/win/ColorDirect2D.cpp:
+        (WebCore::Color::operator D2D1_COLOR_F const):
+        (WebCore::Color::operator D2D1_VECTOR_4F const):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * platform/graphics/win/GradientDirect2D.cpp:
+        (WebCore::Gradient::generateGradient):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * platform/graphics/win/GraphicsContextCGWin.cpp:
+        (WebCore::GraphicsContext::drawDotsForDocumentMarker):
+        Replace direct usage component access from SimpleColor with usage of accessed SRGBA<uint8_t>.
+
+        * platform/graphics/win/GraphicsContextDirect2D.cpp:
+        (WebCore::GraphicsContext::colorWithGlobalAlpha const):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::disabledTextColor const):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::shouldUseConvexGradient):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * rendering/TextPaintStyle.cpp:
+        (WebCore::textColorIsLegibleAgainstBackgroundColor):
+        Replace toSRGBALossy() with toSRGBALossy<float>().
+
+        * svg/properties/SVGAnimationAdditiveValueFunctionImpl.h:
+        (WebCore::SVGAnimationColorFunction::animate):
+        Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.
+
 2020-07-04  Zalan Bujtas  <[email protected]>
 
         [LFC] Remove redundant Display::Box::HorizontalMargin c'tors

Modified: trunk/Source/WebCore/Sources.txt (263940 => 263941)


--- trunk/Source/WebCore/Sources.txt	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/Sources.txt	2020-07-04 19:20:50 UTC (rev 263941)
@@ -1886,7 +1886,6 @@
 platform/graphics/RemoteVideoSample.cpp
 platform/graphics/RoundedRect.cpp
 platform/graphics/ShadowBlur.cpp
-platform/graphics/SimpleColor.cpp
 platform/graphics/StringTruncator.cpp
 platform/graphics/SurrogatePairAwareTextIterator.cpp
 platform/graphics/TextRun.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (263940 => 263941)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-04 19:20:50 UTC (rev 263941)
@@ -9984,7 +9984,6 @@
 		7C30D9801F815AC100268356 /* JSAbortController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAbortController.h; sourceTree = "<group>"; };
 		7C30D9811F815AC100268356 /* JSAbortSignal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAbortSignal.h; sourceTree = "<group>"; };
 		7C30D9821F815AC200268356 /* JSAbortSignal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAbortSignal.cpp; sourceTree = "<group>"; };
-		7C31C88A247AD594005BF319 /* SimpleColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleColor.cpp; sourceTree = "<group>"; };
 		7C31C88C247AD595005BF319 /* SimpleColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleColor.h; sourceTree = "<group>"; };
 		7C330A011DF8FAC600D3395C /* GraphicsContextGLAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLAttributes.h; sourceTree = "<group>"; };
 		7C330A031DF9E95B00D3395C /* PositionOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PositionOptions.idl; sourceTree = "<group>"; };
@@ -25697,7 +25696,6 @@
 				A73F95FD12C97BFE0031AAF9 /* RoundedRect.h */,
 				0F3DD44D12F5EA1B000D9190 /* ShadowBlur.cpp */,
 				0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */,
-				7C31C88A247AD594005BF319 /* SimpleColor.cpp */,
 				7C31C88C247AD595005BF319 /* SimpleColor.h */,
 				CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */,
 				CDC8B5AC1804AE5D0016E685 /* SourceBufferPrivateClient.h */,

Modified: trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp (263940 => 263941)


--- trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -1983,10 +1983,10 @@
     if (!is<HTMLInputElement>(node()))
         return;
 
-    auto color = downcast<HTMLInputElement>(*node()).valueAsColor().toSRGBASimpleColorLossy();
-    r = color.redComponent();
-    g = color.greenComponent();
-    b = color.blueComponent();
+    auto color = downcast<HTMLInputElement>(*node()).valueAsColor().toSRGBALossy<uint8_t>();
+    r = color.red;
+    g = color.green;
+    b = color.blue;
 #endif
 }
 

Modified: trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp (263940 => 263941)


--- trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -92,7 +92,7 @@
 
     Color bgColor = style->visitedDependentColor(CSSPropertyBackgroundColor);
     if (bgColor.isValid()) {
-        auto [r, g, b, a] = bgColor.toSRGBASimpleColorLossy();
+        auto [r, g, b, a] = bgColor.toSRGBALossy<uint8_t>();
         buffer.reset(g_strdup_printf("%i,%i,%i", r, g, b));
         result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_BG_COLOR), buffer.get());
     }
@@ -99,7 +99,7 @@
 
     Color fgColor = style->visitedDependentColor(CSSPropertyColor);
     if (fgColor.isValid()) {
-        auto [r, g, b, a] = fgColor.toSRGBASimpleColorLossy();
+        auto [r, g, b, a] = fgColor.toSRGBALossy<uint8_t>();
         buffer.reset(g_strdup_printf("%i,%i,%i", r, g, b));
         result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_FG_COLOR), buffer.get());
     }

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp (263940 => 263941)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -701,10 +701,10 @@
 
 void AXIsolatedObject::colorValue(int& r, int& g, int& b) const
 {
-    auto color = colorAttributeValue(AXPropertyName::ColorValue).toSRGBASimpleColorLossy();
-    r = color.redComponent();
-    g = color.greenComponent();
-    b = color.blueComponent();
+    auto color = colorAttributeValue(AXPropertyName::ColorValue).toSRGBALossy<uint8_t>();
+    r = color.red;
+    g = color.green;
+    b = color.blue;
 }
 
 AXCoreObject* AXIsolatedObject::accessibilityHitTest(const IntPoint& point) const

Modified: trunk/Source/WebCore/css/DeprecatedCSSOMRGBColor.h (263940 => 263941)


--- trunk/Source/WebCore/css/DeprecatedCSSOMRGBColor.h	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/css/DeprecatedCSSOMRGBColor.h	2020-07-04 19:20:50 UTC (rev 263941)
@@ -37,7 +37,7 @@
     DeprecatedCSSOMPrimitiveValue& blue() { return m_blue; }
     DeprecatedCSSOMPrimitiveValue& alpha() { return m_alpha; }
 
-    SimpleColor color() const { return m_color; }
+    SimpleColor color() const { return makeSimpleColor(m_color); }
 
 private:
     template<typename NumberType> static Ref<DeprecatedCSSOMPrimitiveValue> createWrapper(CSSStyleDeclaration& owner, NumberType number)
@@ -46,15 +46,15 @@
     }
 
     DeprecatedCSSOMRGBColor(CSSStyleDeclaration& owner, const Color& color)
-        : m_color(color.toSRGBASimpleColorLossy())
-        , m_red(createWrapper(owner, m_color.redComponent()))
-        , m_green(createWrapper(owner, m_color.greenComponent()))
-        , m_blue(createWrapper(owner, m_color.blueComponent()))
-        , m_alpha(createWrapper(owner, m_color.alphaComponentAsFloat()))
+        : m_color(color.toSRGBALossy<uint8_t>())
+        , m_red(createWrapper(owner, m_color.red))
+        , m_green(createWrapper(owner, m_color.green))
+        , m_blue(createWrapper(owner, m_color.blue))
+        , m_alpha(createWrapper(owner, convertToComponentFloat(m_color.alpha)))
     {
     }
 
-    SimpleColor m_color;
+    SRGBA<uint8_t> m_color;
     Ref<DeprecatedCSSOMPrimitiveValue> m_red;
     Ref<DeprecatedCSSOMPrimitiveValue> m_green;
     Ref<DeprecatedCSSOMPrimitiveValue> m_blue;

Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (263940 => 263941)


--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm	2020-07-04 19:20:50 UTC (rev 263941)
@@ -621,7 +621,7 @@
                 if (renderStyle) {
                     auto textColor = renderStyle->visitedDependentColor(CSSPropertyColor);
                     if (textColor.isValid()) {
-                        auto hsla = toHSLA(textColor.toSRGBALossy());
+                        auto hsla = toHSLA(textColor.toSRGBALossy<float>());
 
                         // Force the lightness of the underline color to the middle, and multiply the alpha by 38%,
                         // so the color will appear on light and dark backgrounds, since only one color can be specified.

Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/Color.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -86,7 +86,7 @@
     if (isSimple() && asSimple() == black)
         return lightenedBlack;
 
-    auto [r, g, b, a] = toSRGBALossy();
+    auto [r, g, b, a] = toSRGBALossy<float>();
     float v = std::max({ r, g, b });
 
     if (v == 0.0f)
@@ -103,7 +103,7 @@
     if (isSimple() && asSimple() == white)
         return darkenedWhite;
     
-    auto [r, g, b, a] = toSRGBALossy();
+    auto [r, g, b, a] = toSRGBALossy<float>();
 
     float v = std::max({ r, g, b });
     float multiplier = std::max(0.0f, (v - 0.33f) / v);
@@ -114,7 +114,7 @@
 float Color::lightness() const
 {
     // FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms for HSL.
-    return WebCore::lightness(toSRGBALossy());
+    return WebCore::lightness(toSRGBALossy<float>());
 }
 
 float Color::luminance() const
@@ -121,7 +121,7 @@
 {
     // FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms
     // for luminance (e.g. convertToXYZ(c).yComponent()).
-    return WebCore::luminance(toSRGBALossy());
+    return WebCore::luminance(toSRGBALossy<float>());
 }
 
 Color Color::colorWithAlpha(float alpha) const
@@ -149,7 +149,7 @@
     if (isSemantic())
         return *this;
 
-    return { toSRGBASimpleColorLossy(), Semantic };
+    return { makeSimpleColor(toSRGBALossy<uint8_t>()), Semantic };
 }
 
 std::pair<ColorSpace, ColorComponents<float>> Color::colorSpaceAndComponents() const
@@ -159,20 +159,6 @@
     return { ColorSpace::SRGB, asColorComponents(asSimple().asSRGBA<float>()) };
 }
 
-SimpleColor Color::toSRGBASimpleColorLossy() const
-{
-    if (isExtended())
-        return makeSimpleColor(asExtended().toSRGBALossy());
-    return asSimple();
-}
-
-SRGBA<float> Color::toSRGBALossy() const
-{
-    if (isExtended())
-        return asExtended().toSRGBALossy();
-    return asSimple().asSRGBA<float>();
-}
-
 TextStream& operator<<(TextStream& ts, const Color& color)
 {
     return ts << serializationForRenderTreeAsText(color);

Modified: trunk/Source/WebCore/platform/graphics/Color.h (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/Color.h	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2020-07-04 19:20:50 UTC (rev 263941)
@@ -121,11 +121,8 @@
     WEBCORE_EXPORT std::pair<ColorSpace, ColorComponents<float>> colorSpaceAndComponents() const;
 
     // This will convert non-sRGB colorspace colors into sRGB.
-    WEBCORE_EXPORT SimpleColor toSRGBASimpleColorLossy() const;
+    template<typename T> SRGBA<T> toSRGBALossy() const;
 
-    // This will convert non-sRGB colorspace colors into sRGB.
-    WEBCORE_EXPORT SRGBA<float> toSRGBALossy() const;
-
     WEBCORE_EXPORT Color lightened() const;
     WEBCORE_EXPORT Color darkened() const;
 
@@ -268,6 +265,13 @@
     return WTF::intHash(m_colorData.simpleColorAndFlags);
 }
 
+template<typename T> SRGBA<T> Color::toSRGBALossy() const
+{
+    if (isExtended())
+        return asExtended().toSRGBALossy<T>();
+    return asSimple().asSRGBA<T>();
+}
+
 inline Color Color::invertedColorWithAlpha(Optional<float> alpha) const
 {
     return alpha ? invertedColorWithAlpha(alpha.value()) : *this;

Modified: trunk/Source/WebCore/platform/graphics/ColorBlending.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/ColorBlending.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/ColorBlending.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -39,8 +39,8 @@
     if (!source.alpha())
         return backdrop;
 
-    auto [backdropR, backdropG, backdropB, backdropA] = backdrop.toSRGBASimpleColorLossy();
-    auto [sourceR, sourceG, sourceB, sourceA] = source.toSRGBASimpleColorLossy();
+    auto [backdropR, backdropG, backdropB, backdropA] = backdrop.toSRGBALossy<uint8_t>();
+    auto [sourceR, sourceG, sourceB, sourceA] = source.toSRGBALossy<uint8_t>();
 
     int d = 0xFF * (backdropA + sourceA) - backdropA * sourceA;
     int a = d / 0xFF;
@@ -68,7 +68,7 @@
     if (!color.isOpaque())
         return color;
 
-    auto [existingR, existingG, existingB, existingAlpha] = color.toSRGBASimpleColorLossy();
+    auto [existingR, existingG, existingB, existingAlpha] = color.toSRGBALossy<uint8_t>();
 
     SimpleColor result;
     for (int alpha = startAlpha; alpha <= endAlpha; alpha += alphaIncrement) {
@@ -97,18 +97,17 @@
     if (progress == 1 && !to.isValid())
         return { };
 
-    // Since premultiplyCeiling() bails on zero alpha, special-case that.
-    auto premultipliedFrom = from.alpha() ? premultiplyCeiling(from.toSRGBASimpleColorLossy()) : Color::transparent;
-    auto premultipliedTo = to.alpha() ? premultiplyCeiling(to.toSRGBASimpleColorLossy()) : Color::transparent;
+    auto premultipliedFrom = premultipliedCeiling(from.toSRGBALossy<uint8_t>());
+    auto premultipliedTo = premultipliedCeiling(to.toSRGBALossy<uint8_t>());
 
-    auto premultBlended = makeSimpleColor(
-        WebCore::blend(premultipliedFrom.redComponent(), premultipliedTo.redComponent(), progress),
-        WebCore::blend(premultipliedFrom.greenComponent(), premultipliedTo.greenComponent(), progress),
-        WebCore::blend(premultipliedFrom.blueComponent(), premultipliedTo.blueComponent(), progress),
-        WebCore::blend(premultipliedFrom.alphaComponent(), premultipliedTo.alphaComponent(), progress)
+    auto premultipliedBlended = convertToComponentBytes<SRGBA>(
+        WebCore::blend(premultipliedFrom.red, premultipliedTo.red, progress),
+        WebCore::blend(premultipliedFrom.green, premultipliedTo.green, progress),
+        WebCore::blend(premultipliedFrom.blue, premultipliedTo.blue, progress),
+        WebCore::blend(premultipliedFrom.alpha, premultipliedTo.alpha, progress)
     );
 
-    return unpremultiply(premultBlended);
+    return makeSimpleColor(unpremultiplied(premultipliedBlended));
 }
 
 Color blendWithoutPremultiply(const Color& from, const Color& to, double progress)
@@ -118,14 +117,14 @@
     if (progress == 1 && !to.isValid())
         return { };
 
-    auto fromSRGB = from.toSRGBASimpleColorLossy();
-    auto toSRGB = from.toSRGBASimpleColorLossy();
+    auto fromSRGB = from.toSRGBALossy<uint8_t>();
+    auto toSRGB = from.toSRGBALossy<uint8_t>();
 
     return makeSimpleColor(
-        WebCore::blend(fromSRGB.redComponent(), toSRGB.redComponent(), progress),
-        WebCore::blend(fromSRGB.greenComponent(), toSRGB.greenComponent(), progress),
-        WebCore::blend(fromSRGB.blueComponent(), toSRGB.blueComponent(), progress),
-        WebCore::blend(fromSRGB.alphaComponent(), toSRGB.alphaComponent(), progress)
+        WebCore::blend(fromSRGB.red, toSRGB.red, progress),
+        WebCore::blend(fromSRGB.green, toSRGB.green, progress),
+        WebCore::blend(fromSRGB.blue, toSRGB.blue, progress),
+        WebCore::blend(fromSRGB.alpha, toSRGB.alpha, progress)
     );
 }
 

Modified: trunk/Source/WebCore/platform/graphics/ColorTypes.h (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/ColorTypes.h	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/ColorTypes.h	2020-07-04 19:20:50 UTC (rev 263941)
@@ -237,4 +237,21 @@
     return !(a == b);
 }
 
+
+// Packed Color Formats
+
+struct ARGB {
+    uint32_t value;
+};
+
+constexpr ARGB asARGB(SRGBA<uint8_t> color)
+{
+    return { static_cast<unsigned>(color.alpha << 24 | color.red << 16 | color.green << 8 | color.blue) };
+}
+
+constexpr SRGBA<uint8_t> asSRGBA(ARGB color)
+{
+    return { static_cast<uint8_t>(color.value >> 16), static_cast<uint8_t>(color.value >> 8), static_cast<uint8_t>(color.value), static_cast<uint8_t>(color.value >> 24) };
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -66,4 +66,43 @@
     return { r * a, g * a, b * a, a };
 }
 
+SRGBA<float> unpremultiplied(const SRGBA<float>& color)
+{
+    auto [r, g, b, a] = color;
+    return { r / a, g / a, b / a, a };
+}
+
+SRGBA<uint8_t> premultipliedFlooring(SRGBA<uint8_t> color)
+{
+    auto [r, g, b, a] = color;
+    if (!a)
+        return { 0, 0, 0, 0 };
+    if (a == 255)
+        return color;
+    return convertToComponentBytes<SRGBA>(fastDivideBy255(r * a), fastDivideBy255(g * a), fastDivideBy255(b * a), a);
+}
+
+SRGBA<uint8_t> premultipliedCeiling(SRGBA<uint8_t> color)
+{
+    auto [r, g, b, a] = color;
+    if (!a)
+        return { 0, 0, 0, 0 };
+    if (a == 255)
+        return color;
+    return convertToComponentBytes<SRGBA>(fastDivideBy255(r * a + 254), fastDivideBy255(g * a + 254), fastDivideBy255(b * a + 254), a);
+}
+
+static inline uint16_t unpremultipliedComponentByte(uint8_t c, uint8_t a)
+{
+    return (fastMultiplyBy255(c) + a - 1) / a;
+}
+
+SRGBA<uint8_t> unpremultiplied(SRGBA<uint8_t> color)
+{
+    auto [r, g, b, a] = color;
+    if (!a || a == 255)
+        return color;
+    return convertToComponentBytes<SRGBA>(unpremultipliedComponentByte(r, a), unpremultipliedComponentByte(g, a), unpremultipliedComponentByte(b, a), a);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.h (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/ColorUtilities.h	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.h	2020-07-04 19:20:50 UTC (rev 263941)
@@ -38,7 +38,12 @@
 float contrastRatio(const SRGBA<float>&, const SRGBA<float>&);
 
 SRGBA<float> premultiplied(const SRGBA<float>&);
+SRGBA<float> unpremultiplied(const SRGBA<float>&);
 
+SRGBA<uint8_t> premultipliedFlooring(SRGBA<uint8_t>);
+SRGBA<uint8_t> premultipliedCeiling(SRGBA<uint8_t>);
+SRGBA<uint8_t> unpremultiplied(SRGBA<uint8_t>);
+
 inline uint8_t convertPrescaledToComponentByte(float f)
 {
     return std::clamp(std::lround(f), 0l, 255l);
@@ -54,6 +59,28 @@
     return byte / 255.0f;
 }
 
+template<template<typename> typename ColorType> inline ColorType<uint8_t> convertToComponentBytes(const ColorType<float>& color)
+{
+    auto components = asColorComponents(color);
+    return { convertToComponentByte(components[0]), convertToComponentByte(components[1]), convertToComponentByte(components[2]), convertToComponentByte(components[3]) };
+}
+
+template<template<typename> typename ColorType> constexpr ColorType<uint8_t> convertToComponentBytes(int r, int g, int b, int a)
+{
+    return { static_cast<uint8_t>(std::clamp(r, 0, 0xFF)), static_cast<uint8_t>(std::clamp(g, 0, 0xFF)), static_cast<uint8_t>(std::clamp(b, 0, 0xFF)), static_cast<uint8_t>(std::clamp(a, 0, 0xFF)) };
+}
+
+template<template<typename> typename ColorType> constexpr ColorType<float> convertToComponentFloats(const ColorType<uint8_t>& color)
+{
+    auto components = asColorComponents(color);
+    return { convertToComponentFloat(components[0]), convertToComponentFloat(components[1]), convertToComponentFloat(components[2]), convertToComponentFloat(components[3]) };
+}
+
+template<template<typename> typename ColorType> constexpr ColorType<float> convertToComponentFloats(float r, float g, float b, float a)
+{
+    return { std::clamp(r, 0.0f, 1.0f), std::clamp(g, 0.0f, 1.0f), std::clamp(b, 0.0f, 1.0f), std::clamp(a, 0.0f, 1.0f) };
+}
+
 constexpr uint16_t fastMultiplyBy255(uint16_t value)
 {
     return (value << 8) - value;

Modified: trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -57,7 +57,7 @@
     return ExtendedColor::create(1.0f - c1, 1.0f - c2, 1.0f - c3, overrideAlpha, colorSpace());
 }
 
-SRGBA<float> ExtendedColor::toSRGBALossy() const
+SRGBA<float> ExtendedColor::toSRGBAFloatComponentsLossy() const
 {
     switch (m_colorSpace) {
     case ColorSpace::SRGB:

Modified: trunk/Source/WebCore/platform/graphics/ExtendedColor.h (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/ExtendedColor.h	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/ExtendedColor.h	2020-07-04 19:20:50 UTC (rev 263941)
@@ -27,6 +27,8 @@
 
 #include "ColorComponents.h"
 #include "ColorSpace.h"
+#include "ColorTypes.h"
+#include "ColorUtilities.h"
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 
@@ -49,11 +51,18 @@
     Ref<ExtendedColor> colorWithAlpha(float) const;
     Ref<ExtendedColor> invertedColorWithAlpha(float) const;
 
-    SRGBA<float> toSRGBALossy() const;
-
     bool isWhite() const;
     bool isBlack() const;
 
+    // This will convert non-sRGB colorspace colors into sRGB.
+    template<typename T> constexpr SRGBA<T> toSRGBALossy() const
+    {
+        if constexpr (std::is_same_v<T, float>)
+            return toSRGBAFloatComponentsLossy();
+        else if constexpr (std::is_same_v<T, uint8_t>)
+            return convertToComponentBytes(toSRGBAFloatComponentsLossy());
+    }
+
 private:
     ExtendedColor(float c1, float c2, float c3, float alpha, ColorSpace colorSpace)
         : m_components(c1, c2, c3, alpha)
@@ -61,6 +70,8 @@
     {
     }
 
+    WEBCORE_EXPORT SRGBA<float> toSRGBAFloatComponentsLossy() const;
+
     ColorComponents<float> m_components;
     ColorSpace m_colorSpace;
 };

Modified: trunk/Source/WebCore/platform/graphics/ImageBackingStore.h (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/ImageBackingStore.h	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/ImageBackingStore.h	2020-07-04 19:20:50 UTC (rev 263941)
@@ -102,7 +102,7 @@
         }
     }
 
-    void fillRect(const IntRect &rect, unsigned r, unsigned g, unsigned b, unsigned a)
+    void fillRect(const IntRect& rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
     {
         if (rect.isEmpty() || !inBounds(rect))
             return;
@@ -136,45 +136,45 @@
         return m_pixelsPtr + y * m_size.width() + x;
     }
 
-    void setPixel(uint32_t* dest, unsigned r, unsigned g, unsigned b, unsigned a)
+    void setPixel(uint32_t* dest, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
     {
         ASSERT(dest);
         *dest = pixelValue(r, g, b, a);
     }
 
-    void setPixel(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a)
+    void setPixel(int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
     {
         setPixel(pixelAt(x, y), r, g, b, a);
     }
 
-    void blendPixel(uint32_t* dest, unsigned r, unsigned g, unsigned b, unsigned a)
+    void blendPixel(uint32_t* dest, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
     {
         if (!a)
             return;
 
-        SimpleColor pixel { *dest };
+        auto pixel = asSRGBA(ARGB { *dest });
 
-        if (a >= 255 || !pixel.isVisible()) {
+        if (a >= 255 || !pixel.alpha) {
             setPixel(dest, r, g, b, a);
             return;
         }
 
         if (!m_premultiplyAlpha)
-            pixel = premultiplyFlooring(pixel);
+            pixel = premultipliedFlooring(pixel);
 
-        unsigned d = 255 - a;
+        uint8_t d = 255 - a;
 
-        r = fastDivideBy255(r * a + pixel.redComponent() * d);
-        g = fastDivideBy255(g * a + pixel.greenComponent() * d);
-        b = fastDivideBy255(b * a + pixel.blueComponent() * d);
-        a += fastDivideBy255(d * pixel.alphaComponent());
+        r = fastDivideBy255(r * a + pixel.red * d);
+        g = fastDivideBy255(g * a + pixel.green * d);
+        b = fastDivideBy255(b * a + pixel.blue * d);
+        a += fastDivideBy255(d * pixel.alpha);
 
-        auto result = makeSimpleColor(r, g, b, a);
+        auto result = SRGBA { r, g, b, a };
 
         if (!m_premultiplyAlpha)
-            result = unpremultiply(result);
+            result = unpremultiplied(result);
 
-        *dest = result.valueAsARGB();
+        *dest = asARGB(result).value;
     }
 
     static bool isOverSize(const IntSize& size)
@@ -221,17 +221,17 @@
         return IntRect(IntPoint(), m_size).contains(rect);
     }
 
-    uint32_t pixelValue(unsigned r, unsigned g, unsigned b, unsigned a) const
+    uint32_t pixelValue(uint8_t r, uint8_t g, uint8_t b, uint8_t a) const
     {
         if (m_premultiplyAlpha && !a)
             return 0;
 
-        auto result = makeSimpleColor(r, g, b, a);
+        auto result = SRGBA { r, g, b, a };
 
         if (m_premultiplyAlpha && a < 255)
-            result = premultiplyFlooring(result);
+            result = premultipliedFlooring(result);
 
-        return result.valueAsARGB();
+        return asARGB(result).value;
     }
 
     RefPtr<SharedBuffer::DataSegment> m_pixels;

Deleted: trunk/Source/WebCore/platform/graphics/SimpleColor.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/SimpleColor.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/SimpleColor.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2003-2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#include "config.h"
-#include "SimpleColor.h"
-
-namespace WebCore {
-
-SimpleColor premultiplyFlooring(SimpleColor color)
-{
-    auto [r, g, b, a] = color;
-    if (!a || a == 255)
-        return color;
-    return makeSimpleColor(fastDivideBy255(r * a), fastDivideBy255(g * a), fastDivideBy255(b * a), a);
-}
-
-SimpleColor premultiplyCeiling(SimpleColor color)
-{
-    auto [r, g, b, a] = color;
-    if (!a || a == 255)
-        return color;
-    return makeSimpleColor(fastDivideBy255(r * a + 254), fastDivideBy255(g * a + 254), fastDivideBy255(b * a + 254), a);
-}
-
-static inline uint16_t unpremultiplyChannel(uint8_t c, uint8_t a)
-{
-    return (fastMultiplyBy255(c) + a - 1) / a;
-}
-
-SimpleColor unpremultiply(SimpleColor color)
-{
-    auto [r, g, b, a] = color;
-    if (!a || a == 255)
-        return color;
-    return makeSimpleColor(unpremultiplyChannel(r, a), unpremultiplyChannel(g, a), unpremultiplyChannel(b, a), a);
-}
-
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/SimpleColor.h (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/SimpleColor.h	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/SimpleColor.h	2020-07-04 19:20:50 UTC (rev 263941)
@@ -42,11 +42,7 @@
     constexpr uint32_t valueAsARGB() const { return m_value; }
     constexpr uint32_t value() const { return m_value; }
 
-    constexpr uint8_t redComponent() const { return m_value >> 16; }
-    constexpr uint8_t greenComponent() const { return m_value >> 8; }
-    constexpr uint8_t blueComponent() const { return m_value; }
     constexpr uint8_t alphaComponent() const { return m_value >> 24; }
-
     constexpr float alphaComponentAsFloat() const { return convertToComponentFloat(alphaComponent()); }
 
     constexpr bool isOpaque() const { return alphaComponent() == 0xFF; }
@@ -62,7 +58,13 @@
         return { static_cast<uint8_t>(0xFF - redComponent()), static_cast<uint8_t>(0xFF - greenComponent()), static_cast<uint8_t>(0xFF - blueComponent()), alpha };
     }
 
-    template<typename T> constexpr SRGBA<T> asSRGBA() const;
+    template<typename T> constexpr SRGBA<T> asSRGBA() const
+    {
+        if constexpr (std::is_same_v<T, float>)
+            return { convertToComponentFloat(redComponent()), convertToComponentFloat(greenComponent()), convertToComponentFloat(blueComponent()),  convertToComponentFloat(alphaComponent()) };
+        else if constexpr (std::is_same_v<T, uint8_t>)
+            return { redComponent(), greenComponent(), blueComponent(), alphaComponent() };
+    }
 
     template<std::size_t N>
     constexpr uint8_t get() const
@@ -79,6 +81,10 @@
     }
 
 private:
+    constexpr uint8_t redComponent() const { return m_value >> 16; }
+    constexpr uint8_t greenComponent() const { return m_value >> 8; }
+    constexpr uint8_t blueComponent() const { return m_value; }
+
     uint32_t m_value { 0 };
 };
 
@@ -90,10 +96,6 @@
 constexpr SimpleColor makeSimpleColor(const SRGBA<uint8_t>&);
 SimpleColor makeSimpleColor(const SRGBA<float>&);
 
-SimpleColor premultiplyFlooring(SimpleColor);
-SimpleColor premultiplyCeiling(SimpleColor);
-SimpleColor unpremultiply(SimpleColor);
-
 inline bool operator==(SimpleColor a, SimpleColor b)
 {
     return a.value() == b.value();
@@ -116,25 +118,14 @@
 
 constexpr SimpleColor makeSimpleColor(const SRGBA<uint8_t>& sRGBA)
 {
-    auto [r, g, b, a] = sRGBA;
-    return { r, g, b, a };
+    return { sRGBA.red, sRGBA.green, sRGBA.blue, sRGBA.alpha };
 }
 
 inline SimpleColor makeSimpleColor(const SRGBA<float>& sRGBA)
 {
-    auto [r, g, b, a] = sRGBA;
-    return { convertToComponentByte(r), convertToComponentByte(g), convertToComponentByte(b), convertToComponentByte(a) };
+    return makeSimpleColor(convertToComponentBytes(sRGBA));
 }
 
-template<typename T> constexpr SRGBA<T> SimpleColor::asSRGBA() const
-{
-    if constexpr (std::is_floating_point_v<T>)
-        return { convertToComponentFloat(redComponent()), convertToComponentFloat(greenComponent()), convertToComponentFloat(blueComponent()),  convertToComponentFloat(alphaComponent()) };
-    else
-        return { redComponent(), greenComponent(), blueComponent(), alphaComponent() };
-}
-
-
 } // namespace WebCore
 
 namespace std {

Modified: trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm	2020-07-04 19:20:50 UTC (rev 263941)
@@ -396,7 +396,7 @@
 {
     if (!isBasicAnimation())
         return;
-    auto [r, g, b, a] = value.toSRGBASimpleColorLossy();
+    auto [r, g, b, a] = value.toSRGBALossy<uint8_t>();
     [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:@[@(r), @(g), @(b), @(a)]];
 }
 
@@ -439,7 +439,7 @@
 {
     if (!isBasicAnimation())
         return;
-    auto [r, g, b, a] = value.toSRGBASimpleColorLossy();
+    auto [r, g, b, a] = value.toSRGBALossy<uint8_t>();
     [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:@[@(r), @(g), @(b), @(a)]];
 }
 
@@ -496,7 +496,7 @@
         return;
 
     [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:createNSArray(value, [] (auto& color) {
-        auto [r, g, b, a] = color.toSRGBASimpleColorLossy();
+        auto [r, g, b, a] = color.template toSRGBALossy<uint8_t>();
         return @[@(r), @(g), @(b), @(a)];
     }).get()];
 }

Modified: trunk/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -367,8 +367,8 @@
     if (animationType() != Basic)
         return;
 
-    auto simpleColor = value.toSRGBASimpleColorLossy();
-    CGFloat a[4] = { simpleColor.redComponent(), simpleColor.greenComponent(), simpleColor.blueComponent(), simpleColor.alphaComponent() };
+    auto components = value.toSRGBALossy<uint8_t>();
+    CGFloat a[4] = { components.red, components.green, components.blue, components.alpha };
     RetainPtr<CACFVectorRef> v = adoptCF(CACFVectorCreate(4, a));
     CACFAnimationSetFromValue(m_animation.get(), v.get());
 }
@@ -419,8 +419,8 @@
     if (animationType() != Basic)
         return;
 
-    auto simpleColor = value.toSRGBASimpleColorLossy();
-    CGFloat a[4] = { simpleColor.redComponent(), simpleColor.greenComponent(), simpleColor.blueComponent(), simpleColor.alphaComponent() };
+    auto components = value.toSRGBALossy<uint8_t>();
+    CGFloat a[4] = { components.red, components.green, components.blue, components.alpha };
     RetainPtr<CACFVectorRef> v = adoptCF(CACFVectorCreate(4, a));
     CACFAnimationSetToValue(m_animation.get(), v.get());
 }
@@ -489,8 +489,8 @@
         
     RetainPtr<CFMutableArrayRef> array = adoptCF(CFArrayCreateMutable(0, value.size(), &kCFTypeArrayCallBacks));
     for (size_t i = 0; i < value.size(); ++i) {
-        auto simpleColor = value[i].toSRGBASimpleColorLossy();
-        CGFloat a[4] = { simpleColor.redComponent(), simpleColor.greenComponent(), simpleColor.blueComponent(), simpleColor.alphaComponent() };
+        auto components = value[i].toSRGBALossy<uint8_t>();
+        CGFloat a[4] = { components.red, components.green, components.blue, components.alpha };
         RetainPtr<CACFVectorRef> v = adoptCF(CACFVectorCreate(4, a));
         CFArrayAppendValue(array.get(), v.get());
     }

Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -83,7 +83,7 @@
 
 void setSourceRGBAFromColor(cairo_t* context, const Color& color)
 {
-    auto [r, g, b, a] = color.toSRGBALossy();
+    auto [r, g, b, a] = color.toSRGBALossy<float>();
     cairo_set_source_rgba(context, r, g, b, a);
 }
 

Modified: trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -43,7 +43,7 @@
 
 static void addColorStopRGBA(cairo_pattern_t *gradient, Gradient::ColorStop stop, float globalAlpha)
 {
-    auto [r, g, b, a] = stop.color.toSRGBALossy();
+    auto [r, g, b, a] = stop.color.toSRGBALossy<float>();
     cairo_pattern_add_color_stop_rgba(gradient, stop.offset, r, g, b, a * globalAlpha);
 }
 
@@ -55,7 +55,7 @@
 
 static void setCornerColorRGBA(cairo_pattern_t* gradient, int id, Gradient::ColorStop stop, float globalAlpha)
 {
-    auto [r, g, b, a] = stop.color.toSRGBALossy();
+    auto [r, g, b, a] = stop.color.toSRGBALossy<float>();
     cairo_mesh_pattern_set_corner_color_rgba(gradient, id, r, g, b, a * globalAlpha);
 }
 
@@ -135,8 +135,8 @@
 
 static Gradient::ColorStop interpolateColorStop(Gradient::ColorStop from, Gradient::ColorStop to)
 {
-    auto [r1, g1, b1, a1] = from.color.toSRGBALossy();
-    auto [r2, g2, b2, a2] = to.color.toSRGBALossy();
+    auto [r1, g1, b1, a1] = from.color.toSRGBALossy<float>();
+    auto [r2, g2, b2, a2] = to.color.toSRGBALossy<float>();
 
     float offset = from.offset + (to.offset - from.offset) * 0.5f;
     float r = r1 + (r2 - r1) * 0.5f;

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -80,9 +80,9 @@
         unsigned* row = reinterpret_cast_ptr<unsigned*>(dataSrc + stride * y);
         for (int x = 0; x < m_logicalSize.width(); x++) {
             unsigned* pixel = row + x;
-            auto pixelColor = unpremultiply(SimpleColor { *pixel });
-            pixelColor = makeSimpleColor(lookUpTable[pixelColor.redComponent()], lookUpTable[pixelColor.greenComponent()], lookUpTable[pixelColor.blueComponent()], pixelColor.alphaComponent());
-            *pixel = premultiplyCeiling(pixelColor).valueAsARGB();
+            auto pixelComponents = unpremultiplied(asSRGBA(ARGB { *pixel }));
+            pixelComponents = { lookUpTable[pixelComponents.red], lookUpTable[pixelComponents.green], lookUpTable[pixelComponents.blue], pixelComponents.alpha };
+            *pixel = asARGB(premultipliedCeiling(pixelComponents)).value;
         }
     }
     cairo_surface_mark_dirty_rectangle(m_surface.get(), 0, 0, m_logicalSize.width(), m_logicalSize.height());

Modified: trunk/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -54,7 +54,7 @@
         return Color();
 
     unsigned* pixel = reinterpret_cast_ptr<unsigned*>(cairo_image_surface_get_data(image.get()));
-    return unpremultiply(SimpleColor { *pixel });
+    return makeSimpleColor(unpremultiplied(asSRGBA(ARGB { *pixel })));
 }
 
 void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& imageSize, const ImagePaintingOptions& options)

Modified: trunk/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h	2020-07-04 19:20:50 UTC (rev 263941)
@@ -111,11 +111,11 @@
     // Set light source arguments.
     floatArguments.constOne = 1;
 
-    auto simpleColor = m_lightingColor.toSRGBASimpleColorLossy();
+    auto color = m_lightingColor.toSRGBALossy<uint8_t>();
 
-    floatArguments.colorRed = simpleColor.redComponent();
-    floatArguments.colorGreen = simpleColor.greenComponent();
-    floatArguments.colorBlue = simpleColor.blueComponent();
+    floatArguments.colorRed = color.red;
+    floatArguments.colorGreen = color.green;
+    floatArguments.colorBlue = color.blue;
     floatArguments.padding4 = 0;
 
     if (m_lightSource->type() == LS_POINT) {

Modified: trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -405,10 +405,10 @@
     data.heightDecreasedByOne = height - 1;
     
     if (operatingColorSpace() == ColorSpace::LinearRGB) {
-        auto [r, g, b, a] = toLinearSRGBA(m_lightingColor.toSRGBALossy());
+        auto [r, g, b, a] = toLinearSRGBA(m_lightingColor.toSRGBALossy<float>());
         paintingData.initialLightingData.colorVector = FloatPoint3D(r, g, b);
     } else {
-        auto [r, g, b, a] = m_lightingColor.toSRGBALossy();
+        auto [r, g, b, a] = m_lightingColor.toSRGBALossy<float>();
         paintingData.initialLightingData.colorVector = FloatPoint3D(r, g, b);
     }
     m_lightSource->initPaintingData(*this, paintingData);

Modified: trunk/Source/WebCore/platform/graphics/filters/FilterOperations.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/filters/FilterOperations.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterOperations.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -110,7 +110,7 @@
     if (color.isSemantic())
         return false;
 
-    auto sRGBAColor = color.toSRGBALossy();
+    auto sRGBAColor = color.toSRGBALossy<float>();
 
     for (auto& operation : m_operations) {
         if (!operation->transformColor(sRGBAColor))
@@ -129,7 +129,7 @@
     if (color.isSemantic())
         return false;
 
-    auto sRGBAColor = color.toSRGBALossy();
+    auto sRGBAColor = color.toSRGBALossy<float>();
 
     for (auto& operation : m_operations) {
         if (!operation->inverseTransformColor(sRGBAColor))

Modified: trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -32,7 +32,7 @@
 
 Color::operator GdkRGBA() const
 {
-    auto [r, g, b, a] = toSRGBALossy();
+    auto [r, g, b, a] = toSRGBALossy<float>();
     return { r, g, b, a };
 }
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -253,7 +253,7 @@
     Ref<TextureMapperShaderProgram> program = data().getShaderProgram(TextureMapperShaderProgram::SolidColor);
     glUseProgram(program->programID());
 
-    auto [r, g, b, a] = premultiplied(color.toSRGBALossy());
+    auto [r, g, b, a] = premultiplied(color.toSRGBALossy<float>());
     glUniform4f(program->colorLocation(), r, g, b, a);
     glLineWidth(width);
 
@@ -275,7 +275,7 @@
     cairo_t* cr = cairo_create(surface);
 
     // Since we won't swap R+B when uploading a texture, paint with the swapped R+B color.
-    auto [r, g, b, a] = color.toSRGBALossy();
+    auto [r, g, b, a] = color.toSRGBALossy<float>();
     cairo_set_source_rgba(cr, b, g, r, a);
 
     cairo_rectangle(cr, 0, 0, width, height);
@@ -414,7 +414,7 @@
             break;
         case 1:
             // Second pass: we need the shadow color and the content texture for compositing.
-            auto [r, g, b, a] = premultiplied(shadow.color().toSRGBALossy());
+            auto [r, g, b, a] = premultiplied(shadow.color().toSRGBALossy<float>());
             glUniform4f(program.colorLocation(), r, g, b, a);
             glUniform2f(program.blurRadiusLocation(), 0, shadow.stdDeviation() / float(size.height()));
             glUniform2f(program.shadowOffsetLocation(), 0, 0);
@@ -676,7 +676,7 @@
     Ref<TextureMapperShaderProgram> program = data().getShaderProgram(options);
     glUseProgram(program->programID());
 
-    auto [r, g, b, a] = premultiplied(color.toSRGBALossy());
+    auto [r, g, b, a] = premultiplied(color.toSRGBALossy<float>());
     glUniform4f(program->colorLocation(), r, g, b, a);
     if (a < 1 && isBlendingAllowed)
         flags |= ShouldBlend;
@@ -686,7 +686,7 @@
 
 void TextureMapperGL::clearColor(const Color& color)
 {
-    auto [r, g, b, a] = color.toSRGBALossy();
+    auto [r, g, b, a] = color.toSRGBALossy<float>();
     glClearColor(r, g, b, a);
     glClear(GL_COLOR_BUFFER_BIT);
 }

Modified: trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -40,13 +40,13 @@
 
 Color::operator D2D1_COLOR_F() const
 {
-    auto [r, g, b, a] = toSRGBALossy();
+    auto [r, g, b, a] = toSRGBALossy<float>();
     return D2D1::ColorF(r, g, b, a);
 }
 
 Color::operator D2D1_VECTOR_4F() const
 {
-    auto [r, g, b, a] = toSRGBALossy();
+    auto [r, g, b, a] = toSRGBALossy<float>();
     return D2D1::Vector4F(r, g, b, a);
 }
 

Modified: trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -72,7 +72,7 @@
     Vector<D2D1_GRADIENT_STOP> gradientStops;
     // FIXME: Add support for ExtendedColor.
     for (auto stop : m_stops) {
-        auto [r, g, b, a] stop.color.toSRGBALossy();
+        auto [r, g, b, a] stop.color.toSRGBALossy<float>();
         gradientStops.append(D2D1::GradientStop(stop.offset, D2D1::ColorF(r, g, b, a)));
     }
 

Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -202,7 +202,8 @@
     static constexpr SimpleColor grammarPatternColor { makeSimpleColor(0, 128, 0) };
 
     const SimpleColor& patternColor = style.mode == DocumentMarkerLineStyle::Mode::Grammar ? grammarPatternColor : spellingPatternColor;
-    CGContextSetRGBStrokeColor(context, patternColor.redComponent(), patternColor.greenComponent(), patternColor.blueComponent(), patternColor.alphaComponent());
+    auto patternColorComponents = patternColor.asSRGBA<uint8_t>();
+    CGContextSetRGBStrokeColor(context, patternColorComponents.red, patternColorComponents.green, patternColorComponents.blue, patternColorComponents.alpha);
 
     CGAffineTransform userToBase = getUserToBaseCTM(context);
     CGPoint phase = CGPointApplyAffineTransform(point, userToBase);

Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp (263940 => 263941)


--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -379,7 +379,7 @@
 
 D2D1_COLOR_F GraphicsContext::colorWithGlobalAlpha(const Color& color) const
 {
-    auto [r, g, b, a] = color.toSRGBALossy();
+    auto [r, g, b, a] = color.toSRGBALossy<float>();
     return D2D1::ColorF(r, g, b, a * m_data->currentGlobalAlpha());
 }
 

Modified: trunk/Source/WebCore/rendering/RenderTheme.cpp (263940 => 263941)


--- trunk/Source/WebCore/rendering/RenderTheme.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/rendering/RenderTheme.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -1402,7 +1402,7 @@
     // If there's not very much contrast between the disabled color and the background color,
     // just leave the text color alone. We don't want to change a good contrast color scheme so that it has really bad contrast.
     // If the contrast was already poor, then it doesn't do any good to change it to a different poor contrast color scheme.
-    if (contrastRatio(disabledColor.toSRGBALossy(), backgroundColor.toSRGBALossy()) < minColorContrastValue)
+    if (contrastRatio(disabledColor.toSRGBALossy<float>(), backgroundColor.toSRGBALossy<float>()) < minColorContrastValue)
         return textColor;
 
     return disabledColor;

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (263940 => 263941)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2020-07-04 19:20:50 UTC (rev 263941)
@@ -1055,7 +1055,7 @@
 static bool shouldUseConvexGradient(const Color& backgroundColor)
 {
     // FIXME: This should probably be using luminance.
-    auto [r, g, b, a] = backgroundColor.toSRGBALossy();
+    auto [r, g, b, a] = backgroundColor.toSRGBALossy<float>();
     float largestNonAlphaChannel = std::max({ r, g, b });
     return a > 0.5 && largestNonAlphaChannel < 0.5;
 }

Modified: trunk/Source/WebCore/rendering/TextPaintStyle.cpp (263940 => 263941)


--- trunk/Source/WebCore/rendering/TextPaintStyle.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/rendering/TextPaintStyle.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -63,7 +63,7 @@
 {
     // Uses the WCAG 2.0 definition of legibility: a contrast ratio of 4.5:1 or greater.
     // https://www.w3.org/TR/WCAG20/#visual-audio-contrast-contrast
-    return contrastRatio(textColor.toSRGBALossy(), backgroundColor.toSRGBALossy()) > 4.5;
+    return contrastRatio(textColor.toSRGBALossy<float>(), backgroundColor.toSRGBALossy<float>()) > 4.5;
 }
 
 static Color adjustColorForVisibilityOnBackground(const Color& textColor, const Color& backgroundColor)

Modified: trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h (263940 => 263941)


--- trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h	2020-07-04 19:20:50 UTC (rev 263941)
@@ -81,15 +81,15 @@
 
     void animate(SVGElement*, float progress, unsigned repeatCount, Color& animated)
     {
-        auto simpleAnimated = animated.toSRGBASimpleColorLossy();
-        auto simpleFrom = m_animationMode == AnimationMode::To ? simpleAnimated : m_from.toSRGBASimpleColorLossy();
-        auto simpleTo = m_to.toSRGBASimpleColorLossy();
-        auto simpleToAtEndOfDuration = toAtEndOfDuration().toSRGBASimpleColorLossy();
+        auto simpleAnimated = animated.toSRGBALossy<uint8_t>();
+        auto simpleFrom = m_animationMode == AnimationMode::To ? simpleAnimated : m_from.toSRGBALossy<uint8_t>();
+        auto simpleTo = m_to.toSRGBALossy<uint8_t>();
+        auto simpleToAtEndOfDuration = toAtEndOfDuration().toSRGBALossy<uint8_t>();
         
-        float red = Base::animate(progress, repeatCount, simpleFrom.redComponent(), simpleTo.redComponent(), simpleToAtEndOfDuration.redComponent(), simpleAnimated.redComponent());
-        float green = Base::animate(progress, repeatCount, simpleFrom.greenComponent(), simpleTo.greenComponent(), simpleToAtEndOfDuration.greenComponent(), simpleAnimated.greenComponent());
-        float blue = Base::animate(progress, repeatCount, simpleFrom.blueComponent(), simpleTo.blueComponent(), simpleToAtEndOfDuration.blueComponent(), simpleAnimated.blueComponent());
-        float alpha = Base::animate(progress, repeatCount, simpleFrom.alphaComponent(), simpleTo.alphaComponent(), simpleToAtEndOfDuration.alphaComponent(), simpleAnimated.alphaComponent());
+        float red = Base::animate(progress, repeatCount, simpleFrom.red, simpleTo.red, simpleToAtEndOfDuration.red, simpleAnimated.red);
+        float green = Base::animate(progress, repeatCount, simpleFrom.green, simpleTo.green, simpleToAtEndOfDuration.green, simpleAnimated.green);
+        float blue = Base::animate(progress, repeatCount, simpleFrom.blue, simpleTo.blue, simpleToAtEndOfDuration.blue, simpleAnimated.blue);
+        float alpha = Base::animate(progress, repeatCount, simpleFrom.alpha, simpleTo.alpha, simpleToAtEndOfDuration.alpha, simpleAnimated.alpha);
         
         animated = makeSimpleColor(roundAndClampColorChannel(red), roundAndClampColorChannel(green), roundAndClampColorChannel(blue), roundAndClampColorChannel(alpha));
     }
@@ -103,12 +103,12 @@
         if (!toColor.isValid())
             return { };
             
-        auto simpleFrom = fromColor.toSRGBASimpleColorLossy();
-        auto simpleTo = toColor.toSRGBASimpleColorLossy();
+        auto simpleFrom = fromColor.toSRGBALossy<uint8_t>();
+        auto simpleTo = toColor.toSRGBALossy<uint8_t>();
 
-        float red = simpleFrom.redComponent() - simpleTo.redComponent();
-        float green = simpleFrom.greenComponent() - simpleTo.greenComponent();
-        float blue = simpleFrom.blueComponent() - simpleTo.blueComponent();
+        float red = simpleFrom.red - simpleTo.red;
+        float green = simpleFrom.green - simpleTo.green;
+        float blue = simpleFrom.blue - simpleTo.blue;
 
         return std::hypot(red, green, blue);
     }
@@ -126,14 +126,14 @@
 
     void addFromAndToValues(SVGElement*) override
     {
-        auto simpleFrom = m_from.toSRGBASimpleColorLossy();
-        auto simpleTo = m_to.toSRGBASimpleColorLossy();
+        auto simpleFrom = m_from.toSRGBALossy<uint8_t>();
+        auto simpleTo = m_to.toSRGBALossy<uint8_t>();
 
         // Ignores any alpha and sets alpha on result to 100% opaque.
         m_to = makeSimpleColor(
-            roundAndClampColorChannel(simpleTo.redComponent() + simpleFrom.redComponent()),
-            roundAndClampColorChannel(simpleTo.greenComponent() + simpleFrom.greenComponent()),
-            roundAndClampColorChannel(simpleTo.blueComponent() + simpleFrom.blueComponent())
+            roundAndClampColorChannel(simpleTo.red + simpleFrom.red),
+            roundAndClampColorChannel(simpleTo.green + simpleFrom.green),
+            roundAndClampColorChannel(simpleTo.blue + simpleFrom.blue)
         );
     }
 

Modified: trunk/Source/WebKit/ChangeLog (263940 => 263941)


--- trunk/Source/WebKit/ChangeLog	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebKit/ChangeLog	2020-07-04 19:20:50 UTC (rev 263941)
@@ -1,3 +1,20 @@
+2020-07-04  Sam Weinig  <[email protected]>
+
+        Part 1 of SimpleColor and SRGBA<uint8_t> are essentially the same - let's converge them
+        https://bugs.webkit.org/show_bug.cgi?id=213948
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/API/wpe/WebKitColor.cpp:
+        (webkitColorFillFromWebCoreColor):
+        * UIProcess/gtk/ViewGestureControllerGtk.cpp:
+        (WebKit::ViewGestureController::beginSwipeGesture):
+        * WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:
+        (WebKit::animationValueFromKeyframeValue):
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::getDocumentBackgroundColor):
+        Adapt to use templatized toSRGBALossy<float/uint8_t>.
+
 2020-07-03  Darin Adler  <[email protected]>
 
         Make generate-unified-sources.sh not depend on features being listed in FEATURE_DEFINES environment variable

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp (263940 => 263941)


--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -82,7 +82,7 @@
 {
     RELEASE_ASSERT(webCoreColor.isValid());
 
-    auto [r, g, b, a] = webCoreColor.toSRGBALossy();
+    auto [r, g, b, a] = webCoreColor.toSRGBALossy<float>();
     color->red = r;
     color->green = g;
     color->blue = b;

Modified: trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp (263940 => 263941)


--- trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -338,7 +338,7 @@
         if (color.isValid()) {
             m_backgroundColorForCurrentSnapshot = color;
             if (!m_currentSwipeSnapshotPattern) {
-                auto [red, green, blue, alpha] = color.toSRGBALossy();
+                auto [red, green, blue, alpha] = color.toSRGBALossy<float>();
                 m_currentSwipeSnapshotPattern = adoptRef(cairo_pattern_create_rgba(red, green, blue, alpha));
             }
         }

Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm (263940 => 263941)


--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm	2020-07-04 19:20:50 UTC (rev 263941)
@@ -693,7 +693,7 @@
         return @(keyframeValue.numberValue());
             
     case PlatformCAAnimationRemote::KeyframeValue::ColorKeyType: {
-        auto [r, g, b, a] = keyframeValue.colorValue().toSRGBASimpleColorLossy();
+        auto [r, g, b, a] = keyframeValue.colorValue().toSRGBALossy<uint8_t>();
         return @[ @(r), @(g), @(b), @(a) ];
     }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp (263940 => 263941)


--- trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -656,7 +656,7 @@
     if (!bgColor.isValid())
         return false;
 
-    auto [r, g, b, a] = bgColor.toSRGBALossy();
+    auto [r, g, b, a] = bgColor.toSRGBALossy<float>();
     *red = r;
     *green = g;
     *blue = b;

Modified: trunk/Tools/ChangeLog (263940 => 263941)


--- trunk/Tools/ChangeLog	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Tools/ChangeLog	2020-07-04 19:20:50 UTC (rev 263941)
@@ -1,3 +1,16 @@
+2020-07-04  Sam Weinig  <[email protected]>
+
+        Part 1 of SimpleColor and SRGBA<uint8_t> are essentially the same - let's converge them
+        https://bugs.webkit.org/show_bug.cgi?id=213948
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WebCore/ColorTests.cpp:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp:
+        (TestWebKitAPI::TEST):
+        Adapt tests to use templatized toSRGBALossy<float/uint8_t>.
+
 2020-07-04  Sergio Villar Senin  <[email protected]>
 
         [Flatpak SDK] Require OpenXR 1.0.9

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp (263940 => 263941)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -38,7 +38,7 @@
 {
     Color color = Color::white;
 
-    auto hslaColor = toHSLA(color.toSRGBALossy());
+    auto hslaColor = toHSLA(color.toSRGBALossy<float>());
 
     EXPECT_FLOAT_EQ(0, hslaColor.hue);
     EXPECT_FLOAT_EQ(0, hslaColor.saturation);
@@ -54,7 +54,7 @@
 {
     Color color = Color::black;
 
-    auto hslaColor = toHSLA(color.toSRGBALossy());
+    auto hslaColor = toHSLA(color.toSRGBALossy<float>());
 
     EXPECT_FLOAT_EQ(0, hslaColor.hue);
     EXPECT_FLOAT_EQ(0, hslaColor.saturation);
@@ -70,7 +70,7 @@
 {
     Color color = makeSimpleColor(255, 0, 0);
 
-    auto hslaColor = toHSLA(color.toSRGBALossy());
+    auto hslaColor = toHSLA(color.toSRGBALossy<float>());
 
     EXPECT_FLOAT_EQ(0, hslaColor.hue);
     EXPECT_FLOAT_EQ(1, hslaColor.saturation);
@@ -86,7 +86,7 @@
 {
     Color color = makeSimpleColor(0, 255, 0);
 
-    auto hslaColor = toHSLA(color.toSRGBALossy());
+    auto hslaColor = toHSLA(color.toSRGBALossy<float>());
 
     EXPECT_FLOAT_EQ(0.33333334, hslaColor.hue);
     EXPECT_FLOAT_EQ(1, hslaColor.saturation);
@@ -102,7 +102,7 @@
 {
     Color color = makeSimpleColor(0, 0, 255);
 
-    auto hslaColor = toHSLA(color.toSRGBALossy());
+    auto hslaColor = toHSLA(color.toSRGBALossy<float>());
 
     EXPECT_FLOAT_EQ(0.66666669, hslaColor.hue);
     EXPECT_FLOAT_EQ(1, hslaColor.saturation);
@@ -118,7 +118,7 @@
 {
     Color color = Color::darkGray;
 
-    auto hslaColor = toHSLA(color.toSRGBALossy());
+    auto hslaColor = toHSLA(color.toSRGBALossy<float>());
 
     EXPECT_FLOAT_EQ(0, hslaColor.hue);
     EXPECT_FLOAT_EQ(0, hslaColor.saturation);
@@ -134,7 +134,7 @@
 {
     Color color = Color::gray;
 
-    auto hslaColor = toHSLA(color.toSRGBALossy());
+    auto hslaColor = toHSLA(color.toSRGBALossy<float>());
 
     EXPECT_FLOAT_EQ(0, hslaColor.hue);
     EXPECT_FLOAT_EQ(0, hslaColor.saturation);
@@ -150,7 +150,7 @@
 {
     Color color = Color::lightGray;
 
-    auto hslaColor = toHSLA(color.toSRGBALossy());
+    auto hslaColor = toHSLA(color.toSRGBALossy<float>());
 
     EXPECT_FLOAT_EQ(0, hslaColor.hue);
     EXPECT_FLOAT_EQ(0, hslaColor.saturation);
@@ -183,29 +183,29 @@
     validColor = makeSimpleColor(1, 2, 3, 4);
     EXPECT_TRUE(validColor.isValid());
     EXPECT_FALSE(validColor.isExtended());
-    auto simpleValidColor = validColor.toSRGBASimpleColorLossy();
-    EXPECT_EQ(simpleValidColor.redComponent(), 1);
-    EXPECT_EQ(simpleValidColor.greenComponent(), 2);
-    EXPECT_EQ(simpleValidColor.blueComponent(), 3);
-    EXPECT_EQ(simpleValidColor.alphaComponent(), 4);
+    auto validColorComponents = validColor.toSRGBALossy<uint8_t>();
+    EXPECT_EQ(validColorComponents.red, 1);
+    EXPECT_EQ(validColorComponents.green, 2);
+    EXPECT_EQ(validColorComponents.blue, 3);
+    EXPECT_EQ(validColorComponents.alpha, 4);
 
     Color yetAnotherValidColor(WTFMove(validColor));
     EXPECT_TRUE(yetAnotherValidColor.isValid());
     EXPECT_FALSE(yetAnotherValidColor.isExtended());
-    auto simpleYetAnotherValidColor = yetAnotherValidColor.toSRGBASimpleColorLossy();
-    EXPECT_EQ(simpleYetAnotherValidColor.redComponent(), 1);
-    EXPECT_EQ(simpleYetAnotherValidColor.greenComponent(), 2);
-    EXPECT_EQ(simpleYetAnotherValidColor.blueComponent(), 3);
-    EXPECT_EQ(simpleYetAnotherValidColor.alphaComponent(), 4);
+    auto yetAnotherValidColorComponents = yetAnotherValidColor.toSRGBALossy<uint8_t>();
+    EXPECT_EQ(yetAnotherValidColorComponents.red, 1);
+    EXPECT_EQ(yetAnotherValidColorComponents.green, 2);
+    EXPECT_EQ(yetAnotherValidColorComponents.blue, 3);
+    EXPECT_EQ(yetAnotherValidColorComponents.alpha, 4);
 
     otherValidColor = WTFMove(yetAnotherValidColor);
     EXPECT_TRUE(otherValidColor.isValid());
     EXPECT_FALSE(otherValidColor.isExtended());
-    auto simpleOtherValidColor = otherValidColor.toSRGBASimpleColorLossy();
-    EXPECT_EQ(simpleOtherValidColor.redComponent(), 1);
-    EXPECT_EQ(simpleOtherValidColor.greenComponent(), 2);
-    EXPECT_EQ(simpleOtherValidColor.blueComponent(), 3);
-    EXPECT_EQ(simpleOtherValidColor.alphaComponent(), 4);
+    auto otherValidColorComponents = otherValidColor.toSRGBALossy<uint8_t>();
+    EXPECT_EQ(otherValidColorComponents.red, 1);
+    EXPECT_EQ(otherValidColorComponents.green, 2);
+    EXPECT_EQ(otherValidColorComponents.blue, 3);
+    EXPECT_EQ(otherValidColorComponents.alpha, 4);
 }
 
 TEST(Color, Luminance)
@@ -216,21 +216,22 @@
     auto c = makeSimpleColor(85, 90, 160);
     EXPECT_FLOAT_EQ(Color(c).luminance(), 0.11781692);
 
-    EXPECT_EQ(c.redComponent(), 85);
-    EXPECT_EQ(c.greenComponent(), 90);
-    EXPECT_EQ(c.blueComponent(), 160);
+    auto cComponents = c.asSRGBA<uint8_t>();
+    EXPECT_EQ(cComponents.red, 85);
+    EXPECT_EQ(cComponents.green, 90);
+    EXPECT_EQ(cComponents.blue, 160);
 
-    auto cLigtened = Color(c).lightened().toSRGBASimpleColorLossy();
-    EXPECT_FLOAT_EQ(Color(cLigtened).luminance(), 0.29168808);
-    EXPECT_EQ(cLigtened.redComponent(), 130);
-    EXPECT_EQ(cLigtened.greenComponent(), 137);
-    EXPECT_EQ(cLigtened.blueComponent(), 244);
+    auto cLigtened = Color(c).lightened().toSRGBALossy<uint8_t>();
+    EXPECT_FLOAT_EQ(Color(makeSimpleColor(cLigtened)).luminance(), 0.29168808);
+    EXPECT_EQ(cLigtened.red, 130);
+    EXPECT_EQ(cLigtened.green, 137);
+    EXPECT_EQ(cLigtened.blue, 244);
 
-    auto cDarkened = Color(c).darkened().toSRGBASimpleColorLossy();
-    EXPECT_FLOAT_EQ(Color(cDarkened).luminance(), 0.027006727);
-    EXPECT_EQ(cDarkened.redComponent(), 40);
-    EXPECT_EQ(cDarkened.greenComponent(), 43);
-    EXPECT_EQ(cDarkened.blueComponent(), 76);
+    auto cDarkened = Color(c).darkened().toSRGBALossy<uint8_t>();
+    EXPECT_FLOAT_EQ(Color(makeSimpleColor(cDarkened)).luminance(), 0.027006727);
+    EXPECT_EQ(cDarkened.red, 40);
+    EXPECT_EQ(cDarkened.green, 43);
+    EXPECT_EQ(cDarkened.blue, 76);
 }
 
 } // namespace TestWebKitAPI

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp (263940 => 263941)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp	2020-07-04 19:17:30 UTC (rev 263940)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp	2020-07-04 19:20:50 UTC (rev 263941)
@@ -241,7 +241,7 @@
     Color p3Color { makeExtendedColor(1.0, 0.5, 0.25, 0.75, ColorSpace::DisplayP3) };
     EXPECT_TRUE(p3Color.isExtended());
 
-    auto sRGBAColor = p3Color.toSRGBALossy();
+    auto sRGBAColor = p3Color.toSRGBALossy<float>();
     EXPECT_TRUE(WTF::areEssentiallyEqual(sRGBAColor.red, 1.0f));
     EXPECT_TRUE(WTF::areEssentiallyEqual(sRGBAColor.green, 0.462537885f));
     EXPECT_TRUE(WTF::areEssentiallyEqual(sRGBAColor.blue, 0.149147838f));
@@ -252,7 +252,7 @@
 {
     Color linearColor { makeExtendedColor(1.0, 0.5, 0.25, 0.75, ColorSpace::LinearRGB) };
     EXPECT_TRUE(linearColor.isExtended());
-    auto sRGBAColor = linearColor.toSRGBALossy();
+    auto sRGBAColor = linearColor.toSRGBALossy<float>();
     EXPECT_TRUE(WTF::areEssentiallyEqual(sRGBAColor.red, 1.0f));
     EXPECT_TRUE(WTF::areEssentiallyEqual(sRGBAColor.green, 0.735356927f));
     EXPECT_TRUE(WTF::areEssentiallyEqual(sRGBAColor.blue, 0.537098706f));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to