Title: [225021] trunk/Source/WebCore
- Revision
- 225021
- Author
- [email protected]
- Date
- 2017-11-18 14:40:49 -0800 (Sat, 18 Nov 2017)
Log Message
FETurbulence: round the result according to the spec
https://bugs.webkit.org/show_bug.cgi?id=179865
Reviewed by Zalan Bujtas.
The spec explicitly says that the floating point results are multiplied by 255 then
clamped between 0 and 255, so do this instead of using lroundf().
This is also faster (about 10%).
* platform/graphics/ColorUtilities.h:
(WebCore::ColorComponents::ColorComponents):
* platform/graphics/filters/FETurbulence.cpp:
(WebCore::toColorComponents):
(WebCore::FETurbulence::calculateTurbulenceValueForPoint const):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (225020 => 225021)
--- trunk/Source/WebCore/ChangeLog 2017-11-18 22:06:40 UTC (rev 225020)
+++ trunk/Source/WebCore/ChangeLog 2017-11-18 22:40:49 UTC (rev 225021)
@@ -1,5 +1,23 @@
2017-11-18 Simon Fraser <[email protected]>
+ FETurbulence: round the result according to the spec
+ https://bugs.webkit.org/show_bug.cgi?id=179865
+
+ Reviewed by Zalan Bujtas.
+
+ The spec explicitly says that the floating point results are multiplied by 255 then
+ clamped between 0 and 255, so do this instead of using lroundf().
+
+ This is also faster (about 10%).
+
+ * platform/graphics/ColorUtilities.h:
+ (WebCore::ColorComponents::ColorComponents):
+ * platform/graphics/filters/FETurbulence.cpp:
+ (WebCore::toColorComponents):
+ (WebCore::FETurbulence::calculateTurbulenceValueForPoint const):
+
+2017-11-18 Simon Fraser <[email protected]>
+
More FETurbulence cleanup
https://bugs.webkit.org/show_bug.cgi?id=179863
Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.h (225020 => 225021)
--- trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2017-11-18 22:06:40 UTC (rev 225020)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2017-11-18 22:40:49 UTC (rev 225021)
@@ -94,6 +94,14 @@
struct ColorComponents {
ColorComponents() = default;
ColorComponents(const FloatComponents&);
+
+ ColorComponents(uint8_t a = 0, uint8_t b = 0, uint8_t c = 0, uint8_t d = 0)
+ {
+ components[0] = a;
+ components[1] = b;
+ components[2] = c;
+ components[3] = d;
+ }
uint8_t components[4] { };
};
Modified: trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp (225020 => 225021)
--- trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp 2017-11-18 22:06:40 UTC (rev 225020)
+++ trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp 2017-11-18 22:40:49 UTC (rev 225021)
@@ -323,6 +323,17 @@
};
}
+// https://www.w3.org/TR/SVG/filters.html#feTurbulenceElement describes this conversion to color components.
+static inline ColorComponents toColorComponents(const FloatComponents& floatComponents)
+{
+ return {
+ std::max<uint8_t>(0, std::min(static_cast<int>(floatComponents.components[0] * 255), 255)),
+ std::max<uint8_t>(0, std::min(static_cast<int>(floatComponents.components[1] * 255), 255)),
+ std::max<uint8_t>(0, std::min(static_cast<int>(floatComponents.components[2] * 255), 255)),
+ std::max<uint8_t>(0, std::min(static_cast<int>(floatComponents.components[3] * 255), 255))
+ };
+}
+
ColorComponents FETurbulence::calculateTurbulenceValueForPoint(const PaintingData& paintingData, StitchData stitchData, const FloatPoint& point) const
{
FloatComponents turbulenceFunctionResult;
@@ -353,7 +364,7 @@
if (m_type == TurbulenceType::FractalNoise)
turbulenceFunctionResult = turbulenceFunctionResult * 0.5f + 0.5f;
- return turbulenceFunctionResult;
+ return toColorComponents(turbulenceFunctionResult);
}
void FETurbulence::fillRegion(Uint8ClampedArray* pixelArray, const PaintingData& paintingData, StitchData stitchData, int startY, int endY) const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes