1 /* === S Y N F I G ========================================================= */
2 /*! \file halftone2.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "halftone2.h"
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>
46 /* === M A C R O S ========================================================= */
48 using namespace synfig;
52 /* === G L O B A L S ======================================================= */
54 SYNFIG_LAYER_INIT(Halftone2);
55 SYNFIG_LAYER_SET_NAME(Halftone2,"halftone2");
56 SYNFIG_LAYER_SET_LOCAL_NAME(Halftone2,_("Halftone2"));
57 SYNFIG_LAYER_SET_CATEGORY(Halftone2,_("Filters"));
58 SYNFIG_LAYER_SET_VERSION(Halftone2,"0.0");
59 SYNFIG_LAYER_SET_CVS_ID(Halftone2,"$Id$");
61 /* === P R O C E D U R E S ================================================= */
63 /* === M E T H O D S ======================================================= */
65 Halftone2::Halftone2():
66 color_dark(Color::black()),
67 color_light(Color::white())
69 halftone.offset=(synfig::Point(0,0));
70 halftone.size=(synfig::Vector(0.25,0.25));
71 halftone.angle=(Angle::zero());
72 halftone.type=TYPE_SYMMETRIC;
74 set_blend_method(Color::BLEND_STRAIGHT);
78 Halftone2::color_func(const Point &point, float supersample,const Color& color)const
80 const float amount(halftone(point,color.get_y(),supersample));
86 halfcolor=color_light;
88 halfcolor=Color::blend(color_light,color_dark,amount,Color::BLEND_STRAIGHT);
90 halfcolor.set_a(color.get_a());
96 Halftone2::calc_supersample(const synfig::Point &x, float pw,float ph)const
98 return abs(pw/(halftone.size).mag());
101 synfig::Layer::Handle
102 Halftone2::hit_check(synfig::Context context, const synfig::Point &point)const
104 return const_cast<Halftone2*>(this);
108 Halftone2::set_param(const String & param, const ValueBase &value)
113 IMPORT_AS(halftone.size,"size");
114 IMPORT_AS(halftone.type,"type");
115 IMPORT_AS(halftone.angle,"angle");
116 IMPORT_AS(halftone.offset,"offset");
118 return Layer_Composite::set_param(param,value);
122 Halftone2::get_param(const String & param)const
124 EXPORT_AS(halftone.size,"size");
125 EXPORT_AS(halftone.type,"type");
126 EXPORT_AS(halftone.angle,"angle");
127 EXPORT_AS(halftone.offset,"offset");
135 return Layer_Composite::get_param(param);
139 Halftone2::get_param_vocab()const
141 Layer::Vocab ret(Layer_Composite::get_param_vocab());
143 ret.push_back(ParamDesc("offset")
144 .set_local_name(_("Mask Offset"))
147 ret.push_back(ParamDesc("angle")
148 .set_local_name(_("Mask Angle"))
149 .set_origin("offset")
151 ret.push_back(ParamDesc("size")
152 .set_local_name(_("Mask Size"))
154 .set_origin("offset")
156 ret.push_back(ParamDesc("color_light")
157 .set_local_name(_("Light Color"))
159 ret.push_back(ParamDesc("color_dark")
160 .set_local_name(_("Dark Color"))
162 ret.push_back(ParamDesc("type")
163 .set_local_name(_("Type"))
165 .add_enum_value(TYPE_SYMMETRIC,"symmetric",_("Symmetric"))
166 .add_enum_value(TYPE_LIGHTONDARK,"lightondark",_("Light On Dark"))
167 //.add_enum_value(TYPE_DARKONLIGHT,"darkonlight",_("Dark on Light"))
168 .add_enum_value(TYPE_DIAMOND,"diamond",_("Diamond"))
169 .add_enum_value(TYPE_STRIPE,"stripe",_("Stripe"))
176 Halftone2::get_color(Context context, const Point &point)const
178 const Color undercolor(context.get_color(point));
179 const Color color(color_func(point,0,undercolor));
181 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
184 return Color::blend(color,undercolor,get_amount(),get_blend_method());
188 Halftone2::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
190 SuperCallback supercb(cb,0,9500,10000);
192 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
197 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
198 const Point tl(renddesc.get_tl());
199 const int w(surface->get_w());
200 const int h(surface->get_h());
201 const float supersample_size(abs(pw/(halftone.size).mag()));
203 Surface::pen pen(surface->begin());
209 for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
210 for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
221 for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
222 for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
237 // Mark our progress as finished
238 if(cb && !cb->amount_complete(10000,10000))