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) 2013 Google Inc. All rights reserved.
      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 FEMorphology_h
     24 #define FEMorphology_h
     25 
     26 #include "platform/graphics/filters/Filter.h"
     27 #include "platform/graphics/filters/FilterEffect.h"
     28 
     29 namespace WebCore {
     30 
     31 enum MorphologyOperatorType {
     32     FEMORPHOLOGY_OPERATOR_UNKNOWN = 0,
     33     FEMORPHOLOGY_OPERATOR_ERODE = 1,
     34     FEMORPHOLOGY_OPERATOR_DILATE = 2
     35 };
     36 
     37 class PLATFORM_EXPORT FEMorphology : public FilterEffect {
     38 public:
     39     static PassRefPtr<FEMorphology> create(Filter*, MorphologyOperatorType, float radiusX, float radiusY);
     40     MorphologyOperatorType morphologyOperator() const;
     41     bool setMorphologyOperator(MorphologyOperatorType);
     42 
     43     float radiusX() const;
     44     bool setRadiusX(float);
     45 
     46     float radiusY() const;
     47     bool setRadiusY(float);
     48 
     49     virtual PassRefPtr<SkImageFilter> createImageFilter(SkiaImageFilterBuilder*) OVERRIDE;
     50 
     51     virtual FloatRect mapRect(const FloatRect&, bool forward = true) OVERRIDE FINAL;
     52 
     53     virtual TextStream& externalRepresentation(TextStream&, int indention) const OVERRIDE;
     54 
     55     struct PaintingData {
     56         Uint8ClampedArray* srcPixelArray;
     57         Uint8ClampedArray* dstPixelArray;
     58         int width;
     59         int height;
     60         int radiusX;
     61         int radiusY;
     62     };
     63 
     64     static const int s_minimalArea = (300 * 300); // Empirical data limit for parallel jobs
     65 
     66     struct PlatformApplyParameters {
     67         FEMorphology* filter;
     68         int startY;
     69         int endY;
     70         PaintingData* paintingData;
     71     };
     72 
     73 private:
     74     FEMorphology(Filter*, MorphologyOperatorType, float radiusX, float radiusY);
     75 
     76     virtual void applySoftware() OVERRIDE;
     77 
     78     MorphologyOperatorType m_type;
     79     float m_radiusX;
     80     float m_radiusY;
     81 };
     82 
     83 } // namespace WebCore
     84 
     85 #endif // FEMorphology_h
     86