Esempio n. 1
0
inline void
LinearGradient::fill_params(Params &params)const
{
	params.p1=param_p1.get(Point());
	params.p2=param_p2.get(Point());
	params.loop=param_loop.get(bool());
	params.zigzag=param_zigzag.get(bool());
	params.gradient.set(param_gradient.get(Gradient()), params.loop, params.zigzag);
	params.calc_diff();
}
Esempio n. 2
0
bool
LinearGradient::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
{
	Params params;
	fill_params(params);

	if (!renddesc.get_transformation_matrix().is_identity())
	{
		Point origin = params.p1;
		Point axis_x = params.p2 - origin;
		Point axis_y = axis_x.perp();
		origin = renddesc.get_transformation_matrix().get_transformed(origin);
		axis_x = renddesc.get_transformation_matrix().get_transformed(axis_x, false);
		axis_y = renddesc.get_transformation_matrix().get_transformed(axis_y, false);

		Point valid_axis_x = -axis_y.perp();
		Real mag_squared = valid_axis_x.mag_squared();
		if (mag_squared > 0.0)
			valid_axis_x *= (valid_axis_x * axis_x)/mag_squared;
		else
			valid_axis_x = axis_x;

		params.p1 = origin;
		params.p2 = origin + valid_axis_x;
		params.calc_diff();
	}

	SuperCallback supercb(cb,0,9500,10000);

	if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
	{
		surface->set_wh(renddesc.get_w(),renddesc.get_h());
	}
	else
	{
		if(!context.accelerated_render(surface,quality,renddesc,&supercb))
			return false;
		if(get_amount()==0)
			return true;
	}


	int x,y;

	Surface::pen pen(surface->begin());
	const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
	Point pos;
	Point tl(renddesc.get_tl());
	const int w(surface->get_w());
	const int h(surface->get_h());
	synfig::Real supersample = calc_supersample(params, pw, 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)
			for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
				pen.put_value(color_func(params,pos,supersample));
	}
	else
	{
		for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
			for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
				pen.put_value(Color::blend(color_func(params,pos,supersample),pen.get_value(),get_amount(),get_blend_method()));
	}

	// Mark our progress as finished
	if(cb && !cb->amount_complete(10000,10000))
		return false;

	return true;
}