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