1 /* === S Y N F I G ========================================================= */
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 ======================================================= */
36 /* === M A C R O S ========================================================= */
38 using namespace synfig;
42 /* === G L O B A L S ======================================================= */
45 /* === P R O C E D U R E S ================================================= */
47 #define SQRT2 (1.414213562f)
49 /* === M E T H O D S ======================================================= */
52 Halftone::operator()(const Point &point, const float& luma, float supersample)const
54 float halftone(mask(point));
57 supersample=0.4999999999f;
59 halftone=(halftone-0.5f)*(1.0f-supersample*2.0f)+0.5f;
61 const float diff(halftone-luma);
65 const float amount(diff/(supersample*2.0f)+0.5f);
67 if(amount<=0.0f+0.01f)
69 else if(amount>=1.0f-0.01f)
86 Halftone::mask(synfig::Point point)const
94 const float a(Angle::sin(-angle).get()), b(Angle::cos(-angle).get());
95 const float u(point[0]),v(point[1]);
101 if(type==TYPE_STRIPE)
103 Point pnt(fmod(point[0],size[0]),fmod(point[1],size[1]));
104 while(pnt[0]<0)pnt[0]+=abs(size[0]);
105 while(pnt[1]<0)pnt[1]+=abs(size[1]);
107 float x(pnt[1]/size[1]);
114 Point pnt(fmod(point[0],size[0]),fmod(point[1],size[1]));
115 while(pnt[0]<0)pnt[0]+=abs(size[0]);
116 while(pnt[1]<0)pnt[1]+=abs(size[1]);
117 pnt-=Vector(size[0]*0.5,size[1]*0.5);
122 radius1=pnt.mag()/SQRT2;
125 if(type==TYPE_DARKONLIGHT || type== TYPE_LIGHTONDARK)
129 Point pnt(fmod(point[0]+size[0]*0.5,size[0]),fmod(point[1]+size[0]*0.5,size[1]));
130 while(pnt[0]<0)pnt[0]+=abs(size[0]);
131 while(pnt[1]<0)pnt[1]+=abs(size[1]);
132 pnt-=Vector(size[0]*0.5,size[1]*0.5);
137 radius2=pnt.mag()/SQRT2;
141 if(type==TYPE_DIAMOND)
143 //return (radius1+(1.0f-radius2))*0.5;
144 float x((radius1+(1.0f-radius2))*0.5);
145 //float x(((radius2-radius1)*((radius1+(1.0f-radius2))*0.5)+radius1)*2.0f);
148 if(x<0)x=-sqrt(-x);else x=sqrt(x);
155 if(type==TYPE_SYMMETRIC)
157 float x(((radius2-radius1)*((radius1+(1.0f-radius2))*0.5)+radius1)*2.0f);
160 if(x<0)x=-sqrt(-x);else x=sqrt(x);