Home | History | Annotate | Download | only in filters
      1 /*
      2  * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005 Rob Buis <buis (at) kde.org>
      4  * Copyright (C) 2005 Eric Seidel <eric (at) webkit.org>
      5  * Copyright (C) 2010 Zoltan Herczeg <zherczeg (at) webkit.org>
      6  *
      7  * This library is free software; you can redistribute it and/or
      8  * modify it under the terms of the GNU Library General Public
      9  * License as published by the Free Software Foundation; either
     10  * version 2 of the License, or (at your option) any later version.
     11  *
     12  * This library is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  * Library General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU Library General Public License
     18  * along with this library; see the file COPYING.LIB.  If not, write to
     19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     20  * Boston, MA 02110-1301, USA.
     21  */
     22 
     23 #ifndef FEConvolveMatrix_h
     24 #define FEConvolveMatrix_h
     25 
     26 #if ENABLE(FILTERS)
     27 #include "FilterEffect.h"
     28 #include "FloatPoint.h"
     29 #include "FloatSize.h"
     30 #include "Filter.h"
     31 #include <wtf/AlwaysInline.h>
     32 #include <wtf/Vector.h>
     33 
     34 namespace WebCore {
     35 
     36 enum EdgeModeType {
     37     EDGEMODE_UNKNOWN   = 0,
     38     EDGEMODE_DUPLICATE = 1,
     39     EDGEMODE_WRAP      = 2,
     40     EDGEMODE_NONE      = 3
     41 };
     42 
     43 class CanvasPixelArray;
     44 
     45 class FEConvolveMatrix : public FilterEffect {
     46 public:
     47     static PassRefPtr<FEConvolveMatrix> create(Filter*, const IntSize&,
     48             float, float, const IntPoint&, EdgeModeType, const FloatPoint&,
     49             bool, const Vector<float>&);
     50 
     51     IntSize kernelSize() const;
     52     void setKernelSize(const IntSize&);
     53 
     54     const Vector<float>& kernel() const;
     55     void setKernel(const Vector<float>&);
     56 
     57     float divisor() const;
     58     bool setDivisor(float);
     59 
     60     float bias() const;
     61     bool setBias(float);
     62 
     63     IntPoint targetOffset() const;
     64     bool setTargetOffset(const IntPoint&);
     65 
     66     EdgeModeType edgeMode() const;
     67     bool setEdgeMode(EdgeModeType);
     68 
     69     FloatPoint kernelUnitLength() const;
     70     bool setKernelUnitLength(const FloatPoint&);
     71 
     72     bool preserveAlpha() const;
     73     bool setPreserveAlpha(bool);
     74 
     75     virtual void apply();
     76     virtual void dump();
     77 
     78     virtual void determineAbsolutePaintRect() { setAbsolutePaintRect(enclosingIntRect(maxEffectRect())); }
     79 
     80     virtual TextStream& externalRepresentation(TextStream&, int indention) const;
     81 
     82 private:
     83     FEConvolveMatrix(Filter*, const IntSize&, float, float,
     84             const IntPoint&, EdgeModeType, const FloatPoint&, bool, const Vector<float>&);
     85 
     86     struct PaintingData {
     87         ByteArray* srcPixelArray;
     88         ByteArray* dstPixelArray;
     89         int width;
     90         int height;
     91         float bias;
     92     };
     93 
     94     template<bool preserveAlphaValues>
     95     ALWAYS_INLINE void fastSetInteriorPixels(PaintingData&, int clipRight, int clipBottom);
     96 
     97     ALWAYS_INLINE int getPixelValue(PaintingData&, int x, int y);
     98 
     99     template<bool preserveAlphaValues>
    100     void fastSetOuterPixels(PaintingData&, int x1, int y1, int x2, int y2);
    101 
    102     // Wrapper functions
    103     ALWAYS_INLINE void setInteriorPixels(PaintingData& paintingData, int clipRight, int clipBottom);
    104     ALWAYS_INLINE void setOuterPixels(PaintingData& paintingData, int x1, int y1, int x2, int y2);
    105 
    106     IntSize m_kernelSize;
    107     float m_divisor;
    108     float m_bias;
    109     IntPoint m_targetOffset;
    110     EdgeModeType m_edgeMode;
    111     FloatPoint m_kernelUnitLength;
    112     bool m_preserveAlpha;
    113     Vector<float> m_kernelMatrix;
    114 };
    115 
    116 } // namespace WebCore
    117 
    118 #endif // ENABLE(FILTERS)
    119 
    120 #endif // FEConvolveMatrix_h
    121