Blame synfig-core/src/synfig/rendering/common/optimizer/optimizerdraft.cpp

61c381
/* === S Y N F I G ========================================================= */
a39fef
/*!	\file synfig/rendering/common/optimizer/optimizerdraft.cpp
a39fef
**	\brief Draft Optimizers
61c381
**
61c381
**	$Id$
61c381
**
61c381
**	\legal
11c2eb
**	......... ... 2017-2018 Ivan Mahonin
61c381
**
61c381
**	This package is free software; you can redistribute it and/or
61c381
**	modify it under the terms of the GNU General Public License as
61c381
**	published by the Free Software Foundation; either version 2 of
61c381
**	the License, or (at your option) any later version.
61c381
**
61c381
**	This package is distributed in the hope that it will be useful,
61c381
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
61c381
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
61c381
**	General Public License for more details.
61c381
**	\endlegal
61c381
*/
61c381
/* ========================================================================= */
61c381
61c381
/* === H E A D E R S ======================================================= */
61c381
61c381
#ifdef USING_PCH
61c381
#	include "pch.h"
61c381
#else
61c381
#ifdef HAVE_CONFIG_H
61c381
#	include <config.h></config.h>
61c381
#endif
61c381
a39fef
#include "optimizerdraft.h"
61c381
a39fef
#include "../task/taskcontour.h"
a39fef
#include "../task/taskblur.h"
a39fef
#include "../task/tasklayer.h"
5e2754
#include "../task/tasktransformation.h"
61c381
61c381
#endif
61c381
61c381
using namespace synfig;
61c381
using namespace rendering;
61c381
61c381
/* === M A C R O S ========================================================= */
61c381
61c381
/* === G L O B A L S ======================================================= */
61c381
61c381
/* === P R O C E D U R E S ================================================= */
61c381
61c381
/* === M E T H O D S ======================================================= */
61c381
a39fef
11c2eb
// OptimizerDraft
11c2eb
11c2eb
OptimizerDraft::OptimizerDraft()
11c2eb
{
11c2eb
	category_id = CATEGORY_ID_BEGIN;
11c2eb
	for_task = true;
11c2eb
}
11c2eb
11c2eb
11c2eb
// OptimizerDraftLowRes
11c2eb
11c2eb
OptimizerDraftLowRes::OptimizerDraftLowRes(Real scale): scale(scale)
11c2eb
{
11c2eb
	for_root_task = true;
11c2eb
	for_task = false;
11c2eb
}
11c2eb
61c381
void
11c2eb
OptimizerDraftLowRes::run(const RunParams ¶ms) const
61c381
{
ae6532
	if (!params.parent && params.ref_task && !params.ref_task.type_is<tasksurface>())</tasksurface>
61c381
	{
61c381
		Task::Handle sub_task = params.ref_task->clone();
61c381
11c2eb
		TaskTransformationAffine::Handle affine = new TaskTransformationAffine();
11c2eb
		affine->sub_task() = sub_task;
11c2eb
		affine->supersample = Vector(1.0/scale, 1.0/scale);
11c2eb
		affine->interpolation = Color::INTERPOLATION_NEAREST;
11c2eb
		affine->sub_task() = sub_task;
61c381
ae6532
		// swap target
ae6532
		affine->assign_target(*sub_task);
ae6532
		sub_task->target_surface.reset();
ae6532
		sub_task->source_rect = Rect::infinite();
ae6532
		sub_task->target_rect = RectInt::zero();
61c381
11c2eb
		apply(params, affine);
61c381
	}
61c381
}
61c381
a39fef
11c2eb
// OptimizerDraftTransformation
11c2eb
a39fef
void
11c2eb
OptimizerDraftTransformation::run(const RunParams ¶ms) const
a39fef
{
11c2eb
	if (TaskTransformation::Handle transformation = TaskTransformation::Handle::cast_dynamic(params.ref_task))
a39fef
	{
8af0f3
		const bool affine = transformation->get_transformation().type_is<transformationaffine>();</transformationaffine>
8af0f3
		const Real supersample_max = affine ? 1 : 0.5;
17812b
		if ( transformation->interpolation != Color::INTERPOLATION_NEAREST
8af0f3
		  || approximate_greater_lp(transformation->supersample[0], supersample_max)
8af0f3
		  || approximate_greater_lp(transformation->supersample[1], supersample_max) )
a39fef
		{
11c2eb
			transformation = TaskTransformation::Handle::cast_dynamic( transformation->clone() );
17812b
			transformation->interpolation = Color::INTERPOLATION_NEAREST;
8af0f3
			transformation->supersample[0] = std::min(transformation->supersample[0], supersample_max);
8af0f3
			transformation->supersample[1] = std::min(transformation->supersample[1], supersample_max);
11c2eb
			apply(params, transformation);
a39fef
		}
a39fef
	}
a39fef
}
a39fef
a39fef
11c2eb
// OptimizerDraftContour
11c2eb
11c2eb
OptimizerDraftContour::OptimizerDraftContour(Real detail, bool antialias):
11c2eb
	detail(detail), antialias(antialias) { }
11c2eb
a39fef
void
11c2eb
OptimizerDraftContour::run(const RunParams ¶ms) const
a39fef
{
a39fef
	if (TaskContour::Handle contour = TaskContour::Handle::cast_dynamic(params.ref_task))
a39fef
	{
11c2eb
		if ( approximate_less_lp(contour->detail, detail)
11c2eb
		 || ( !antialias
11c2eb
		   && contour->contour
11c2eb
		   && contour->contour->antialias
11c2eb
		   && contour->allow_antialias ))
a39fef
		{
a39fef
			contour = TaskContour::Handle::cast_dynamic(contour->clone());
11c2eb
			if (contour->detail < detail) contour->detail = detail;
11c2eb
			if (!antialias) contour->allow_antialias = false;
a39fef
			apply(params, contour);
a39fef
		}
a39fef
	}
a39fef
}
a39fef
a39fef
11c2eb
// OptimizerDraftBlur
11c2eb
a39fef
void
11c2eb
OptimizerDraftBlur::run(const RunParams ¶ms) const
a39fef
{
a39fef
	if (TaskBlur::Handle blur = TaskBlur::Handle::cast_dynamic(params.ref_task))
a39fef
	{
11c2eb
		if (blur->blur.type != Blur::BOX && blur->blur.type != Blur::CROSS)
a39fef
		{
a39fef
			blur = TaskBlur::Handle::cast_dynamic(blur->clone());
a39fef
			blur->blur.type = Blur::BOX;
a39fef
			apply(params, blur);
a39fef
		}
a39fef
	}
a39fef
}
a39fef
a39fef
11c2eb
// OptimizerDraftLayerRemove
11c2eb
11c2eb
OptimizerDraftLayerRemove::OptimizerDraftLayerRemove(const String &layername):
11c2eb
	layername(layername) { }
11c2eb
a39fef
void
11c2eb
OptimizerDraftLayerRemove::run(const RunParams ¶ms) const
a39fef
{
a39fef
	if (TaskLayer::Handle layer = TaskLayer::Handle::cast_dynamic(params.ref_task))
a39fef
		if (layer->layer && layer->layer->get_name() == layername)
11c2eb
			apply(params, Task::Handle());
a39fef
}
a39fef
a39fef
11c2eb
// OptimizerDraftLayerSkip
11c2eb
11c2eb
OptimizerDraftLayerSkip::OptimizerDraftLayerSkip(const String &layername):
11c2eb
	layername(layername)
11c2eb
	{ mode |= MODE_REPEAT_LAST; }
11c2eb
a39fef
void
11c2eb
OptimizerDraftLayerSkip::run(const RunParams ¶ms) const
a39fef
{
a39fef
	if (TaskLayer::Handle layer = TaskLayer::Handle::cast_dynamic(params.ref_task))
a39fef
		if (layer->layer && layer->layer->get_name() == layername)
a39fef
			apply(params, layer->sub_task());
a39fef
}
a39fef
a39fef
61c381
/* === E N T R Y P O I N T ================================================= */