1 /* === S I N F G =========================================================== */
5 ** $Id: halftone.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 ======================================================= */
35 /* === M A C R O S ========================================================= */
37 using namespace sinfg;
41 /* === G L O B A L S ======================================================= */
44 /* === P R O C E D U R E S ================================================= */
46 #define SQRT2 (1.414213562f)
48 /* === M E T H O D S ======================================================= */
51 Halftone::operator()(const Point &point, const float& luma, float supersample)const
53 float halftone(mask(point));
56 supersample=0.4999999999f;
58 halftone=(halftone-0.5f)*(1.0f-supersample*2.0f)+0.5f;
60 const float diff(halftone-luma);
64 const float amount(diff/(supersample*2.0f)+0.5f);
66 if(amount<=0.0f+0.01f)
68 else if(amount>=1.0f-0.01f)
85 Halftone::mask(sinfg::Point point)const
93 const float a(Angle::sin(-angle).get()), b(Angle::cos(-angle).get());
94 const float u(point[0]),v(point[1]);
100 if(type==TYPE_STRIPE)
102 Point pnt(fmod(point[0],size[0]),fmod(point[1],size[1]));
103 while(pnt[0]<0)pnt[0]+=abs(size[0]);
104 while(pnt[1]<0)pnt[1]+=abs(size[1]);
106 float x(pnt[1]/size[1]);
113 Point pnt(fmod(point[0],size[0]),fmod(point[1],size[1]));
114 while(pnt[0]<0)pnt[0]+=abs(size[0]);
115 while(pnt[1]<0)pnt[1]+=abs(size[1]);
116 pnt-=Vector(size[0]*0.5,size[1]*0.5);
121 radius1=pnt.mag()/SQRT2;
124 if(type==TYPE_DARKONLIGHT || type== TYPE_LIGHTONDARK)
128 Point pnt(fmod(point[0]+size[0]*0.5,size[0]),fmod(point[1]+size[0]*0.5,size[1]));
129 while(pnt[0]<0)pnt[0]+=abs(size[0]);
130 while(pnt[1]<0)pnt[1]+=abs(size[1]);
131 pnt-=Vector(size[0]*0.5,size[1]*0.5);
136 radius2=pnt.mag()/SQRT2;
140 if(type==TYPE_DIAMOND)
142 //return (radius1+(1.0f-radius2))*0.5;
143 float x((radius1+(1.0f-radius2))*0.5);
144 //float x(((radius2-radius1)*((radius1+(1.0f-radius2))*0.5)+radius1)*2.0f);
147 if(x<0)x=-sqrt(-x);else x=sqrt(x);
154 if(type==TYPE_SYMMETRIC)
156 float x(((radius2-radius1)*((radius1+(1.0f-radius2))*0.5)+radius1)*2.0f);
159 if(x<0)x=-sqrt(-x);else x=sqrt(x);