|
Carlos Lopez |
a09598 |
/* === S Y N F I G ========================================================= */
|
|
Carlos Lopez |
a09598 |
/*! \file layer_composite.cpp
|
|
Carlos Lopez |
a09598 |
** \brief Template File
|
|
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) 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 |
/* ========================================================================= */
|
|
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 |
|
|
|
8bbd89 |
#include <synfig general.h=""></synfig>
|
|
bw |
94d8a6 |
#include <synfig localization.h=""></synfig>
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig context.h=""></synfig>
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig time.h=""></synfig>
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig color.h=""></synfig>
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig surface.h=""></synfig>
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig renddesc.h=""></synfig>
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig target.h=""></synfig>
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig render.h=""></synfig>
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig paramdesc.h=""></synfig>
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig cairo_renddesc.h=""></synfig>
|
|
Carlos Lopez |
a4a229 |
|
|
|
8bbd89 |
#include "layer_composite.h"
|
|
|
8bbd89 |
|
|
|
8bbd89 |
#include "layer_pastecanvas.h"
|
|
|
8bbd89 |
#include "layer_bitmap.h"
|
|
|
8bbd89 |
#include <synfig common="" rendering="" task="" taskblend.h=""></synfig>
|
|
|
c78990 |
#include <synfig common="" rendering="" task="" tasklayer.h=""></synfig>
|
|
|
da01ef |
#include <synfig rendering="" software="" surfacesw.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#endif
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === U S I N G =========================================================== */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
using namespace std;
|
|
Carlos Lopez |
a09598 |
using namespace etl;
|
|
Carlos Lopez |
a09598 |
using namespace synfig;
|
|
Carlos Lopez |
a09598 |
|
|
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 |
/* === 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 |
7d86f4 |
Layer_Composite::Layer_Composite(Real a, Color::BlendMethod bm):
|
|
Carlos Lopez |
7d86f4 |
param_amount (a),
|
|
|
d89783 |
param_blend_method ((int)Color::BlendMethod(bm)),
|
|
Carlos Lopez |
18bd95 |
converted_blend_ (false),
|
|
Carlos Lopez |
18bd95 |
transparent_color_ (false)
|
|
Carlos Lopez |
18bd95 |
{
|
|
Carlos Lopez |
b3fcc2 |
SET_INTERPOLATION_DEFAULTS();
|
|
Carlos Lopez |
b3fcc2 |
SET_STATIC_DEFAULTS();
|
|
Carlos Lopez |
18bd95 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Rect
|
|
Carlos Lopez |
a09598 |
Layer_Composite::get_full_bounding_rect(Context context)const
|
|
Carlos Lopez |
a09598 |
{
|
|
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 |
return context.get_full_bounding_rect()|get_bounding_rect();
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Layer::Vocab
|
|
Carlos Lopez |
a09598 |
Layer_Composite::get_param_vocab()const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
5ea9ef |
//! First fills the returning vocabulary with the ancestor class
|
|
Carlos Lopez |
a09598 |
Layer::Vocab ret(Layer::get_param_vocab());
|
|
Carlos Lopez |
5ea9ef |
//! Now inserts the two parameters that this layer knows.
|
|
Carlos Lopez |
7d86f4 |
ret.push_back(ParamDesc(param_amount,"amount")
|
|
|
b8e722 |
.set_local_name(_("Opacity"))
|
|
Carlos Lopez |
42e8f2 |
.set_description(_("Alpha channel of the layer"))
|
|
Carlos Lopez |
a09598 |
);
|
|
Carlos Lopez |
7d86f4 |
ret.push_back(ParamDesc(param_blend_method,"blend_method")
|
|
Carlos Lopez |
a09598 |
.set_local_name(_("Blend Method"))
|
|
Carlos Lopez |
42e8f2 |
.set_description(_("The blending method used to composite on the layers below"))
|
|
Carlos Lopez |
619970 |
.set_static(true)
|
|
Carlos Lopez |
a09598 |
);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return ret;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
bool
|
|
Carlos Lopez |
a09598 |
Layer_Composite::set_param(const String & param, const ValueBase &value)
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
7d86f4 |
IMPORT_VALUE(param_amount)
|
|
Carlos Lopez |
7d86f4 |
IMPORT_VALUE_PLUS(param_blend_method,
|
|
Carlos Lopez |
7d86f4 |
Color::BlendMethod blend_method = static_cast<color::blendmethod>(value.get(int()));</color::blendmethod>
|
|
Carlos Lopez |
18bd95 |
if (blend_method < 0 || blend_method >= Color::BLEND_END)
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
18bd95 |
warning("illegal value (%d) for blend_method - using Composite instead", blend_method);
|
|
|
d89783 |
param_blend_method.set((int)Color::BLEND_COMPOSITE);
|
|
Carlos Lopez |
a09598 |
return false;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
18bd95 |
if (blend_method == Color::BLEND_STRAIGHT && !reads_context())
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
Canvas::Handle canvas(get_canvas());
|
|
Carlos Lopez |
a09598 |
if (canvas)
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
String version(canvas->get_version());
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
if (version == "0.1" || version == "0.2")
|
|
Carlos Lopez |
a09598 |
{
|
|
|
a53027 |
if (dynamic_cast<layer_pastecanvas*>(this) != NULL)</layer_pastecanvas*>
|
|
Carlos Lopez |
a09598 |
warning("loaded a version %s canvas with a 'Straight' blended PasteCanvas (%s) - check it renders OK",
|
|
Carlos Lopez |
a09598 |
version.c_str(), get_non_empty_description().c_str());
|
|
Carlos Lopez |
a09598 |
else
|
|
Carlos Lopez |
a09598 |
{
|
|
|
d89783 |
param_blend_method.set(int(Color::BLEND_COMPOSITE));
|
|
Carlos Lopez |
a09598 |
converted_blend_ = true;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
// if this layer has a transparent color, go back and set the color again
|
|
Carlos Lopez |
a09598 |
// now that we know we are converting the blend method as well. that will
|
|
Carlos Lopez |
a09598 |
// make the color non-transparent, and change the blend method to alpha over
|
|
Carlos Lopez |
a09598 |
if (transparent_color_)
|
|
Carlos Lopez |
a09598 |
set_param("color", get_param("color"));
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
7d86f4 |
);
|
|
Carlos Lopez |
7d86f4 |
|
|
Carlos Lopez |
7d86f4 |
return Layer::set_param(param,value);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
ValueBase
|
|
Carlos Lopez |
a09598 |
Layer_Composite::get_param(const String & param)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
e6b894 |
|
|
Carlos Lopez |
7d86f4 |
EXPORT_VALUE(param_amount)
|
|
Carlos Lopez |
7d86f4 |
EXPORT_VALUE(param_blend_method)
|
|
Carlos Lopez |
5ea9ef |
//! If it is unknown then call the ancestor's get param member
|
|
Carlos Lopez |
5ea9ef |
//! to see if it can handle that parameter's string.
|
|
Carlos Lopez |
a09598 |
return Layer::get_param(param);
|
|
Carlos Lopez |
a09598 |
}
|
|
|
8bbd89 |
|
|
|
8bbd89 |
rendering::Task::Handle
|
|
|
8bbd89 |
Layer_Composite::build_composite_task_vfunc(ContextParams /*context_params*/)const
|
|
|
8bbd89 |
{
|
|
|
516c51 |
return new rendering::TaskLayer();
|
|
|
516c51 |
//rendering::TaskLayer::Handle task = new rendering::TaskLayer();
|
|
|
516c51 |
//// TODO: This is not thread-safe
|
|
|
516c51 |
//task->layer = const_cast<layer_composite*>(this);//clone(NULL);</layer_composite*>
|
|
|
516c51 |
//return task;
|
|
|
e222d9 |
}
|
|
|
e222d9 |
|
|
|
e222d9 |
rendering::Task::Handle
|
|
|
8bbd89 |
Layer_Composite::build_rendering_task_vfunc(Context context)const
|
|
|
8bbd89 |
{
|
|
|
516c51 |
rendering::Task::Handle sub_task = build_composite_task_vfunc(context.get_params());
|
|
|
516c51 |
if (sub_task.type_is<rendering::tasklayer>())</rendering::tasklayer>
|
|
|
516c51 |
return Layer::build_rendering_task_vfunc(context);
|
|
|
739062 |
|
|
|
8bbd89 |
rendering::TaskBlend::Handle task_blend(new rendering::TaskBlend());
|
|
|
5e7eb6 |
task_blend->amount = get_amount() * Context::z_depth_visibility(context.get_params(), *this);
|
|
|
8bbd89 |
task_blend->blend_method = get_blend_method();
|
|
|
516c51 |
task_blend->sub_task_a() = context.build_rendering_task();
|
|
|
516c51 |
task_blend->sub_task_b() = sub_task;
|
|
|
8bbd89 |
return task_blend;
|
|
|
8bbd89 |
}
|