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) 2009 Dirk Schulze <krit (at) webkit.org>
      6  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
      7  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  */
     23 
     24 #include "config.h"
     25 
     26 #if ENABLE(FILTERS)
     27 #include "FEOffset.h"
     28 
     29 #include "Filter.h"
     30 #include "GraphicsContext.h"
     31 #include "RenderTreeAsText.h"
     32 #include "TextStream.h"
     33 
     34 namespace WebCore {
     35 
     36 FEOffset::FEOffset(Filter* filter, float dx, float dy)
     37     : FilterEffect(filter)
     38     , m_dx(dx)
     39     , m_dy(dy)
     40 {
     41 }
     42 
     43 PassRefPtr<FEOffset> FEOffset::create(Filter* filter, float dx, float dy)
     44 {
     45     return adoptRef(new FEOffset(filter, dx, dy));
     46 }
     47 
     48 float FEOffset::dx() const
     49 {
     50     return m_dx;
     51 }
     52 
     53 void FEOffset::setDx(float dx)
     54 {
     55     m_dx = dx;
     56 }
     57 
     58 float FEOffset::dy() const
     59 {
     60     return m_dy;
     61 }
     62 
     63 void FEOffset::setDy(float dy)
     64 {
     65     m_dy = dy;
     66 }
     67 
     68 void FEOffset::determineAbsolutePaintRect()
     69 {
     70     FloatRect paintRect = inputEffect(0)->absolutePaintRect();
     71     Filter* filter = this->filter();
     72     paintRect.move(filter->applyHorizontalScale(m_dx), filter->applyVerticalScale(m_dy));
     73     paintRect.intersect(maxEffectRect());
     74     setAbsolutePaintRect(enclosingIntRect(paintRect));
     75 }
     76 
     77 void FEOffset::apply()
     78 {
     79     if (hasResult())
     80         return;
     81     FilterEffect* in = inputEffect(0);
     82     in->apply();
     83     if (!in->hasResult())
     84         return;
     85 
     86     ImageBuffer* resultImage = createImageBufferResult();
     87     if (!resultImage)
     88         return;
     89 
     90     setIsAlphaImage(in->isAlphaImage());
     91 
     92     FloatRect drawingRegion = drawingRegionOfInputImage(in->absolutePaintRect());
     93     Filter* filter = this->filter();
     94     drawingRegion.move(filter->applyHorizontalScale(m_dx), filter->applyVerticalScale(m_dy));
     95     resultImage->context()->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegion);
     96 }
     97 
     98 void FEOffset::dump()
     99 {
    100 }
    101 
    102 TextStream& FEOffset::externalRepresentation(TextStream& ts, int indent) const
    103 {
    104     writeIndent(ts, indent);
    105     ts << "[feOffset";
    106     FilterEffect::externalRepresentation(ts);
    107     ts << " dx=\"" << dx() << "\" dy=\"" << dy() << "\"]\n";
    108     inputEffect(0)->externalRepresentation(ts, indent + 1);
    109     return ts;
    110 }
    111 
    112 } // namespace WebCore
    113 
    114 #endif // ENABLE(FILTERS)
    115