1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include "config.h"
23
24 #if ENABLE(FILTERS)
25 #include "FEMerge.h"
26
27 #include "Filter.h"
28 #include "GraphicsContext.h"
29 #include "RenderTreeAsText.h"
30 #include "TextStream.h"
31
32 namespace WebCore {
33
FEMerge(Filter * filter)34 FEMerge::FEMerge(Filter* filter)
35 : FilterEffect(filter)
36 {
37 }
38
create(Filter * filter)39 PassRefPtr<FEMerge> FEMerge::create(Filter* filter)
40 {
41 return adoptRef(new FEMerge(filter));
42 }
43
apply()44 void FEMerge::apply()
45 {
46 if (hasResult())
47 return;
48 unsigned size = numberOfEffectInputs();
49 ASSERT(size > 0);
50 for (unsigned i = 0; i < size; ++i) {
51 FilterEffect* in = inputEffect(i);
52 in->apply();
53 if (!in->hasResult())
54 return;
55 }
56
57 ImageBuffer* resultImage = createImageBufferResult();
58 if (!resultImage)
59 return;
60
61 GraphicsContext* filterContext = resultImage->context();
62 for (unsigned i = 0; i < size; ++i) {
63 FilterEffect* in = inputEffect(i);
64 filterContext->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()));
65 }
66 }
67
dump()68 void FEMerge::dump()
69 {
70 }
71
externalRepresentation(TextStream & ts,int indent) const72 TextStream& FEMerge::externalRepresentation(TextStream& ts, int indent) const
73 {
74 writeIndent(ts, indent);
75 ts << "[feMerge";
76 FilterEffect::externalRepresentation(ts);
77 unsigned size = numberOfEffectInputs();
78 ASSERT(size > 0);
79 ts << " mergeNodes=\"" << size << "\"]\n";
80 for (unsigned i = 0; i < size; ++i)
81 inputEffect(i)->externalRepresentation(ts, indent + 1);
82 return ts;
83 }
84
85 } // namespace WebCore
86
87 #endif // ENABLE(FILTERS)
88