-/*! ========================================================================
-** Synfig
-** Template File
-** $Id: curvegradient.cpp,v 1.2 2005/01/13 06:48:39 darco Exp $
+/* === S Y N F I G ========================================================= */
+/*! \file curvegradient.cpp
+** \brief Template Header
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**
** This package is free software; you can redistribute it and/or
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**
** This package is free software; you can redistribute it and/or
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
SYNFIG_LAYER_SET_LOCAL_NAME(CurveGradient,_("Curve Gradient"));
SYNFIG_LAYER_SET_CATEGORY(CurveGradient,_("Gradients"));
SYNFIG_LAYER_SET_VERSION(CurveGradient,"0.0");
SYNFIG_LAYER_SET_LOCAL_NAME(CurveGradient,_("Curve Gradient"));
SYNFIG_LAYER_SET_CATEGORY(CurveGradient,_("Gradients"));
SYNFIG_LAYER_SET_VERSION(CurveGradient,"0.0");
{
std::vector<synfig::BLinePoint>::const_iterator iter,next,ret;
std::vector<synfig::BLinePoint>::const_iterator end(bline.end());
{
std::vector<synfig::BLinePoint>::const_iterator iter,next,ret;
std::vector<synfig::BLinePoint>::const_iterator end(bline.end());
{
std::vector<synfig::BLinePoint>::const_iterator iter,next,ret;
std::vector<synfig::BLinePoint>::const_iterator end(bline.end());
{
std::vector<synfig::BLinePoint>::const_iterator iter,next,ret;
std::vector<synfig::BLinePoint>::const_iterator end(bline.end());
next=bline.begin();
float best_bline_dist(0);
float best_bline_len(0);
float total_bline_dist(0);
etl::hermite<Vector> best_curve;
next=bline.begin();
float best_bline_dist(0);
float best_bline_len(0);
float total_bline_dist(0);
etl::hermite<Vector> best_curve;
/*
const float t(curve.find_closest(p,6,0.01,0.99));
/*
const float t(curve.find_closest(p,6,0.01,0.99));
*bline_dist_ret=best_bline_dist+best_curve.find_distance(0,best_curve.find_closest(p));
// *bline_dist_ret=best_bline_dist+best_curve.find_closest(p)*best_bline_len;
}
*bline_dist_ret=best_bline_dist+best_curve.find_distance(0,best_curve.find_closest(p));
// *bline_dist_ret=best_bline_dist+best_curve.find_closest(p)*best_bline_len;
}
bline.push_back(BLinePoint());
bline.push_back(BLinePoint());
bline.push_back(BLinePoint());
bline.push_back(BLinePoint());
bline.push_back(BLinePoint());
bline.push_back(BLinePoint());
- bline[0].set_vertex(Point(0,1));
- bline[1].set_vertex(Point(0,-1));
+ bline[0].set_vertex(Point(0,1));
+ bline[1].set_vertex(Point(0,-1));
- bline[0].set_tangent(bline[1].get_vertex()-bline[2].get_vertex()*0.5f);
- bline[1].set_tangent(bline[2].get_vertex()-bline[0].get_vertex()*0.5f);
- bline[2].set_tangent(bline[0].get_vertex()-bline[1].get_vertex()*0.5f);
- bline[0].set_width(1.0f);
- bline[1].set_width(1.0f);
- bline[2].set_width(1.0f);
+ bline[0].set_tangent(bline[1].get_vertex()-bline[2].get_vertex()*0.5f);
+ bline[1].set_tangent(bline[2].get_vertex()-bline[0].get_vertex()*0.5f);
+ bline[2].set_tangent(bline[0].get_vertex()-bline[1].get_vertex()*0.5f);
+ bline[0].set_width(1.0f);
+ bline[1].set_width(1.0f);
+ bline[2].set_width(1.0f);
// Figure out the BLinePoints we will be using,
// Taking into account looping.
if(perpendicular)
// Figure out the BLinePoints we will be using,
// Taking into account looping.
if(perpendicular)
-
- // Setup the derivative function
- etl::derivative<etl::hermite<Vector> > deriv(curve);
-
- int search_iterations(7);
-
- /*if(quality==0)search_iterations=8;
- else if(quality<=2)search_iterations=10;
- else if(quality<=4)search_iterations=8;
- */
- if(!perpendicular)
- {
- if(quality<=6)search_iterations=7;
- else if(quality<=7)search_iterations=6;
- else if(quality<=8)search_iterations=5;
- else search_iterations=4;
- }
- else
- {
- if(quality>7)
- search_iterations=4;
- }
-
- // Figure out the closest point on the curve
- const float t(curve.find_closest(point,search_iterations));
-
-
- // Calculate our values
- p1=curve(t);
- tangent=deriv(t).norm();
-
- if(perpendicular)
- {
- tangent*=curve_length_;
- p1-=tangent*perp_dist;
- tangent=-tangent.perp();
- }
- else
- {
- thickness=(next->get_width()-iter->get_width())*t+iter->get_width();
- }
- //}
+
+ // Setup the derivative function
+ etl::derivative<etl::hermite<Vector> > deriv(curve);
+
+ int search_iterations(7);
+
+ /*if(quality==0)search_iterations=8;
+ else if(quality<=2)search_iterations=10;
+ else if(quality<=4)search_iterations=8;
+ */
+ if(!perpendicular)
+ {
+ if(quality<=6)search_iterations=7;
+ else if(quality<=7)search_iterations=6;
+ else if(quality<=8)search_iterations=5;
+ else search_iterations=4;
+ }
+ else
+ {
+ if(quality>7)
+ search_iterations=4;
+ }
+
+ // Figure out the closest point on the curve
+ const float t(curve.find_closest(point,search_iterations));
+
+
+ // Calculate our values
+ p1=curve(t);
+ tangent=deriv(t).norm();
+
+ if(perpendicular)
+ {
+ tangent*=curve_length_;
+ p1-=tangent*perp_dist;
+ tangent=-tangent.perp();
+ }
+ else
+ {
+ thickness=(next->get_width()-iter->get_width())*t+iter->get_width();
+ }
+ //}
- diff=tangent.perp()*thickness*width;
- p1-=diff*0.5;
- const Real mag(diff.inv_mag());
- supersample=supersample*mag;
- diff*=mag*mag;
- dist=((point_-offset)*diff-p1*diff);
+ diff=tangent.perp()*thickness*width;
+ p1-=diff*0.5;
+ const Real mag(diff.inv_mag());
+ supersample=supersample*mag;
+ diff*=mag*mag;
+ dist=((point_-offset)*diff-p1*diff);
- diff=tangent.perp();
- //p1-=diff*0.5;
- const Real mag(diff.inv_mag());
- supersample=supersample*mag;
- diff*=mag*mag;
- dist=((point_-offset)*diff-p1*diff);
+ diff=tangent.perp();
+ //p1-=diff*0.5;
+ const Real mag(diff.inv_mag());
+ supersample=supersample*mag;
+ diff*=mag*mag;
+ dist=((point_-offset)*diff-p1*diff);
- Color pool(gradient(dist,supersample*0.5).premult_alpha()*(1.0-(dist-supersample*0.5)));
- pool+=gradient((dist+supersample*0.5)-1.0,supersample*0.5).premult_alpha()*((dist+supersample*0.5)-1.0);
+ float left(supersample*0.5-(dist-1.0));
+ float right(supersample*0.5+(dist-1.0));
+ Color pool(gradient(1.0-(left*0.5),left).premult_alpha()*left/supersample);
+ if (zigzag) pool+=gradient(1.0-right*0.5,right).premult_alpha()*right/supersample;
+ else pool+=gradient(right*0.5,right).premult_alpha()*right/supersample;
- Color pool(gradient(dist,supersample*0.5).premult_alpha()*(dist+supersample*0.5));
- pool+=gradient(1.0-(dist-supersample*0.5),supersample*0.5).premult_alpha()*(-(dist-supersample*0.5));
+ float left(supersample*0.5-dist);
+ float right(supersample*0.5+dist);
+ Color pool(gradient(right*0.5,right).premult_alpha()*right/supersample);
+ if (zigzag) pool+=gradient(left*0.5,left).premult_alpha()*left/supersample;
+ else pool+=gradient(1.0-left*0.5,left).premult_alpha()*left/supersample;
Point tl(renddesc.get_tl());
const int w(surface->get_w());
const int h(surface->get_h());
Point tl(renddesc.get_tl());
const int w(surface->get_w());
const int h(surface->get_h());
if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
{
for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
{
for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)