Changeset 226315 in webkit


Ignore:
Timestamp:
Jan 1, 2018, 11:53:39 AM (8 years ago)
Author:
Simon Fraser
Message:

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

Reviewed by Dan Bates.

Source/WebCore:

SVG filters, like feLighting, that poke values directly into buffers rather than going
through CG like feFlood, need to convert colors into the operating color space. So add
conversion functions to go between linear and sRGB colors, and use these in feLighting,
and in ImageBuffer (which is only used for non-CG platforms).

Tests: svg/filters/feSpotLight-color.svg

  • platform/graphics/ColorUtilities.cpp:

(WebCore::linearToSRGBColorComponent):
(WebCore::sRGBToLinearColorComponent):
(WebCore::linearToSRGBColor):
(WebCore::sRGBToLinearColor):

  • platform/graphics/ColorUtilities.h:
  • platform/graphics/ImageBuffer.cpp:

(WebCore::ImageBuffer::transformColorSpace):

  • platform/graphics/filters/FELighting.cpp:

(WebCore::FELighting::drawLighting):

LayoutTests:

Compare a far-away green spotlight with a green flood. The bottom right pixel always
has the wrong color (webkit.org/b/181203), so mask it out.

  • svg/filters/feSpotLight-color-expected.svg: Added.
  • svg/filters/feSpotLight-color.svg: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r226309 r226315  
     12017-12-30  Simon Fraser  <simon.fraser@apple.com>
     2
     3        SVG lighting colors need to be converted into linearSRGB
     4        https://bugs.webkit.org/show_bug.cgi?id=181196
     5
     6        Reviewed by Dan Bates.
     7
     8        Compare a far-away green spotlight with a green flood. The bottom right pixel always
     9        has the wrong color (webkit.org/b/181203), so mask it out.
     10
     11        * svg/filters/feSpotLight-color-expected.svg: Added.
     12        * svg/filters/feSpotLight-color.svg: Added.
     13
    1142017-12-28  Zalan Bujtas  <zalan@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r226314 r226315  
     12017-12-30  Simon Fraser  <simon.fraser@apple.com>
     2
     3        SVG lighting colors need to be converted into linearSRGB
     4        https://bugs.webkit.org/show_bug.cgi?id=181196
     5
     6        Reviewed by Dan Bates.
     7
     8        SVG filters, like feLighting, that poke values directly into buffers rather than going
     9        through CG like feFlood, need to convert colors into the operating color space. So add
     10        conversion functions to go between linear and sRGB colors, and use these in feLighting,
     11        and in ImageBuffer (which is only used for non-CG platforms).
     12
     13        Tests: svg/filters/feSpotLight-color.svg
     14
     15        * platform/graphics/ColorUtilities.cpp:
     16        (WebCore::linearToSRGBColorComponent):
     17        (WebCore::sRGBToLinearColorComponent):
     18        (WebCore::linearToSRGBColor):
     19        (WebCore::sRGBToLinearColor):
     20        * platform/graphics/ColorUtilities.h:
     21        * platform/graphics/ImageBuffer.cpp:
     22        (WebCore::ImageBuffer::transformColorSpace):
     23        * platform/graphics/filters/FELighting.cpp:
     24        (WebCore::FELighting::drawLighting):
     25
    1262017-12-31  Jiewen Tan  <jiewen_tan@apple.com>
    227
  • trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp

    r225009 r226315  
    2727#include "ColorUtilities.h"
    2828
     29#include "Color.h"
     30#include <wtf/MathExtras.h>
     31
    2932namespace WebCore {
    3033
     
    3740}
    3841
     42// These are the standard sRGB <-> linearRGB conversion functions (https://en.wikipedia.org/wiki/SRGB).
     43float linearToSRGBColorComponent(float c)
     44{
     45    if (c < 0.0031308)
     46        return 12.92 * c;
     47
     48    return clampTo<float>(1.055 * powf(c, 1.0 / 2.4) - 0.055, 0, 1);
     49}
     50
     51float sRGBToLinearColorComponent(float c)
     52{
     53    if (c <= 0.04045)
     54        return c / 12.92;
     55
     56    return clampTo<float>(powf((c + 0.055) / 1.055, 2.4), 0, 1);
     57}
     58
     59Color linearToSRGBColor(const Color& color)
     60{
     61    float r, g, b, a;
     62    color.getRGBA(r, g, b, a);
     63    r = linearToSRGBColorComponent(r);
     64    g = linearToSRGBColorComponent(g);
     65    b = linearToSRGBColorComponent(b);
     66
     67    return Color(r, g, b, a);
     68}
     69
     70Color sRGBToLinearColor(const Color& color)
     71{
     72    float r, g, b, a;
     73    color.getRGBA(r, g, b, a);
     74    r = sRGBToLinearColorComponent(r);
     75    g = sRGBToLinearColorComponent(g);
     76    b = sRGBToLinearColorComponent(b);
     77
     78    return Color(r, g, b, a);
     79}
     80
    3981} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/ColorUtilities.h

    r225183 r226315  
    2626#pragma once
    2727
     28#include "Color.h"
    2829#include <algorithm>
    2930#include <math.h>
     
    148149}
    149150
     151// 0-1 components, result is clamped.
     152float linearToSRGBColorComponent(float);
     153float sRGBToLinearColorComponent(float);
     154   
     155Color linearToSRGBColor(const Color&);
     156Color sRGBToLinearColor(const Color&);
     157
    150158} // namespace WebCore
    151159
  • trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp

    r225797 r226315  
    2929#include "ImageBuffer.h"
    3030
     31#include "ColorUtilities.h"
    3132#include "GraphicsContext.h"
    3233#include "IntRect.h"
     
    136137            for (unsigned i = 0; i < 256; i++) {
    137138                float color = i / 255.0f;
    138                 color = (color <= 0.04045f ? color / 12.92f : pow((color + 0.055f) / 1.055f, 2.4f));
    139                 color = std::max(0.0f, color);
    140                 color = std::min(1.0f, color);
     139                color = sRGBToLinearColorComponent(color);
    141140                array[i] = static_cast<uint8_t>(round(color * 255));
    142141            }
     
    149148            for (unsigned i = 0; i < 256; i++) {
    150149                float color = i / 255.0f;
    151                 color = (powf(color, 1.0f / 2.4f) * 1.055f) - 0.055f;
    152                 color = std::max(0.0f, color);
    153                 color = std::min(1.0f, color);
     150                color = linearToSRGBColorComponent(color);
    154151                array[i] = static_cast<uint8_t>(round(color * 255));
    155152            }
  • trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp

    r225147 r226315  
    2828#include "FELighting.h"
    2929
     30#include "ColorUtilities.h"
    3031#include "FELightingNEON.h"
    3132#include <wtf/ParallelJobs.h>
     
    398399    data.widthDecreasedByOne = width - 1;
    399400    data.heightDecreasedByOne = height - 1;
    400     paintingData.intialLightingData.colorVector = FloatPoint3D(m_lightingColor.red(), m_lightingColor.green(), m_lightingColor.blue());
     401   
     402    Color lightColor = (operatingColorSpace() == ColorSpaceLinearRGB) ? sRGBToLinearColor(m_lightingColor) : m_lightingColor;
     403    paintingData.intialLightingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green(), lightColor.blue());
    401404    m_lightSource->initPaintingData(paintingData);
    402405
Note: See TracChangeset for help on using the changeset viewer.