Reviewed by Oliver Hunt.
SVG feDisplacementMap is not implemented
[https://bugs.webkit.org/show_bug.cgi?id=31255]
This is the implementation of the SVG filter effect
feDisplacementMap.
Test: svg/filters/feDisplacementMap.svg
* svg/graphics/filters/SVGFEDisplacementMap.cpp:
(WebCore::FEDisplacementMap::apply):
Test for SVG filter effect feDisplacementMap.
* platform/mac/svg/filters/feDisplacementMap-expected.checksum: Added.
* platform/mac/svg/filters/feDisplacementMap-expected.png: Added.
* platform/mac/svg/filters/feDisplacementMap-expected.txt: Added.
* svg/filters/feDisplacementMap.svg: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@50718
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2009-11-09 Dirk Schulze <krit@webkit.org>
+
+ Reviewed by Oliver Hunt.
+
+ Test for SVG filter effect feDisplacementMap.
+
+ * platform/mac/svg/filters/feDisplacementMap-expected.checksum: Added.
+ * platform/mac/svg/filters/feDisplacementMap-expected.png: Added.
+ * platform/mac/svg/filters/feDisplacementMap-expected.txt: Added.
+ * svg/filters/feDisplacementMap.svg: Added.
+
2009-11-03 Shinichiro Hamaji <hamaji@chromium.org>
Reviewed by Eric Seidel.
--- /dev/null
+9e20468ff7a8395c8cf735e054ca4772
\ No newline at end of file
--- /dev/null
+KRenderingPaintServer {id="linGrad" [type=LINEAR-GRADIENT] [stops=[(0.00,#FF0000), (1.00,#00FF00)]] [start=(0,0)] [end=(1,1)]}
+KRenderingPaintServer {id="radGrad" [type=RADIAL-GRADIENT] [stops=[(0.00,#FF0000), (1.00,#00FF00)]] [center=(0.50,0.50)] [focal=(0.50,0.50)] [radius=0.50]}
+layer at (0,0) size 800x600
+ RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+ RenderSVGRoot {svg} at (10,10) size 220x100
+ RenderSVGHiddenContainer {defs} at (0,0) size 0x0
+ RenderSVGHiddenContainer {linearGradient} at (0,0) size 0x0
+ RenderSVGGradientStop {stop} at (0,0) size 0x0
+ RenderSVGGradientStop {stop} at (0,0) size 0x0
+ RenderSVGHiddenContainer {radialGradient} at (0,0) size 0x0
+ RenderSVGGradientStop {stop} at (0,0) size 0x0
+ RenderSVGGradientStop {stop} at (0,0) size 0x0
+ RenderSVGImage {image} at (10,10) size 100x100 [filter=f1]
+ RenderSVGImage {image} at (130,10) size 100x100 [filter=f1]
--- /dev/null
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<defs>
+<linearGradient id="linGrad" x1="0%" y1="0%" x2="100%" y2="100%">
+<stop offset="0%" style="stop-color:rgb(255,0,0);stop-opacity:1"/>
+<stop offset="100%" style="stop-color:rgb(0,255,0);stop-opacity:1"/>
+</linearGradient>
+<radialGradient id="radGrad" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
+<stop offset="0%" style="stop-color:rgb(255,0,0);stop-opacity:1"/>
+<stop offset="100%" style="stop-color:rgb(0,255,0);stop-opacity:1"/>
+</radialGradient>
+<filter id="f1" filterUnits="objectBoundingBox" x="0" y="0" width="1" height="1" primitiveUnits="objectBoundingBox">
+<feFlood flood-color="#000" x="5%" y="5%" width="5%" height="5%" result="flood1"/>
+<feFlood flood-color="#000" x="0%" y="0%" width="5%" height="5%" result="flood2"/>
+<feComposite in="flood1" in2="flood2" result="pair"/>
+<feTile in="pair" result="tile"/>
+<feDisplacementMap in="tile" in2="SourceGraphic" scale="64" xChannelSelector="R" yChannelSelector="G"/>
+</filter>
+</defs>
+<image x="10" y="10" width="100" height="100" xlink:href="../W3C-SVG-1.1/resources/rotate20.png" filter="url(#f1)"/>
+<image x="130" y="10" width="100" height="100" xlink:href="../W3C-SVG-1.1/resources/sphere.png" filter="url(#f1)"/>
+</svg>
+
+2009-11-09 Dirk Schulze <krit@webkit.org>
+
+ Reviewed by Oliver Hunt.
+
+ SVG feDisplacementMap is not implemented
+ [https://bugs.webkit.org/show_bug.cgi?id=31255]
+
+ This is the implementation of the SVG filter effect
+ feDisplacementMap.
+
+ Test: svg/filters/feDisplacementMap.svg
+
+ * svg/graphics/filters/SVGFEDisplacementMap.cpp:
+ (WebCore::FEDisplacementMap::apply):
+
2009-11-09 Kent Tamura <tkent@chromium.org>
Reviewed by Darin Adler.
Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
2004, 2005 Rob Buis <buis@kde.org>
2005 Eric Seidel <eric@webkit.org>
+ 2009 Dirk Schulze <krit@webkit.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
#if ENABLE(SVG) && ENABLE(FILTERS)
#include "SVGFEDisplacementMap.h"
-#include "SVGRenderTreeAsText.h"
+
+#include "CanvasPixelArray.h"
#include "Filter.h"
+#include "GraphicsContext.h"
+#include "ImageData.h"
+#include "SVGRenderTreeAsText.h"
namespace WebCore {
m_scale = scale;
}
-void FEDisplacementMap::apply(Filter*)
+void FEDisplacementMap::apply(Filter* filter)
{
+ m_in->apply(filter);
+ m_in2->apply(filter);
+ if (!m_in->resultImage() || !m_in2->resultImage())
+ return;
+
+ if (m_xChannelSelector == CHANNEL_UNKNOWN || m_yChannelSelector == CHANNEL_UNKNOWN)
+ return;
+
+ if (!getEffectContext())
+ return;
+
+ IntRect effectADrawingRect = calculateDrawingIntRect(m_in->subRegion());
+ RefPtr<CanvasPixelArray> srcPixelArrayA(m_in->resultImage()->getPremultipliedImageData(effectADrawingRect)->data());
+
+ IntRect effectBDrawingRect = calculateDrawingIntRect(m_in2->subRegion());
+ RefPtr<CanvasPixelArray> srcPixelArrayB(m_in2->resultImage()->getUnmultipliedImageData(effectBDrawingRect)->data());
+
+ IntRect imageRect(IntPoint(), resultImage()->size());
+ RefPtr<ImageData> imageData = ImageData::create(imageRect.width(), imageRect.height());
+
+ ASSERT(srcPixelArrayA->length() == srcPixelArrayB->length());
+
+ float scale = m_scale / 255.f;
+ float scaleAdjustment = 0.5f - 0.5f * m_scale;
+ int stride = imageRect.width() * 4;
+ for (int y = 0; y < imageRect.height(); ++y) {
+ int line = y * stride;
+ for (int x = 0; x < imageRect.width(); ++x) {
+ int dstIndex = line + x * 4;
+ int srcX = x + static_cast<int>(scale * srcPixelArrayB->get(dstIndex + m_xChannelSelector - 1) + scaleAdjustment);
+ int srcY = y + static_cast<int>(scale * srcPixelArrayB->get(dstIndex + m_yChannelSelector - 1) + scaleAdjustment);
+ for (unsigned channel = 0; channel < 4; ++channel) {
+ if (srcX < 0 || srcX >= imageRect.width() || srcY < 0 || srcY >= imageRect.height())
+ imageData->data()->set(dstIndex + channel, static_cast<unsigned char>(0));
+ else {
+ unsigned char pixelValue = srcPixelArrayA->get(srcY * stride + srcX * 4 + channel);
+ imageData->data()->set(dstIndex + channel, pixelValue);
+ }
+ }
+
+ }
+ }
+ resultImage()->putPremultipliedImageData(imageData.get(), imageRect, IntPoint());
}
void FEDisplacementMap::dump()