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  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  */
     21 
     22 #ifndef FEComponentTransfer_h
     23 #define FEComponentTransfer_h
     24 
     25 #if ENABLE(FILTERS)
     26 #include "FilterEffect.h"
     27 
     28 #include "Filter.h"
     29 #include <wtf/Vector.h>
     30 
     31 namespace WebCore {
     32 
     33 enum ComponentTransferType {
     34     FECOMPONENTTRANSFER_TYPE_UNKNOWN  = 0,
     35     FECOMPONENTTRANSFER_TYPE_IDENTITY = 1,
     36     FECOMPONENTTRANSFER_TYPE_TABLE    = 2,
     37     FECOMPONENTTRANSFER_TYPE_DISCRETE = 3,
     38     FECOMPONENTTRANSFER_TYPE_LINEAR   = 4,
     39     FECOMPONENTTRANSFER_TYPE_GAMMA    = 5
     40 };
     41 
     42 struct ComponentTransferFunction {
     43     ComponentTransferFunction()
     44         : type(FECOMPONENTTRANSFER_TYPE_UNKNOWN)
     45         , slope(0)
     46         , intercept(0)
     47         , amplitude(0)
     48         , exponent(0)
     49         , offset(0)
     50     {
     51     }
     52 
     53     ComponentTransferType type;
     54 
     55     float slope;
     56     float intercept;
     57     float amplitude;
     58     float exponent;
     59     float offset;
     60 
     61     Vector<float> tableValues;
     62 };
     63 
     64 class FEComponentTransfer : public FilterEffect {
     65 public:
     66     static PassRefPtr<FEComponentTransfer> create(Filter*, const ComponentTransferFunction& redFunc, const ComponentTransferFunction& greenFunc,
     67                                                   const ComponentTransferFunction& blueFunc, const ComponentTransferFunction& alphaFunc);
     68 
     69     ComponentTransferFunction redFunction() const;
     70     void setRedFunction(const ComponentTransferFunction&);
     71 
     72     ComponentTransferFunction greenFunction() const;
     73     void setGreenFunction(const ComponentTransferFunction&);
     74 
     75     ComponentTransferFunction blueFunction() const;
     76     void setBlueFunction(const ComponentTransferFunction&);
     77 
     78     ComponentTransferFunction alphaFunction() const;
     79     void setAlphaFunction(const ComponentTransferFunction&);
     80 
     81     virtual void apply();
     82     virtual void dump();
     83 
     84     virtual TextStream& externalRepresentation(TextStream&, int indention) const;
     85 
     86 private:
     87     FEComponentTransfer(Filter*, const ComponentTransferFunction& redFunc, const ComponentTransferFunction& greenFunc,
     88                         const ComponentTransferFunction& blueFunc, const ComponentTransferFunction& alphaFunc);
     89 
     90     ComponentTransferFunction m_redFunc;
     91     ComponentTransferFunction m_greenFunc;
     92     ComponentTransferFunction m_blueFunc;
     93     ComponentTransferFunction m_alphaFunc;
     94 };
     95 
     96 } // namespace WebCore
     97 
     98 #endif // ENABLE(FILTERS)
     99 
    100 #endif // FEComponentTransfer_h
    101