Title: [231559] trunk/Source/WebCore
Revision
231559
Author
[email protected]
Date
2018-05-09 08:21:59 -0700 (Wed, 09 May 2018)

Log Message

SVG lighting colors need to be converted into linearSRGB
https://bugs.webkit.org/show_bug.cgi?id=181196

Reviewed by Darin Adler.

Address post-commit comments. Don't make a Color that contains linearRGB components,
but use FloatComponents instead. Since these FloatComponents are in the 0-1 range,
FELighting::setPixelInternal() needs to multiply by 255 since the output pixels are
8-bit 0-255.

Change linearToSRGBColorComponent() and sRGBToLinearColorComponent() to do math in
floats without promoting to doubles.

* platform/graphics/ColorUtilities.cpp:
(WebCore::FloatComponents::FloatComponents):
(WebCore::linearToSRGBColorComponent):
(WebCore::sRGBToLinearColorComponent):
(WebCore::sRGBColorToLinearComponents):
(WebCore::linearToSRGBColor): Deleted.
(WebCore::sRGBToLinearColor): Deleted.
* platform/graphics/ColorUtilities.h:
* platform/graphics/filters/FELighting.cpp:
(WebCore::FELighting::setPixelInternal):
(WebCore::FELighting::drawLighting):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (231558 => 231559)


--- trunk/Source/WebCore/ChangeLog	2018-05-09 15:20:36 UTC (rev 231558)
+++ trunk/Source/WebCore/ChangeLog	2018-05-09 15:21:59 UTC (rev 231559)
@@ -1,3 +1,30 @@
+2018-05-08  Simon Fraser  <[email protected]>
+
+        SVG lighting colors need to be converted into linearSRGB
+        https://bugs.webkit.org/show_bug.cgi?id=181196
+
+        Reviewed by Darin Adler.
+
+        Address post-commit comments. Don't make a Color that contains linearRGB components,
+        but use FloatComponents instead. Since these FloatComponents are in the 0-1 range,
+        FELighting::setPixelInternal() needs to multiply by 255 since the output pixels are
+        8-bit 0-255.
+        
+        Change linearToSRGBColorComponent() and sRGBToLinearColorComponent() to do math in
+        floats without promoting to doubles.
+
+        * platform/graphics/ColorUtilities.cpp:
+        (WebCore::FloatComponents::FloatComponents):
+        (WebCore::linearToSRGBColorComponent):
+        (WebCore::sRGBToLinearColorComponent):
+        (WebCore::sRGBColorToLinearComponents):
+        (WebCore::linearToSRGBColor): Deleted.
+        (WebCore::sRGBToLinearColor): Deleted.
+        * platform/graphics/ColorUtilities.h:
+        * platform/graphics/filters/FELighting.cpp:
+        (WebCore::FELighting::setPixelInternal):
+        (WebCore::FELighting::drawLighting):
+
 2018-05-09  Timothy Hatcher  <[email protected]>
 
         Use StyleColor::Options in more places.

Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp (231558 => 231559)


--- trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp	2018-05-09 15:20:36 UTC (rev 231558)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp	2018-05-09 15:21:59 UTC (rev 231559)
@@ -31,6 +31,11 @@
 
 namespace WebCore {
 
+FloatComponents::FloatComponents(const Color& color)
+{
+    color.getRGBA(components[0], components[1], components[2], components[3]);
+}
+
 ColorComponents::ColorComponents(const FloatComponents& floatComponents)
 {
     components[0] = clampedColorComponent(floatComponents.components[0]);
@@ -42,43 +47,33 @@
 // These are the standard sRGB <-> linearRGB conversion functions (https://en.wikipedia.org/wiki/SRGB).
 float linearToSRGBColorComponent(float c)
 {
-    if (c < 0.0031308)
-        return 12.92 * c;
+    if (c < 0.0031308f)
+        return 12.92f * c;
 
-    return clampTo<float>(1.055 * powf(c, 1.0 / 2.4) - 0.055, 0, 1);
+    return clampTo<float>(1.055f * std::pow(c, 1.0f / 2.4f) - 0.055f, 0, 1);
 }
 
 float sRGBToLinearColorComponent(float c)
 {
-    if (c <= 0.04045)
-        return c / 12.92;
+    if (c <= 0.04045f)
+        return c / 12.92f;
 
-    return clampTo<float>(powf((c + 0.055) / 1.055, 2.4), 0, 1);
+    return clampTo<float>(std::pow((c + 0.055f) / 1.055f, 2.4f), 0, 1);
 }
 
-Color linearToSRGBColor(const Color& color)
+FloatComponents sRGBColorToLinearComponents(const Color& color)
 {
     float r, g, b, a;
     color.getRGBA(r, g, b, a);
-    r = linearToSRGBColorComponent(r);
-    g = linearToSRGBColorComponent(g);
-    b = linearToSRGBColorComponent(b);
-
-    return Color(r, g, b, a);
+    return {
+        sRGBToLinearColorComponent(r),
+        sRGBToLinearColorComponent(g),
+        sRGBToLinearColorComponent(b),
+        a
+    };
 }
 
-Color sRGBToLinearColor(const Color& color)
-{
-    float r, g, b, a;
-    color.getRGBA(r, g, b, a);
-    r = sRGBToLinearColorComponent(r);
-    g = sRGBToLinearColorComponent(g);
-    b = sRGBToLinearColorComponent(b);
 
-    return Color(r, g, b, a);
-}
-
-
 ColorMatrix::ColorMatrix()
 {
     makeIdentity();

Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.h (231558 => 231559)


--- trunk/Source/WebCore/platform/graphics/ColorUtilities.h	2018-05-09 15:20:36 UTC (rev 231558)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.h	2018-05-09 15:21:59 UTC (rev 231559)
@@ -40,6 +40,8 @@
         components[3] = d;
     }
 
+    FloatComponents(const Color&);
+
     FloatComponents& operator+=(const FloatComponents& rhs)
     {
         components[0] += rhs.components[0];
@@ -151,10 +153,9 @@
 // 0-1 components, result is clamped.
 float linearToSRGBColorComponent(float);
 float sRGBToLinearColorComponent(float);
-    
-Color linearToSRGBColor(const Color&);
-Color sRGBToLinearColor(const Color&);
 
+FloatComponents sRGBColorToLinearComponents(const Color&);
+
 class ColorMatrix {
 public:
     static ColorMatrix grayscaleMatrix(float);

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


--- trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp	2018-05-09 15:20:36 UTC (rev 231558)
+++ trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp	2018-05-09 15:21:59 UTC (rev 231559)
@@ -295,9 +295,9 @@
         lightStrength = 0;
 
     uint8_t pixelValue[3] = {
-        static_cast<uint8_t>(lightStrength * lightingData.colorVector.x()),
-        static_cast<uint8_t>(lightStrength * lightingData.colorVector.y()),
-        static_cast<uint8_t>(lightStrength * lightingData.colorVector.z())
+        static_cast<uint8_t>(lightStrength * lightingData.colorVector.x() * 255.0f),
+        static_cast<uint8_t>(lightStrength * lightingData.colorVector.y() * 255.0f),
+        static_cast<uint8_t>(lightStrength * lightingData.colorVector.z() * 255.0f)
     };
     
     data.pixels->setRange(pixelValue, 3, offset);
@@ -403,8 +403,8 @@
     data.widthDecreasedByOne = width - 1;
     data.heightDecreasedByOne = height - 1;
     
-    Color lightColor = (operatingColorSpace() == ColorSpaceLinearRGB) ? sRGBToLinearColor(m_lightingColor) : m_lightingColor;
-    paintingData.initialLightingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green(), lightColor.blue());
+    FloatComponents lightColor = (operatingColorSpace() == ColorSpaceLinearRGB) ? sRGBColorToLinearComponents(m_lightingColor) : FloatComponents(m_lightingColor);
+    paintingData.initialLightingData.colorVector = FloatPoint3D(lightColor.components[0], lightColor.components[1], lightColor.components[2]);
     m_lightSource->initPaintingData(*this, paintingData);
 
     // Top left.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to