1 /* === S Y N F I G ========================================================= */
2 /*! \file halftone2.cpp
3 ** \brief Implementation of the "Halftone 2" layer
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007-2008 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 ======================================================= */
33 #include "halftone2.h"
36 #include <synfig/string.h>
37 #include <synfig/time.h>
38 #include <synfig/context.h>
39 #include <synfig/paramdesc.h>
40 #include <synfig/renddesc.h>
41 #include <synfig/surface.h>
42 #include <synfig/value.h>
43 #include <synfig/valuenode.h>
47 /* === M A C R O S ========================================================= */
49 using namespace synfig;
53 /* === G L O B A L S ======================================================= */
55 SYNFIG_LAYER_INIT(Halftone2);
56 SYNFIG_LAYER_SET_NAME(Halftone2,"halftone2");
57 SYNFIG_LAYER_SET_LOCAL_NAME(Halftone2,N_("Halftone 2"));
58 SYNFIG_LAYER_SET_CATEGORY(Halftone2,N_("Filters"));
59 SYNFIG_LAYER_SET_VERSION(Halftone2,"0.0");
60 SYNFIG_LAYER_SET_CVS_ID(Halftone2,"$Id$");
62 /* === P R O C E D U R E S ================================================= */
64 /* === M E T H O D S ======================================================= */
66 Halftone2::Halftone2():
67 color_dark(Color::black()),
68 color_light(Color::white())
70 halftone.origin=(synfig::Point(0,0));
71 halftone.size=(synfig::Vector(0.25,0.25));
72 halftone.angle=(Angle::zero());
73 halftone.type=TYPE_SYMMETRIC;
75 set_blend_method(Color::BLEND_STRAIGHT);
79 Halftone2::color_func(const Point &point, float supersample,const Color& color)const
81 const float amount(halftone(point,color.get_y(),supersample));
87 halfcolor=color_light;
89 halfcolor=Color::blend(color_light,color_dark,amount,Color::BLEND_STRAIGHT);
91 halfcolor.set_a(color.get_a());
97 Halftone2::calc_supersample(const synfig::Point &/*x*/, float pw,float /*ph*/)const
99 return abs(pw/(halftone.size).mag());
102 synfig::Layer::Handle
103 Halftone2::hit_check(synfig::Context /*context*/, const synfig::Point &/*point*/)const
105 return const_cast<Halftone2*>(this);
109 Halftone2::set_param(const String & param, const ValueBase &value)
114 IMPORT_AS(halftone.size,"size");
115 IMPORT_AS(halftone.type,"type");
116 IMPORT_AS(halftone.angle,"angle");
117 IMPORT_AS(halftone.origin,"origin");
119 IMPORT_AS(halftone.origin,"offset");
121 return Layer_Composite::set_param(param,value);
125 Halftone2::get_param(const String & param)const
127 EXPORT_AS(halftone.size,"size");
128 EXPORT_AS(halftone.type,"type");
129 EXPORT_AS(halftone.angle,"angle");
130 EXPORT_AS(halftone.origin,"origin");
138 return Layer_Composite::get_param(param);
142 Halftone2::get_param_vocab()const
144 Layer::Vocab ret(Layer_Composite::get_param_vocab());
146 ret.push_back(ParamDesc("origin")
147 .set_local_name(_("Mask Origin"))
150 ret.push_back(ParamDesc("angle")
151 .set_local_name(_("Mask Angle"))
152 .set_origin("origin")
154 ret.push_back(ParamDesc("size")
155 .set_local_name(_("Mask Size"))
157 .set_origin("origin")
159 ret.push_back(ParamDesc("color_light")
160 .set_local_name(_("Light Color"))
162 ret.push_back(ParamDesc("color_dark")
163 .set_local_name(_("Dark Color"))
165 ret.push_back(ParamDesc("type")
166 .set_local_name(_("Type"))
168 .add_enum_value(TYPE_SYMMETRIC,"symmetric",_("Symmetric"))
169 .add_enum_value(TYPE_LIGHTONDARK,"lightondark",_("Light On Dark"))
170 //.add_enum_value(TYPE_DARKONLIGHT,"darkonlight",_("Dark on Light"))
171 .add_enum_value(TYPE_DIAMOND,"diamond",_("Diamond"))
172 .add_enum_value(TYPE_STRIPE,"stripe",_("Stripe"))
179 Halftone2::get_color(Context context, const Point &point)const
181 const Color undercolor(context.get_color(point));
182 const Color color(color_func(point,0,undercolor));
184 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
187 return Color::blend(color,undercolor,get_amount(),get_blend_method());
191 Halftone2::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
193 SuperCallback supercb(cb,0,9500,10000);
195 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
200 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
201 const Point tl(renddesc.get_tl());
202 const int w(surface->get_w());
203 const int h(surface->get_h());
204 const float supersample_size(abs(pw/(halftone.size).mag()));
206 Surface::pen pen(surface->begin());
212 for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
213 for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
224 for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
225 for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
240 // Mark our progress as finished
241 if(cb && !cb->amount_complete(10000,10000))