Blame synfig-core/src/modules/lyr_std/supersample.cpp

Carlos Lopez a09598
/* === S Y N F I G ========================================================= */
Carlos Lopez a09598
/*!	\file supersample.cpp
Carlos Lopez a09598
**	\brief Implementation of the "Super Sample" layer
Carlos Lopez a09598
**
Carlos Lopez a09598
**	$Id$
Carlos Lopez a09598
**
Carlos Lopez a09598
**	\legal
Carlos Lopez a09598
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
Carlos Lopez e83454
**	Copyright (c) 2011-2013 Carlos Lรณpez
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is free software; you can redistribute it and/or
Carlos Lopez a09598
**	modify it under the terms of the GNU General Public License as
Carlos Lopez a09598
**	published by the Free Software Foundation; either version 2 of
Carlos Lopez a09598
**	the License, or (at your option) any later version.
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is distributed in the hope that it will be useful,
Carlos Lopez a09598
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
Carlos Lopez a09598
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Carlos Lopez a09598
**	General Public License for more details.
Carlos Lopez a09598
**	\endlegal
Carlos Lopez a09598
**
Carlos Lopez a09598
** === N O T E S ===========================================================
Carlos Lopez a09598
**
Carlos Lopez a09598
** ========================================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === H E A D E R S ======================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
#ifdef USING_PCH
Carlos Lopez a09598
#	include "pch.h"
Carlos Lopez a09598
#else
Carlos Lopez a09598
#ifdef HAVE_CONFIG_H
Carlos Lopez a09598
#	include <config.h></config.h>
Carlos Lopez a09598
#endif
Carlos Lopez a09598
bw 94d8a6
#include <synfig localization.h=""></synfig>
bw 94d8a6
#include <synfig general.h=""></synfig>
bw 94d8a6
Carlos Lopez a09598
#include <synfig context.h=""></synfig>
79c3b0
#include <synfig cairo_renddesc.h=""></synfig>
Carlos Lopez a09598
#include <synfig paramdesc.h=""></synfig>
Carlos Lopez a09598
#include <synfig renddesc.h=""></synfig>
79c3b0
#include <synfig render.h=""></synfig>
79c3b0
#include <synfig common="" rendering="" task="" tasktransformation.h=""></synfig>
79c3b0
#include <synfig string.h=""></synfig>
Carlos Lopez a09598
#include <synfig surface.h=""></synfig>
79c3b0
#include <synfig target.h=""></synfig>
79c3b0
#include <synfig target_scanline.h=""></synfig>
79c3b0
#include <synfig time.h=""></synfig>
Carlos Lopez a09598
#include <synfig value.h=""></synfig>
Carlos Lopez a09598
#include <synfig valuenode.h=""></synfig>
Carlos Lopez a09598
79c3b0
#include "supersample.h"
Carlos Lopez a09598
Carlos Lopez a09598
#endif
Carlos Lopez a09598
9f3c68
using namespace std;
9f3c68
using namespace etl;
9f3c68
using namespace synfig;
144d3f
using namespace modules;
9f3c68
using namespace lyr_std;
9f3c68
Carlos Lopez a09598
/* === M A C R O S ========================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === G L O B A L S ======================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
SYNFIG_LAYER_INIT(SuperSample);
Carlos Lopez a09598
SYNFIG_LAYER_SET_NAME(SuperSample,"super_sample");
Carlos Lopez a09598
SYNFIG_LAYER_SET_LOCAL_NAME(SuperSample,N_("Super Sample"));
Carlos Lopez a09598
SYNFIG_LAYER_SET_CATEGORY(SuperSample,N_("Other"));
Carlos Lopez a09598
SYNFIG_LAYER_SET_VERSION(SuperSample,"0.1");
Carlos Lopez a09598
SYNFIG_LAYER_SET_CVS_ID(SuperSample,"$Id$");
Carlos Lopez a09598
Carlos Lopez a09598
/* === P R O C E D U R E S ================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === M E T H O D S ======================================================= */
Carlos Lopez a09598
Carlos Lopez 523469
SuperSample::SuperSample():
Carlos Lopez 523469
param_width(ValueBase(int(2))),
Carlos Lopez 523469
param_height(ValueBase(int(2)))
Carlos Lopez a09598
{
Carlos Lopez 523469
	param_scanline=ValueBase(false);
Carlos Lopez 523469
	param_alpha_aware=ValueBase(true);
Carlos Lopez 5c5090
	SET_INTERPOLATION_DEFAULTS();
Carlos Lopez 5c5090
	SET_STATIC_DEFAULTS();
Carlos Lopez e37ea8
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
bool
Carlos Lopez a09598
SuperSample::set_param(const String & param, const ValueBase &value)
Carlos Lopez a09598
{
Carlos Lopez 523469
	IMPORT_VALUE_PLUS(param_width,
Carlos Lopez 523469
		{
Carlos Lopez 523469
			int width=param_width.get(int());
Carlos Lopez 523469
			if(value.get(int()) < 1) width = 1;
Carlos Lopez 523469
			else width=value.get(int());
Carlos Lopez 523469
			param_width.set(width);
Carlos Lopez 523469
			return true;
Carlos Lopez 523469
		}
Carlos Lopez 523469
		);
Carlos Lopez 523469
	IMPORT_VALUE_PLUS(param_height,
Carlos Lopez 523469
		{
Carlos Lopez 523469
			int height=param_height.get(int());
Carlos Lopez 523469
			if(value.get(int()) < 1) height = 1;
Carlos Lopez 523469
			else height=value.get(int());
Carlos Lopez 523469
			param_height.set(height);
Carlos Lopez 523469
			return true;
Carlos Lopez 523469
		}
Carlos Lopez 523469
		);
Carlos Lopez 523469
	IMPORT_VALUE(param_scanline);
Carlos Lopez 523469
	IMPORT_VALUE(param_alpha_aware);
Carlos Lopez a09598
Carlos Lopez a09598
	return false;
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
ValueBase
Carlos Lopez a09598
SuperSample::get_param(const String& param)const
Carlos Lopez a09598
{
Carlos Lopez 523469
	EXPORT_VALUE(param_width);
Carlos Lopez 523469
	EXPORT_VALUE(param_height);
Carlos Lopez 523469
    EXPORT_VALUE(param_scanline);
Carlos Lopez 523469
    EXPORT_VALUE(param_alpha_aware);
Carlos Lopez a09598
Carlos Lopez a09598
	EXPORT_NAME();
Carlos Lopez a09598
	EXPORT_VERSION();
Carlos Lopez a09598
Carlos Lopez a09598
	return ValueBase();
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
Layer::Vocab
Carlos Lopez a09598
SuperSample::get_param_vocab(void)const
Carlos Lopez a09598
{
Carlos Lopez a09598
	Layer::Vocab ret;
Carlos Lopez a09598
Carlos Lopez a09598
	ret.push_back(ParamDesc("width")
Carlos Lopez a09598
		.set_local_name(_("Width"))
Carlos Lopez a09598
		.set_description(_("Width of sample area (In pixels)"))
Carlos Lopez a09598
	);
Carlos Lopez a09598
	ret.push_back(ParamDesc("height")
Carlos Lopez a09598
		.set_local_name(_("Height"))
Carlos Lopez a09598
		.set_description(_("Height of sample area (In pixels)"))
Carlos Lopez a09598
	);
Carlos Lopez a09598
	ret.push_back(ParamDesc("scanline")
Carlos Lopez a09598
		.set_local_name(_("Use Parametric"))
Carlos Lopez a09598
		.set_description(_("Use the Parametric Renderer"))
Carlos Lopez a09598
	);
Carlos Lopez a09598
	ret.push_back(ParamDesc("alpha_aware")
Carlos Lopez a09598
		.set_local_name(_("Be Alpha Safe"))
Carlos Lopez 42e8f2
		.set_description(_("Avoid alpha artifacts when checked"))
Carlos Lopez a09598
	);
Carlos Lopez a09598
Carlos Lopez a09598
	return ret;
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
Rect
Carlos Lopez a09598
SuperSample::get_bounding_rect(Context context)const
Carlos Lopez a09598
{
Carlos Lopez a09598
	return context.get_full_bounding_rect();
Carlos Lopez a09598
}
79c3b0
79c3b0
rendering::Task::Handle
79c3b0
SuperSample::build_rendering_task_vfunc(Context context)const
79c3b0
{
79c3b0
	int width = param_width.get(int());
79c3b0
	int height = param_height.get(int());
79c3b0
	if (width < 1) width = 1;
79c3b0
	if (height < 1) height = 1;
79c3b0
79c3b0
	rendering::Task::Handle sub_task = context.build_rendering_task();
79c3b0
	if (width == 1 && height == 1)
79c3b0
		return sub_task;
79c3b0
79c3b0
	rendering::TaskTransformationAffine::Handle task_transformation(new rendering::TaskTransformationAffine());
79c3b0
	task_transformation->supersample[0] = width;
79c3b0
	task_transformation->supersample[1] = height;
79c3b0
	task_transformation->sub_task() = sub_task;
79c3b0
	return task_transformation;
79c3b0
}