|
Carlos Lopez |
a09598 |
/* === S Y N F I G ========================================================= */
|
|
Carlos Lopez |
a09598 |
/*! \file mod_filter/blur.cpp
|
|
Carlos Lopez |
a09598 |
** \brief Implementation of the "Blur" 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 |
a09598 |
** Copyright (c) 2008 Chris Moore
|
|
Carlos Lopez |
e83454 |
** Copyright (c) 2012-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 |
/* ========================================================================= */
|
|
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 |
|
|
|
2be551 |
#include <cstring></cstring>
|
|
|
2be551 |
|
|
Carlos Lopez |
a09598 |
#include "blur.h"
|
|
Carlos Lopez |
a09598 |
|
|
bw |
94d8a6 |
#include <synfig localization.h=""></synfig>
|
|
bw |
94d8a6 |
#include <synfig general.h=""></synfig>
|
|
bw |
94d8a6 |
|
|
Carlos Lopez |
a09598 |
#include <synfig string.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig time.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig context.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig paramdesc.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig renddesc.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig surface.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig value.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig valuenode.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig segment.h=""></synfig>
|
|
Carlos Lopez |
d33a97 |
#include <synfig cairo_renddesc.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
|
|
|
2be551 |
#include <synfig common="" rendering="" task="" taskblend.h=""></synfig>
|
|
|
2be551 |
#include <synfig common="" rendering="" task="" taskblur.h=""></synfig>
|
|
|
7ef4d4 |
#include <synfig blur.h="" function="" rendering="" software=""></synfig>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#endif
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
using namespace synfig;
|
|
Carlos Lopez |
a09598 |
using namespace etl;
|
|
Carlos Lopez |
a09598 |
using namespace std;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*#define TYPE_BOX 0
|
|
Carlos Lopez |
a09598 |
#define TYPE_FASTGUASSIAN 1
|
|
Carlos Lopez |
a09598 |
#define TYPE_FASTGAUSSIAN 1
|
|
Carlos Lopez |
a09598 |
#define TYPE_CROSS 2
|
|
Carlos Lopez |
a09598 |
#define TYPE_GUASSIAN 3
|
|
Carlos Lopez |
a09598 |
#define TYPE_GAUSSIAN 3
|
|
Carlos Lopez |
a09598 |
#define TYPE_DISC 4
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* -- G L O B A L S --------------------------------------------------------- */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_INIT(Blur_Layer);
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_SET_NAME(Blur_Layer,"blur");
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_SET_LOCAL_NAME(Blur_Layer,N_("Blur"));
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_SET_CATEGORY(Blur_Layer,N_("Blurs"));
|
|
|
7ef4d4 |
SYNFIG_LAYER_SET_VERSION(Blur_Layer,"0.3");
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_SET_CVS_ID(Blur_Layer,"$Id$");
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* -- F U N C T I O N S ----------------------------------------------------- */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
inline void clamp(synfig::Vector &v)
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
if(v[0]<0.0)v[0]=0.0;
|
|
Carlos Lopez |
a09598 |
if(v[1]<0.0)v[1]=0.0;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Blur_Layer::Blur_Layer():
|
|
|
e222d9 |
Layer_CompositeFork(1.0,Color::BLEND_STRAIGHT),
|
|
Carlos Lopez |
df5b93 |
param_size(ValueBase(Point(0.1,0.1))),
|
|
Carlos Lopez |
df5b93 |
param_type(ValueBase(int(Blur::FASTGAUSSIAN)))
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
df5b93 |
SET_INTERPOLATION_DEFAULTS();
|
|
Carlos Lopez |
df5b93 |
SET_STATIC_DEFAULTS();
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
bool
|
|
Carlos Lopez |
a09598 |
Blur_Layer::set_param(const String ¶m, const ValueBase &value)
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
df5b93 |
IMPORT_VALUE_PLUS(param_size,
|
|
Carlos Lopez |
df5b93 |
{
|
|
Carlos Lopez |
df5b93 |
synfig::Point size=param_size.get(Point());
|
|
Carlos Lopez |
df5b93 |
clamp(size);
|
|
Carlos Lopez |
df5b93 |
param_size.set(size);
|
|
Carlos Lopez |
df5b93 |
});
|
|
Carlos Lopez |
df5b93 |
|
|
Carlos Lopez |
df5b93 |
IMPORT_VALUE(param_type);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return Layer_Composite::set_param(param,value);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
ValueBase
|
|
Carlos Lopez |
a09598 |
Blur_Layer::get_param(const String ¶m)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
df5b93 |
EXPORT_VALUE(param_size);
|
|
Carlos Lopez |
df5b93 |
EXPORT_VALUE(param_type);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
EXPORT_NAME();
|
|
Carlos Lopez |
a09598 |
EXPORT_VERSION();
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return Layer_Composite::get_param(param);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Color
|
|
Carlos Lopez |
a09598 |
Blur_Layer::get_color(Context context, const Point &pos)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
df5b93 |
synfig::Point size=param_size.get(Point());
|
|
Carlos Lopez |
df5b93 |
int type=param_type.get(int());
|
|
|
7ef4d4 |
size *= rendering::software::Blur::get_size_amplifier((rendering::Blur::Type)type)
|
|
|
7ef4d4 |
* ::Blur::get_size_amplifier(type);
|
|
Carlos Lopez |
df5b93 |
|
|
Carlos Lopez |
a09598 |
Point blurpos = Blur(size,type)(pos);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
|
|
Carlos Lopez |
a09598 |
return context.get_color(blurpos);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
if(get_amount()==0.0)
|
|
Carlos Lopez |
a09598 |
return context.get_color(pos);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return Color::blend(context.get_color(blurpos),context.get_color(pos),get_amount(),get_blend_method());
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Layer::Vocab
|
|
Carlos Lopez |
a09598 |
Blur_Layer::get_param_vocab(void)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
Layer::Vocab ret(Layer_Composite::get_param_vocab());
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
ret.push_back(ParamDesc("size")
|
|
Carlos Lopez |
a09598 |
.set_local_name(_("Size"))
|
|
Carlos Lopez |
a09598 |
.set_description(_("Size of Blur"))
|
|
Carlos Lopez |
a09598 |
);
|
|
Carlos Lopez |
a09598 |
ret.push_back(ParamDesc("type")
|
|
Carlos Lopez |
a09598 |
.set_local_name(_("Type"))
|
|
Carlos Lopez |
a09598 |
.set_description(_("Type of blur to use"))
|
|
Carlos Lopez |
a09598 |
.set_hint("enum")
|
|
Carlos Lopez |
a09598 |
.add_enum_value(Blur::BOX,"box",_("Box Blur"))
|
|
Carlos Lopez |
a09598 |
.add_enum_value(Blur::FASTGAUSSIAN,"fastgaussian",_("Fast Gaussian Blur"))
|
|
Carlos Lopez |
a09598 |
.add_enum_value(Blur::CROSS,"cross",_("Cross-Hatch Blur"))
|
|
Carlos Lopez |
a09598 |
.add_enum_value(Blur::GAUSSIAN,"gaussian",_("Gaussian Blur"))
|
|
Carlos Lopez |
a09598 |
.add_enum_value(Blur::DISC,"disc",_("Disc Blur"))
|
|
Carlos Lopez |
a09598 |
);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return ret;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Rect
|
|
Carlos Lopez |
a09598 |
Blur_Layer::get_full_bounding_rect(Context context)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
df5b93 |
synfig::Point size=param_size.get(Point());
|
|
|
7ef4d4 |
int type=param_type.get(int());
|
|
|
7ef4d4 |
size *= rendering::software::Blur::get_size_amplifier((rendering::Blur::Type)type)
|
|
|
7ef4d4 |
* ::Blur::get_size_amplifier(type);
|
|
Carlos Lopez |
df5b93 |
|
|
Carlos Lopez |
a09598 |
if(is_disabled() || Color::is_onto(get_blend_method()))
|
|
Carlos Lopez |
a09598 |
return context.get_full_bounding_rect();
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Rect bounds(context.get_full_bounding_rect().expand_x(size[0]).expand_y(size[1]));
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return bounds;
|
|
Carlos Lopez |
a09598 |
}
|
|
|
2be551 |
|
|
|
2be551 |
rendering::Task::Handle
|
|
|
e222d9 |
Blur_Layer::build_composite_fork_task_vfunc(ContextParams /* context_params */, rendering::Task::Handle sub_task)const
|
|
|
2be551 |
{
|
|
|
2be551 |
Vector size = param_size.get(Point());
|
|
|
7ef4d4 |
rendering::Blur::Type type = (rendering::Blur::Type)param_type.get(int());
|
|
|
7ef4d4 |
|
|
|
2be551 |
rendering::TaskBlur::Handle task_blur(new rendering::TaskBlur());
|
|
|
7ef4d4 |
task_blur->blur.size = size;
|
|
|
7ef4d4 |
task_blur->blur.type = type;
|
|
|
8964ca |
task_blur->sub_task() = sub_task ? sub_task->clone_recursive() : rendering::Task::Handle();
|
|
|
2be551 |
|
|
|
2be551 |
return task_blur;
|
|
|
2be551 |
}
|