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