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

Matthew Finkel noreply at github.com
Thu May 11 12:13:22 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: eabcb3ec87c6f18886f8c12bbd3321486703fbd4
      https://github.com/WebKit/WebKit/commit/eabcb3ec87c6f18886f8c12bbd3321486703fbd4
  Author: Matthew Finkel <sysrqb at apple.com>
  Date:   2023-05-11 (Thu, 11 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/263979@main




More information about the webkit-changes mailing list