From 1a972b5062db8b61e5217bd35986f8dbdd36b75e Mon Sep 17 00:00:00 2001 From: Sam Weinig Date: Sat, 4 Jul 2020 19:20:50 +0000 Subject: [PATCH] Part 1 of SimpleColor and SRGBA 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, starting with removing usages that were getting SimpleColors to access or operate on the color's components. - Replace toSRGBASimpleColorLossy() with toSRGBALossy - Replace toSRGBALossy() with toSRGBALossy(). - 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 and rename them to match existing function operating on SRGBA. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: Removes SimpleColor.cpp * accessibility/AccessibilityNodeObject.cpp: (WebCore::AccessibilityNodeObject::colorValue const): Replace toSRGBASimpleColorLossy() with toSRGBALossy. * accessibility/atk/WebKitAccessibleInterfaceText.cpp: (getAttributeSetForAccessibilityObject): Replace toSRGBASimpleColorLossy() with toSRGBALossy. * accessibility/isolatedtree/AXIsolatedObject.cpp: (WebCore::AXIsolatedObject::colorValue const): Replace toSRGBASimpleColorLossy() with toSRGBALossy. * css/DeprecatedCSSOMRGBColor.h: Replace toSRGBASimpleColorLossy() with toSRGBALossy. * editing/cocoa/DataDetection.mm: (WebCore::DataDetection::detectContentInRange): Replace toSRGBALossy() with toSRGBALossy(). * 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. (WebCore::blend): (WebCore::blendWithoutPremultiply): Replace toSRGBASimpleColorLossy() with toSRGBALossy. Adopt new premultipliedCeiling and unpremultiplied functions that operate on SRGBA (rather than SimpleColor) and clamping conversion to SRGBA via convertToComponentBytes. 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. 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. 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. * platform/graphics/ca/win/PlatformCAAnimationWin.cpp: (PlatformCAAnimationWin::setFromValue): (PlatformCAAnimationWin::setToValue): (PlatformCAAnimationWin::setValues): Replace toSRGBASimpleColorLossy() with toSRGBALossy. * platform/graphics/cairo/CairoUtilities.cpp: (WebCore::setSourceRGBAFromColor): Replace toSRGBALossy() with toSRGBALossy(). * platform/graphics/cairo/GradientCairo.cpp: (WebCore::addColorStopRGBA): (WebCore::setCornerColorRGBA): (WebCore::interpolateColorStop): Replace toSRGBALossy() with toSRGBALossy(). * platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp: (WebCore::ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace): Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA. 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. Update to use new premulitplication functions. * platform/graphics/cpu/arm/filters/FELightingNEON.h: (WebCore::FELighting::platformApplyNeon): Replace toSRGBASimpleColorLossy() with toSRGBALossy. * platform/graphics/filters/FELighting.cpp: (WebCore::FELighting::drawLighting): Replace toSRGBALossy() with toSRGBALossy(). * platform/graphics/filters/FilterOperations.cpp: (WebCore::FilterOperations::transformColor const): (WebCore::FilterOperations::inverseTransformColor const): Replace toSRGBALossy() with toSRGBALossy(). * platform/graphics/gtk/ColorGtk.cpp: (WebCore::Color::operator GdkRGBA const): Replace toSRGBALossy() with toSRGBALossy(). * platform/graphics/texmap/TextureMapperGL.cpp: (WebCore::TextureMapperGL::drawBorder): (WebCore::TextureMapperGL::drawNumber): (WebCore::prepareFilterProgram): (WebCore::TextureMapperGL::drawSolidColor): (WebCore::TextureMapperGL::clearColor): Replace toSRGBALossy() with toSRGBALossy(). * platform/graphics/win/ColorDirect2D.cpp: (WebCore::Color::operator D2D1_COLOR_F const): (WebCore::Color::operator D2D1_VECTOR_4F const): Replace toSRGBALossy() with toSRGBALossy(). * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::generateGradient): Replace toSRGBALossy() with toSRGBALossy(). * platform/graphics/win/GraphicsContextCGWin.cpp: (WebCore::GraphicsContext::drawDotsForDocumentMarker): Replace direct usage component access from SimpleColor with usage of accessed SRGBA. * platform/graphics/win/GraphicsContextDirect2D.cpp: (WebCore::GraphicsContext::colorWithGlobalAlpha const): Replace toSRGBALossy() with toSRGBALossy(). * rendering/RenderTheme.cpp: (WebCore::RenderTheme::disabledTextColor const): Replace toSRGBALossy() with toSRGBALossy(). * rendering/RenderThemeIOS.mm: (WebCore::shouldUseConvexGradient): Replace toSRGBALossy() with toSRGBALossy(). * rendering/TextPaintStyle.cpp: (WebCore::textColorIsLegibleAgainstBackgroundColor): Replace toSRGBALossy() with toSRGBALossy(). * svg/properties/SVGAnimationAdditiveValueFunctionImpl.h: (WebCore::SVGAnimationColorFunction::animate): Replace toSRGBASimpleColorLossy() with toSRGBALossy. 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. Tools: * TestWebKitAPI/Tests/WebCore/ColorTests.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp: (TestWebKitAPI::TEST): Adapt tests to use templatized toSRGBALossy. Canonical link: https://commits.webkit.org/226765@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263941 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 210 ++++++++++++++++++ Source/WebCore/Sources.txt | 1 - .../WebCore/WebCore.xcodeproj/project.pbxproj | 2 - .../accessibility/AccessibilityNodeObject.cpp | 8 +- .../atk/WebKitAccessibleInterfaceText.cpp | 4 +- .../isolatedtree/AXIsolatedObject.cpp | 8 +- Source/WebCore/css/DeprecatedCSSOMRGBColor.h | 14 +- Source/WebCore/editing/cocoa/DataDetection.mm | 2 +- Source/WebCore/platform/graphics/Color.cpp | 24 +- Source/WebCore/platform/graphics/Color.h | 12 +- .../platform/graphics/ColorBlending.cpp | 35 ++- Source/WebCore/platform/graphics/ColorTypes.h | 17 ++ .../platform/graphics/ColorUtilities.cpp | 39 ++++ .../platform/graphics/ColorUtilities.h | 27 +++ .../platform/graphics/ExtendedColor.cpp | 2 +- .../WebCore/platform/graphics/ExtendedColor.h | 15 +- .../platform/graphics/ImageBackingStore.h | 38 ++-- .../WebCore/platform/graphics/SimpleColor.cpp | 61 ----- .../WebCore/platform/graphics/SimpleColor.h | 35 ++- .../ca/cocoa/PlatformCAAnimationCocoa.mm | 6 +- .../ca/win/PlatformCAAnimationWin.cpp | 12 +- .../graphics/cairo/CairoUtilities.cpp | 2 +- .../platform/graphics/cairo/GradientCairo.cpp | 8 +- .../ImageBufferCairoImageSurfaceBackend.cpp | 6 +- .../graphics/cairo/NativeImageCairo.cpp | 2 +- .../graphics/cpu/arm/filters/FELightingNEON.h | 8 +- .../platform/graphics/filters/FELighting.cpp | 4 +- .../graphics/filters/FilterOperations.cpp | 4 +- .../platform/graphics/gtk/ColorGtk.cpp | 2 +- .../graphics/texmap/TextureMapperGL.cpp | 10 +- .../platform/graphics/win/ColorDirect2D.cpp | 4 +- .../graphics/win/GradientDirect2D.cpp | 2 +- .../graphics/win/GraphicsContextCGWin.cpp | 3 +- .../graphics/win/GraphicsContextDirect2D.cpp | 2 +- Source/WebCore/rendering/RenderTheme.cpp | 2 +- Source/WebCore/rendering/RenderThemeIOS.mm | 2 +- Source/WebCore/rendering/TextPaintStyle.cpp | 2 +- .../SVGAnimationAdditiveValueFunctionImpl.h | 36 +-- Source/WebKit/ChangeLog | 17 ++ .../WebKit/UIProcess/API/wpe/WebKitColor.cpp | 2 +- .../gtk/ViewGestureControllerGtk.cpp | 2 +- .../PlatformCAAnimationRemote.mm | 2 +- Source/WebKit/WebProcess/WebPage/WebFrame.cpp | 2 +- Tools/ChangeLog | 13 ++ .../Tests/WebCore/ColorTests.cpp | 77 +++---- .../Tests/WebCore/ExtendedColorTests.cpp | 4 +- 46 files changed, 521 insertions(+), 269 deletions(-) delete mode 100644 Source/WebCore/platform/graphics/SimpleColor.cpp diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 971355f82aed..d3653b77013d 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,213 @@ +2020-07-04 Sam Weinig + + Part 1 of SimpleColor and SRGBA 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, starting with removing usages that + were getting SimpleColors to access or operate on the color's components. + + - Replace toSRGBASimpleColorLossy() with toSRGBALossy + - Replace toSRGBALossy() with toSRGBALossy(). + - 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 and rename them to + match existing function operating on SRGBA. + + * Sources.txt: + * WebCore.xcodeproj/project.pbxproj: + Removes SimpleColor.cpp + + * accessibility/AccessibilityNodeObject.cpp: + (WebCore::AccessibilityNodeObject::colorValue const): + Replace toSRGBASimpleColorLossy() with toSRGBALossy. + + * accessibility/atk/WebKitAccessibleInterfaceText.cpp: + (getAttributeSetForAccessibilityObject): + Replace toSRGBASimpleColorLossy() with toSRGBALossy. + + * accessibility/isolatedtree/AXIsolatedObject.cpp: + (WebCore::AXIsolatedObject::colorValue const): + Replace toSRGBASimpleColorLossy() with toSRGBALossy. + + * css/DeprecatedCSSOMRGBColor.h: + Replace toSRGBASimpleColorLossy() with toSRGBALossy. + + * editing/cocoa/DataDetection.mm: + (WebCore::DataDetection::detectContentInRange): + Replace toSRGBALossy() with toSRGBALossy(). + + * 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. + + (WebCore::blend): + (WebCore::blendWithoutPremultiply): + Replace toSRGBASimpleColorLossy() with toSRGBALossy. Adopt new premultipliedCeiling + and unpremultiplied functions that operate on SRGBA (rather than SimpleColor) and + clamping conversion to SRGBA via convertToComponentBytes. 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. 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. + 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. + + * platform/graphics/ca/win/PlatformCAAnimationWin.cpp: + (PlatformCAAnimationWin::setFromValue): + (PlatformCAAnimationWin::setToValue): + (PlatformCAAnimationWin::setValues): + Replace toSRGBASimpleColorLossy() with toSRGBALossy. + + * platform/graphics/cairo/CairoUtilities.cpp: + (WebCore::setSourceRGBAFromColor): + Replace toSRGBALossy() with toSRGBALossy(). + + * platform/graphics/cairo/GradientCairo.cpp: + (WebCore::addColorStopRGBA): + (WebCore::setCornerColorRGBA): + (WebCore::interpolateColorStop): + Replace toSRGBALossy() with toSRGBALossy(). + + * platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp: + (WebCore::ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace): + Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA. + 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. + Update to use new premulitplication functions. + + * platform/graphics/cpu/arm/filters/FELightingNEON.h: + (WebCore::FELighting::platformApplyNeon): + Replace toSRGBASimpleColorLossy() with toSRGBALossy. + + * platform/graphics/filters/FELighting.cpp: + (WebCore::FELighting::drawLighting): + Replace toSRGBALossy() with toSRGBALossy(). + + * platform/graphics/filters/FilterOperations.cpp: + (WebCore::FilterOperations::transformColor const): + (WebCore::FilterOperations::inverseTransformColor const): + Replace toSRGBALossy() with toSRGBALossy(). + + * platform/graphics/gtk/ColorGtk.cpp: + (WebCore::Color::operator GdkRGBA const): + Replace toSRGBALossy() with toSRGBALossy(). + + * platform/graphics/texmap/TextureMapperGL.cpp: + (WebCore::TextureMapperGL::drawBorder): + (WebCore::TextureMapperGL::drawNumber): + (WebCore::prepareFilterProgram): + (WebCore::TextureMapperGL::drawSolidColor): + (WebCore::TextureMapperGL::clearColor): + Replace toSRGBALossy() with toSRGBALossy(). + + * platform/graphics/win/ColorDirect2D.cpp: + (WebCore::Color::operator D2D1_COLOR_F const): + (WebCore::Color::operator D2D1_VECTOR_4F const): + Replace toSRGBALossy() with toSRGBALossy(). + + * platform/graphics/win/GradientDirect2D.cpp: + (WebCore::Gradient::generateGradient): + Replace toSRGBALossy() with toSRGBALossy(). + + * platform/graphics/win/GraphicsContextCGWin.cpp: + (WebCore::GraphicsContext::drawDotsForDocumentMarker): + Replace direct usage component access from SimpleColor with usage of accessed SRGBA. + + * platform/graphics/win/GraphicsContextDirect2D.cpp: + (WebCore::GraphicsContext::colorWithGlobalAlpha const): + Replace toSRGBALossy() with toSRGBALossy(). + + * rendering/RenderTheme.cpp: + (WebCore::RenderTheme::disabledTextColor const): + Replace toSRGBALossy() with toSRGBALossy(). + + * rendering/RenderThemeIOS.mm: + (WebCore::shouldUseConvexGradient): + Replace toSRGBALossy() with toSRGBALossy(). + + * rendering/TextPaintStyle.cpp: + (WebCore::textColorIsLegibleAgainstBackgroundColor): + Replace toSRGBALossy() with toSRGBALossy(). + + * svg/properties/SVGAnimationAdditiveValueFunctionImpl.h: + (WebCore::SVGAnimationColorFunction::animate): + Replace toSRGBASimpleColorLossy() with toSRGBALossy. + 2020-07-04 Zalan Bujtas [LFC] Remove redundant Display::Box::HorizontalMargin c'tors diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt index a76c3816b847..88f1a6c52120 100644 --- a/Source/WebCore/Sources.txt +++ b/Source/WebCore/Sources.txt @@ -1886,7 +1886,6 @@ platform/graphics/Region.cpp 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 diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj index 8b95e7fa4f5e..45d97c9018fe 100644 --- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj +++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj @@ -9984,7 +9984,6 @@ 7C30D9801F815AC100268356 /* JSAbortController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAbortController.h; sourceTree = ""; }; 7C30D9811F815AC100268356 /* JSAbortSignal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAbortSignal.h; sourceTree = ""; }; 7C30D9821F815AC200268356 /* JSAbortSignal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAbortSignal.cpp; sourceTree = ""; }; - 7C31C88A247AD594005BF319 /* SimpleColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleColor.cpp; sourceTree = ""; }; 7C31C88C247AD595005BF319 /* SimpleColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleColor.h; sourceTree = ""; }; 7C330A011DF8FAC600D3395C /* GraphicsContextGLAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLAttributes.h; sourceTree = ""; }; 7C330A031DF9E95B00D3395C /* PositionOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PositionOptions.idl; sourceTree = ""; }; @@ -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 */, diff --git a/Source/WebCore/accessibility/AccessibilityNodeObject.cpp b/Source/WebCore/accessibility/AccessibilityNodeObject.cpp index 29e22bb0d6b2..be24bded3429 100644 --- a/Source/WebCore/accessibility/AccessibilityNodeObject.cpp +++ b/Source/WebCore/accessibility/AccessibilityNodeObject.cpp @@ -1983,10 +1983,10 @@ void AccessibilityNodeObject::colorValue(int& r, int& g, int& b) const if (!is(node())) return; - auto color = downcast(*node()).valueAsColor().toSRGBASimpleColorLossy(); - r = color.redComponent(); - g = color.greenComponent(); - b = color.blueComponent(); + auto color = downcast(*node()).valueAsColor().toSRGBALossy(); + r = color.red; + g = color.green; + b = color.blue; #endif } diff --git a/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp b/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp index be3be057f02e..d5e2ae0b05cf 100644 --- a/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp +++ b/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp @@ -92,14 +92,14 @@ static AtkAttributeSet* getAttributeSetForAccessibilityObject(const Accessibilit Color bgColor = style->visitedDependentColor(CSSPropertyBackgroundColor); if (bgColor.isValid()) { - auto [r, g, b, a] = bgColor.toSRGBASimpleColorLossy(); + auto [r, g, b, a] = bgColor.toSRGBALossy(); 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()); } Color fgColor = style->visitedDependentColor(CSSPropertyColor); if (fgColor.isValid()) { - auto [r, g, b, a] = fgColor.toSRGBASimpleColorLossy(); + auto [r, g, b, a] = fgColor.toSRGBALossy(); 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()); } diff --git a/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp b/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp index 061e9a6860da..361db2d3629f 100644 --- a/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp +++ b/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp @@ -701,10 +701,10 @@ void AXIsolatedObject::setPreventKeyboardDOMEventDispatch(bool value) 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(); + r = color.red; + g = color.green; + b = color.blue; } AXCoreObject* AXIsolatedObject::accessibilityHitTest(const IntPoint& point) const diff --git a/Source/WebCore/css/DeprecatedCSSOMRGBColor.h b/Source/WebCore/css/DeprecatedCSSOMRGBColor.h index 49fedfcce3b2..38c8f6935a87 100644 --- a/Source/WebCore/css/DeprecatedCSSOMRGBColor.h +++ b/Source/WebCore/css/DeprecatedCSSOMRGBColor.h @@ -37,7 +37,7 @@ class DeprecatedCSSOMRGBColor final : public RefCounted 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 static Ref createWrapper(CSSStyleDeclaration& owner, NumberType number) @@ -46,15 +46,15 @@ class DeprecatedCSSOMRGBColor final : public RefCounted } 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()) + , 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 m_color; Ref m_red; Ref m_green; Ref m_blue; diff --git a/Source/WebCore/editing/cocoa/DataDetection.mm b/Source/WebCore/editing/cocoa/DataDetection.mm index 130327f74cad..c1f41e16ca21 100644 --- a/Source/WebCore/editing/cocoa/DataDetection.mm +++ b/Source/WebCore/editing/cocoa/DataDetection.mm @@ -621,7 +621,7 @@ static inline CFComparisonResult queryOffsetCompare(DDQueryOffset o1, DDQueryOff if (renderStyle) { auto textColor = renderStyle->visitedDependentColor(CSSPropertyColor); if (textColor.isValid()) { - auto hsla = toHSLA(textColor.toSRGBALossy()); + auto hsla = toHSLA(textColor.toSRGBALossy()); // 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. diff --git a/Source/WebCore/platform/graphics/Color.cpp b/Source/WebCore/platform/graphics/Color.cpp index b64e82908d80..a4603ad4a768 100644 --- a/Source/WebCore/platform/graphics/Color.cpp +++ b/Source/WebCore/platform/graphics/Color.cpp @@ -86,7 +86,7 @@ Color Color::lightened() const if (isSimple() && asSimple() == black) return lightenedBlack; - auto [r, g, b, a] = toSRGBALossy(); + auto [r, g, b, a] = toSRGBALossy(); float v = std::max({ r, g, b }); if (v == 0.0f) @@ -103,7 +103,7 @@ Color Color::darkened() const if (isSimple() && asSimple() == white) return darkenedWhite; - auto [r, g, b, a] = toSRGBALossy(); + auto [r, g, b, a] = toSRGBALossy(); float v = std::max({ r, g, b }); float multiplier = std::max(0.0f, (v - 0.33f) / v); @@ -114,14 +114,14 @@ Color Color::darkened() const 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 Color::luminance() const { // 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()); } Color Color::colorWithAlpha(float alpha) const @@ -149,7 +149,7 @@ Color Color::semanticColor() const if (isSemantic()) return *this; - return { toSRGBASimpleColorLossy(), Semantic }; + return { makeSimpleColor(toSRGBALossy()), Semantic }; } std::pair> Color::colorSpaceAndComponents() const @@ -159,20 +159,6 @@ std::pair> Color::colorSpaceAndComponents() c return { ColorSpace::SRGB, asColorComponents(asSimple().asSRGBA()) }; } -SimpleColor Color::toSRGBASimpleColorLossy() const -{ - if (isExtended()) - return makeSimpleColor(asExtended().toSRGBALossy()); - return asSimple(); -} - -SRGBA Color::toSRGBALossy() const -{ - if (isExtended()) - return asExtended().toSRGBALossy(); - return asSimple().asSRGBA(); -} - TextStream& operator<<(TextStream& ts, const Color& color) { return ts << serializationForRenderTreeAsText(color); diff --git a/Source/WebCore/platform/graphics/Color.h b/Source/WebCore/platform/graphics/Color.h index ce7c423a5723..398dd13498e2 100644 --- a/Source/WebCore/platform/graphics/Color.h +++ b/Source/WebCore/platform/graphics/Color.h @@ -121,10 +121,7 @@ class Color { WEBCORE_EXPORT std::pair> colorSpaceAndComponents() const; // This will convert non-sRGB colorspace colors into sRGB. - WEBCORE_EXPORT SimpleColor toSRGBASimpleColorLossy() const; - - // This will convert non-sRGB colorspace colors into sRGB. - WEBCORE_EXPORT SRGBA toSRGBALossy() const; + template SRGBA toSRGBALossy() const; WEBCORE_EXPORT Color lightened() const; WEBCORE_EXPORT Color darkened() const; @@ -268,6 +265,13 @@ inline unsigned Color::hash() const return WTF::intHash(m_colorData.simpleColorAndFlags); } +template SRGBA Color::toSRGBALossy() const +{ + if (isExtended()) + return asExtended().toSRGBALossy(); + return asSimple().asSRGBA(); +} + inline Color Color::invertedColorWithAlpha(Optional alpha) const { return alpha ? invertedColorWithAlpha(alpha.value()) : *this; diff --git a/Source/WebCore/platform/graphics/ColorBlending.cpp b/Source/WebCore/platform/graphics/ColorBlending.cpp index f0729305b3c7..abc7ca478e1e 100644 --- a/Source/WebCore/platform/graphics/ColorBlending.cpp +++ b/Source/WebCore/platform/graphics/ColorBlending.cpp @@ -39,8 +39,8 @@ Color blendSourceOver(const Color& backdrop, const Color& source) 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(); + auto [sourceR, sourceG, sourceB, sourceA] = source.toSRGBALossy(); int d = 0xFF * (backdropA + sourceA) - backdropA * sourceA; int a = d / 0xFF; @@ -68,7 +68,7 @@ Color blendWithWhite(const Color& color) if (!color.isOpaque()) return color; - auto [existingR, existingG, existingB, existingAlpha] = color.toSRGBASimpleColorLossy(); + auto [existingR, existingG, existingB, existingAlpha] = color.toSRGBALossy(); SimpleColor result; for (int alpha = startAlpha; alpha <= endAlpha; alpha += alphaIncrement) { @@ -97,18 +97,17 @@ Color blend(const Color& from, const Color& to, double progress) 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()); + auto premultipliedTo = premultipliedCeiling(to.toSRGBALossy()); - 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( + 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 @@ Color blendWithoutPremultiply(const Color& from, const Color& to, double progres if (progress == 1 && !to.isValid()) return { }; - auto fromSRGB = from.toSRGBASimpleColorLossy(); - auto toSRGB = from.toSRGBASimpleColorLossy(); + auto fromSRGB = from.toSRGBALossy(); + auto toSRGB = from.toSRGBALossy(); 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) ); } diff --git a/Source/WebCore/platform/graphics/ColorTypes.h b/Source/WebCore/platform/graphics/ColorTypes.h index 262547856b32..f066cb779d7c 100644 --- a/Source/WebCore/platform/graphics/ColorTypes.h +++ b/Source/WebCore/platform/graphics/ColorTypes.h @@ -237,4 +237,21 @@ template constexpr bool operator!=(const XYZA& a, const XYZA& return !(a == b); } + +// Packed Color Formats + +struct ARGB { + uint32_t value; +}; + +constexpr ARGB asARGB(SRGBA color) +{ + return { static_cast(color.alpha << 24 | color.red << 16 | color.green << 8 | color.blue) }; +} + +constexpr SRGBA asSRGBA(ARGB color) +{ + return { static_cast(color.value >> 16), static_cast(color.value >> 8), static_cast(color.value), static_cast(color.value >> 24) }; +} + } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/ColorUtilities.cpp b/Source/WebCore/platform/graphics/ColorUtilities.cpp index 4a3cad3361f8..be4e47edd925 100644 --- a/Source/WebCore/platform/graphics/ColorUtilities.cpp +++ b/Source/WebCore/platform/graphics/ColorUtilities.cpp @@ -66,4 +66,43 @@ SRGBA premultiplied(const SRGBA& color) return { r * a, g * a, b * a, a }; } +SRGBA unpremultiplied(const SRGBA& color) +{ + auto [r, g, b, a] = color; + return { r / a, g / a, b / a, a }; +} + +SRGBA premultipliedFlooring(SRGBA color) +{ + auto [r, g, b, a] = color; + if (!a) + return { 0, 0, 0, 0 }; + if (a == 255) + return color; + return convertToComponentBytes(fastDivideBy255(r * a), fastDivideBy255(g * a), fastDivideBy255(b * a), a); +} + +SRGBA premultipliedCeiling(SRGBA color) +{ + auto [r, g, b, a] = color; + if (!a) + return { 0, 0, 0, 0 }; + if (a == 255) + return color; + return convertToComponentBytes(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 unpremultiplied(SRGBA color) +{ + auto [r, g, b, a] = color; + if (!a || a == 255) + return color; + return convertToComponentBytes(unpremultipliedComponentByte(r, a), unpremultipliedComponentByte(g, a), unpremultipliedComponentByte(b, a), a); +} + } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/ColorUtilities.h b/Source/WebCore/platform/graphics/ColorUtilities.h index b0a48ab403e4..4d314fda5d5f 100644 --- a/Source/WebCore/platform/graphics/ColorUtilities.h +++ b/Source/WebCore/platform/graphics/ColorUtilities.h @@ -38,6 +38,11 @@ float luminance(const SRGBA&); float contrastRatio(const SRGBA&, const SRGBA&); SRGBA premultiplied(const SRGBA&); +SRGBA unpremultiplied(const SRGBA&); + +SRGBA premultipliedFlooring(SRGBA); +SRGBA premultipliedCeiling(SRGBA); +SRGBA unpremultiplied(SRGBA); inline uint8_t convertPrescaledToComponentByte(float f) { @@ -54,6 +59,28 @@ constexpr float convertToComponentFloat(uint8_t byte) return byte / 255.0f; } +template typename ColorType> inline ColorType convertToComponentBytes(const ColorType& color) +{ + auto components = asColorComponents(color); + return { convertToComponentByte(components[0]), convertToComponentByte(components[1]), convertToComponentByte(components[2]), convertToComponentByte(components[3]) }; +} + +template typename ColorType> constexpr ColorType convertToComponentBytes(int r, int g, int b, int a) +{ + return { static_cast(std::clamp(r, 0, 0xFF)), static_cast(std::clamp(g, 0, 0xFF)), static_cast(std::clamp(b, 0, 0xFF)), static_cast(std::clamp(a, 0, 0xFF)) }; +} + +template typename ColorType> constexpr ColorType convertToComponentFloats(const ColorType& color) +{ + auto components = asColorComponents(color); + return { convertToComponentFloat(components[0]), convertToComponentFloat(components[1]), convertToComponentFloat(components[2]), convertToComponentFloat(components[3]) }; +} + +template typename ColorType> constexpr ColorType 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; diff --git a/Source/WebCore/platform/graphics/ExtendedColor.cpp b/Source/WebCore/platform/graphics/ExtendedColor.cpp index 24d9b4b1dcec..b3fd8e495ecb 100644 --- a/Source/WebCore/platform/graphics/ExtendedColor.cpp +++ b/Source/WebCore/platform/graphics/ExtendedColor.cpp @@ -57,7 +57,7 @@ Ref ExtendedColor::invertedColorWithAlpha(float overrideAlpha) co return ExtendedColor::create(1.0f - c1, 1.0f - c2, 1.0f - c3, overrideAlpha, colorSpace()); } -SRGBA ExtendedColor::toSRGBALossy() const +SRGBA ExtendedColor::toSRGBAFloatComponentsLossy() const { switch (m_colorSpace) { case ColorSpace::SRGB: diff --git a/Source/WebCore/platform/graphics/ExtendedColor.h b/Source/WebCore/platform/graphics/ExtendedColor.h index 39e84e687fdc..8a69c0c181d4 100644 --- a/Source/WebCore/platform/graphics/ExtendedColor.h +++ b/Source/WebCore/platform/graphics/ExtendedColor.h @@ -27,6 +27,8 @@ #include "ColorComponents.h" #include "ColorSpace.h" +#include "ColorTypes.h" +#include "ColorUtilities.h" #include #include @@ -49,11 +51,18 @@ class ExtendedColor : public RefCounted { Ref colorWithAlpha(float) const; Ref invertedColorWithAlpha(float) const; - SRGBA toSRGBALossy() const; - bool isWhite() const; bool isBlack() const; + // This will convert non-sRGB colorspace colors into sRGB. + template constexpr SRGBA toSRGBALossy() const + { + if constexpr (std::is_same_v) + return toSRGBAFloatComponentsLossy(); + else if constexpr (std::is_same_v) + 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 @@ class ExtendedColor : public RefCounted { { } + WEBCORE_EXPORT SRGBA toSRGBAFloatComponentsLossy() const; + ColorComponents m_components; ColorSpace m_colorSpace; }; diff --git a/Source/WebCore/platform/graphics/ImageBackingStore.h b/Source/WebCore/platform/graphics/ImageBackingStore.h index 4b9b5f228f9f..41901a755d79 100644 --- a/Source/WebCore/platform/graphics/ImageBackingStore.h +++ b/Source/WebCore/platform/graphics/ImageBackingStore.h @@ -102,7 +102,7 @@ class ImageBackingStore { } } - 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 @@ class ImageBackingStore { 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 @@ class ImageBackingStore { 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 m_pixels; diff --git a/Source/WebCore/platform/graphics/SimpleColor.cpp b/Source/WebCore/platform/graphics/SimpleColor.cpp deleted file mode 100644 index e09500b83b62..000000000000 --- a/Source/WebCore/platform/graphics/SimpleColor.cpp +++ /dev/null @@ -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 diff --git a/Source/WebCore/platform/graphics/SimpleColor.h b/Source/WebCore/platform/graphics/SimpleColor.h index f27b89d49817..4f7940cf26f4 100644 --- a/Source/WebCore/platform/graphics/SimpleColor.h +++ b/Source/WebCore/platform/graphics/SimpleColor.h @@ -42,11 +42,7 @@ class SimpleColor { 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 @@ class SimpleColor { return { static_cast(0xFF - redComponent()), static_cast(0xFF - greenComponent()), static_cast(0xFF - blueComponent()), alpha }; } - template constexpr SRGBA asSRGBA() const; + template constexpr SRGBA asSRGBA() const + { + if constexpr (std::is_same_v) + return { convertToComponentFloat(redComponent()), convertToComponentFloat(greenComponent()), convertToComponentFloat(blueComponent()), convertToComponentFloat(alphaComponent()) }; + else if constexpr (std::is_same_v) + return { redComponent(), greenComponent(), blueComponent(), alphaComponent() }; + } template constexpr uint8_t get() const @@ -79,6 +81,10 @@ class SimpleColor { } 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(int r, int g, int b, int a); constexpr SimpleColor makeSimpleColor(const SRGBA&); SimpleColor makeSimpleColor(const SRGBA&); -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(int r, int g, int b, int a) constexpr SimpleColor makeSimpleColor(const SRGBA& 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& sRGBA) { - auto [r, g, b, a] = sRGBA; - return { convertToComponentByte(r), convertToComponentByte(g), convertToComponentByte(b), convertToComponentByte(a) }; + return makeSimpleColor(convertToComponentBytes(sRGBA)); } -template constexpr SRGBA SimpleColor::asSRGBA() const -{ - if constexpr (std::is_floating_point_v) - return { convertToComponentFloat(redComponent()), convertToComponentFloat(greenComponent()), convertToComponentFloat(blueComponent()), convertToComponentFloat(alphaComponent()) }; - else - return { redComponent(), greenComponent(), blueComponent(), alphaComponent() }; -} - - } // namespace WebCore namespace std { diff --git a/Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm b/Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm index 97ccea614cf1..d9d81067800e 100644 --- a/Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm +++ b/Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm @@ -396,7 +396,7 @@ void setHasExplicitBeginTime(CAAnimation *animation, bool value) { if (!isBasicAnimation()) return; - auto [r, g, b, a] = value.toSRGBASimpleColorLossy(); + auto [r, g, b, a] = value.toSRGBALossy(); [static_cast(m_animation.get()) setFromValue:@[@(r), @(g), @(b), @(a)]]; } @@ -439,7 +439,7 @@ void setHasExplicitBeginTime(CAAnimation *animation, bool value) { if (!isBasicAnimation()) return; - auto [r, g, b, a] = value.toSRGBASimpleColorLossy(); + auto [r, g, b, a] = value.toSRGBALossy(); [static_cast(m_animation.get()) setToValue:@[@(r), @(g), @(b), @(a)]]; } @@ -496,7 +496,7 @@ void setHasExplicitBeginTime(CAAnimation *animation, bool value) return; [static_cast(m_animation.get()) setValues:createNSArray(value, [] (auto& color) { - auto [r, g, b, a] = color.toSRGBASimpleColorLossy(); + auto [r, g, b, a] = color.template toSRGBALossy(); return @[@(r), @(g), @(b), @(a)]; }).get()]; } diff --git a/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp b/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp index 027f13e2c5f5..0744d750790c 100644 --- a/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp +++ b/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp @@ -367,8 +367,8 @@ void PlatformCAAnimationWin::setFromValue(const WebCore::Color& value) if (animationType() != Basic) return; - auto simpleColor = value.toSRGBASimpleColorLossy(); - CGFloat a[4] = { simpleColor.redComponent(), simpleColor.greenComponent(), simpleColor.blueComponent(), simpleColor.alphaComponent() }; + auto components = value.toSRGBALossy(); + CGFloat a[4] = { components.red, components.green, components.blue, components.alpha }; RetainPtr v = adoptCF(CACFVectorCreate(4, a)); CACFAnimationSetFromValue(m_animation.get(), v.get()); } @@ -419,8 +419,8 @@ void PlatformCAAnimationWin::setToValue(const WebCore::Color& value) if (animationType() != Basic) return; - auto simpleColor = value.toSRGBASimpleColorLossy(); - CGFloat a[4] = { simpleColor.redComponent(), simpleColor.greenComponent(), simpleColor.blueComponent(), simpleColor.alphaComponent() }; + auto components = value.toSRGBALossy(); + CGFloat a[4] = { components.red, components.green, components.blue, components.alpha }; RetainPtr v = adoptCF(CACFVectorCreate(4, a)); CACFAnimationSetToValue(m_animation.get(), v.get()); } @@ -489,8 +489,8 @@ void PlatformCAAnimationWin::setValues(const Vector& value) RetainPtr 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(); + CGFloat a[4] = { components.red, components.green, components.blue, components.alpha }; RetainPtr v = adoptCF(CACFVectorCreate(4, a)); CFArrayAppendValue(array.get(), v.get()); } diff --git a/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp b/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp index 92b81d3210b8..d732dcdb9564 100644 --- a/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp +++ b/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp @@ -83,7 +83,7 @@ void copyContextProperties(cairo_t* srcCr, cairo_t* dstCr) void setSourceRGBAFromColor(cairo_t* context, const Color& color) { - auto [r, g, b, a] = color.toSRGBALossy(); + auto [r, g, b, a] = color.toSRGBALossy(); cairo_set_source_rgba(context, r, g, b, a); } diff --git a/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp b/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp index 00e1599d302a..fb04692bab4f 100644 --- a/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp @@ -43,7 +43,7 @@ void Gradient::platformDestroy() 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(); cairo_pattern_add_color_stop_rgba(gradient, stop.offset, r, g, b, a * globalAlpha); } @@ -55,7 +55,7 @@ typedef struct point_t { 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(); cairo_mesh_pattern_set_corner_color_rgba(gradient, id, r, g, b, a * globalAlpha); } @@ -135,8 +135,8 @@ static void addConicSector(cairo_pattern_t *gradient, float cx, float cy, float 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(); + auto [r2, g2, b2, a2] = to.color.toSRGBALossy(); float offset = from.offset + (to.offset - from.offset) * 0.5f; float r = r1 + (r2 - r1) * 0.5f; diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp b/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp index d00060cb8ab6..552ee5dd17f1 100644 --- a/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp +++ b/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp @@ -80,9 +80,9 @@ void ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace(const std: unsigned* row = reinterpret_cast_ptr(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()); diff --git a/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp b/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp index e5d0d09b7601..f4612bfe3303 100644 --- a/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp @@ -54,7 +54,7 @@ Color nativeImageSinglePixelSolidColor(const NativeImagePtr& image) return Color(); unsigned* pixel = reinterpret_cast_ptr(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) diff --git a/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h b/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h index 69a266cc6358..1163891d1e40 100644 --- a/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h +++ b/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h @@ -111,11 +111,11 @@ inline void FELighting::platformApplyNeon(const LightingData& data, const LightS // Set light source arguments. floatArguments.constOne = 1; - auto simpleColor = m_lightingColor.toSRGBASimpleColorLossy(); + auto color = m_lightingColor.toSRGBALossy(); - 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) { diff --git a/Source/WebCore/platform/graphics/filters/FELighting.cpp b/Source/WebCore/platform/graphics/filters/FELighting.cpp index 316342a6a208..2bad0faf4858 100644 --- a/Source/WebCore/platform/graphics/filters/FELighting.cpp +++ b/Source/WebCore/platform/graphics/filters/FELighting.cpp @@ -405,10 +405,10 @@ bool FELighting::drawLighting(Uint8ClampedArray& pixels, int width, int height) 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()); paintingData.initialLightingData.colorVector = FloatPoint3D(r, g, b); } else { - auto [r, g, b, a] = m_lightingColor.toSRGBALossy(); + auto [r, g, b, a] = m_lightingColor.toSRGBALossy(); paintingData.initialLightingData.colorVector = FloatPoint3D(r, g, b); } m_lightSource->initPaintingData(*this, paintingData); diff --git a/Source/WebCore/platform/graphics/filters/FilterOperations.cpp b/Source/WebCore/platform/graphics/filters/FilterOperations.cpp index b3c519c92ae4..0c4175a7b555 100644 --- a/Source/WebCore/platform/graphics/filters/FilterOperations.cpp +++ b/Source/WebCore/platform/graphics/filters/FilterOperations.cpp @@ -110,7 +110,7 @@ bool FilterOperations::transformColor(Color& color) const if (color.isSemantic()) return false; - auto sRGBAColor = color.toSRGBALossy(); + auto sRGBAColor = color.toSRGBALossy(); for (auto& operation : m_operations) { if (!operation->transformColor(sRGBAColor)) @@ -129,7 +129,7 @@ bool FilterOperations::inverseTransformColor(Color& color) const if (color.isSemantic()) return false; - auto sRGBAColor = color.toSRGBALossy(); + auto sRGBAColor = color.toSRGBALossy(); for (auto& operation : m_operations) { if (!operation->inverseTransformColor(sRGBAColor)) diff --git a/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp b/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp index 985bbf824fe6..bc841682375e 100644 --- a/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp +++ b/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp @@ -32,7 +32,7 @@ Color::Color(const GdkRGBA& color) Color::operator GdkRGBA() const { - auto [r, g, b, a] = toSRGBALossy(); + auto [r, g, b, a] = toSRGBALossy(); return { r, g, b, a }; } diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp index ecf42c590d43..ba42e7c63d3b 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp @@ -253,7 +253,7 @@ void TextureMapperGL::drawBorder(const Color& color, float width, const FloatRec Ref program = data().getShaderProgram(TextureMapperShaderProgram::SolidColor); glUseProgram(program->programID()); - auto [r, g, b, a] = premultiplied(color.toSRGBALossy()); + auto [r, g, b, a] = premultiplied(color.toSRGBALossy()); glUniform4f(program->colorLocation(), r, g, b, a); glLineWidth(width); @@ -275,7 +275,7 @@ void TextureMapperGL::drawNumber(int number, const Color& color, const FloatPoin 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(); cairo_set_source_rgba(cr, b, g, r, a); cairo_rectangle(cr, 0, 0, width, height); @@ -414,7 +414,7 @@ static void prepareFilterProgram(TextureMapperShaderProgram& program, const Filt 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()); 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 @@ void TextureMapperGL::drawSolidColor(const FloatRect& rect, const Transformation Ref program = data().getShaderProgram(options); glUseProgram(program->programID()); - auto [r, g, b, a] = premultiplied(color.toSRGBALossy()); + auto [r, g, b, a] = premultiplied(color.toSRGBALossy()); glUniform4f(program->colorLocation(), r, g, b, a); if (a < 1 && isBlendingAllowed) flags |= ShouldBlend; @@ -686,7 +686,7 @@ void TextureMapperGL::drawSolidColor(const FloatRect& rect, const Transformation void TextureMapperGL::clearColor(const Color& color) { - auto [r, g, b, a] = color.toSRGBALossy(); + auto [r, g, b, a] = color.toSRGBALossy(); glClearColor(r, g, b, a); glClear(GL_COLOR_BUFFER_BIT); } diff --git a/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp b/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp index 4c241335b988..5dc73896c450 100644 --- a/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp +++ b/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp @@ -40,13 +40,13 @@ Color::Color(D2D1_COLOR_F color) Color::operator D2D1_COLOR_F() const { - auto [r, g, b, a] = toSRGBALossy(); + auto [r, g, b, a] = toSRGBALossy(); 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(); return D2D1::Vector4F(r, g, b, a); } diff --git a/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp b/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp index fe96143b8e6e..04e4d764932f 100644 --- a/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp +++ b/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp @@ -72,7 +72,7 @@ void Gradient::generateGradient(ID2D1RenderTarget* renderTarget) Vector 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(); gradientStops.append(D2D1::GradientStop(stop.offset, D2D1::ColorF(r, g, b, a))); } diff --git a/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp b/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp index baeb11a31658..a707a29030f0 100644 --- a/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp +++ b/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp @@ -202,7 +202,8 @@ void GraphicsContext::drawDotsForDocumentMarker(const FloatRect& rect, DocumentM 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(); + CGContextSetRGBStrokeColor(context, patternColorComponents.red, patternColorComponents.green, patternColorComponents.blue, patternColorComponents.alpha); CGAffineTransform userToBase = getUserToBaseCTM(context); CGPoint phase = CGPointApplyAffineTransform(point, userToBase); diff --git a/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp b/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp index cbc51ea278e9..374071715bcb 100644 --- a/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp +++ b/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp @@ -379,7 +379,7 @@ void GraphicsContextPlatformPrivate::rotate(float angle) D2D1_COLOR_F GraphicsContext::colorWithGlobalAlpha(const Color& color) const { - auto [r, g, b, a] = color.toSRGBALossy(); + auto [r, g, b, a] = color.toSRGBALossy(); return D2D1::ColorF(r, g, b, a * m_data->currentGlobalAlpha()); } diff --git a/Source/WebCore/rendering/RenderTheme.cpp b/Source/WebCore/rendering/RenderTheme.cpp index fc80cb73e784..8f518397ce2f 100644 --- a/Source/WebCore/rendering/RenderTheme.cpp +++ b/Source/WebCore/rendering/RenderTheme.cpp @@ -1402,7 +1402,7 @@ Color RenderTheme::disabledTextColor(const Color& textColor, const Color& backgr // 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(), backgroundColor.toSRGBALossy()) < minColorContrastValue) return textColor; return disabledColor; diff --git a/Source/WebCore/rendering/RenderThemeIOS.mm b/Source/WebCore/rendering/RenderThemeIOS.mm index f276599e048a..b0ad6041b157 100644 --- a/Source/WebCore/rendering/RenderThemeIOS.mm +++ b/Source/WebCore/rendering/RenderThemeIOS.mm @@ -1055,7 +1055,7 @@ static void adjustInputElementButtonStyle(RenderStyle& style, const HTMLInputEle 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 largestNonAlphaChannel = std::max({ r, g, b }); return a > 0.5 && largestNonAlphaChannel < 0.5; } diff --git a/Source/WebCore/rendering/TextPaintStyle.cpp b/Source/WebCore/rendering/TextPaintStyle.cpp index 38290bc4071e..e5dc1a8f4262 100644 --- a/Source/WebCore/rendering/TextPaintStyle.cpp +++ b/Source/WebCore/rendering/TextPaintStyle.cpp @@ -63,7 +63,7 @@ bool textColorIsLegibleAgainstBackgroundColor(const Color& textColor, const Colo { // 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(), backgroundColor.toSRGBALossy()) > 4.5; } static Color adjustColorForVisibilityOnBackground(const Color& textColor, const Color& backgroundColor) diff --git a/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h b/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h index 0b2deeefbfcd..39e81354b3fc 100644 --- a/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h +++ b/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h @@ -81,15 +81,15 @@ class SVGAnimationColorFunction : public SVGAnimationAdditiveValueFunction(); + auto simpleFrom = m_animationMode == AnimationMode::To ? simpleAnimated : m_from.toSRGBALossy(); + auto simpleTo = m_to.toSRGBALossy(); + auto simpleToAtEndOfDuration = toAtEndOfDuration().toSRGBALossy(); - 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 @@ class SVGAnimationColorFunction : public SVGAnimationAdditiveValueFunction(); + auto simpleTo = toColor.toSRGBALossy(); - 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 @@ class SVGAnimationColorFunction : public SVGAnimationAdditiveValueFunction(); + auto simpleTo = m_to.toSRGBALossy(); // 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) ); } diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog index ba322b54d113..864e7cfa8a07 100644 --- a/Source/WebKit/ChangeLog +++ b/Source/WebKit/ChangeLog @@ -1,3 +1,20 @@ +2020-07-04 Sam Weinig + + Part 1 of SimpleColor and SRGBA 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. + 2020-07-03 Darin Adler Make generate-unified-sources.sh not depend on features being listed in FEATURE_DEFINES environment variable diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp b/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp index 9d8059a5bd50..b5c903ef014e 100644 --- a/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp +++ b/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp @@ -82,7 +82,7 @@ void webkitColorFillFromWebCoreColor(const WebCore::Color& webCoreColor, WebKitC { RELEASE_ASSERT(webCoreColor.isValid()); - auto [r, g, b, a] = webCoreColor.toSRGBALossy(); + auto [r, g, b, a] = webCoreColor.toSRGBALossy(); color->red = r; color->green = g; color->blue = b; diff --git a/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp b/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp index 1eebd9e93498..426dadd1ffd3 100644 --- a/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp +++ b/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp @@ -338,7 +338,7 @@ void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem if (color.isValid()) { m_backgroundColorForCurrentSnapshot = color; if (!m_currentSwipeSnapshotPattern) { - auto [red, green, blue, alpha] = color.toSRGBALossy(); + auto [red, green, blue, alpha] = color.toSRGBALossy(); m_currentSwipeSnapshotPattern = adoptRef(cairo_pattern_create_rgba(red, green, blue, alpha)); } } diff --git a/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm b/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm index b7702c25b8bc..b39d793553c4 100644 --- a/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm +++ b/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm @@ -693,7 +693,7 @@ - (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished return @(keyframeValue.numberValue()); case PlatformCAAnimationRemote::KeyframeValue::ColorKeyType: { - auto [r, g, b, a] = keyframeValue.colorValue().toSRGBASimpleColorLossy(); + auto [r, g, b, a] = keyframeValue.colorValue().toSRGBALossy(); return @[ @(r), @(g), @(b), @(a) ]; } diff --git a/Source/WebKit/WebProcess/WebPage/WebFrame.cpp b/Source/WebKit/WebProcess/WebPage/WebFrame.cpp index 4b7a77b4e673..75db64af4a2d 100644 --- a/Source/WebKit/WebProcess/WebPage/WebFrame.cpp +++ b/Source/WebKit/WebProcess/WebPage/WebFrame.cpp @@ -656,7 +656,7 @@ bool WebFrame::getDocumentBackgroundColor(double* red, double* green, double* bl if (!bgColor.isValid()) return false; - auto [r, g, b, a] = bgColor.toSRGBALossy(); + auto [r, g, b, a] = bgColor.toSRGBALossy(); *red = r; *green = g; *blue = b; diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 5fa57eee7c8b..8640f3e2d3ee 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,16 @@ +2020-07-04 Sam Weinig + + Part 1 of SimpleColor and SRGBA 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. + 2020-07-04 Sergio Villar Senin [Flatpak SDK] Require OpenXR 1.0.9 diff --git a/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp b/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp index e49469d284df..4b56eca734bb 100644 --- a/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp +++ b/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp @@ -38,7 +38,7 @@ TEST(Color, RGBToHSL_White) { Color color = Color::white; - auto hslaColor = toHSLA(color.toSRGBALossy()); + auto hslaColor = toHSLA(color.toSRGBALossy()); EXPECT_FLOAT_EQ(0, hslaColor.hue); EXPECT_FLOAT_EQ(0, hslaColor.saturation); @@ -54,7 +54,7 @@ TEST(Color, RGBToHSL_Black) { Color color = Color::black; - auto hslaColor = toHSLA(color.toSRGBALossy()); + auto hslaColor = toHSLA(color.toSRGBALossy()); EXPECT_FLOAT_EQ(0, hslaColor.hue); EXPECT_FLOAT_EQ(0, hslaColor.saturation); @@ -70,7 +70,7 @@ TEST(Color, RGBToHSL_Red) { Color color = makeSimpleColor(255, 0, 0); - auto hslaColor = toHSLA(color.toSRGBALossy()); + auto hslaColor = toHSLA(color.toSRGBALossy()); EXPECT_FLOAT_EQ(0, hslaColor.hue); EXPECT_FLOAT_EQ(1, hslaColor.saturation); @@ -86,7 +86,7 @@ TEST(Color, RGBToHSL_Green) { Color color = makeSimpleColor(0, 255, 0); - auto hslaColor = toHSLA(color.toSRGBALossy()); + auto hslaColor = toHSLA(color.toSRGBALossy()); EXPECT_FLOAT_EQ(0.33333334, hslaColor.hue); EXPECT_FLOAT_EQ(1, hslaColor.saturation); @@ -102,7 +102,7 @@ TEST(Color, RGBToHSL_Blue) { Color color = makeSimpleColor(0, 0, 255); - auto hslaColor = toHSLA(color.toSRGBALossy()); + auto hslaColor = toHSLA(color.toSRGBALossy()); EXPECT_FLOAT_EQ(0.66666669, hslaColor.hue); EXPECT_FLOAT_EQ(1, hslaColor.saturation); @@ -118,7 +118,7 @@ TEST(Color, RGBToHSL_DarkGray) { Color color = Color::darkGray; - auto hslaColor = toHSLA(color.toSRGBALossy()); + auto hslaColor = toHSLA(color.toSRGBALossy()); EXPECT_FLOAT_EQ(0, hslaColor.hue); EXPECT_FLOAT_EQ(0, hslaColor.saturation); @@ -134,7 +134,7 @@ TEST(Color, RGBToHSL_Gray) { Color color = Color::gray; - auto hslaColor = toHSLA(color.toSRGBALossy()); + auto hslaColor = toHSLA(color.toSRGBALossy()); EXPECT_FLOAT_EQ(0, hslaColor.hue); EXPECT_FLOAT_EQ(0, hslaColor.saturation); @@ -150,7 +150,7 @@ TEST(Color, RGBToHSL_LightGray) { Color color = Color::lightGray; - auto hslaColor = toHSLA(color.toSRGBALossy()); + auto hslaColor = toHSLA(color.toSRGBALossy()); EXPECT_FLOAT_EQ(0, hslaColor.hue); EXPECT_FLOAT_EQ(0, hslaColor.saturation); @@ -183,29 +183,29 @@ TEST(Color, Validity) 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(); + 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(); + 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(); + 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 @@ TEST(Color, Luminance) 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 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 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 cComponents = c.asSRGBA(); + EXPECT_EQ(cComponents.red, 85); + EXPECT_EQ(cComponents.green, 90); + EXPECT_EQ(cComponents.blue, 160); + + auto cLigtened = Color(c).lightened().toSRGBALossy(); + 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().toSRGBALossy(); + 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 diff --git a/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp b/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp index 3810149049c0..5b07e82256aa 100644 --- a/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp +++ b/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp @@ -241,7 +241,7 @@ TEST(ExtendedColor, P3ConversionToSRGB) 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(); 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 @@ TEST(ExtendedColor, LinearSRGBConversionToSRGB) { 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(); EXPECT_TRUE(WTF::areEssentiallyEqual(sRGBAColor.red, 1.0f)); EXPECT_TRUE(WTF::areEssentiallyEqual(sRGBAColor.green, 0.735356927f)); EXPECT_TRUE(WTF::areEssentiallyEqual(sRGBAColor.blue, 0.537098706f));