1 /*
2 Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
4 2005 Eric Seidel <eric@webkit.org>
5 2010 Dirk Schulze <krit@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 aint 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 "SVGPreserveAspectRatio.h"
32 #include "SVGRenderTreeAsText.h"
33
34 namespace WebCore {
35
FEImage(RefPtr<Image> image,SVGPreserveAspectRatio preserveAspectRatio)36 FEImage::FEImage(RefPtr<Image> image, SVGPreserveAspectRatio preserveAspectRatio)
37 : FilterEffect()
38 , m_image(image)
39 , m_preserveAspectRatio(preserveAspectRatio)
40 {
41 }
42
create(RefPtr<Image> image,SVGPreserveAspectRatio preserveAspectRatio)43 PassRefPtr<FEImage> FEImage::create(RefPtr<Image> image, SVGPreserveAspectRatio preserveAspectRatio)
44 {
45 return adoptRef(new FEImage(image, preserveAspectRatio));
46 }
47
apply(Filter *)48 void FEImage::apply(Filter*)
49 {
50 if (!m_image.get())
51 return;
52
53 GraphicsContext* filterContext = getEffectContext();
54 if (!filterContext)
55 return;
56
57 FloatRect srcRect(FloatPoint(), m_image->size());
58 FloatRect destRect(FloatPoint(), subRegion().size());
59
60 m_preserveAspectRatio.transformRect(destRect, srcRect);
61
62 filterContext->drawImage(m_image.get(), DeviceColorSpace, destRect, srcRect);
63 }
64
dump()65 void FEImage::dump()
66 {
67 }
68
externalRepresentation(TextStream & ts) const69 TextStream& FEImage::externalRepresentation(TextStream& ts) const
70 {
71 ts << "[type=IMAGE] ";
72 FilterEffect::externalRepresentation(ts);
73 // FIXME: should this dump also object returned by SVGFEImage::image() ?
74 return ts;
75 }
76
77 } // namespace WebCore
78
79 #endif // ENABLE(SVG) && ENABLE(FILTERS)
80