Title: [266266] trunk/Source/WebCore
Revision
266266
Author
[email protected]
Date
2020-08-27 18:24:15 -0700 (Thu, 27 Aug 2020)

Log Message

CSS Filter invert() and opacity() Implementation Should Use Linear Transfer Function for Clarity and Simplicity
https://bugs.webkit.org/show_bug.cgi?id=215896

Simplify CSS filters, invert() and opacity() implementation by using "linear" transfer function,
instead of using a more confusing transfer function, "table". For invert(), the transfer function
is type="table" tableValues="[amount] (1 - [amount])", which is equivalent to a linear function
of slope 1 - 2 * [amount] and intercept [amount]; for opacity the transfer function is type="table" tableValues="0 [amount]"
which is equivalent to a linear transfer function of slope [amount] and intercept 0. This change will make the implementation
clearer and simpler.

Patch by Frank Yang <[email protected]> on 2020-08-27
Reviewed by Myles C. Maxfield.

No new tests needed, using existing tests in css/filter-effects

* rendering/CSSFilter.cpp:
(WebCore::CSSFilter::build): Modified the implementation of invert() and opacity() so that they both use
     a linear component transfer function instead of a more confusing table transfer function.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (266265 => 266266)


--- trunk/Source/WebCore/ChangeLog	2020-08-28 01:18:07 UTC (rev 266265)
+++ trunk/Source/WebCore/ChangeLog	2020-08-28 01:24:15 UTC (rev 266266)
@@ -1,3 +1,24 @@
+2020-08-27  Frank Yang  <[email protected]>
+
+        CSS Filter invert() and opacity() Implementation Should Use Linear Transfer Function for Clarity and Simplicity
+        https://bugs.webkit.org/show_bug.cgi?id=215896
+
+        Simplify CSS filters, invert() and opacity() implementation by using "linear" transfer function, 
+        instead of using a more confusing transfer function, "table". For invert(), the transfer function 
+        is type="table" tableValues="[amount] (1 - [amount])", which is equivalent to a linear function
+        of slope 1 - 2 * [amount] and intercept [amount]; for opacity the transfer function is type="table" tableValues="0 [amount]"
+        which is equivalent to a linear transfer function of slope [amount] and intercept 0. This change will make the implementation 
+        clearer and simpler.
+
+        Reviewed by Myles C. Maxfield.
+
+        No new tests needed, using existing tests in css/filter-effects
+
+        * rendering/CSSFilter.cpp:
+        (WebCore::CSSFilter::build): Modified the implementation of invert() and opacity() so that they both use 
+             a linear component transfer function instead of a more confusing table transfer function.
+
+
 2020-08-27  Devin Rousso  <[email protected]>
 
         [iOS] provide a way to get previously inserted alternatives for the selected text

Modified: trunk/Source/WebCore/rendering/CSSFilter.cpp (266265 => 266266)


--- trunk/Source/WebCore/rendering/CSSFilter.cpp	2020-08-28 01:18:07 UTC (rev 266265)
+++ trunk/Source/WebCore/rendering/CSSFilter.cpp	2020-08-28 01:24:15 UTC (rev 266266)
@@ -221,11 +221,10 @@
         case FilterOperation::INVERT: {
             auto& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             ComponentTransferFunction transferFunction;
-            transferFunction.type = FECOMPONENTTRANSFER_TYPE_TABLE;
-            Vector<float> transferParameters;
-            transferParameters.append(narrowPrecisionToFloat(componentTransferOperation.amount()));
-            transferParameters.append(narrowPrecisionToFloat(1 - componentTransferOperation.amount()));
-            transferFunction.tableValues = transferParameters;
+            transferFunction.type = FECOMPONENTTRANSFER_TYPE_LINEAR;
+            float amount = narrowPrecisionToFloat(componentTransferOperation.amount());
+            transferFunction.slope = 1 - 2 * amount;
+            transferFunction.intercept = amount;
 
             ComponentTransferFunction nullFunction;
             effect = FEComponentTransfer::create(*this, transferFunction, transferFunction, transferFunction, nullFunction);
@@ -237,11 +236,10 @@
         case FilterOperation::OPACITY: {
             auto& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             ComponentTransferFunction transferFunction;
-            transferFunction.type = FECOMPONENTTRANSFER_TYPE_TABLE;
-            Vector<float> transferParameters;
-            transferParameters.append(0);
-            transferParameters.append(narrowPrecisionToFloat(componentTransferOperation.amount()));
-            transferFunction.tableValues = transferParameters;
+            transferFunction.type = FECOMPONENTTRANSFER_TYPE_LINEAR;
+            float amount = narrowPrecisionToFloat(componentTransferOperation.amount());
+            transferFunction.slope = amount;
+            transferFunction.intercept = 0;
 
             ComponentTransferFunction nullFunction;
             effect = FEComponentTransfer::create(*this, nullFunction, nullFunction, nullFunction, transferFunction);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to