1 /* === S Y N F I G ========================================================= */
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 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 ======================================================= */
37 /* === M A C R O S ========================================================= */
39 using namespace synfig;
43 /* === G L O B A L S ======================================================= */
46 /* === P R O C E D U R E S ================================================= */
48 #define SQRT2 (1.414213562f)
50 /* === M E T H O D S ======================================================= */
53 Halftone::operator()(const Point &point, const float& luma, float supersample)const
55 float halftone(mask(point));
58 supersample=0.4999999999f;
60 halftone=(halftone-0.5f)*(1.0f-supersample*2.0f)+0.5f;
62 const float diff(halftone-luma);
66 const float amount(diff/(supersample*2.0f)+0.5f);
68 if(amount<=0.0f+0.01f)
70 else if(amount>=1.0f-0.01f)
87 Halftone::mask(synfig::Point point)const
95 const float a(Angle::sin(-angle).get()), b(Angle::cos(-angle).get());
96 const float u(point[0]),v(point[1]);
102 if(type==TYPE_STRIPE)
104 Point pnt(fmod(point[0],size[0]),fmod(point[1],size[1]));
105 while(pnt[0]<0)pnt[0]+=abs(size[0]);
106 while(pnt[1]<0)pnt[1]+=abs(size[1]);
108 float x(pnt[1]/size[1]);
115 Point pnt(fmod(point[0],size[0]),fmod(point[1],size[1]));
116 while(pnt[0]<0)pnt[0]+=abs(size[0]);
117 while(pnt[1]<0)pnt[1]+=abs(size[1]);
118 pnt-=Vector(size[0]*0.5,size[1]*0.5);
123 radius1=pnt.mag()/SQRT2;
126 if(type==TYPE_DARKONLIGHT || type== TYPE_LIGHTONDARK)
130 Point pnt(fmod(point[0]+size[0]*0.5,size[0]),fmod(point[1]+size[0]*0.5,size[1]));
131 while(pnt[0]<0)pnt[0]+=abs(size[0]);
132 while(pnt[1]<0)pnt[1]+=abs(size[1]);
133 pnt-=Vector(size[0]*0.5,size[1]*0.5);
138 radius2=pnt.mag()/SQRT2;
142 if(type==TYPE_DIAMOND)
144 //return (radius1+(1.0f-radius2))*0.5;
145 float x((radius1+(1.0f-radius2))*0.5);
146 //float x(((radius2-radius1)*((radius1+(1.0f-radius2))*0.5)+radius1)*2.0f);
149 if(x<0)x=-sqrt(-x);else x=sqrt(x);
156 if(type==TYPE_SYMMETRIC)
158 float x(((radius2-radius1)*((radius1+(1.0f-radius2))*0.5)+radius1)*2.0f);
161 if(x<0)x=-sqrt(-x);else x=sqrt(x);