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 "core/platform/graphics/filters/FilterEffect.h" 27 28 #include "core/platform/graphics/filters/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 PassRefPtr<SkImageFilter> createImageFilter(SkiaImageFilterBuilder*) OVERRIDE; 82 83 virtual TextStream& externalRepresentation(TextStream&, int indention) const; 84 85 private: 86 FEComponentTransfer(Filter*, const ComponentTransferFunction& redFunc, const ComponentTransferFunction& greenFunc, 87 const ComponentTransferFunction& blueFunc, const ComponentTransferFunction& alphaFunc); 88 89 virtual void applySoftware() OVERRIDE; 90 virtual bool applySkia() 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