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 FEComponentTransfer_h
     24 #define FEComponentTransfer_h
     25 
     26 #include "platform/graphics/filters/Filter.h"
     27 #include "platform/graphics/filters/FilterEffect.h"
     28 #include "wtf/Vector.h"
     29 
     30 namespace WebCore {
     31 
     32 enum ComponentTransferType {
     33     FECOMPONENTTRANSFER_TYPE_UNKNOWN  = 0,
     34     FECOMPONENTTRANSFER_TYPE_IDENTITY = 1,
     35     FECOMPONENTTRANSFER_TYPE_TABLE    = 2,
     36     FECOMPONENTTRANSFER_TYPE_DISCRETE = 3,
     37     FECOMPONENTTRANSFER_TYPE_LINEAR   = 4,
     38     FECOMPONENTTRANSFER_TYPE_GAMMA    = 5
     39 };
     40 
     41 struct ComponentTransferFunction {
     42     ComponentTransferFunction()
     43         : type(FECOMPONENTTRANSFER_TYPE_UNKNOWN)
     44         , slope(0)
     45         , intercept(0)
     46         , amplitude(0)
     47         , exponent(0)
     48         , offset(0)
     49     {
     50     }
     51 
     52     ComponentTransferType type;
     53 
     54     float slope;
     55     float intercept;
     56     float amplitude;
     57     float exponent;
     58     float offset;
     59 
     60     Vector<float> tableValues;
     61 };
     62 
     63 class PLATFORM_EXPORT FEComponentTransfer : public FilterEffect {
     64 public:
     65     static PassRefPtr<FEComponentTransfer> create(Filter*, const ComponentTransferFunction& redFunc, const ComponentTransferFunction& greenFunc,
     66         const ComponentTransferFunction& blueFunc, const ComponentTransferFunction& alphaFunc);
     67 
     68     ComponentTransferFunction redFunction() const;
     69     void setRedFunction(const ComponentTransferFunction&);
     70 
     71     ComponentTransferFunction greenFunction() const;
     72     void setGreenFunction(const ComponentTransferFunction&);
     73 
     74     ComponentTransferFunction blueFunction() const;
     75     void setBlueFunction(const ComponentTransferFunction&);
     76 
     77     ComponentTransferFunction alphaFunction() const;
     78     void setAlphaFunction(const ComponentTransferFunction&);
     79 
     80     virtual PassRefPtr<SkImageFilter> createImageFilter(SkiaImageFilterBuilder*) OVERRIDE;
     81 
     82     virtual TextStream& externalRepresentation(TextStream&, int indention) const OVERRIDE;
     83 
     84 private:
     85     FEComponentTransfer(Filter*, const ComponentTransferFunction& redFunc, const ComponentTransferFunction& greenFunc,
     86         const ComponentTransferFunction& blueFunc, const ComponentTransferFunction& alphaFunc);
     87 
     88     virtual void applySoftware() OVERRIDE;
     89 
     90     virtual bool affectsTransparentPixels() OVERRIDE;
     91 
     92     void getValues(unsigned char rValues[256], unsigned char gValues[256], unsigned char bValues[256], unsigned char aValues[256]);
     93 
     94     ComponentTransferFunction m_redFunc;
     95     ComponentTransferFunction m_greenFunc;
     96     ComponentTransferFunction m_blueFunc;
     97     ComponentTransferFunction m_alphaFunc;
     98 };
     99 
    100 } // namespace WebCore
    101 
    102 #endif // FEComponentTransfer_h
    103