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 #include "config.h"
     24 #include "platform/graphics/filters/FEDiffuseLighting.h"
     25 
     26 #include "platform/graphics/filters/LightSource.h"
     27 #include "platform/text/TextStream.h"
     28 
     29 namespace blink {
     30 
     31 FEDiffuseLighting::FEDiffuseLighting(Filter* filter, const Color& lightingColor, float surfaceScale,
     32     float diffuseConstant, float kernelUnitLengthX, float kernelUnitLengthY, PassRefPtr<LightSource> lightSource)
     33     : FELighting(filter, DiffuseLighting, lightingColor, surfaceScale, diffuseConstant, 0, 0, kernelUnitLengthX, kernelUnitLengthY, lightSource)
     34 {
     35 }
     36 
     37 PassRefPtr<FEDiffuseLighting> FEDiffuseLighting::create(Filter* filter, const Color& lightingColor,
     38     float surfaceScale, float diffuseConstant, float kernelUnitLengthX,
     39     float kernelUnitLengthY, PassRefPtr<LightSource> lightSource)
     40 {
     41     return adoptRef(new FEDiffuseLighting(filter, lightingColor, surfaceScale, diffuseConstant, kernelUnitLengthX, kernelUnitLengthY, lightSource));
     42 }
     43 
     44 FEDiffuseLighting::~FEDiffuseLighting()
     45 {
     46 }
     47 
     48 Color FEDiffuseLighting::lightingColor() const
     49 {
     50     return m_lightingColor;
     51 }
     52 
     53 bool FEDiffuseLighting::setLightingColor(const Color& lightingColor)
     54 {
     55     if (m_lightingColor == lightingColor)
     56         return false;
     57     m_lightingColor = lightingColor;
     58     return true;
     59 }
     60 
     61 float FEDiffuseLighting::surfaceScale() const
     62 {
     63     return m_surfaceScale;
     64 }
     65 
     66 bool FEDiffuseLighting::setSurfaceScale(float surfaceScale)
     67 {
     68     if (m_surfaceScale == surfaceScale)
     69         return false;
     70     m_surfaceScale = surfaceScale;
     71     return true;
     72 }
     73 
     74 float FEDiffuseLighting::diffuseConstant() const
     75 {
     76     return m_diffuseConstant;
     77 }
     78 
     79 bool FEDiffuseLighting::setDiffuseConstant(float diffuseConstant)
     80 {
     81     diffuseConstant = std::max(diffuseConstant, 0.0f);
     82     if (m_diffuseConstant == diffuseConstant)
     83         return false;
     84     m_diffuseConstant = diffuseConstant;
     85     return true;
     86 }
     87 
     88 float FEDiffuseLighting::kernelUnitLengthX() const
     89 {
     90     return m_kernelUnitLengthX;
     91 }
     92 
     93 bool FEDiffuseLighting::setKernelUnitLengthX(float kernelUnitLengthX)
     94 {
     95     if (m_kernelUnitLengthX == kernelUnitLengthX)
     96         return false;
     97     m_kernelUnitLengthX = kernelUnitLengthX;
     98     return true;
     99 }
    100 
    101 float FEDiffuseLighting::kernelUnitLengthY() const
    102 {
    103     return m_kernelUnitLengthY;
    104 }
    105 
    106 bool FEDiffuseLighting::setKernelUnitLengthY(float kernelUnitLengthY)
    107 {
    108     if (m_kernelUnitLengthY == kernelUnitLengthY)
    109         return false;
    110     m_kernelUnitLengthY = kernelUnitLengthY;
    111     return true;
    112 }
    113 
    114 const LightSource* FEDiffuseLighting::lightSource() const
    115 {
    116     return m_lightSource.get();
    117 }
    118 
    119 void FEDiffuseLighting::setLightSource(PassRefPtr<LightSource> lightSource)
    120 {
    121     m_lightSource = lightSource;
    122 }
    123 
    124 TextStream& FEDiffuseLighting::externalRepresentation(TextStream& ts, int indent) const
    125 {
    126     writeIndent(ts, indent);
    127     ts << "[feDiffuseLighting";
    128     FilterEffect::externalRepresentation(ts);
    129     ts << " surfaceScale=\"" << m_surfaceScale << "\" "
    130        << "diffuseConstant=\"" << m_diffuseConstant << "\" "
    131        << "kernelUnitLength=\"" << m_kernelUnitLengthX << ", " << m_kernelUnitLengthY << "\"]\n";
    132     inputEffect(0)->externalRepresentation(ts, indent + 1);
    133     return ts;
    134 }
    135 
    136 } // namespace blink
    137