Blame synfig-core/src/synfig/rendering/common/task/tasktransformation.cpp

853fdb
/* === S Y N F I G ========================================================= */
da4398
/*!	\file synfig/rendering/common/task/tasktransformation.cpp
da4398
**	\brief TaskTransformation
853fdb
**
853fdb
**	$Id$
853fdb
**
853fdb
**	\legal
da4398
**	......... ... 2015-2018 Ivan Mahonin
853fdb
**
853fdb
**	This package is free software; you can redistribute it and/or
853fdb
**	modify it under the terms of the GNU General Public License as
853fdb
**	published by the Free Software Foundation; either version 2 of
853fdb
**	the License, or (at your option) any later version.
853fdb
**
853fdb
**	This package is distributed in the hope that it will be useful,
853fdb
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
853fdb
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
853fdb
**	General Public License for more details.
853fdb
**	\endlegal
853fdb
*/
853fdb
/* ========================================================================= */
853fdb
853fdb
/* === H E A D E R S ======================================================= */
853fdb
853fdb
#ifdef USING_PCH
853fdb
#	include "pch.h"
853fdb
#else
853fdb
#ifdef HAVE_CONFIG_H
853fdb
#	include <config.h></config.h>
853fdb
#endif
853fdb
da4398
#include "tasktransformation.h"
853fdb
853fdb
#endif
853fdb
853fdb
using namespace synfig;
853fdb
using namespace rendering;
853fdb
853fdb
/* === M A C R O S ========================================================= */
853fdb
853fdb
/* === G L O B A L S ======================================================= */
853fdb
853fdb
/* === P R O C E D U R E S ================================================= */
853fdb
853fdb
/* === M E T H O D S ======================================================= */
853fdb
da4398
5e2754
Task::Token TaskTransformation::token(
111532
	DescAbstract<tasktransformation>("Transformation") );</tasktransformation>
5e2754
Task::Token TaskTransformationAffine::token(
111532
	DescAbstract<tasktransformationaffine, tasktransformation="">("TransformationAffine") );</tasktransformationaffine,>
da4398
da4398
81df8d
TaskTransformation::TaskTransformation():
81df8d
	interpolation(Color::INTERPOLATION_CUBIC),
81df8d
	supersample(Vector(1.0, 1.0)) { }
81df8d
81df8d
81df8d
bool
81df8d
TaskTransformation::is_simple() const {
81df8d
	return interpolation != Color::INTERPOLATION_NEAREST
81df8d
		&& supersample.is_equal_to(Vector(1.0, 1.0));
81df8d
}
81df8d
ae6532
int
ae6532
TaskTransformation::get_pass_subtask_index() const
ae6532
{
ae6532
	return sub_task() && get_transformation()
ae6532
		 ? PASSTO_THIS_TASK : PASSTO_NO_TASK;
ae6532
}
ae6532
ae6532
da4398
Rect
da4398
TaskTransformation::calc_bounds() const
da4398
{
da4398
	if (!sub_task())
da4398
		return Rect();
da4398
	Transformation::Handle transformation = get_transformation();
da4398
	if (!transformation)
da4398
		return Rect();
da4398
	Rect bounds = sub_task()->get_bounds();
da4398
	if (!bounds.is_valid())
da4398
		return Rect();
48c23f
48c23f
	// transform_bounds() cannot transform infinity,
48c23f
	// because transform_bounds() calculates bounds with resolution
48c23f
	if (bounds.is_full_infinite())
48c23f
		return bounds;
48c23f
5e2754
	return transformation->transform_bounds(bounds).rect;
da4398
}
da4398
e788a2
void
da4398
TaskTransformation::set_coords_sub_tasks()
853fdb
{
da4398
	if (!sub_task())
da4398
		{ trunc_to_zero(); return; }
da4398
da4398
	if ( is_valid_coords()
f44ff0
	  && approximate_greater(supersample[0], Real(0))
f44ff0
	  && approximate_greater(supersample[1], Real(0)) )
da4398
	{
da4398
		if (Transformation::Handle transformation = get_transformation())
da4398
		{
da4398
			if (Transformation::Handle back_transformation = transformation->create_inverted())
da4398
			{
f44ff0
				Transformation::DiscreteBounds discrete_bounds =
f44ff0
					Transformation::make_discrete_bounds(
f44ff0
						back_transformation->transform_bounds(
f44ff0
							source_rect,
f44ff0
							get_pixels_per_unit().multiply_coords(supersample) ));
f44ff0
				if (discrete_bounds.is_valid())
da4398
				{
f44ff0
					sub_task()->set_coords(discrete_bounds.rect, discrete_bounds.size);
da4398
					return;
da4398
				}
da4398
			}
da4398
		}
da4398
	}
da4398
da4398
	sub_task()->set_coords_zero();
da4398
	trunc_to_zero();
853fdb
}
853fdb
ae6532
ae6532
int
ae6532
TaskTransformationAffine::get_pass_subtask_index() const
ae6532
{
ae6532
	if (is_simple() && transformation->matrix.is_identity())
ae6532
		return 0;
ae6532
	return TaskTransformation::get_pass_subtask_index();
ae6532
}
f44ff0
853fdb
/* === E N T R Y P O I N T ================================================= */