Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc3 / src / modules / mod_filter / lumakey.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file lumakey.cpp
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
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.
15 **
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.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "lumakey.h"
34
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>
44
45 #endif
46
47 using namespace synfig;
48 using namespace std;
49 using namespace etl;
50
51 /* === M A C R O S ========================================================= */
52
53 /* === G L O B A L S ======================================================= */
54
55 SYNFIG_LAYER_INIT(LumaKey);
56 SYNFIG_LAYER_SET_NAME(LumaKey,"lumakey");
57 SYNFIG_LAYER_SET_LOCAL_NAME(LumaKey,_("Luma Key"));
58 SYNFIG_LAYER_SET_CATEGORY(LumaKey,_("Filters"));
59 SYNFIG_LAYER_SET_VERSION(LumaKey,"0.1");
60 SYNFIG_LAYER_SET_CVS_ID(LumaKey,"$Id$");
61
62 /* === P R O C E D U R E S ================================================= */
63
64 /* === M E T H O D S ======================================================= */
65
66 LumaKey::LumaKey():
67         Layer_Composite (1.0,Color::BLEND_STRAIGHT)
68 {
69         set_blend_method(Color::BLEND_STRAIGHT);
70 }
71
72
73 bool
74 LumaKey::set_param(const String &param, const ValueBase &value)
75 {
76         return Layer_Composite::set_param(param,value);
77 }
78
79 ValueBase
80 LumaKey::get_param(const String &param)const
81 {
82         EXPORT_NAME();
83         EXPORT_VERSION();
84
85         return Layer_Composite::get_param(param);
86 }
87
88 Layer::Vocab
89 LumaKey::get_param_vocab()const
90 {
91         Layer::Vocab ret(Layer_Composite::get_param_vocab());
92
93 /*      ret.push_back(ParamDesc("color")
94                 .set_local_name(_("Color"))
95                 .set_description(_("Color of checkers"))
96         );
97         ret.push_back(ParamDesc("pos")
98                 .set_local_name(_("Offset"))
99         );
100         ret.push_back(ParamDesc("size")
101                 .set_local_name(_("Size"))
102                 .set_description(_("Size of checkers"))
103                 .set_origin("pos")
104         );
105 */
106         return ret;
107 }
108
109 synfig::Layer::Handle
110 LumaKey::hit_check(synfig::Context context, const synfig::Point &getpos)const
111 {
112         return context.hit_check(getpos);
113 }
114
115 Color
116 LumaKey::get_color(Context context, const Point &getpos)const
117 {
118         const Color color(context.get_color(getpos));
119
120         if(get_amount()==0.0)
121                 return color;
122
123         Color ret(color);
124         ret.set_a(ret.get_y()*ret.get_a());
125         ret.set_y(1);
126
127         if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
128                 return ret;
129
130         return Color::blend(ret,color,get_amount(),get_blend_method());
131 }
132
133 bool
134 LumaKey::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
135 {
136         SuperCallback supercb(cb,0,9500,10000);
137
138         if(!context.accelerated_render(surface,quality,renddesc,&supercb))
139                 return false;
140
141         int x,y;
142
143         Surface::pen pen(surface->begin());
144
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())
147                 {
148                         Color tmp(pen.get_value());
149                         tmp.set_a(tmp.get_y()*tmp.get_a());
150                         tmp.set_y(1);
151                         pen.put_value(tmp);
152                 }
153
154         // Mark our progress as finished
155         if(cb && !cb->amount_complete(10000,10000))
156                 return false;
157
158         return true;
159 }
160
161 Rect
162 LumaKey::get_bounding_rect(Context context)const
163 {
164         if(is_disabled())
165                 return Rect::zero();
166
167         return context.get_full_bounding_rect();
168 }