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) 2010 Dirk Schulze <krit (at) webkit.org> 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 25 #if ENABLE(SVG) && ENABLE(FILTERS) 26 #include "SVGFEImage.h" 27 28 #include "AffineTransform.h" 29 #include "Filter.h" 30 #include "GraphicsContext.h" 31 #include "RenderTreeAsText.h" 32 #include "SVGPreserveAspectRatio.h" 33 #include "TextStream.h" 34 35 namespace WebCore { 36 37 FEImage::FEImage(Filter* filter, RefPtr<Image> image, const SVGPreserveAspectRatio& preserveAspectRatio) 38 : FilterEffect(filter) 39 , m_image(image) 40 , m_preserveAspectRatio(preserveAspectRatio) 41 { 42 } 43 44 PassRefPtr<FEImage> FEImage::create(Filter* filter, RefPtr<Image> image, const SVGPreserveAspectRatio& preserveAspectRatio) 45 { 46 return adoptRef(new FEImage(filter, image, preserveAspectRatio)); 47 } 48 49 void FEImage::determineAbsolutePaintRect() 50 { 51 ASSERT(m_image); 52 FloatRect srcRect(FloatPoint(), m_image->size()); 53 FloatRect paintRect(m_absoluteSubregion); 54 m_preserveAspectRatio.transformRect(paintRect, srcRect); 55 paintRect.intersect(maxEffectRect()); 56 setAbsolutePaintRect(enclosingIntRect(paintRect)); 57 } 58 59 void FEImage::apply() 60 { 61 if (!m_image.get() || hasResult()) 62 return; 63 64 ImageBuffer* resultImage = createImageBufferResult(); 65 if (!resultImage) 66 return; 67 68 FloatRect srcRect(FloatPoint(), m_image->size()); 69 FloatRect destRect(m_absoluteSubregion); 70 m_preserveAspectRatio.transformRect(destRect, srcRect); 71 72 IntPoint paintLocation = absolutePaintRect().location(); 73 destRect.move(-paintLocation.x(), -paintLocation.y()); 74 75 resultImage->context()->drawImage(m_image.get(), ColorSpaceDeviceRGB, destRect, srcRect); 76 } 77 78 void FEImage::dump() 79 { 80 } 81 82 TextStream& FEImage::externalRepresentation(TextStream& ts, int indent) const 83 { 84 ASSERT(m_image); 85 IntSize imageSize = m_image->size(); 86 writeIndent(ts, indent); 87 ts << "[feImage"; 88 FilterEffect::externalRepresentation(ts); 89 ts << " image-size=\"" << imageSize.width() << "x" << imageSize.height() << "\"]\n"; 90 // FIXME: should this dump also object returned by SVGFEImage::image() ? 91 return ts; 92 } 93 94 } // namespace WebCore 95 96 #endif // ENABLE(SVG) && ENABLE(FILTERS) 97