Set the description of some parameters
[synfig.git] / synfig-core / src / modules / lyr_std / clamp.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file clamp.cpp
3 **      \brief Implementation of the "Clamp" layer
4 **
5 **      $Id$
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 "clamp.h"
33 #include <synfig/string.h>
34 #include <synfig/time.h>
35 #include <synfig/context.h>
36 #include <synfig/paramdesc.h>
37 #include <synfig/renddesc.h>
38 #include <synfig/surface.h>
39 #include <synfig/value.h>
40 #include <synfig/valuenode.h>
41
42 #endif
43
44 /* === U S I N G =========================================================== */
45
46 using namespace etl;
47 using namespace std;
48 using namespace synfig;
49
50 /* === G L O B A L S ======================================================= */
51
52 SYNFIG_LAYER_INIT(Layer_Clamp);
53 SYNFIG_LAYER_SET_NAME(Layer_Clamp,"clamp");
54 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Clamp,N_("Clamp"));
55 SYNFIG_LAYER_SET_CATEGORY(Layer_Clamp,N_("Filters"));
56 SYNFIG_LAYER_SET_VERSION(Layer_Clamp,"0.2");
57 SYNFIG_LAYER_SET_CVS_ID(Layer_Clamp,"$Id$");
58
59 /* === P R O C E D U R E S ================================================= */
60
61 /* === M E T H O D S ======================================================= */
62
63 /* === E N T R Y P O I N T ================================================= */
64
65 Layer_Clamp::Layer_Clamp():
66         invert_negative(false),
67         clamp_ceiling(true),
68         ceiling(1.0f),
69         floor(0.0f)
70 {
71         Layer::Vocab voc(get_param_vocab());
72         Layer::fill_static(voc);
73 }
74
75 inline Color
76 Layer_Clamp::clamp_color(const Color &in)const
77 {
78         Color ret(in);
79
80         if(ret.get_a()==0)
81                 return Color::alpha();
82
83         if(invert_negative)
84         {
85                 if(ret.get_a()<floor)
86                         ret=-ret;
87
88                 if(ret.get_r()<floor)
89                 {
90                         ret.set_g(ret.get_g()-ret.get_r());
91                         ret.set_b(ret.get_b()-ret.get_r());
92                         ret.set_r(floor);
93                 }
94                 if(ret.get_g()<floor)
95                 {
96                         ret.set_r(ret.get_r()-ret.get_g());
97                         ret.set_b(ret.get_b()-ret.get_g());
98                         ret.set_g(floor);
99                 }
100                 if(ret.get_b()<floor)
101                 {
102                         ret.set_g(ret.get_g()-ret.get_b());
103                         ret.set_r(ret.get_r()-ret.get_b());
104                         ret.set_b(floor);
105                 }
106         }
107         else
108         {
109                 if(ret.get_r()<floor) ret.set_r(floor);
110                 if(ret.get_g()<floor) ret.set_g(floor);
111                 if(ret.get_b()<floor) ret.set_b(floor);
112                 if(ret.get_a()<floor) ret.set_a(floor);
113         }
114
115         if(clamp_ceiling)
116         {
117                 if(ret.get_r()>ceiling) ret.set_r(ceiling);
118                 if(ret.get_g()>ceiling) ret.set_g(ceiling);
119                 if(ret.get_b()>ceiling) ret.set_b(ceiling);
120                 if(ret.get_a()>ceiling) ret.set_a(ceiling);
121         }
122         return ret;
123 }
124
125 bool
126 Layer_Clamp::set_param(const String & param, const ValueBase &value)
127 {
128         IMPORT(invert_negative);
129         IMPORT(clamp_ceiling);
130         IMPORT(ceiling);
131         IMPORT(floor);
132
133         return false;
134 }
135
136 ValueBase
137 Layer_Clamp::get_param(const String &param)const
138 {
139         EXPORT(invert_negative);
140         EXPORT(clamp_ceiling);
141
142         EXPORT(ceiling);
143         EXPORT(floor);
144
145         EXPORT_NAME();
146         EXPORT_VERSION();
147
148         return ValueBase();
149 }
150
151 Layer::Vocab
152 Layer_Clamp::get_param_vocab()const
153 {
154         Layer::Vocab ret;
155
156         ret.push_back(ParamDesc("invert_negative")
157                 .set_local_name(_("Invert Negative"))
158         );
159
160         ret.push_back(ParamDesc("clamp_ceiling")
161                 .set_local_name(_("Clamp Ceiling"))
162                 .set_description(_("When checked the Ceiling value is used"))
163         );
164
165         ret.push_back(ParamDesc("ceiling")
166                 .set_local_name(_("Ceiling"))
167                 .set_description(_("Upper boundary of the clamping"))
168         );
169
170         ret.push_back(ParamDesc("floor")
171                 .set_local_name(_("Floor"))
172                 .set_description(_("Lower boundary of the clamping"))
173         );
174
175         return ret;
176 }
177
178 Color
179 Layer_Clamp::get_color(Context context, const Point &pos)const
180 {
181         return clamp_color(context.get_color(pos));
182 }
183
184 bool
185 Layer_Clamp::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
186 {
187         SuperCallback supercb(cb,0,9500,10000);
188
189         if(!context.accelerated_render(surface,quality,renddesc,&supercb))
190                 return false;
191
192         int x,y;
193
194         Surface::pen pen(surface->begin());
195
196         for(y=0;y<renddesc.get_h();y++,pen.inc_y(),pen.dec_x(x))
197                 for(x=0;x<renddesc.get_w();x++,pen.inc_x())
198                         pen.put_value(clamp_color(pen.get_value()));
199
200         // Mark our progress as finished
201         if(cb && !cb->amount_complete(10000,10000))
202                 return false;
203
204         return true;
205 }
206
207
208 Rect
209 Layer_Clamp::get_full_bounding_rect(Context context)const
210 {
211         return context.get_full_bounding_rect();
212 }