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
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "layer_composite.h"
40 #include "layer_bitmap.h"
44 #include "paramdesc.h"
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
54 /* === M A C R O S ========================================================= */
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
63 Layer_Composite::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc_, ProgressCallback *cb) const
65 RendDesc renddesc(renddesc_);
68 return context.accelerated_render(surface,quality,renddesc,cb);
72 SuperCallback stageone(cb,0,50000,100000);
73 SuperCallback stagetwo(cb,50000,100000,100000);
75 Layer_Bitmap::Handle surfacelayer(new class Layer_Bitmap());
79 for(iter=context;*iter;iter++)
80 image.push_back(*iter);
82 image.push_front(surfacelayer.get());
84 // We want to go ahead and schedule any other
86 // while(dynamic_cast<Layer_Composite*>(context->get()))
87 // while(context->get() &&
88 // &context->get()->AcceleratedRender==
89 // &Layer_Composite::AcceleratedRender)
90 // image.push_back(*(context++));
92 image.push_back(0); // Alpha black
94 // Render the backdrop
95 if(!context.accelerated_render(&surfacelayer->surface,quality,renddesc,&stageone))
98 if(quality<=4)surfacelayer->c=3;else
99 if(quality<=5)surfacelayer->c=2;
100 else if(quality<=6)surfacelayer->c=1;
101 else surfacelayer->c=0;
102 surfacelayer->tl=renddesc.get_tl();
103 surfacelayer->br=renddesc.get_br();
104 surfacelayer->set_blend_method(Color::BLEND_STRAIGHT);
106 image.push_front(const_cast<synfig::Layer_Composite*>(this));
108 // Set up a surface target
109 Target::Handle target(surface_target(surface));
113 if(cb)cb->error(_("Unable to create surface target"));
117 RendDesc desc(renddesc);
119 target->set_rend_desc(&desc);
122 return render(Context(image.begin()),target,desc,&stagetwo);
123 //return render_threaded(Context(image.begin()),target,desc,&stagetwo,2);
127 Layer_Composite::get_full_bounding_rect(Context context)const
129 if(is_disabled() || Color::is_onto(get_blend_method()))
130 return context.get_full_bounding_rect();
132 return context.get_full_bounding_rect()|get_bounding_rect();
136 Layer_Composite::get_param_vocab()const
138 Layer::Vocab ret(Layer::get_param_vocab());
140 ret.push_back(ParamDesc(amount_,"amount")
141 .set_local_name(_("Amount"))
143 ret.push_back(ParamDesc(blend_method_,"blend_method")
144 .set_local_name(_("Blend Method"))
151 Layer_Composite::set_param(const String & param, const ValueBase &value)
153 if(param=="amount" && value.same_type_as(amount_))
154 amount_=value.get(amount_);
156 if(param=="blend_method" && value.same_type_as(int()))
158 blend_method_ = static_cast<Color::BlendMethod>(value.get(int()));
160 if (blend_method_ < 0 || blend_method_ >= Color::BLEND_END)
162 warning("illegal value (%d) for blend_method - using Composite instead", blend_method_);
163 blend_method_ = Color::BLEND_COMPOSITE;
167 if (blend_method_ == Color::BLEND_STRAIGHT && !reads_context())
169 Canvas::Handle canvas(get_canvas());
172 String version(canvas->get_version());
174 if (version == "0.1" || version == "0.2")
176 if (get_name() == "PasteCanvas")
177 warning("loaded a version %s canvas with a 'Straight' blended PasteCanvas (%s) - check it renders OK",
178 version.c_str(), get_non_empty_description().c_str());
181 blend_method_ = Color::BLEND_COMPOSITE;
182 converted_blend_ = true;
184 // if this layer has a transparent color, go back and set the color again
185 // now that we know we are converting the blend method as well. that will
186 // make the color non-transparent, and change the blend method to alpha over
187 if (transparent_color_)
188 set_param("color", get_param("color"));
195 return Layer::set_param(param,value);
200 Layer_Composite::get_param(const String & param)const
204 if(param=="blend_method")
205 return static_cast<int>(get_blend_method());
206 return Layer::get_param(param);