[webkit-changes] [WebKit/WebKit] e4317a: Improve Canvas ImageData noise injection algorithm

Matthew Finkel noreply at github.com
Thu Jun 15 16:36:19 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: e4317abe6ad69ce6d7c4be9087003cc4180790e4
      https://github.com/WebKit/WebKit/commit/e4317abe6ad69ce6d7c4be9087003cc4180790e4
  Author: Matthew Finkel <sysrqb at apple.com>
  Date:   2023-06-15 (Thu, 15 Jun 2023)

  Changed paths:
    M Source/WebCore/html/CanvasNoiseInjection.cpp
    M Tools/TestWebKitAPI/Tests/WebKit/AdvancedPrivacyProtections.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/canvas-fingerprinting.html

  Log Message:
  -----------
  Improve Canvas ImageData noise injection algorithm
https://bugs.webkit.org/show_bug.cgi?id=257574
rdar://109271231

Reviewed by Kimmo Kinnunen.

The current algorithm attempts to recognize gradients within a PixelBuffer, but
the logic for detecting a gradient is incorrect where it assumes a gradient
region always contain strictly increase (or decreasing) colors. This assumption
resulted in poor gradient detection and very visible anomalies in some cases.
In addition, in the case where the gradient was correctly detected, in some
cases the amount of added noise was too large and it cause a clustering effect
around some colors within the resulting image.

In this patch, I modified the noise-addition algorithm such that it provides
the best result for every pixel depending on its surrounding colors, instead of
restricting special behavior to gradients. We introduce a concept of "related
colors" which identifies two colors as related if the difference between each
of their RGBA components is not more than 8 - this threshold was mostly chosen
by experimentation.

The algorithm proceeds as follows:
1) For each color, identify if any of the immediately surrounding colors are related.
2) If any of the colors are related, then find the colors with the smallest distance.
3) If any related colors were identified, then those colors define the upper/lower
   bounds within which noise can be added.
4) Furthermore, if any related colors were identified, then noise is restricted
   to +/-1 (~0.5%), otherwise it is restricted to +/-3 (~1%);
5) After identifying the closest surrounding colors, we define the upper and lower
   bounds for each color component.
6) Finally, each color component is mutated by adding the noise value

* Source/WebCore/html/CanvasNoiseInjection.cpp:
(WebCore::setTightnessBounds):
(WebCore::boundingNeighbors):
(WebCore::CanvasNoiseInjection::postProcessDirtyCanvasBuffer):
(WebCore::lowerAndUpperBound):
(WebCore::adjustNeighborColorBounds):
(WebCore::CanvasNoiseInjection::postProcessPixelBufferResults const):
(WebCore::getGradientNeighbors): Deleted.
* Tools/TestWebKitAPI/Tests/WebKit/AdvancedPrivacyProtections.mm:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/canvas-fingerprinting.html:

Canonical link: https://commits.webkit.org/265216@main




More information about the webkit-changes mailing list