1 /* === S Y N F I G ========================================================= */
2 /*! \file layer_composite.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "layer_composite.h"
41 #include "layer_bitmap.h"
45 #include "paramdesc.h"
49 /* === U S I N G =========================================================== */
53 using namespace synfig;
55 /* === M A C R O S ========================================================= */
57 /* === G L O B A L S ======================================================= */
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
62 Layer_Composite::Layer_Composite(float a, Color::BlendMethod bm):
65 converted_blend_ (false),
66 transparent_color_ (false)
68 Layer::Vocab voc(get_param_vocab());
69 Layer::fill_static(voc);
73 Layer_Composite::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc_, ProgressCallback *cb) const
75 RendDesc renddesc(renddesc_);
78 return context.accelerated_render(surface,quality,renddesc,cb);
82 SuperCallback stageone(cb,0,50000,100000);
83 SuperCallback stagetwo(cb,50000,100000,100000);
85 Layer_Bitmap::Handle surfacelayer(new class Layer_Bitmap());
89 for(iter=context;*iter;iter++)
90 image.push_back(*iter);
92 image.push_front(surfacelayer.get());
94 // We want to go ahead and schedule any other
96 // while(dynamic_cast<Layer_Composite*>(context->get()))
97 // while(context->get() &&
98 // &context->get()->AcceleratedRender==
99 // &Layer_Composite::AcceleratedRender)
100 // image.push_back(*(context++));
102 image.push_back(0); // Alpha black
104 // Render the backdrop on the surface layer's surface.
105 if(!context.accelerated_render(&surfacelayer->surface,quality,renddesc,&stageone))
107 // Sets up the interpolation of the context (now the surface layer is the first one)
108 // depending on the quality
109 if(quality<=4)surfacelayer->c=3;else
110 if(quality<=5)surfacelayer->c=2;
111 else if(quality<=6)surfacelayer->c=1;
112 else surfacelayer->c=0;
113 surfacelayer->tl=renddesc.get_tl();
114 surfacelayer->br=renddesc.get_br();
115 // Sets the blend method to straight. See below
116 surfacelayer->set_blend_method(Color::BLEND_STRAIGHT);
117 // Push this layer on the image. The blending result is only this layer
118 // adn the surface layer. The rest of the context is ignored by the straight
119 // blend method of surface layer
120 image.push_front(const_cast<synfig::Layer_Composite*>(this));
122 // Set up a surface target
123 Target::Handle target(surface_target(surface));
127 if(cb)cb->error(_("Unable to create surface target"));
131 RendDesc desc(renddesc);
133 target->set_rend_desc(&desc);
136 return render(Context(image.begin()),target,desc,&stagetwo);
137 //return render_threaded(Context(image.begin()),target,desc,&stagetwo,2);
141 Layer_Composite::get_full_bounding_rect(Context context)const
143 if(is_disabled() || Color::is_onto(get_blend_method()))
144 return context.get_full_bounding_rect();
146 return context.get_full_bounding_rect()|get_bounding_rect();
150 Layer_Composite::get_param_vocab()const
152 //! First fills the returning vocabulary with the ancestor class
153 Layer::Vocab ret(Layer::get_param_vocab());
154 //! Now inserts the two parameters that this layer knows.
155 ret.push_back(ParamDesc(amount,"amount")
156 .set_local_name(_("Amount"))
158 ret.push_back(ParamDesc(blend_method,"blend_method")
159 .set_local_name(_("Blend Method"))
166 Layer_Composite::set_param(const String & param, const ValueBase &value)
168 if(param=="amount" && value.same_type_as(amount))
170 amount=value.get(amount);
171 set_param_static(param,value.get_static());
174 if(param=="blend_method" && value.same_type_as(int()))
176 blend_method = static_cast<Color::BlendMethod>(value.get(int()));
177 set_param_static(param,value.get_static());
179 if (blend_method < 0 || blend_method >= Color::BLEND_END)
181 warning("illegal value (%d) for blend_method - using Composite instead", blend_method);
182 blend_method = Color::BLEND_COMPOSITE;
186 if (blend_method == Color::BLEND_STRAIGHT && !reads_context())
188 Canvas::Handle canvas(get_canvas());
191 String version(canvas->get_version());
193 if (version == "0.1" || version == "0.2")
195 if (get_name() == "PasteCanvas")
196 warning("loaded a version %s canvas with a 'Straight' blended PasteCanvas (%s) - check it renders OK",
197 version.c_str(), get_non_empty_description().c_str());
200 blend_method = Color::BLEND_COMPOSITE;
201 converted_blend_ = true;
203 // if this layer has a transparent color, go back and set the color again
204 // now that we know we are converting the blend method as well. that will
205 // make the color non-transparent, and change the blend method to alpha over
206 if (transparent_color_)
207 set_param("color", get_param("color"));
214 return Layer::set_param(param,value);
219 Layer_Composite::get_param(const String & param)const
222 //! First check if the parameter's string is known.
225 synfig::ValueBase ret(get_amount());
226 ret.set_static(get_param_static(param));
229 if(param=="blend_method")
231 synfig::ValueBase ret(static_cast<int>(get_blend_method()));
232 ret.set_static(get_param_static(param));
235 //! If it is unknown then call the ancestor's get param member
236 //! to see if it can handle that parameter's string.
237 return Layer::get_param(param);