1 /* === S I N F G =========================================================== */
2 /*! \file halftone2.cpp
5 ** $Id: halftone2.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
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.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "halftone2.h"
34 #include <sinfg/string.h>
35 #include <sinfg/time.h>
36 #include <sinfg/context.h>
37 #include <sinfg/paramdesc.h>
38 #include <sinfg/renddesc.h>
39 #include <sinfg/surface.h>
40 #include <sinfg/value.h>
41 #include <sinfg/valuenode.h>
45 /* === M A C R O S ========================================================= */
47 using namespace sinfg;
51 /* === G L O B A L S ======================================================= */
53 SINFG_LAYER_INIT(Halftone2);
54 SINFG_LAYER_SET_NAME(Halftone2,"halftone2");
55 SINFG_LAYER_SET_LOCAL_NAME(Halftone2,_("Halftone2"));
56 SINFG_LAYER_SET_CATEGORY(Halftone2,_("Filters"));
57 SINFG_LAYER_SET_VERSION(Halftone2,"0.0");
58 SINFG_LAYER_SET_CVS_ID(Halftone2,"$Id: halftone2.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
60 /* === P R O C E D U R E S ================================================= */
62 /* === M E T H O D S ======================================================= */
64 Halftone2::Halftone2():
65 color_dark(Color::black()),
66 color_light(Color::white())
68 halftone.offset=(sinfg::Point(0,0));
69 halftone.size=(sinfg::Vector(0.25,0.25));
70 halftone.angle=(Angle::zero());
71 halftone.type=TYPE_SYMMETRIC;
73 set_blend_method(Color::BLEND_STRAIGHT);
77 Halftone2::color_func(const Point &point, float supersample,const Color& color)const
79 const float amount(halftone(point,color.get_y(),supersample));
85 halfcolor=color_light;
87 halfcolor=Color::blend(color_light,color_dark,amount,Color::BLEND_STRAIGHT);
89 halfcolor.set_a(color.get_a());
95 Halftone2::calc_supersample(const sinfg::Point &x, float pw,float ph)const
97 return abs(pw/(halftone.size).mag());
101 Halftone2::hit_check(sinfg::Context context, const sinfg::Point &point)const
103 return const_cast<Halftone2*>(this);
107 Halftone2::set_param(const String & param, const ValueBase &value)
112 IMPORT_AS(halftone.size,"size");
113 IMPORT_AS(halftone.type,"type");
114 IMPORT_AS(halftone.angle,"angle");
115 IMPORT_AS(halftone.offset,"offset");
117 return Layer_Composite::set_param(param,value);
121 Halftone2::get_param(const String & param)const
123 EXPORT_AS(halftone.size,"size");
124 EXPORT_AS(halftone.type,"type");
125 EXPORT_AS(halftone.angle,"angle");
126 EXPORT_AS(halftone.offset,"offset");
134 return Layer_Composite::get_param(param);
138 Halftone2::get_param_vocab()const
140 Layer::Vocab ret(Layer_Composite::get_param_vocab());
142 ret.push_back(ParamDesc("offset")
143 .set_local_name(_("Mask Offset"))
146 ret.push_back(ParamDesc("angle")
147 .set_local_name(_("Mask Angle"))
148 .set_origin("offset")
150 ret.push_back(ParamDesc("size")
151 .set_local_name(_("Mask Size"))
153 .set_origin("offset")
155 ret.push_back(ParamDesc("color_light")
156 .set_local_name(_("Light Color"))
158 ret.push_back(ParamDesc("color_dark")
159 .set_local_name(_("Dark Color"))
161 ret.push_back(ParamDesc("type")
162 .set_local_name(_("Type"))
164 .add_enum_value(TYPE_SYMMETRIC,"symmetric",_("Symmetric"))
165 .add_enum_value(TYPE_LIGHTONDARK,"lightondark",_("Light On Dark"))
166 //.add_enum_value(TYPE_DARKONLIGHT,"darkonlight",_("Dark on Light"))
167 .add_enum_value(TYPE_DIAMOND,"diamond",_("Diamond"))
168 .add_enum_value(TYPE_STRIPE,"stripe",_("Stripe"))
175 Halftone2::get_color(Context context, const Point &point)const
177 const Color undercolor(context.get_color(point));
178 const Color color(color_func(point,0,undercolor));
180 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
183 return Color::blend(color,undercolor,get_amount(),get_blend_method());
187 Halftone2::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
189 SuperCallback supercb(cb,0,9500,10000);
191 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
196 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
197 const Point tl(renddesc.get_tl());
198 const int w(surface->get_w());
199 const int h(surface->get_h());
200 const float supersample_size(abs(pw/(halftone.size).mag()));
202 Surface::pen pen(surface->begin());
208 for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
209 for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
220 for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
221 for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
236 // Mark our progress as finished
237 if(cb && !cb->amount_complete(10000,10000))