From a94d4956d42ef7e495e2933f9c62e14380c075bb Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Feb 23 2016 09:05:15 +0000 Subject: Cobra support for layers Clamp and ColorCorrect --- diff --git a/synfig-core/src/modules/lyr_std/clamp.cpp b/synfig-core/src/modules/lyr_std/clamp.cpp index 20d503d..9bde682 100644 --- a/synfig-core/src/modules/lyr_std/clamp.cpp +++ b/synfig-core/src/modules/lyr_std/clamp.cpp @@ -44,6 +44,8 @@ #include #include +#include + #endif /* === U S I N G =========================================================== */ @@ -223,3 +225,15 @@ Layer_Clamp::get_full_bounding_rect(Context context)const { return context.get_full_bounding_rect(); } + +rendering::Task::Handle +Layer_Clamp::build_rendering_task_vfunc(Context context)const +{ + rendering::TaskClamp::Handle task_clamp(new rendering::TaskClamp()); + task_clamp->invert_negative = param_invert_negative.get(bool()); + task_clamp->clamp_ceiling = param_clamp_ceiling.get(bool()); + task_clamp->floor = param_floor.get(Real()); + task_clamp->ceiling = param_ceiling.get(Real()); + task_clamp->sub_task() = context.build_rendering_task(); + return task_clamp; +} diff --git a/synfig-core/src/modules/lyr_std/clamp.h b/synfig-core/src/modules/lyr_std/clamp.h index 89761c1..2d0a569 100644 --- a/synfig-core/src/modules/lyr_std/clamp.h +++ b/synfig-core/src/modules/lyr_std/clamp.h @@ -74,6 +74,8 @@ public: virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const; virtual Vocab get_param_vocab()const; + + virtual rendering::Task::Handle build_rendering_task_vfunc(Context context)const; }; // END of class Layer_Clamp }; // END of namespace lyr_std diff --git a/synfig-core/src/modules/mod_filter/colorcorrect.cpp b/synfig-core/src/modules/mod_filter/colorcorrect.cpp index 6727c66..18519b4 100644 --- a/synfig-core/src/modules/mod_filter/colorcorrect.cpp +++ b/synfig-core/src/modules/mod_filter/colorcorrect.cpp @@ -44,6 +44,8 @@ #include #include +#include + #endif /* === U S I N G =========================================================== */ @@ -333,3 +335,16 @@ Layer_ColorCorrect::get_full_bounding_rect(Context context)const { return context.get_full_bounding_rect(); } + +rendering::Task::Handle +Layer_ColorCorrect::build_rendering_task_vfunc(Context context)const +{ + rendering::TaskColorCorrect::Handle task_color_correct(new rendering::TaskColorCorrect()); + task_color_correct->hue_adjust = param_hue_adjust.get(Angle()); + task_color_correct->brightness = param_brightness.get(Real()); + task_color_correct->contrast = param_contrast.get(Real()); + task_color_correct->exposure = param_exposure.get(Real()); + task_color_correct->gamma = param_gamma.get(Real()); + task_color_correct->sub_task() = context.build_rendering_task(); + return task_color_correct; +} diff --git a/synfig-core/src/modules/mod_filter/colorcorrect.h b/synfig-core/src/modules/mod_filter/colorcorrect.h index 1f987d9..f31883e 100644 --- a/synfig-core/src/modules/mod_filter/colorcorrect.h +++ b/synfig-core/src/modules/mod_filter/colorcorrect.h @@ -78,6 +78,8 @@ public: virtual bool accelerated_cairorender(Context context,cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const; virtual Vocab get_param_vocab()const; + + virtual rendering::Task::Handle build_rendering_task_vfunc(Context context)const; }; // END of class Layer_ColorCorrect }; // END of namespace synfig diff --git a/synfig-core/src/synfig/rendering/Makefile_insert b/synfig-core/src/synfig/rendering/Makefile_insert index f34d0fe..e0fce71 100644 --- a/synfig-core/src/synfig/rendering/Makefile_insert +++ b/synfig-core/src/synfig/rendering/Makefile_insert @@ -18,6 +18,7 @@ include rendering/common/Makefile_insert if WITH_OPENGL include rendering/opengl/Makefile_insert endif +include rendering/module/Makefile_insert include rendering/primitive/Makefile_insert include rendering/software/Makefile_insert diff --git a/synfig-core/src/synfig/rendering/common/optimizer/Makefile_insert b/synfig-core/src/synfig/rendering/common/optimizer/Makefile_insert index cd779b1..5630302 100644 --- a/synfig-core/src/synfig/rendering/common/optimizer/Makefile_insert +++ b/synfig-core/src/synfig/rendering/common/optimizer/Makefile_insert @@ -8,6 +8,7 @@ RENDERING_COMMON_OPTIMIZER_HH = \ rendering/common/optimizer/optimizercalcbounds.h \ rendering/common/optimizer/optimizerlinear.h \ rendering/common/optimizer/optimizerlist.h \ + rendering/common/optimizer/optimizerpixelprocessorsplit.h \ rendering/common/optimizer/optimizersplit.h \ rendering/common/optimizer/optimizersurface.h \ rendering/common/optimizer/optimizersurfaceconvert.h \ @@ -27,6 +28,7 @@ RENDERING_COMMON_OPTIMIZER_CC = \ rendering/common/optimizer/optimizercalcbounds.cpp \ rendering/common/optimizer/optimizerlinear.cpp \ rendering/common/optimizer/optimizerlist.cpp \ + rendering/common/optimizer/optimizerpixelprocessorsplit.cpp \ rendering/common/optimizer/optimizersplit.cpp \ rendering/common/optimizer/optimizersurface.cpp \ rendering/common/optimizer/optimizersurfaceconvert.cpp \ diff --git a/synfig-core/src/synfig/rendering/common/optimizer/optimizerpixelprocessorsplit.cpp b/synfig-core/src/synfig/rendering/common/optimizer/optimizerpixelprocessorsplit.cpp new file mode 100644 index 0000000..0665c94 --- /dev/null +++ b/synfig-core/src/synfig/rendering/common/optimizer/optimizerpixelprocessorsplit.cpp @@ -0,0 +1,156 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/common/optimizer/optimizerpixelprocessorsplit.cpp +** \brief OptimizerPixelProcessorSplit +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef _WIN32 +#include +#include +#include +#endif + +#include +#include + +#include "optimizerpixelprocessorsplit.h" + +#include "../task/taskpixelprocessor.h" +#include "../task/tasklist.h" + +#endif + +using namespace synfig; +using namespace rendering; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +void +OptimizerPixelProcessorSplit::run(const RunParams& params) const +{ + TaskPixelProcessor::Handle pixelprocesor = TaskPixelProcessor::Handle::cast_dynamic(params.ref_task); + if ( pixelprocesor + && pixelprocesor->target_surface + && pixelprocesor->sub_task() + && pixelprocesor->sub_task()->target_surface + && !pixelprocesor->is_affects_transparent() ) + { + if (TaskList::Handle list = TaskList::Handle::cast_dynamic(pixelprocesor->sub_task())) + { + // try to find dedicated groups + std::vector groups; + for(Task::List::const_iterator i = list->sub_tasks.begin(); i != list->sub_tasks.end(); ++i) + if (*i && (*i)->valid_target()) + groups.push_back((*i)->get_target_rect()); + + #ifndef NDEBUG + int sub_tasks_count = (int)groups.size(); + #endif + + bool retry = true; + while(retry) + { + retry = false; + for(int i = 0; i < (int)groups.size(); ++i) + { + for(int j = i+1; j < (int)groups.size(); ++j) + { + if (etl::intersect(groups[i], groups[j])) + { + etl::set_union(groups[i], groups[i], groups[j]); + groups.erase(groups.begin() + j); + --j; + retry = true; + } + } + } + } + + // split task + if (groups.size() > 1) + { + // create list + TaskList::Handle list; + list = new TaskList(); + assign(list, Task::Handle(pixelprocesor)); + list->sub_tasks.clear(); + + #ifndef NDEBUG + Task::Set processed; + #endif + + // fill list + for(int j = 0; j < (int)groups.size(); ++j) + { + // create sub-pixelprocessor + TaskList::Handle sub_list = TaskList::Handle::cast_dynamic(pixelprocesor->sub_task()->clone()); + sub_list->sub_tasks.clear(); + sub_list->trunc_target_rect(groups[j]); + + RectInt rect = groups[j] + + pixelprocesor->get_target_offset() + + pixelprocesor->get_offset(); + TaskPixelProcessor::Handle sub_pixelprocesor = TaskPixelProcessor::Handle::cast_dynamic(pixelprocesor->clone()); + sub_pixelprocesor->trunc_target_rect(rect); + sub_pixelprocesor->sub_task() = sub_list; + + list->sub_tasks.push_back(sub_pixelprocesor); + + // fill list of sub-pixelprocesor + for(Task::List::const_iterator i = list->sub_tasks.begin(); i != list->sub_tasks.end(); ++i) + if (*i && (*i)->valid_target() && etl::contains(groups[j], (*i)->get_target_rect())) + { + #ifndef NDEBUG + assert(processed.count(*i) == 0); + processed.insert(*i); + #endif + sub_list->sub_tasks.push_back(*i); + } + + // optimization for list with single task + if (sub_list->sub_tasks.size() == 1) + sub_pixelprocesor->sub_task() = sub_list->sub_tasks[0]; + } + + #ifndef NDEBUG + assert((int)processed.size() == sub_tasks_count); + #endif + + apply(params, list); + } + } + } +} + +/* === E N T R Y P O I N T ================================================= */ diff --git a/synfig-core/src/synfig/rendering/common/optimizer/optimizerpixelprocessorsplit.h b/synfig-core/src/synfig/rendering/common/optimizer/optimizerpixelprocessorsplit.h new file mode 100644 index 0000000..04c9616 --- /dev/null +++ b/synfig-core/src/synfig/rendering/common/optimizer/optimizerpixelprocessorsplit.h @@ -0,0 +1,63 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/common/optimizer/optimizerpixelprocessorsplit.h +** \brief OptimizerPixelProcessorSplit Header +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_RENDERING_OPTIMIZERPIXELPROCESSORSPLIT_H +#define __SYNFIG_RENDERING_OPTIMIZERPIXELPROCESSORSPLIT_H + +/* === H E A D E R S ======================================================= */ + +#include "../../optimizer.h" + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig +{ +namespace rendering +{ + +class OptimizerPixelProcessorSplit: public Optimizer +{ +public: + OptimizerPixelProcessorSplit() + { + category_id = CATEGORY_ID_POST_SPECIALIZE; + depends_from = CATEGORY_SPECIALIZE; + mode = MODE_REPEAT_PARENT; + deep_first = true; + for_task = true; + } + + virtual void run(const RunParams ¶ms) const; +}; + +} /* end namespace rendering */ +} /* end namespace synfig */ + +/* -- E N D ----------------------------------------------------------------- */ + +#endif diff --git a/synfig-core/src/synfig/rendering/common/task/Makefile_insert b/synfig-core/src/synfig/rendering/common/task/Makefile_insert index 90a0bfe..36b33d4 100644 --- a/synfig-core/src/synfig/rendering/common/task/Makefile_insert +++ b/synfig-core/src/synfig/rendering/common/task/Makefile_insert @@ -7,6 +7,7 @@ RENDERING_COMMON_TASK_HH = \ rendering/common/task/tasklayer.h \ rendering/common/task/tasklist.h \ rendering/common/task/taskmesh.h \ + rendering/common/task/taskpixelprocessor.h \ rendering/common/task/tasksolid.h \ rendering/common/task/tasksplittable.h \ rendering/common/task/tasksurface.h \ @@ -21,6 +22,7 @@ RENDERING_COMMON_TASK_HH = \ RENDERING_COMMON_TASK_CC = \ rendering/common/task/taskblend.cpp \ rendering/common/task/taskblur.cpp \ + rendering/common/task/taskpixelprocessor.cpp \ rendering/common/task/tasksurfaceconvert.cpp \ rendering/common/task/tasksurfacecreate.cpp \ rendering/common/task/tasksurfacedestroy.cpp \ diff --git a/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.cpp b/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.cpp new file mode 100644 index 0000000..1993abb --- /dev/null +++ b/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.cpp @@ -0,0 +1,69 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/common/task/taskpixelprocessor.cpp +** \brief TaskPixelProcessor +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef _WIN32 +#include +#include +#include +#endif + +#include "taskpixelprocessor.h" + +#endif + +using namespace synfig; +using namespace rendering; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +Rect +TaskPixelProcessor::calc_bounds() const +{ + return is_affects_transparent() ? Rect::infinite() + : sub_task() ? sub_task()->get_bounds() + : Rect::zero(); +} + +VectorInt +TaskPixelProcessor::get_offset() const +{ + if (!sub_task()) return VectorInt::zero(); + Vector offset = (sub_task()->get_source_rect_lt() - get_source_rect_lt()).multiply_coords(get_pixels_per_unit()); + return VectorInt((int)round(offset[0]), (int)round(offset[1])) - sub_task()->get_target_offset(); +} + +/* === E N T R Y P O I N T ================================================= */ diff --git a/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.h b/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.h new file mode 100644 index 0000000..beb480f --- /dev/null +++ b/synfig-core/src/synfig/rendering/common/task/taskpixelprocessor.h @@ -0,0 +1,65 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/common/task/taskpixelprocessor.h +** \brief TaskPixelProcessor Header +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_RENDERING_TASKPIXELPROCESSOR_H +#define __SYNFIG_RENDERING_TASKPIXELPROCESSOR_H + +/* === H E A D E R S ======================================================= */ + +#include "../../task.h" + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig +{ +namespace rendering +{ + +class TaskPixelProcessor: public Task +{ +public: + typedef etl::handle Handle; + + TaskPixelProcessor() { } + Task::Handle clone() const { return clone_pointer(this); } + + const Task::Handle& sub_task() const { return Task::sub_task(0); } + Task::Handle& sub_task() { return Task::sub_task(0); } + + VectorInt get_offset() const; + + virtual Rect calc_bounds() const; + virtual bool is_affects_transparent() const { return false; } +}; + +} /* end namespace rendering */ +} /* end namespace synfig */ + +/* -- E N D ----------------------------------------------------------------- */ + +#endif diff --git a/synfig-core/src/synfig/rendering/module/Makefile_insert b/synfig-core/src/synfig/rendering/module/Makefile_insert new file mode 100644 index 0000000..02a8e51 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/Makefile_insert @@ -0,0 +1,13 @@ +RENDERING_MODULE_HH = + +RENDERING_MODULE_CC = + +include rendering/module/common/Makefile_insert +include rendering/module/software/Makefile_insert + +RENDERING_HH += \ + $(RENDERING_MODULE_HH) + +RENDERING_CC += \ + $(RENDERING_MODULE_CC) + diff --git a/synfig-core/src/synfig/rendering/module/common/Makefile_insert b/synfig-core/src/synfig/rendering/module/common/Makefile_insert new file mode 100644 index 0000000..da9d398 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/common/Makefile_insert @@ -0,0 +1,12 @@ +RENDERING_MODULE_COMMON_HH = + +RENDERING_MODULE_COMMON_CC = + +include rendering/module/common/task/Makefile_insert + +RENDERING_MODULE_HH += \ + $(RENDERING_MODULE_COMMON_HH) + +RENDERING_MODULE_CC += \ + $(RENDERING_MODULE_COMMON_CC) + diff --git a/synfig-core/src/synfig/rendering/module/common/task/Makefile_insert b/synfig-core/src/synfig/rendering/module/common/task/Makefile_insert new file mode 100644 index 0000000..784f1ad --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/common/task/Makefile_insert @@ -0,0 +1,12 @@ +RENDERING_MODULE_COMMON_TASK_HH = \ + rendering/module/common/task/taskclamp.h \ + rendering/module/common/task/taskcolorcorrect.h + +RENDERING_MODULE_COMMON_TASK_CC = + +RENDERING_MODULE_COMMON_HH += \ + $(RENDERING_MODULE_COMMON_TASK_HH) + +RENDERING_MODULE_COMMON_CC += \ + $(RENDERING_MODULE_COMMON_TASK_CC) + diff --git a/synfig-core/src/synfig/rendering/module/common/task/taskclamp.h b/synfig-core/src/synfig/rendering/module/common/task/taskclamp.h new file mode 100644 index 0000000..881c888 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/common/task/taskclamp.h @@ -0,0 +1,68 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/common/task/taskclamp.h +** \brief TaskClamp Header +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_RENDERING_MODULE_TASKCLAMP_H +#define __SYNFIG_RENDERING_MODULE_TASKCLAMP_H + +/* === H E A D E R S ======================================================= */ + +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig +{ +namespace rendering +{ + +class TaskClamp: public TaskPixelProcessor +{ +public: + typedef etl::handle Handle; + + bool invert_negative; + bool clamp_floor; + bool clamp_ceiling; + Real floor; + Real ceiling; + + TaskClamp(): + invert_negative(false), + clamp_floor(true), + clamp_ceiling(true), + floor(0.0), + ceiling(1.0) { } + Task::Handle clone() const { return clone_pointer(this); } +}; + +} /* end namespace rendering */ +} /* end namespace synfig */ + +/* -- E N D ----------------------------------------------------------------- */ + +#endif diff --git a/synfig-core/src/synfig/rendering/module/common/task/taskcolorcorrect.h b/synfig-core/src/synfig/rendering/module/common/task/taskcolorcorrect.h new file mode 100644 index 0000000..e922a13 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/common/task/taskcolorcorrect.h @@ -0,0 +1,68 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/common/task/taskcolorcorrect.h +** \brief TaskColorCorrect Header +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_RENDERING_MODULE_TASKCOLORCORRECT_H +#define __SYNFIG_RENDERING_MODULE_TASKCOLORCORRECT_H + +/* === H E A D E R S ======================================================= */ + +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig +{ +namespace rendering +{ + +class TaskColorCorrect: public TaskPixelProcessor +{ +public: + typedef etl::handle Handle; + + Angle hue_adjust; + Real brightness; + Real contrast; + Real exposure; + Real gamma; + + TaskColorCorrect(): + hue_adjust(Angle::zero()), + brightness(0.0), + contrast(1.0), + exposure(0.0), + gamma(1.0) { } + Task::Handle clone() const { return clone_pointer(this); } +}; + +} /* end namespace rendering */ +} /* end namespace synfig */ + +/* -- E N D ----------------------------------------------------------------- */ + +#endif diff --git a/synfig-core/src/synfig/rendering/module/software/Makefile_insert b/synfig-core/src/synfig/rendering/module/software/Makefile_insert new file mode 100644 index 0000000..d82d9c3 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/Makefile_insert @@ -0,0 +1,13 @@ +RENDERING_MODULE_SOFTWARE_HH = + +RENDERING_MODULE_SOFTWARE_CC = + +include rendering/module/software/optimizer/Makefile_insert +include rendering/module/software/task/Makefile_insert + +RENDERING_MODULE_HH += \ + $(RENDERING_MODULE_SOFTWARE_HH) + +RENDERING_MODULE_CC += \ + $(RENDERING_MODULE_SOFTWARE_CC) + diff --git a/synfig-core/src/synfig/rendering/module/software/optimizer/Makefile_insert b/synfig-core/src/synfig/rendering/module/software/optimizer/Makefile_insert new file mode 100644 index 0000000..1630763 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/optimizer/Makefile_insert @@ -0,0 +1,14 @@ +RENDERING_MODULE_SOFTWARE_OPTIMIZER_HH = \ + rendering/module/software/optimizer/optimizerclampsw.h \ + rendering/module/software/optimizer/optimizercolorcorrectsw.h + +RENDERING_MODULE_SOFTWARE_OPTIMIZER_CC = \ + rendering/module/software/optimizer/optimizerclampsw.cpp \ + rendering/module/software/optimizer/optimizercolorcorrectsw.cpp + +RENDERING_MODULE_SOFTWARE_HH += \ + $(RENDERING_MODULE_SOFTWARE_OPTIMIZER_HH) + +RENDERING_MODULE_SOFTWARE_CC += \ + $(RENDERING_MODULE_SOFTWARE_OPTIMIZER_CC) + diff --git a/synfig-core/src/synfig/rendering/module/software/optimizer/optimizerclampsw.cpp b/synfig-core/src/synfig/rendering/module/software/optimizer/optimizerclampsw.cpp new file mode 100644 index 0000000..f708a21 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/optimizer/optimizerclampsw.cpp @@ -0,0 +1,89 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/software/optimizer/optimizerclampsw.cpp +** \brief OptimizerClampSW +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef _WIN32 +#include +#include +#include +#endif + +#include "optimizerclampsw.h" + +#include + +#include "../task/taskclampsw.h" + + +#endif + +using namespace synfig; +using namespace rendering; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +void +OptimizerClampSW::run(const RunParams& params) const +{ + TaskClamp::Handle clamp = TaskClamp::Handle::cast_dynamic(params.ref_task); + if ( clamp + && clamp->target_surface + && clamp.type_equal() ) + { + TaskClampSW::Handle clamp_sw; + init_and_assign_all(clamp_sw, clamp); + + // TODO: Are we really need to check 'is_temporary' flag? + if ( clamp_sw->sub_task()->target_surface->is_temporary ) + { + clamp_sw->sub_task()->target_surface = clamp_sw->target_surface; + clamp_sw->sub_task()->move_target_rect( + clamp_sw->get_target_offset() ); + } + else + { + clamp_sw->sub_task()->set_target_origin( VectorInt::zero() ); + clamp_sw->sub_task()->target_surface->set_size( + clamp_sw->sub_task()->get_target_rect().maxx, + clamp_sw->sub_task()->get_target_rect().maxy ); + } + assert( clamp_sw->sub_task()->check() ); + + apply(params, clamp_sw); + } +} + +/* === E N T R Y P O I N T ================================================= */ diff --git a/synfig-core/src/synfig/rendering/module/software/optimizer/optimizerclampsw.h b/synfig-core/src/synfig/rendering/module/software/optimizer/optimizerclampsw.h new file mode 100644 index 0000000..428ec25 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/optimizer/optimizerclampsw.h @@ -0,0 +1,61 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/software/optimizer/optimizerclampsw.h +** \brief OptimizerClampSW Header +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_RENDERING_OPTIMIZERCLAMPSW_H +#define __SYNFIG_RENDERING_OPTIMIZERCLAMPSW_H + +/* === H E A D E R S ======================================================= */ + +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig +{ +namespace rendering +{ + +class OptimizerClampSW: public Optimizer +{ +public: + OptimizerClampSW() + { + category_id = CATEGORY_ID_SPECIALIZE; + depends_from = CATEGORY_COMMON & CATEGORY_PRE_SPECIALIZE; + for_task = true; + } + + virtual void run(const RunParams ¶ms) const; +}; + +} /* end namespace rendering */ +} /* end namespace synfig */ + +/* -- E N D ----------------------------------------------------------------- */ + +#endif diff --git a/synfig-core/src/synfig/rendering/module/software/optimizer/optimizercolorcorrectsw.cpp b/synfig-core/src/synfig/rendering/module/software/optimizer/optimizercolorcorrectsw.cpp new file mode 100644 index 0000000..8361427 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/optimizer/optimizercolorcorrectsw.cpp @@ -0,0 +1,89 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/software/optimizer/optimizercolorcorrectsw.cpp +** \brief OptimizerColorCorrectSW +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef _WIN32 +#include +#include +#include +#endif + +#include "optimizercolorcorrectsw.h" + +#include + +#include "../task/taskcolorcorrectsw.h" + + +#endif + +using namespace synfig; +using namespace rendering; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +void +OptimizerColorCorrectSW::run(const RunParams& params) const +{ + TaskColorCorrect::Handle color_correct = TaskColorCorrect::Handle::cast_dynamic(params.ref_task); + if ( color_correct + && color_correct->target_surface + && color_correct.type_equal() ) + { + TaskColorCorrectSW::Handle color_correct_sw; + init_and_assign_all(color_correct_sw, color_correct); + + // TODO: Are we really need to check 'is_temporary' flag? + if ( color_correct_sw->sub_task()->target_surface->is_temporary ) + { + color_correct_sw->sub_task()->target_surface = color_correct_sw->target_surface; + color_correct_sw->sub_task()->move_target_rect( + color_correct_sw->get_target_offset() ); + } + else + { + color_correct_sw->sub_task()->set_target_origin( VectorInt::zero() ); + color_correct_sw->sub_task()->target_surface->set_size( + color_correct_sw->sub_task()->get_target_rect().maxx, + color_correct_sw->sub_task()->get_target_rect().maxy ); + } + assert( color_correct_sw->sub_task()->check() ); + + apply(params, color_correct_sw); + } +} + +/* === E N T R Y P O I N T ================================================= */ diff --git a/synfig-core/src/synfig/rendering/module/software/optimizer/optimizercolorcorrectsw.h b/synfig-core/src/synfig/rendering/module/software/optimizer/optimizercolorcorrectsw.h new file mode 100644 index 0000000..2ce850e --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/optimizer/optimizercolorcorrectsw.h @@ -0,0 +1,61 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/software/optimizer/optimizercolorcorrectsw.h +** \brief OptimizerColorCorrectSW Header +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_RENDERING_OPTIMIZERCOLORCORRECTSW_H +#define __SYNFIG_RENDERING_OPTIMIZERCOLORCORRECTSW_H + +/* === H E A D E R S ======================================================= */ + +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig +{ +namespace rendering +{ + +class OptimizerColorCorrectSW: public Optimizer +{ +public: + OptimizerColorCorrectSW() + { + category_id = CATEGORY_ID_SPECIALIZE; + depends_from = CATEGORY_COMMON & CATEGORY_PRE_SPECIALIZE; + for_task = true; + } + + virtual void run(const RunParams ¶ms) const; +}; + +} /* end namespace rendering */ +} /* end namespace synfig */ + +/* -- E N D ----------------------------------------------------------------- */ + +#endif diff --git a/synfig-core/src/synfig/rendering/module/software/task/Makefile_insert b/synfig-core/src/synfig/rendering/module/software/task/Makefile_insert new file mode 100644 index 0000000..8ad3c03 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/task/Makefile_insert @@ -0,0 +1,14 @@ +RENDERING_MODULE_SOFTWARE_TASK_HH = \ + rendering/module/software/task/taskclampsw.h \ + rendering/module/software/task/taskcolorcorrectsw.h + +RENDERING_MODULE_SOFTWARE_TASK_CC = \ + rendering/module/software/task/taskclampsw.cpp \ + rendering/module/software/task/taskcolorcorrectsw.cpp + +RENDERING_MODULE_SOFTWARE_HH += \ + $(RENDERING_MODULE_SOFTWARE_TASK_HH) + +RENDERING_MODULE_SOFTWARE_CC += \ + $(RENDERING_MODULE_SOFTWARE_TASK_CC) + diff --git a/synfig-core/src/synfig/rendering/module/software/task/taskclampsw.cpp b/synfig-core/src/synfig/rendering/module/software/task/taskclampsw.cpp new file mode 100644 index 0000000..13ace1c --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/task/taskclampsw.cpp @@ -0,0 +1,163 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/software/task/taskclampsw.cpp +** \brief TaskClampSW +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef _WIN32 +#include +#include +#include +#endif + +#include +#include + +#include "taskclampsw.h" + +#include +#include + +#endif + +using namespace synfig; +using namespace rendering; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +void +TaskClampSW::split(const RectInt &sub_target_rect) +{ + trunc_target_rect(sub_target_rect); + if (valid_target() && sub_task() && sub_task()->valid_target()) + { + sub_task() = sub_task()->clone(); + sub_task()->trunc_target_rect( + get_target_rect() + - get_target_offset() + - get_offset() ); + } +} + +void +TaskClampSW::clamp_pixel(Color &dst, const Color &src) const +{ + if (fabs(src.get_a()) < 1e-8) + { dst = Color::alpha(); return; } + + dst = src; + + if (invert_negative) + { + if (dst.get_a() < floor) + dst = -dst; + + if(dst.get_r() < floor) + { + dst.set_g(dst.get_g() - dst.get_r()); + dst.set_b(dst.get_b() - dst.get_r()); + dst.set_r(floor); + } + + if(dst.get_g() < floor) + { + dst.set_r(dst.get_r() - dst.get_g()); + dst.set_b(dst.get_b() - dst.get_g()); + dst.set_g(floor); + } + + if(dst.get_b() < floor) + { + dst.set_g(dst.get_g() - dst.get_b()); + dst.set_r(dst.get_r() - dst.get_b()); + dst.set_b(floor); + } + } + else + if (clamp_floor) + { + if (dst.get_r() < floor) dst.set_r(floor); + if (dst.get_g() < floor) dst.set_g(floor); + if (dst.get_b() < floor) dst.set_b(floor); + if (dst.get_a() < floor) dst.set_a(floor); + } + + if (clamp_ceiling) + { + if (dst.get_r() > ceiling) dst.set_r(ceiling); + if (dst.get_g() > ceiling) dst.set_g(ceiling); + if (dst.get_b() > ceiling) dst.set_b(ceiling); + if (dst.get_a() > ceiling) dst.set_a(ceiling); + } +} + +bool +TaskClampSW::run(RunParams & /* params */) const +{ + const synfig::Surface &a = + SurfaceSW::Handle::cast_dynamic( sub_task()->target_surface )->get_surface(); + synfig::Surface &c = + SurfaceSW::Handle::cast_dynamic( target_surface )->get_surface(); + + //debug::DebugSurface::save_to_file(a, "TaskClampSW__run__a"); + + RectInt r = get_target_rect(); + if (r.valid()) + { + VectorInt offset = get_offset(); + RectInt ra = sub_task()->get_target_rect() + r.get_min() + get_offset(); + if (ra.valid()) + { + etl::set_intersect(ra, ra, r); + if (ra.valid()) + { + synfig::Surface::pen pc = c.get_pen(ra.minx, ra.maxx); + synfig::Surface::pen pa = c.get_pen(ra.minx, ra.maxx); + for(int y = ra.miny; y < ra.maxy; ++y) + { + const Color *ca = &a[y - r.miny + offset[1]][ra.minx - r.minx + offset[0]]; + Color *cc = &c[y][ra.minx]; + for(int x = ra.minx; x < ra.maxx; ++x, ++ca, ++cc) + clamp_pixel(*cc, *ca); + } + } + } + } + + //debug::DebugSurface::save_to_file(c, "TaskClampSW__run__c"); + + return true; +} + +/* === E N T R Y P O I N T ================================================= */ diff --git a/synfig-core/src/synfig/rendering/module/software/task/taskclampsw.h b/synfig-core/src/synfig/rendering/module/software/task/taskclampsw.h new file mode 100644 index 0000000..41a8b75 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/task/taskclampsw.h @@ -0,0 +1,63 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/software/task/taskclampsw.h +** \brief TaskClampSW Header +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_RENDERING_MODULE_TASKBLENDSW_H +#define __SYNFIG_RENDERING_MODULE_TASKBLENDSW_H + +/* === H E A D E R S ======================================================= */ + +#include "../../common/task/taskclamp.h" + +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig +{ +namespace rendering +{ + +class TaskClampSW: public TaskClamp, public TaskSW, public TaskSplittable +{ +private: + void clamp_pixel(Color &dst, const Color &src) const; + +public: + typedef etl::handle Handle; + Task::Handle clone() const { return clone_pointer(this); } + virtual void split(const RectInt &sub_target_rect); + virtual bool run(RunParams ¶ms) const; +}; + +} /* end namespace rendering */ +} /* end namespace synfig */ + +/* -- E N D ----------------------------------------------------------------- */ + +#endif diff --git a/synfig-core/src/synfig/rendering/module/software/task/taskcolorcorrectsw.cpp b/synfig-core/src/synfig/rendering/module/software/task/taskcolorcorrectsw.cpp new file mode 100644 index 0000000..9b74b39 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/task/taskcolorcorrectsw.cpp @@ -0,0 +1,192 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/software/task/taskcolorcorrectsw.cpp +** \brief TaskColorCorrectSW +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef _WIN32 +#include +#include +#include +#endif + +#include +#include + +#include "taskcolorcorrectsw.h" + +#include +#include + +#endif + +using namespace synfig; +using namespace rendering; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +void +TaskColorCorrectSW::split(const RectInt &sub_target_rect) +{ + trunc_target_rect(sub_target_rect); + if (valid_target() && sub_task() && sub_task()->valid_target()) + { + sub_task() = sub_task()->clone(); + sub_task()->trunc_target_rect( + get_target_rect() + - get_target_offset() + - get_offset() ); + } +} + +void +TaskColorCorrectSW::correct_pixel(Color &dst, const Color &src, const Angle &hue_adjust, ColorReal shift, ColorReal amplifier, const Gamma &gamma) const +{ + static const double precision = 1e-8; + + dst = src; + + if (fabs(gamma.get_gamma_r() - 1.0) > precision) + { + if (dst.get_r() < 0) + dst.set_r(-gamma.r_F32_to_F32(-dst.get_r())); + else + dst.set_r(gamma.r_F32_to_F32(dst.get_r())); + } + + if (fabs(gamma.get_gamma_g() - 1.0) > precision) + { + if (dst.get_g() < 0) + dst.set_g(-gamma.g_F32_to_F32(-dst.get_g())); + else + dst.set_g(gamma.g_F32_to_F32(dst.get_g())); + } + + if (fabs(gamma.get_gamma_b() - 1.0) > precision) + { + if (dst.get_b() < 0) + dst.set_b(-gamma.b_F32_to_F32(-dst.get_b())); + else + dst.set_b(gamma.b_F32_to_F32(dst.get_b())); + } + + assert(!isnan(dst.get_r())); + assert(!isnan(dst.get_g())); + assert(!isnan(dst.get_b())); + + if (fabs(amplifier - 1.0) > precision) + { + dst.set_r(dst.get_r()*amplifier); + dst.set_g(dst.get_g()*amplifier); + dst.set_b(dst.get_b()*amplifier); + } + + if (fabs(shift) > precision) + { + // Adjust R Channel Brightness + if (dst.get_r() > -shift) + dst.set_r(dst.get_r() + shift); + else + if(dst.get_r() < shift) + dst.set_r(dst.get_r() - shift); + else + dst.set_r(0); + + // Adjust G Channel Brightness + if (dst.get_g() > -shift) + dst.set_g(dst.get_g() + shift); + else + if(dst.get_g() < shift) + dst.set_g(dst.get_g() - shift); + else + dst.set_g(0); + + // Adjust B Channel Brightness + if (dst.get_b() > -shift) + dst.set_b(dst.get_b() + shift); + else + if(dst.get_b() < shift) + dst.set_b(dst.get_b() - shift); + else + dst.set_b(0); + } + + // Return the color, adjusting the hue if necessary + if (!!hue_adjust) + dst.rotate_uv(hue_adjust); +} + +bool +TaskColorCorrectSW::run(RunParams & /* params */) const +{ + const synfig::Surface &a = + SurfaceSW::Handle::cast_dynamic( sub_task()->target_surface )->get_surface(); + synfig::Surface &c = + SurfaceSW::Handle::cast_dynamic( target_surface )->get_surface(); + + //debug::DebugSurface::save_to_file(a, "TaskClampSW__run__a"); + + RectInt r = get_target_rect(); + if (r.valid()) + { + VectorInt offset = get_offset(); + RectInt ra = sub_task()->get_target_rect() + r.get_min() + get_offset(); + if (ra.valid()) + { + etl::set_intersect(ra, ra, r); + if (ra.valid()) + { + ColorReal amplifier = (ColorReal)(contrast*exp(exposure)); + ColorReal shift = (ColorReal)((brightness - 0.5)*contrast + 0.5); + Gamma g(fabs(gamma) < 1e-8 ? 1.0 : 1.0/gamma); + + synfig::Surface::pen pc = c.get_pen(ra.minx, ra.maxx); + synfig::Surface::pen pa = c.get_pen(ra.minx, ra.maxx); + for(int y = ra.miny; y < ra.maxy; ++y) + { + const Color *ca = &a[y - r.miny + offset[1]][ra.minx - r.minx + offset[0]]; + Color *cc = &c[y][ra.minx]; + for(int x = ra.minx; x < ra.maxx; ++x, ++ca, ++cc) + correct_pixel(*cc, *ca, hue_adjust, shift, amplifier, g); + } + } + } + } + + //debug::DebugSurface::save_to_file(c, "TaskClampSW__run__c"); + + return true; +} + +/* === E N T R Y P O I N T ================================================= */ diff --git a/synfig-core/src/synfig/rendering/module/software/task/taskcolorcorrectsw.h b/synfig-core/src/synfig/rendering/module/software/task/taskcolorcorrectsw.h new file mode 100644 index 0000000..4894928 --- /dev/null +++ b/synfig-core/src/synfig/rendering/module/software/task/taskcolorcorrectsw.h @@ -0,0 +1,64 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/rendering/module/software/task/taskcolorcorrectsw.h +** \brief TaskColorCorrectSW Header +** +** $Id$ +** +** \legal +** ......... ... 2016 Ivan Mahonin +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_RENDERING_MODULE_TASKCOLORCORRECTSW_H +#define __SYNFIG_RENDERING_MODULE_TASKCOLORCORRECTSW_H + +/* === H E A D E R S ======================================================= */ + +#include "../../common/task/taskcolorcorrect.h" + +#include +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig +{ +namespace rendering +{ + +class TaskColorCorrectSW: public TaskColorCorrect, public TaskSW, public TaskSplittable +{ +private: + void correct_pixel(Color &dst, const Color &src, const Angle &hue_djust, ColorReal shift, ColorReal amplifier, const Gamma &gamma) const; + +public: + typedef etl::handle Handle; + Task::Handle clone() const { return clone_pointer(this); } + virtual void split(const RectInt &sub_target_rect); + virtual bool run(RunParams ¶ms) const; +}; + +} /* end namespace rendering */ +} /* end namespace synfig */ + +/* -- E N D ----------------------------------------------------------------- */ + +#endif diff --git a/synfig-core/src/synfig/rendering/opengl/renderergl.cpp b/synfig-core/src/synfig/rendering/opengl/renderergl.cpp index 4860e78..682b039 100644 --- a/synfig-core/src/synfig/rendering/opengl/renderergl.cpp +++ b/synfig-core/src/synfig/rendering/opengl/renderergl.cpp @@ -56,10 +56,14 @@ #include "optimizer/optimizersurfaceresamplegl.h" #include "../software/optimizer/optimizerblendsw.h" +#include "../software/optimizer/optimizerblursw.h" #include "../software/optimizer/optimizercontoursw.h" #include "../software/optimizer/optimizerlayersw.h" #include "../software/optimizer/optimizermeshsw.h" +#include "../module/software/optimizer/optimizerclampsw.h" +#include "../module/software/optimizer/optimizercolorcorrectsw.h" + #endif using namespace synfig; @@ -80,10 +84,14 @@ RendererGL::RendererGL() register_optimizer(new OptimizerCalcBounds()); register_optimizer(new OptimizerBlendGL()); + register_optimizer(new OptimizerBlurSW()); register_optimizer(new OptimizerContourGL()); register_optimizer(new OptimizerLayerSW()); register_optimizer(new OptimizerSurfaceResampleGL()); + register_optimizer(new OptimizerClampSW()); + register_optimizer(new OptimizerColorCorrectSW()); + register_optimizer(new OptimizerSurfaceConvert()); register_optimizer(new OptimizerLinear()); diff --git a/synfig-core/src/synfig/rendering/software/renderersafe.cpp b/synfig-core/src/synfig/rendering/software/renderersafe.cpp index cbe82d4..c27660d 100644 --- a/synfig-core/src/synfig/rendering/software/renderersafe.cpp +++ b/synfig-core/src/synfig/rendering/software/renderersafe.cpp @@ -55,6 +55,9 @@ #include "optimizer/optimizermeshsw.h" #include "optimizer/optimizersurfaceresamplesw.h" +#include "../module/software/optimizer/optimizerclampsw.h" +#include "../module/software/optimizer/optimizercolorcorrectsw.h" + #endif using namespace synfig; @@ -81,6 +84,9 @@ RendererSafe::RendererSafe() register_optimizer(new OptimizerLayerSW()); register_optimizer(new OptimizerSurfaceResampleSW()); + register_optimizer(new OptimizerClampSW()); + register_optimizer(new OptimizerColorCorrectSW()); + register_optimizer(new OptimizerSurfaceConvert()); register_optimizer(new OptimizerLinear()); diff --git a/synfig-core/src/synfig/rendering/software/renderersw.cpp b/synfig-core/src/synfig/rendering/software/renderersw.cpp index f2f718e..e9e0d89 100644 --- a/synfig-core/src/synfig/rendering/software/renderersw.cpp +++ b/synfig-core/src/synfig/rendering/software/renderersw.cpp @@ -48,6 +48,7 @@ #include "../common/optimizer/optimizercalcbounds.h" #include "../common/optimizer/optimizerlinear.h" #include "../common/optimizer/optimizerlist.h" +#include "../common/optimizer/optimizerpixelprocessorsplit.h" #include "../common/optimizer/optimizersplit.h" #include "../common/optimizer/optimizersurface.h" #include "../common/optimizer/optimizersurfaceconvert.h" @@ -64,6 +65,9 @@ #include "optimizer/optimizermeshsw.h" #include "optimizer/optimizersurfaceresamplesw.h" +#include "../module/software/optimizer/optimizerclampsw.h" +#include "../module/software/optimizer/optimizercolorcorrectsw.h" + #include "function/fft.h" #endif @@ -92,6 +96,9 @@ RendererSW::RendererSW() register_optimizer(new OptimizerLayerSW()); register_optimizer(new OptimizerSurfaceResampleSW()); + register_optimizer(new OptimizerClampSW()); + register_optimizer(new OptimizerColorCorrectSW()); + register_optimizer(new OptimizerBlendZero()); register_optimizer(new OptimizerBlendBlend()); register_optimizer(new OptimizerBlendComposite()); @@ -99,6 +106,7 @@ RendererSW::RendererSW() register_optimizer(new OptimizerBlendAssociative()); register_optimizer(new OptimizerBlendSeparate()); register_optimizer(new OptimizerBlendSplit()); + register_optimizer(new OptimizerPixelProcessorSplit()); register_optimizer(new OptimizerSurfaceConvert()); register_optimizer(new OptimizerLinear());