Changeset 50604 in webkit


Ignore:
Timestamp:
Nov 6, 2009 1:08:10 PM (14 years ago)
Author:
krit@webkit.org
Message:

2009-11-06 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

feMorphology filter is not implemented
https://bugs.webkit.org/show_bug.cgi?id=5863

The Implementation of feMorphology.


Test: We have allready a test for feMorphology

svg/W3C-SVG-1.1/filters-morph-01-f.svg

  • svg/graphics/filters/SVGFEMorphology.cpp: (WebCore::FEMorphology::apply):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r50603 r50604  
     12009-11-06  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        feMorphology filter is not implemented
     6        [https://bugs.webkit.org/show_bug.cgi?id=5863]
     7
     8        The Implementation of feMorphology.
     9       
     10        Test: We have allready a test for feMorphology
     11              svg/W3C-SVG-1.1/filters-morph-01-f.svg
     12
     13        * svg/graphics/filters/SVGFEMorphology.cpp:
     14        (WebCore::FEMorphology::apply):
     15
    1162009-11-06  Steve Block  <steveblock@google.com>
    217
  • trunk/WebCore/svg/graphics/filters/SVGFEMorphology.cpp

    r49400 r50604  
    33                  2004, 2005 Rob Buis <buis@kde.org>
    44                  2005 Eric Seidel <eric@webkit.org>
     5                  2009 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 "SVGFEMorphology.h"
     27
     28#include "CanvasPixelArray.h"
     29#include "Filter.h"
     30#include "ImageData.h"
    2631#include "SVGRenderTreeAsText.h"
    27 #include "Filter.h"
     32
     33#include <wtf/Vector.h>
     34
     35using std::min;
     36using std::max;
    2837
    2938namespace WebCore {
     
    7382}
    7483
    75 void FEMorphology::apply(Filter*)
     84void FEMorphology::apply(Filter* filter)
    7685{
     86    m_in->apply(filter);
     87    if (!m_in->resultImage())
     88        return;
     89   
     90    if (!getEffectContext())
     91        return;
     92
     93    if (!m_radiusX || !m_radiusY)
     94        return;
     95
     96    IntRect imageRect(IntPoint(), resultImage()->size());
     97    IntRect effectDrawingRect = calculateDrawingIntRect(m_in->subRegion());
     98    RefPtr<CanvasPixelArray> srcPixelArray(m_in->resultImage()->getPremultipliedImageData(effectDrawingRect)->data());
     99    RefPtr<ImageData> imageData = ImageData::create(imageRect.width(), imageRect.height());
     100
     101    int radiusX = static_cast<int>(m_radiusX);
     102    int radiusY = static_cast<int>(m_radiusY);
     103    int effectWidth = effectDrawingRect.width() * 4;
     104   
     105    // Limit the radius size to effect width
     106    radiusX = min(effectDrawingRect.width() - 1, radiusX);
     107   
     108    Vector<unsigned char> extrema;
     109    for (int y = 0; y < effectDrawingRect.height(); ++y) {
     110        int startY = max(0, y - radiusY);
     111        int endY = min(effectDrawingRect.height() - 1, y + radiusY);
     112        for (unsigned channel = 0; channel < 4; ++channel) {
     113            // Fill the kernel
     114            extrema.clear();
     115            for (int j = 0; j <= radiusX; ++j) {
     116                unsigned char columnExtrema = srcPixelArray->get(startY * effectWidth + 4 * j + channel);
     117                for (int i = startY; i <= endY; ++i) {
     118                    unsigned char pixel = srcPixelArray->get(i * effectWidth + 4 * j + channel);
     119                    if ((m_type == FEMORPHOLOGY_OPERATOR_ERODE && pixel <= columnExtrema) ||
     120                        (m_type == FEMORPHOLOGY_OPERATOR_DILATE && pixel >= columnExtrema))
     121                        columnExtrema = pixel;
     122                }
     123                extrema.append(columnExtrema);
     124            }
     125           
     126            // Kernel is filled, get extrema of next column
     127            for (int x = 0; x < effectDrawingRect.width(); ++x) {
     128                unsigned endX = min(x + radiusX, effectDrawingRect.width() - 1);
     129                unsigned char columnExtrema = srcPixelArray->get(startY * effectWidth + endX * 4 + channel);
     130                for (int i = startY; i <= endY; ++i) {
     131                    unsigned char pixel = srcPixelArray->get(i * effectWidth + endX * 4 + channel);
     132                    if ((m_type == FEMORPHOLOGY_OPERATOR_ERODE && pixel <= columnExtrema) ||
     133                        (m_type == FEMORPHOLOGY_OPERATOR_DILATE && pixel >= columnExtrema))
     134                        columnExtrema = pixel;
     135                }
     136                if (x - radiusX >= 0)
     137                    extrema.remove(0);
     138                if (x + radiusX <= effectDrawingRect.width())
     139                    extrema.append(columnExtrema);
     140                unsigned char entireExtrema = extrema[0];
     141                for (unsigned kernelIndex = 0; kernelIndex < extrema.size(); ++kernelIndex) {
     142                    if ((m_type == FEMORPHOLOGY_OPERATOR_ERODE && extrema[kernelIndex] <= entireExtrema) ||
     143                        (m_type == FEMORPHOLOGY_OPERATOR_DILATE && extrema[kernelIndex] >= entireExtrema))
     144                        entireExtrema = extrema[kernelIndex];
     145                }
     146                imageData->data()->set(y * effectWidth + 4 * x + channel, entireExtrema);
     147            }
     148        }
     149    }
     150    resultImage()->putPremultipliedImageData(imageData.get(), imageRect, IntPoint());
    77151}
    78152
Note: See TracChangeset for help on using the changeset viewer.