2009-11-09 Dirk Schulze <krit@webkit.org>
authorkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2009 07:23:39 +0000 (07:23 +0000)
committerkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2009 07:23:39 +0000 (07:23 +0000)
        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

LayoutTests/ChangeLog
LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.txt [new file with mode: 0644]
LayoutTests/svg/filters/feDisplacementMap.svg [new file with mode: 0644]
WebCore/ChangeLog
WebCore/svg/graphics/filters/SVGFEDisplacementMap.cpp

index 99b16996697f36d0bbeb974dd62f28d53d224c97..d7245f9f9e763d0df66a74dd4a42d5f9c21ddfc4 100644 (file)
@@ -1,3 +1,14 @@
+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.
diff --git a/LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.checksum b/LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.checksum
new file mode 100644 (file)
index 0000000..49ccafd
--- /dev/null
@@ -0,0 +1 @@
+9e20468ff7a8395c8cf735e054ca4772
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.png b/LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.png
new file mode 100644 (file)
index 0000000..f9774bf
Binary files /dev/null and b/LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.png differ
diff --git a/LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.txt b/LayoutTests/platform/mac/svg/filters/feDisplacementMap-expected.txt
new file mode 100644 (file)
index 0000000..7ad8c2b
--- /dev/null
@@ -0,0 +1,15 @@
+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]
diff --git a/LayoutTests/svg/filters/feDisplacementMap.svg b/LayoutTests/svg/filters/feDisplacementMap.svg
new file mode 100644 (file)
index 0000000..4d2c322
--- /dev/null
@@ -0,0 +1,22 @@
+<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>
+
index 30e8fc60e7d6d40b58f489d6cc7ed27822174f16..f440e80c339d12e640f885d7125a0c27d9a1970b 100644 (file)
@@ -1,3 +1,18 @@
+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.
index abb57ee9ce88403d029a36e99a3331c618bbaac2..cc5a4b3091394cef7e448b2eb7b116f0aa568cf9 100644 (file)
@@ -2,6 +2,7 @@
     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 {
 
@@ -75,8 +80,51 @@ void FEDisplacementMap::setScale(float scale)
     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()