Changeset 52865 in webkit


Ignore:
Timestamp:
Jan 6, 2010 1:10:35 PM (14 years ago)
Author:
krit@webkit.org
Message:

2010-01-06 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

SVG feImage support
https://bugs.webkit.org/show_bug.cgi?id=31905

This implements the SVG Filter effect feImage with support of fragment urls.
It also includes a bug fix for feComposite. feComposite didn't cover values
bigger than 255 correctly on composite oeprator arithmetic.

Tests: There are already many feImage tests in trunk. They just needed updated

pixel test results.
The feComposite bug is covered by svg/W3C-SVG-1.1/filters-composite-02-b.svg
and depends on feImage.

  • platform/graphics/filters/FEComposite.cpp: (WebCore::arithmetic):
  • rendering/RenderSVGImage.cpp: (WebCore::RenderSVGImage::paint):
  • rendering/RenderSVGImage.h:
  • svg/SVGFEImageElement.cpp: (WebCore::SVGFEImageElement::requestImageResource): (WebCore::SVGFEImageElement::parseMappedAttribute): (WebCore::SVGFEImageElement::notifyFinished): (WebCore::SVGFEImageElement::build):
  • svg/SVGFEImageElement.h:
  • svg/SVGFEImageElement.idl:
  • svg/SVGPreserveAspectRatio.cpp: (WebCore::SVGPreserveAspectRatio::transformRect):
  • svg/SVGPreserveAspectRatio.h:
  • svg/graphics/filters/SVGFEImage.cpp: (WebCore::FEImage::FEImage): (WebCore::FEImage::create): (WebCore::FEImage::apply):
  • svg/graphics/filters/SVGFEImage.h:

2010-01-06 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

SVG feImage support
https://bugs.webkit.org/show_bug.cgi?id=31905

The implementation of feImage requires pixel test result updates of the already
available tests.

There is also an update for svg/filters/feComposite.svg, since the patch also
fixed a bug in feComposite.

  • platform/mac/svg/W3C-SVG-1.1/filters-composite-02-b-expected.checksum:
  • platform/mac/svg/W3C-SVG-1.1/filters-composite-02-b-expected.png:
  • platform/mac/svg/W3C-SVG-1.1/filters-displace-01-f-expected.checksum:
  • platform/mac/svg/W3C-SVG-1.1/filters-displace-01-f-expected.png:
  • platform/mac/svg/W3C-SVG-1.1/filters-image-01-b-expected.checksum:
  • platform/mac/svg/W3C-SVG-1.1/filters-image-01-b-expected.png:
  • platform/mac/svg/custom/feDisplacementMap-01-expected.checksum:
  • platform/mac/svg/custom/feDisplacementMap-01-expected.png:
  • platform/mac/svg/filters/feComposite-expected.checksum:
  • platform/mac/svg/filters/feComposite-expected.png:
  • platform/mac/svg/webarchive/svg-feimage-subresources-expected.checksum:
  • platform/mac/svg/webarchive/svg-feimage-subresources-expected.png:

2010-01-06 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

SVG feImage support
https://bugs.webkit.org/show_bug.cgi?id=31905

Update SVG status page. We support feDisplacementMap and feImage now.

  • projects/svg/status.xml:
