-/*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
-*\r
-* This file is part of CasparCG.\r
-*\r
-* CasparCG is free software: you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation, either version 3 of the License, or\r
-* (at your option) any later version.\r
-*\r
-* CasparCG is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-\r
-* You should have received a copy of the GNU General Public License\r
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
-*\r
-*/\r
-// TODO: Move layer specific stuff out of frame related classes.\r
-#include "../../stdafx.h"\r
-\r
-#include "image_transform.h"\r
-\r
-#include <common/utility/assert.h>\r
-\r
-namespace caspar { namespace core {\r
- \r
-image_transform::image_transform() \r
- : opacity_(1.0)\r
- , brightness_(1.0)\r
- , contrast_(1.0)\r
- , saturation_(1.0)\r
- , is_key_(false)\r
- , field_mode_(field_mode::progressive)\r
-{\r
- std::fill(fill_translation_.begin(), fill_translation_.end(), 0.0);\r
- std::fill(fill_scale_.begin(), fill_scale_.end(), 1.0);\r
- std::fill(clip_translation_.begin(), clip_translation_.end(), 0.0);\r
- std::fill(clip_scale_.begin(), clip_scale_.end(), 1.0);\r
-}\r
-\r
-void image_transform::set_opacity(double value)\r
-{\r
- opacity_ = std::max(value, 0.0);\r
-}\r
-\r
-double image_transform::get_opacity() const\r
-{\r
- return opacity_;\r
-}\r
-\r
-void image_transform::set_brightness(double value)\r
-{\r
- brightness_ = std::max(0.0, value);\r
-}\r
-\r
-double image_transform::get_brightness() const\r
-{\r
- return brightness_;\r
-}\r
-\r
-void image_transform::set_contrast(double value)\r
-{\r
- contrast_ = std::max(0.0, value);\r
-}\r
-\r
-double image_transform::get_contrast() const\r
-{\r
- return contrast_;\r
-}\r
-\r
-void image_transform::set_saturation(double value)\r
-{\r
- saturation_ = std::max(0.0, value);\r
-}\r
-\r
-double image_transform::get_saturation() const\r
-{\r
- return saturation_;\r
-}\r
-\r
-void image_transform::set_levels(const image_transform::levels& value)\r
-{\r
- levels_ = value;\r
-}\r
-\r
-image_transform::levels image_transform::get_levels() const\r
-{\r
- return levels_;\r
-}\r
-\r
-\r
-void image_transform::set_fill_translation(double x, double y)\r
-{\r
- fill_translation_[0] = x;\r
- fill_translation_[1] = y;\r
-}\r
-\r
-void image_transform::set_fill_scale(double x, double y)\r
-{\r
- fill_scale_[0] = x;\r
- fill_scale_[1] = y; \r
-}\r
-\r
-std::array<double, 2> image_transform::get_fill_translation() const\r
-{\r
- return fill_translation_;\r
-}\r
-\r
-std::array<double, 2> image_transform::get_fill_scale() const\r
-{\r
- return fill_scale_;\r
-}\r
-\r
-void image_transform::set_clip_translation(double x, double y)\r
-{\r
- clip_translation_[0] = x;\r
- clip_translation_[1] = y;\r
-}\r
-\r
-void image_transform::set_clip_scale(double x, double y)\r
-{\r
- clip_scale_[0] = x;\r
- clip_scale_[1] = y; \r
-}\r
-\r
-std::array<double, 2> image_transform::get_clip_translation() const\r
-{\r
- return clip_translation_;\r
-}\r
-\r
-std::array<double, 2> image_transform::get_clip_scale() const\r
-{\r
- return clip_scale_;\r
-}\r
-\r
-void image_transform::set_field_mode(field_mode::type field_mode)\r
-{\r
- field_mode_ = field_mode;\r
-}\r
-\r
-field_mode::type image_transform::get_field_mode() const\r
-{\r
- return field_mode_;\r
-}\r
-\r
-image_transform& image_transform::operator*=(const image_transform &other)\r
-{\r
- opacity_ *= other.opacity_; \r
- brightness_ *= other.brightness_;\r
- contrast_ *= other.contrast_;\r
- saturation_ *= other.saturation_;\r
-\r
- levels_.min_input = std::max(levels_.min_input, other.levels_.min_input);\r
- levels_.max_input = std::min(levels_.max_input, other.levels_.max_input);\r
- \r
- levels_.min_output = std::max(levels_.min_output, other.levels_.min_output);\r
- levels_.max_output = std::min(levels_.max_output, other.levels_.max_output);\r
-\r
- levels_.gamma *= other.levels_.gamma;\r
-\r
- field_mode_ = static_cast<field_mode::type>(field_mode_ & other.field_mode_);\r
- is_key_ |= other.is_key_;\r
- fill_translation_[0] += other.fill_translation_[0]*fill_scale_[0];\r
- fill_translation_[1] += other.fill_translation_[1]*fill_scale_[1];\r
- fill_scale_[0] *= other.fill_scale_[0];\r
- fill_scale_[1] *= other.fill_scale_[1];\r
- clip_translation_[0] += other.clip_translation_[0]*clip_scale_[0];\r
- clip_translation_[1] += other.clip_translation_[1]*clip_scale_[1];\r
- clip_scale_[0] *= other.clip_scale_[0];\r
- clip_scale_[1] *= other.clip_scale_[1];\r
- return *this;\r
-}\r
-\r
-const image_transform image_transform::operator*(const image_transform &other) const\r
-{\r
- return image_transform(*this) *= other;\r
-}\r
-\r
-void image_transform::set_is_key(bool value){is_key_ = value;}\r
-bool image_transform::get_is_key() const{return is_key_;}\r
-\r
-image_transform tween(double time, const image_transform& source, const image_transform& dest, double duration, const tweener_t& tweener)\r
-{ \r
- auto do_tween = [](double time, double source, double dest, double duration, const tweener_t& tweener)\r
- {\r
- return tweener(time, source, dest-source, duration);\r
- };\r
- \r
- image_transform result; \r
- result.set_is_key (source.get_is_key() | dest.get_is_key());\r
- result.set_field_mode (static_cast<field_mode::type>(source.get_field_mode() & dest.get_field_mode()));\r
- result.set_brightness (do_tween(time, source.get_brightness(), dest.get_brightness(), duration, tweener));\r
- result.set_contrast (do_tween(time, source.get_contrast(), dest.get_contrast(), duration, tweener));\r
- result.set_saturation (do_tween(time, source.get_saturation(), dest.get_saturation(), duration, tweener));\r
- result.set_opacity (do_tween(time, source.get_opacity(), dest.get_opacity(), duration, tweener));\r
- result.set_fill_translation (do_tween(time, source.get_fill_translation()[0], dest.get_fill_translation()[0], duration, tweener), do_tween(time, source.get_fill_translation()[1], dest.get_fill_translation()[1], duration, tweener));\r
- result.set_fill_scale (do_tween(time, source.get_fill_scale()[0], dest.get_fill_scale()[0], duration, tweener), do_tween(time, source.get_fill_scale()[1], dest.get_fill_scale()[1], duration, tweener));\r
- result.set_clip_translation (do_tween(time, source.get_clip_translation()[0], dest.get_clip_translation()[0], duration, tweener), do_tween(time, source.get_clip_translation()[1], dest.get_clip_translation()[1], duration, tweener));\r
- result.set_clip_scale (do_tween(time, source.get_clip_scale()[0], dest.get_clip_scale()[0], duration, tweener), do_tween(time, source.get_clip_scale()[1], dest.get_clip_scale()[1], duration, tweener));\r
- \r
- auto s_levels = source.get_levels();\r
- auto d_levels = dest.get_levels();\r
-\r
- d_levels.max_input = do_tween(time, s_levels.max_input, d_levels.max_input, duration, tweener);\r
- d_levels.min_input = do_tween(time, s_levels.min_input, d_levels.min_input, duration, tweener);\r
- \r
- d_levels.max_output = do_tween(time, s_levels.max_output, d_levels.max_output, duration, tweener);\r
- d_levels.min_output = do_tween(time, s_levels.min_output, d_levels.min_output, duration, tweener);\r
-\r
- d_levels.gamma = do_tween(time, s_levels.gamma, d_levels.gamma, duration, tweener);\r
-\r
- result.set_levels(d_levels);\r
-\r
- return result;\r
-}\r
-\r
-bool operator<(const image_transform& lhs, const image_transform& rhs)\r
-{\r
- return memcmp(&lhs, &rhs, sizeof(image_transform)) < 0;\r
-}\r
-\r
-bool operator==(const image_transform& lhs, const image_transform& rhs)\r
-{\r
- return memcmp(&lhs, &rhs, sizeof(image_transform)) == 0;\r
-}\r
-\r
-bool operator!=(const image_transform& lhs, const image_transform& rhs)\r
-{\r
- return !(lhs == rhs);\r
-}\r
-\r
-}}
\ No newline at end of file