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 ======================================================= */
64 Layer_Composite::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc_, ProgressCallback *cb) const
66 RendDesc renddesc(renddesc_);
69 return context.accelerated_render(surface,quality,renddesc,cb);
73 SuperCallback stageone(cb,0,50000,100000);
74 SuperCallback stagetwo(cb,50000,100000,100000);
76 Layer_Bitmap::Handle surfacelayer(new class Layer_Bitmap());
80 for(iter=context;*iter;iter++)
81 image.push_back(*iter);
83 image.push_front(surfacelayer.get());
85 // We want to go ahead and schedule any other
87 // while(dynamic_cast<Layer_Composite*>(context->get()))
88 // while(context->get() &&
89 // &context->get()->AcceleratedRender==
90 // &Layer_Composite::AcceleratedRender)
91 // image.push_back(*(context++));
93 image.push_back(0); // Alpha black
95 // Render the backdrop on the surface layer's surface.
96 if(!context.accelerated_render(&surfacelayer->surface,quality,renddesc,&stageone))
98 // Sets up the interpolation of the context (now the surface layer is the first one)
99 // depending on the quality
100 if(quality<=4)surfacelayer->c=3;else
101 if(quality<=5)surfacelayer->c=2;
102 else if(quality<=6)surfacelayer->c=1;
103 else surfacelayer->c=0;
104 surfacelayer->tl=renddesc.get_tl();
105 surfacelayer->br=renddesc.get_br();
106 // Sets the blend method to straight. See below
107 surfacelayer->set_blend_method(Color::BLEND_STRAIGHT);
108 // Push this layer on the image. The blending result is only this layer
109 // adn the surface layer. The rest of the context is ignored by the straight
110 // blend method of surface layer
111 image.push_front(const_cast<synfig::Layer_Composite*>(this));
113 // Set up a surface target
114 Target::Handle target(surface_target(surface));
118 if(cb)cb->error(_("Unable to create surface target"));
122 RendDesc desc(renddesc);
124 target->set_rend_desc(&desc);
127 return render(Context(image.begin()),target,desc,&stagetwo);
128 //return render_threaded(Context(image.begin()),target,desc,&stagetwo,2);
132 Layer_Composite::get_full_bounding_rect(Context context)const
134 if(is_disabled() || Color::is_onto(get_blend_method()))
135 return context.get_full_bounding_rect();
137 return context.get_full_bounding_rect()|get_bounding_rect();
141 Layer_Composite::get_param_vocab()const
143 //! First fills the returning vocabulary with the ancestor class
144 Layer::Vocab ret(Layer::get_param_vocab());
145 //! Now inserts the two parameters that this layer knows.
146 ret.push_back(ParamDesc(amount_,"amount")
147 .set_local_name(_("Amount"))
149 ret.push_back(ParamDesc(blend_method_,"blend_method")
150 .set_local_name(_("Blend Method"))
157 Layer_Composite::set_param(const String & param, const ValueBase &value)
159 if(param=="amount" && value.same_type_as(amount_))
160 amount_=value.get(amount_);
162 if(param=="blend_method" && value.same_type_as(int()))
164 blend_method_ = static_cast<Color::BlendMethod>(value.get(int()));
166 if (blend_method_ < 0 || blend_method_ >= Color::BLEND_END)
168 warning("illegal value (%d) for blend_method - using Composite instead", blend_method_);
169 blend_method_ = Color::BLEND_COMPOSITE;
173 if (blend_method_ == Color::BLEND_STRAIGHT && !reads_context())
175 Canvas::Handle canvas(get_canvas());
178 String version(canvas->get_version());
180 if (version == "0.1" || version == "0.2")
182 if (get_name() == "PasteCanvas")
183 warning("loaded a version %s canvas with a 'Straight' blended PasteCanvas (%s) - check it renders OK",
184 version.c_str(), get_non_empty_description().c_str());
187 blend_method_ = Color::BLEND_COMPOSITE;
188 converted_blend_ = true;
190 // if this layer has a transparent color, go back and set the color again
191 // now that we know we are converting the blend method as well. that will
192 // make the color non-transparent, and change the blend method to alpha over
193 if (transparent_color_)
194 set_param("color", get_param("color"));
201 return Layer::set_param(param,value);
206 Layer_Composite::get_param(const String & param)const
208 //! First check if the parameter's string is known.
211 if(param=="blend_method")
212 return static_cast<int>(get_blend_method());
213 //! If it is unknown then call the ancestor's get param member
214 //! to see if it can handle that parameter's string.
215 return Layer::get_param(param);