Location:
trunk
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r52864 r52865  
     12010-01-06  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        SVG feImage support
     6        https://bugs.webkit.org/show_bug.cgi?id=31905
     7
     8        The implementation of feImage requires pixel test result updates of the already
     9        available tests.
     10
     11        There is also an update for svg/filters/feComposite.svg, since the patch also
     12        fixed a bug in feComposite.
     13
     14        * platform/mac/svg/W3C-SVG-1.1/filters-composite-02-b-expected.checksum:
     15        * platform/mac/svg/W3C-SVG-1.1/filters-composite-02-b-expected.png:
     16        * platform/mac/svg/W3C-SVG-1.1/filters-displace-01-f-expected.checksum:
     17        * platform/mac/svg/W3C-SVG-1.1/filters-displace-01-f-expected.png:
     18        * platform/mac/svg/W3C-SVG-1.1/filters-image-01-b-expected.checksum:
     19        * platform/mac/svg/W3C-SVG-1.1/filters-image-01-b-expected.png:
     20        * platform/mac/svg/custom/feDisplacementMap-01-expected.checksum:
     21        * platform/mac/svg/custom/feDisplacementMap-01-expected.png:
     22        * platform/mac/svg/filters/feComposite-expected.checksum:
     23        * platform/mac/svg/filters/feComposite-expected.png:
     24        * platform/mac/svg/webarchive/svg-feimage-subresources-expected.checksum:
     25        * platform/mac/svg/webarchive/svg-feimage-subresources-expected.png:
     26
    1272010-01-06  Darin Adler  <darin@apple.com>
    228
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/filters-composite-02-b-expected.checksum

    r51800 r52865  
    1 595cf6946aa045acc21ed50e49871010
     14e2d58b2588a2a7b8d42e789a80f789f
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/filters-displace-01-f-expected.checksum

    r51800 r52865  
    1 a5b60846615b1ff8ccd1bbb5062c6fe5
     1b6c63dd5fe1fda01e3ff9b0dfd771915
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/filters-image-01-b-expected.checksum

    r51800 r52865  
    1 5a1e5687cc46137b116c062c175d83d5
     1cfb233bae17cc624073e47952c53e490
  • trunk/LayoutTests/platform/mac/svg/custom/feDisplacementMap-01-expected.checksum

    r51800 r52865  
    1 37725a2315328ea128fc2cfe3549a4f9
     1c13733cd61a1b84ab863558aa67ee47b
  • trunk/LayoutTests/platform/mac/svg/filters/feComposite-expected.checksum

    r51800 r52865  
    1 2393c34443caa35be741e4cc3e05edd2
     1d0fabba10fec772a87a338fa3bf1b627
  • trunk/LayoutTests/platform/mac/svg/webarchive/svg-feimage-subresources-expected.checksum

    r51800 r52865  
    1 853de00567d121bea0b7bece66a5d61c
     1c6ab9fc121db160df3116601d024db23
  • trunk/WebCore/ChangeLog

    r52862 r52865  
     12010-01-06  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        SVG feImage support
     6        https://bugs.webkit.org/show_bug.cgi?id=31905
     7
     8        This implements the SVG Filter effect feImage with support of fragment urls.
     9        It also includes a bug fix for feComposite. feComposite didn't cover values
     10        bigger than 255 correctly on composite oeprator arithmetic.
     11
     12        Tests: There are already many feImage tests in trunk. They just needed updated
     13               pixel test results.
     14               The feComposite bug is covered by svg/W3C-SVG-1.1/filters-composite-02-b.svg
     15               and depends on feImage.
     16
     17        * platform/graphics/filters/FEComposite.cpp:
     18        (WebCore::arithmetic):
     19        * rendering/RenderSVGImage.cpp:
     20        (WebCore::RenderSVGImage::paint):
     21        * rendering/RenderSVGImage.h:
     22        * svg/SVGFEImageElement.cpp:
     23        (WebCore::SVGFEImageElement::requestImageResource):
     24        (WebCore::SVGFEImageElement::parseMappedAttribute):
     25        (WebCore::SVGFEImageElement::notifyFinished):
     26        (WebCore::SVGFEImageElement::build):
     27        * svg/SVGFEImageElement.h:
     28        * svg/SVGFEImageElement.idl:
     29        * svg/SVGPreserveAspectRatio.cpp:
     30        (WebCore::SVGPreserveAspectRatio::transformRect):
     31        * svg/SVGPreserveAspectRatio.h:
     32        * svg/graphics/filters/SVGFEImage.cpp:
     33        (WebCore::FEImage::FEImage):
     34        (WebCore::FEImage::create):
     35        (WebCore::FEImage::apply):
     36        * svg/graphics/filters/SVGFEImage.h:
     37
    1382010-01-06  Yong Li  <yoli@rim.com>
    239
  • trunk/WebCore/platform/graphics/filters/FEComposite.cpp

    r51310 r52865  
    112112            unsigned char i2 = srcPixelArrayB->get(pixelOffset + channel);
    113113
    114             unsigned char result = scaledK1 * i1 * i2 + k2 * i1 + k3 * i2 + scaledK4;
    115             if (channel == 3 && i1 == 0 && i2 == 0)
    116                 result = 0;
     114            double result = scaledK1 * i1 * i2 + k2 * i1 + k3 * i2 + scaledK4;
    117115            srcPixelArrayB->set(pixelOffset + channel, result);
    118116        }
  • trunk/WebCore/rendering/RenderSVGImage.cpp

    r52647 r52865  
    4949}
    5050
    51 void RenderSVGImage::adjustRectsForAspectRatio(FloatRect& destRect, FloatRect& srcRect, const SVGPreserveAspectRatio& aspectRatio)
    52 {
    53     float origDestWidth = destRect.width();
    54     float origDestHeight = destRect.height();
    55     if (aspectRatio.meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_MEET) {
    56         float widthToHeightMultiplier = srcRect.height() / srcRect.width();
    57         if (origDestHeight > (origDestWidth * widthToHeightMultiplier)) {
    58             destRect.setHeight(origDestWidth * widthToHeightMultiplier);
    59             switch (aspectRatio.align()) {
    60                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
    61                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
    62                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
    63                     destRect.setY(destRect.y() + origDestHeight / 2.0f - destRect.height() / 2.0f);
    64                     break;
    65                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
    66                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
    67                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
    68                     destRect.setY(destRect.y() + origDestHeight - destRect.height());
    69                     break;
    70             }
    71         }
    72         if (origDestWidth > (origDestHeight / widthToHeightMultiplier)) {
    73             destRect.setWidth(origDestHeight / widthToHeightMultiplier);
    74             switch (aspectRatio.align()) {
    75                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
    76                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
    77                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
    78                     destRect.setX(destRect.x() + origDestWidth / 2.0f - destRect.width() / 2.0f);
    79                     break;
    80                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
    81                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
    82                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
    83                     destRect.setX(destRect.x() + origDestWidth - destRect.width());
    84                     break;
    85             }
    86         }
    87     } else if (aspectRatio.meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE) {
    88         float widthToHeightMultiplier = srcRect.height() / srcRect.width();
    89         // if the destination height is less than the height of the image we'll be drawing
    90         if (origDestHeight < (origDestWidth * widthToHeightMultiplier)) {
    91             float destToSrcMultiplier = srcRect.width() / destRect.width();
    92             srcRect.setHeight(destRect.height() * destToSrcMultiplier);
    93             switch (aspectRatio.align()) {
    94                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
    95                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
    96                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
    97                     srcRect.setY(destRect.y() + image()->height() / 2.0f - srcRect.height() / 2.0f);
    98                     break;
    99                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
    100                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
    101                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
    102                     srcRect.setY(destRect.y() + image()->height() - srcRect.height());
    103                     break;
    104             }
    105         }
    106         // if the destination width is less than the width of the image we'll be drawing
    107         if (origDestWidth < (origDestHeight / widthToHeightMultiplier)) {
    108             float destToSrcMultiplier = srcRect.height() / destRect.height();
    109             srcRect.setWidth(destRect.width() * destToSrcMultiplier);
    110             switch (aspectRatio.align()) {
    111                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
    112                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
    113                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
    114                     srcRect.setX(destRect.x() + image()->width() / 2.0f - srcRect.width() / 2.0f);
    115                     break;
    116                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
    117                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
    118                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
    119                     srcRect.setX(destRect.x() + image()->width() - srcRect.width());
    120                     break;
    121             }
    122         }
    123     }
    124 }
    125 
    12651void RenderSVGImage::layout()
    12752{
     
    16691            SVGImageElement* imageElt = static_cast<SVGImageElement*>(node());
    16792            if (imageElt->preserveAspectRatio().align() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE)
    168                 adjustRectsForAspectRatio(destRect, srcRect, imageElt->preserveAspectRatio());
     93                imageElt->preserveAspectRatio().transformRect(destRect, srcRect);
    16994
    17095            paintInfo.context->drawImage(image(), DeviceColorSpace, destRect, srcRect);
  • trunk/WebCore/rendering/RenderSVGImage.h

    r52647 r52865  
    6060
    6161        virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
    62         void adjustRectsForAspectRatio(FloatRect& destRect, FloatRect& srcRect, const SVGPreserveAspectRatio&);
    6362       
    6463        virtual void layout();
  • trunk/WebCore/svg/SVGFEImageElement.cpp

    r52373 r52865  
    22    Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
    33                  2004, 2005 Rob Buis <buis@kde.org>
     4                  2010 Dirk Schulze <krit@webkit.org>
    45
    56    This library is free software; you can redistribute it and/or
     
    3233#include "SVGNames.h"
    3334#include "SVGPreserveAspectRatio.h"
     35#include "SVGRenderSupport.h"
    3436#include "SVGResourceFilter.h"
    3537
     
    5355}
    5456
     57void SVGFEImageElement::requestImageResource()
     58{
     59    if (m_cachedImage) {
     60        m_cachedImage->removeClient(this);
     61        m_cachedImage = 0;
     62    }
     63
     64    Element* hrefElement = document()->getElementById(SVGURIReference::getTarget(href()));
     65    if (hrefElement && hrefElement->isSVGElement() && hrefElement->renderer())
     66        return;
     67
     68    m_cachedImage = ownerDocument()->docLoader()->requestImage(href());
     69
     70    if (m_cachedImage)
     71        m_cachedImage->addClient(this);
     72}
     73
    5574void SVGFEImageElement::parseMappedAttribute(MappedAttribute* attr)
    5675{
     
    6079    else {
    6180        if (SVGURIReference::parseMappedAttribute(attr)) {
    62             if (!href().startsWith("#")) {
    63                 // FIXME: this code needs to special-case url fragments and later look them up using getElementById instead of loading them here
    64                 if (m_cachedImage)
    65                     m_cachedImage->removeClient(this);
    66                 m_cachedImage = ownerDocument()->docLoader()->requestImage(href());
    67                 if (m_cachedImage)
    68                     m_cachedImage->addClient(this);
    69             }
     81            requestImageResource();
    7082            return;
    7183        }
     
    8193void SVGFEImageElement::notifyFinished(CachedResource*)
    8294{
     95    SVGStyledElement::invalidateResourcesInAncestorChain();
    8396}
    8497
    8598bool SVGFEImageElement::build(SVGResourceFilter* filterResource)
    8699{
    87     if (!m_cachedImage)
    88         return false;
     100    if (!m_cachedImage && !m_targetImage) {
     101        Element* hrefElement = document()->getElementById(SVGURIReference::getTarget(href()));
     102        if (!hrefElement || !hrefElement->isSVGElement())
     103            return false;
    89104
    90     RefPtr<FilterEffect> effect = FEImage::create(m_cachedImage.get());
     105        RenderObject* renderer = hrefElement->renderer();
     106        if (!renderer)
     107            return false;
     108
     109        IntRect targetRect = enclosingIntRect(renderer->objectBoundingBox());
     110        m_targetImage = ImageBuffer::create(targetRect.size(), LinearRGB);
     111
     112        renderSubtreeToImage(m_targetImage.get(), renderer);
     113    }
     114
     115    RefPtr<FilterEffect> effect = FEImage::create(m_targetImage ? m_targetImage->image() : m_cachedImage->image(), preserveAspectRatio());
    91116    filterResource->addFilterEffect(this, effect.release());
    92117
  • trunk/WebCore/svg/SVGFEImageElement.h

    r49602 r52865  
    2424#if ENABLE(SVG) && ENABLE(FILTERS)
    2525#include "CachedResourceHandle.h"
    26 #include "SVGFilterPrimitiveStandardAttributes.h"
    27 #include "SVGURIReference.h"
    28 #include "SVGLangSpace.h"
     26#include "ImageBuffer.h"
    2927#include "SVGExternalResourcesRequired.h"
    3028#include "SVGFEImage.h"
     29#include "SVGFilterPrimitiveStandardAttributes.h"
     30#include "SVGLangSpace.h"
    3131#include "SVGPreserveAspectRatio.h"
     32#include "SVGURIReference.h"
    3233
    3334namespace WebCore {
     
    4950
    5051    private:
     52        void requestImageResource();
     53
    5154        ANIMATED_PROPERTY_DECLARATIONS(SVGFEImageElement, SVGNames::feImageTagString, SVGNames::preserveAspectRatioAttrString, SVGPreserveAspectRatio, PreserveAspectRatio, preserveAspectRatio)
    5255
     
    6063
    6164        CachedResourceHandle<CachedImage> m_cachedImage;
     65        OwnPtr<ImageBuffer> m_targetImage;
    6266    };
    6367
  • trunk/WebCore/svg/SVGFEImageElement.idl

    r44253 r52865  
    2727
    2828    interface [Conditional=SVG&FILTERS] SVGFEImageElement : SVGElement,
    29                                                     SVGURIReference,
    30                                                     SVGLangSpace,
    31                                                     SVGExternalResourcesRequired,
    32                                                     SVGFilterPrimitiveStandardAttributes {
     29                                                            SVGURIReference,
     30                                                            SVGLangSpace,
     31                                                            SVGExternalResourcesRequired,
     32                                                            SVGFilterPrimitiveStandardAttributes {
     33        readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio;
    3334    };
    3435
  • trunk/WebCore/svg/SVGPreserveAspectRatio.cpp

    r52373 r52865  
    22    Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
    33                  2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
     4                  2010 Dirk Schulze <krit@webkit.org>
    45
    56    This library is free software; you can redistribute it and/or
     
    159160}
    160161
     162void SVGPreserveAspectRatio::transformRect(FloatRect& destRect, FloatRect& srcRect)
     163{
     164    FloatSize imageSize = srcRect.size();
     165    float origDestWidth = destRect.width();
     166    float origDestHeight = destRect.height();
     167    if (meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_MEET) {
     168        float widthToHeightMultiplier = srcRect.height() / srcRect.width();
     169        if (origDestHeight > (origDestWidth * widthToHeightMultiplier)) {
     170            destRect.setHeight(origDestWidth * widthToHeightMultiplier);
     171            switch (align()) {
     172            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
     173            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
     174            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
     175                destRect.setY(destRect.y() + origDestHeight / 2.0f - destRect.height() / 2.0f);
     176                break;
     177            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
     178            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
     179            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
     180                destRect.setY(destRect.y() + origDestHeight - destRect.height());
     181                break;
     182            }
     183        }
     184        if (origDestWidth > (origDestHeight / widthToHeightMultiplier)) {
     185            destRect.setWidth(origDestHeight / widthToHeightMultiplier);
     186            switch (align()) {
     187            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
     188            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
     189            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
     190                destRect.setX(destRect.x() + origDestWidth / 2.0f - destRect.width() / 2.0f);
     191                break;
     192            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
     193            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
     194            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
     195                destRect.setX(destRect.x() + origDestWidth - destRect.width());
     196                break;
     197            }
     198        }
     199    } else if (meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE) {
     200        float widthToHeightMultiplier = srcRect.height() / srcRect.width();
     201        // if the destination height is less than the height of the image we'll be drawing
     202        if (origDestHeight < (origDestWidth * widthToHeightMultiplier)) {
     203            float destToSrcMultiplier = srcRect.width() / destRect.width();
     204            srcRect.setHeight(destRect.height() * destToSrcMultiplier);
     205            switch (align()) {
     206            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
     207            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
     208            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
     209                srcRect.setY(destRect.y() + imageSize.height() / 2.0f - srcRect.height() / 2.0f);
     210                break;
     211            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
     212            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
     213            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
     214                srcRect.setY(destRect.y() + imageSize.height() - srcRect.height());
     215                break;
     216            }
     217        }
     218        // if the destination width is less than the width of the image we'll be drawing
     219        if (origDestWidth < (origDestHeight / widthToHeightMultiplier)) {
     220            float destToSrcMultiplier = srcRect.height() / destRect.height();
     221            srcRect.setWidth(destRect.width() * destToSrcMultiplier);
     222            switch (align()) {
     223            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
     224            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
     225            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
     226                srcRect.setX(destRect.x() + imageSize.width() / 2.0f - srcRect.width() / 2.0f);
     227                break;
     228            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
     229            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
     230            case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
     231                srcRect.setX(destRect.x() + imageSize.width() - srcRect.width());
     232                break;
     233            }
     234        }
     235    }
     236}
     237
    161238TransformationMatrix SVGPreserveAspectRatio::getCTM(double logicX, double logicY,
    162239                                               double logicWidth, double logicHeight,
  • trunk/WebCore/svg/SVGPreserveAspectRatio.h

    r52373 r52865  
    2323
    2424#if ENABLE(SVG)
     25#include "FloatRect.h"
    2526#include "PlatformString.h"
    2627#include "SVGNames.h"
     
    6162        void setMeetOrSlice(unsigned short);
    6263        unsigned short meetOrSlice() const;
     64
     65        void transformRect(FloatRect& destRect, FloatRect& srcRect);
    6366       
    6467        TransformationMatrix getCTM(double logicX, double logicY,
  • trunk/WebCore/svg/graphics/filters/SVGFEImage.cpp

    r44655 r52865  
    33                  2004, 2005 Rob Buis <buis@kde.org>
    44                  2005 Eric Seidel <eric@webkit.org>
     5                  2010 Dirk Schulze <krit@webkit.org>
    56
    67    This library is free software; you can redistribute it and/or
     
    2425#if ENABLE(SVG) && ENABLE(FILTERS)
    2526#include "SVGFEImage.h"
     27
     28#include "Filter.h"
     29#include "GraphicsContext.h"
     30#include "SVGPreserveAspectRatio.h"
    2631#include "SVGRenderTreeAsText.h"
    27 #include "Filter.h"
     32#include "TransformationMatrix.h"
    2833
    2934namespace WebCore {
    3035
    31 FEImage::FEImage(CachedImage* cachedImage)
     36FEImage::FEImage(RefPtr<Image> image, SVGPreserveAspectRatio preserveAspectRatio)
    3237    : FilterEffect()
    33     , m_cachedImage(cachedImage)
     38    , m_image(image)
     39    , m_preserveAspectRatio(preserveAspectRatio)
    3440{
    35     m_cachedImage->addClient(this);
    3641}
    3742
    38 PassRefPtr<FEImage> FEImage::create(CachedImage* cachedImage)
     43PassRefPtr<FEImage> FEImage::create(RefPtr<Image> image, SVGPreserveAspectRatio preserveAspectRatio)
    3944{
    40     return adoptRef(new FEImage(cachedImage));
    41 }
    42 
    43 FEImage::~FEImage()
    44 {
    45     if (m_cachedImage)
    46         m_cachedImage->removeClient(this);
    47 }
    48 
    49 CachedImage* FEImage::cachedImage() const
    50 {
    51     return m_cachedImage.get();
    52 }
    53 
    54 void FEImage::setCachedImage(CachedImage* image)
    55 {
    56     if (m_cachedImage == image)
    57         return;
    58    
    59     if (m_cachedImage)
    60         m_cachedImage->removeClient(this);
    61 
    62     m_cachedImage = image;
    63 
    64     if (m_cachedImage)
    65         m_cachedImage->addClient(this);
     45    return adoptRef(new FEImage(image, preserveAspectRatio));
    6646}
    6747
    6848void FEImage::apply(Filter*)
    6949{
     50    if (!m_image.get())
     51        return;
     52
     53    GraphicsContext* filterContext = getEffectContext();
     54    if (!filterContext)
     55        return;
     56
     57    FloatRect srcRect(FloatPoint(), m_image->size());
     58    FloatRect destRect(FloatPoint(), subRegion().size());
     59
     60    m_preserveAspectRatio.transformRect(destRect, srcRect);
     61
     62    filterContext->drawImage(m_image.get(), DeviceColorSpace, destRect, srcRect);
    7063}
    7164
  • trunk/WebCore/svg/graphics/filters/SVGFEImage.h

    r44655 r52865  
    33                  2004, 2005 Rob Buis <buis@kde.org>
    44                  2005 Eric Seidel <eric@webkit.org>
     5                  2010 Dirk Schulze <krit@webkit.org>
    56
    67    This library is free software; you can redistribute it and/or
     
    2425
    2526#if ENABLE(SVG) && ENABLE(FILTERS)
    26 #include "CachedImage.h"
    27 #include "CachedResourceClient.h"
    28 #include "CachedResourceHandle.h"
     27#include "Image.h"
    2928#include "FilterEffect.h"
    3029#include "Filter.h"
     30#include "SVGPreserveAspectRatio.h"
    3131
    3232namespace WebCore {
    3333
    34     class FEImage : public FilterEffect
    35                      , public CachedResourceClient {
     34    class FEImage : public FilterEffect {
    3635    public:
    37         static PassRefPtr<FEImage> create(CachedImage*);
    38         virtual ~FEImage();
    39 
    40         // FIXME: We need to support <svg> (RenderObject*) as well as image data.
    41 
    42         CachedImage* cachedImage() const;
    43         void setCachedImage(CachedImage*);
     36        static PassRefPtr<FEImage> create(RefPtr<Image>, SVGPreserveAspectRatio);
    4437
    4538        void apply(Filter*);
     
    4841       
    4942    private:
    50         FEImage(CachedImage*);
     43        FEImage(RefPtr<Image>, SVGPreserveAspectRatio);
    5144
    52         CachedResourceHandle<CachedImage> m_cachedImage;
     45        RefPtr<Image> m_image;
     46        SVGPreserveAspectRatio m_preserveAspectRatio;
    5347    };
    5448
  • trunk/WebKitSite/ChangeLog

    r52433 r52865  
     12010-01-06  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        SVG feImage support
     6        https://bugs.webkit.org/show_bug.cgi?id=31905
     7
     8        Update SVG status page. We support feDisplacementMap and feImage now.
     9
     10        * projects/svg/status.xml:
     11
    1122009-12-20  Chris Jerdonek  <chris.jerdonek@gmail.com>
    213
  • trunk/WebKitSite/projects/svg/status.xml

    r50606 r52865  
    77    </p>
    88    <p>
    9     Last update: Nov 5th, 2009.
     9    Last update: Jan 5th, 2010.
    1010    </p>
    1111    <p>
     
    294294                    <issue>Tracking Bug <bug>26389</bug>.</issue>
    295295                    <issue>Filters look grainy when scaled <bug>5526</bug></issue>
    296                     <issue>Filters don't support filterRes <bug>6021</bug></issue>
    297296                    <issue>Need support sources other than SourceGraphic <bug>6022</bug></issue>
    298297                    <issue>Support 'color-interpolation-filters' and draw in correct colorspace <bug>6033</bug></issue>
     
    300299                    <issue>Handle missing filter elements correctly <bug>12569</bug></issue>
    301300                    <issue>Filter Effects being cleared and reloaded multiple times <bug>19388</bug></issue>
    302                     <issue>Big filterRegions <bug>26380</bug></issue>
    303301                </issues>
    304302            </element>
     
    339337                <name>feDisplacementMap</name>
    340338                <url>http://www.w3.org/TR/SVG11/filters.html#feDisplacementMapElement</url>
    341                 <status>Unimplemented</status>
     339                <status>Implemented</status>
    342340            </element>
    343341            <element>
     
    354352                <name>feImage</name>
    355353                <url>http://www.w3.org/TR/SVG11/filters.html#feImageElement</url>
    356                 <status>Unimplemented</status>
    357                 <issues>
    358                     <issue>Does not support SVG fragment URLs <bug>12027</bug></issue>
    359                 </issues>
     354                <status>Implemented</status>
    360355            </element>
    361356            <element>
Note: See TracChangeset for help on using the changeset viewer.