1 /* === S Y N F I G ========================================================= */
3 ** \brief Implementation of the "Luma Key" layer
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 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 ======================================================= */
35 #include <synfig/string.h>
36 #include <synfig/time.h>
37 #include <synfig/context.h>
38 #include <synfig/paramdesc.h>
39 #include <synfig/renddesc.h>
40 #include <synfig/surface.h>
41 #include <synfig/value.h>
42 #include <synfig/valuenode.h>
43 #include <synfig/segment.h>
47 using namespace synfig;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 SYNFIG_LAYER_INIT(LumaKey);
56 SYNFIG_LAYER_SET_NAME(LumaKey,"lumakey");
57 SYNFIG_LAYER_SET_LOCAL_NAME(LumaKey,N_("Luma Key"));
58 SYNFIG_LAYER_SET_CATEGORY(LumaKey,N_("Filters"));
59 SYNFIG_LAYER_SET_VERSION(LumaKey,"0.1");
60 SYNFIG_LAYER_SET_CVS_ID(LumaKey,"$Id$");
62 /* === P R O C E D U R E S ================================================= */
64 /* === M E T H O D S ======================================================= */
67 Layer_Composite (1.0,Color::BLEND_STRAIGHT)
69 set_blend_method(Color::BLEND_STRAIGHT);
74 LumaKey::set_param(const String ¶m, const ValueBase &value)
76 return Layer_Composite::set_param(param,value);
80 LumaKey::get_param(const String ¶m)const
85 return Layer_Composite::get_param(param);
89 LumaKey::get_param_vocab()const
91 Layer::Vocab ret(Layer_Composite::get_param_vocab());
93 /* ret.push_back(ParamDesc("color")
94 .set_local_name(_("Color"))
95 .set_description(_("Color of checkers"))
97 ret.push_back(ParamDesc("pos")
98 .set_local_name(_("Offset"))
100 ret.push_back(ParamDesc("size")
101 .set_local_name(_("Size"))
102 .set_description(_("Size of checkers"))
109 synfig::Layer::Handle
110 LumaKey::hit_check(synfig::Context context, const synfig::Point &getpos)const
112 return context.hit_check(getpos);
116 LumaKey::get_color(Context context, const Point &getpos)const
118 const Color color(context.get_color(getpos));
120 if(get_amount()==0.0)
124 ret.set_a(ret.get_y()*ret.get_a());
127 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
130 return Color::blend(ret,color,get_amount(),get_blend_method());
134 LumaKey::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
136 SuperCallback supercb(cb,0,9500,10000);
138 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
143 Surface::pen pen(surface->begin());
145 for(y=0;y<renddesc.get_h();y++,pen.inc_y(),pen.dec_x(x))
146 for(x=0;x<renddesc.get_w();x++,pen.inc_x())
148 Color tmp(pen.get_value());
149 tmp.set_a(tmp.get_y()*tmp.get_a());
154 // Mark our progress as finished
155 if(cb && !cb->amount_complete(10000,10000))
162 LumaKey::get_bounding_rect(Context context)const
167 return context.get_full_bounding_rect();