[webkit-changes] [WebKit/WebKit] bfc25d: Refactor Canvas noise injection logic and improve ...

Matthew Finkel noreply at github.com
Fri May 12 10:39:45 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: bfc25dc6ca1cf6a7213d58065c036c846beaddac
      https://github.com/WebKit/WebKit/commit/bfc25dc6ca1cf6a7213d58065c036c846beaddac
  Author: Matthew Finkel <sysrqb at apple.com>
  Date:   2023-05-12 (Fri, 12 May 2023)

  Changed paths:
    M Source/WebCore/Headers.cmake
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/html/CanvasBase.cpp
    M Source/WebCore/html/CanvasBase.h
    A Source/WebCore/html/CanvasNoiseInjection.cpp
    A Source/WebCore/html/CanvasNoiseInjection.h
    M Source/WebCore/html/HTMLCanvasElement.cpp

  Log Message:
  -----------
  Refactor Canvas noise injection logic and improve support for gradients in post-processed ImageData
https://bugs.webkit.org/show_bug.cgi?id=255993
rdar://107371244

Reviewed by Kimmo Kinnunen.

Gradients present an interesting problem when post-processing canvas ImageData
because tweaking colors result in significant visual anomalies. This change
introduces some naive gradient detection by looking at all of the immediate
neighbors of a pixel. We decide that a pixel is within a gradient if the
current color is between its opposing adjacent colors (e.g., above and below,
left and right, etc). If a color is decided to be within a gradient, then we
set those adjacent colors as bounds within which we can tweak the current
color.

In addition, within this change, we move the noise injection logic into its own
class, it removes the dependency on supplied colors for post-processing, and it
reduces the magnitude of noise from ~5% to ~1%.

* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/html/CanvasBase.cpp:
(WebCore::CanvasBase::makeRenderingResultsAvailable):
(WebCore::CanvasBase::didDraw): We clip the rect before passing it into
CanvasNoiseInjection, and if the rect is std::nullopt then we pass in the
entire canvas.

(WebCore::CanvasBase::postProcessPixelBufferResults const):
(WebCore::CanvasBase::postProcessDirtyCanvasBuffer const): Deleted.
* Source/WebCore/html/CanvasBase.h:
* Source/WebCore/html/CanvasNoiseInjection.cpp: Added.
(WebCore::CanvasNoiseInjection::updateDirtyRect):
(WebCore::isIndexInBounds):
(WebCore::setTightnessBounds):
(WebCore::getGradientNeighbors):
(WebCore::CanvasNoiseInjection::postProcessDirtyCanvasBuffer):
(WebCore::CanvasNoiseInjection::postProcessPixelBufferResults const):
* Source/WebCore/html/CanvasNoiseInjection.h: Added.
* Source/WebCore/html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getImageData):

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




More information about the webkit-changes mailing list