]> git.sesse.net Git - casparcg/blobdiff - core/frame/frame_transform.h
[ffmpeg] use implicit constructor of video_format_desc for clarity
[casparcg] / core / frame / frame_transform.h
index 0159b695f4ebfaab6565c467c0254ba39765d2e6..bf2cdb35f550a12e299a90b6c05f70446482d751 100644 (file)
-/*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
-*\r
-* This file is part of CasparCG (www.casparcg.com).\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
-* Author: Robert Nagy, ronag89@gmail.com\r
-*/\r
-\r
-#pragma once\r
-\r
-#include <common/utility/tweener.h>\r
-#include <core/video_format.h>\r
-\r
-#include <boost/array.hpp>\r
-\r
-namespace caspar { namespace core {\r
-                       \r
-struct levels sealed\r
-{\r
-       levels() \r
-               : min_input(0.0)\r
-               , max_input(1.0)\r
-               , gamma(1.0)\r
-               , min_output(0.0)\r
-               , max_output(1.0)\r
-       {               \r
-       }\r
-       double min_input;\r
-       double max_input;\r
-       double gamma;\r
-       double min_output;\r
-       double max_output;\r
-};\r
-\r
-struct frame_transform sealed\r
-{\r
-public:\r
-\r
-       frame_transform();\r
-\r
-       double                                  volume;\r
-       double                                  opacity;\r
-       double                                  contrast;\r
-       double                                  brightness;\r
-       double                                  saturation;\r
-       boost::array<double, 2> fill_translation; \r
-       boost::array<double, 2> fill_scale; \r
-       boost::array<double, 2> clip_translation;  \r
-       boost::array<double, 2> clip_scale;  \r
-       levels                                  levels;\r
-\r
-       field_mode                              field_mode;\r
-       bool                                    is_key;\r
-       bool                                    is_mix;\r
-       \r
-       frame_transform& frame_transform::operator*=(const frame_transform &other);\r
-       frame_transform frame_transform::operator*(const frame_transform &other) const;\r
-};\r
-\r
-frame_transform tween(double time, const frame_transform& source, const frame_transform& dest, double duration, const tweener_t& tweener);\r
-\r
-bool operator<(const frame_transform& lhs, const frame_transform& rhs);\r
-bool operator==(const frame_transform& lhs, const frame_transform& rhs);\r
-bool operator!=(const frame_transform& lhs, const frame_transform& rhs);\r
-\r
-}}
\ No newline at end of file
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG 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 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG 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.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+
+#pragma once
+
+#include <common/tweener.h>
+#include <common/env.h>
+
+#include <core/video_format.h>
+#include <core/mixer/image/blend_modes.h>
+
+#include <boost/array.hpp>
+#include <boost/property_tree/ptree.hpp>
+
+namespace caspar { namespace core {
+
+struct chroma
+{
+       enum class type
+       {
+               none,
+               green,
+               blue
+       };
+
+       type    key                     = type::none;
+       double  threshold       = 0.0;
+       double  softness        = 0.0;
+       double  spill           = 0.0;
+};
+
+struct levels final
+{
+       double min_input        = 0.0;
+       double max_input        = 1.0;
+       double gamma            = 1.0;
+       double min_output       = 0.0;
+       double max_output       = 1.0;
+};
+
+struct corners final
+{
+       boost::array<double, 2> ul = boost::array<double, 2> { { 0.0, 0.0 } };
+       boost::array<double, 2> ur = boost::array<double, 2> { { 1.0, 0.0 } };
+       boost::array<double, 2> lr = boost::array<double, 2> { { 1.0, 1.0 } };
+       boost::array<double, 2> ll = boost::array<double, 2> { { 0.0, 1.0 } };
+};
+
+struct rectangle final
+{
+       boost::array<double, 2> ul = boost::array<double, 2> { { 0.0, 0.0 } };
+       boost::array<double, 2> lr = boost::array<double, 2> { { 1.0, 1.0 } };
+};
+
+struct image_transform final
+{
+       double                                  opacity                         = 1.0;
+       double                                  contrast                        = 1.0;
+       double                                  brightness                      = 1.0;
+       double                                  saturation                      = 1.0;
+
+       // A bug in VS 2013 prevents us from writing:
+       // boost::array<double, 2> fill_translation = { { 0.0, 0.0 } };
+       // See http://blogs.msdn.com/b/vcblog/archive/2014/08/19/the-future-of-non-static-data-member-initialization.aspx
+       boost::array<double, 2> anchor                          = boost::array<double, 2> { { 0.0, 0.0 } };
+       boost::array<double, 2> fill_translation        = boost::array<double, 2> { { 0.0, 0.0 } };
+       boost::array<double, 2> fill_scale                      = boost::array<double, 2> { { 1.0, 1.0 } };
+       boost::array<double, 2> clip_translation        = boost::array<double, 2> { { 0.0, 0.0 } };
+       boost::array<double, 2> clip_scale                      = boost::array<double, 2> { { 1.0, 1.0 } };
+       double                                  angle                           = 0.0;
+       rectangle                               crop;
+       corners                                 perspective;
+       core::levels                    levels;
+       core::chroma                    chroma;
+
+       core::field_mode                field_mode                      = core::field_mode::progressive;
+       bool                                    is_key                          = false;
+       bool                                    is_mix                          = false;
+       bool                                    is_still                        = false;
+       bool                                    use_mipmap                      = false;
+       core::blend_mode                blend_mode                      = core::blend_mode::normal;
+       int                                             layer_depth                     = 0;
+       
+       image_transform& operator*=(const image_transform &other);
+       image_transform operator*(const image_transform &other) const;
+
+       static image_transform tween(double time, const image_transform& source, const image_transform& dest, double duration, const tweener& tween);
+};
+
+bool operator==(const image_transform& lhs, const image_transform& rhs);
+bool operator!=(const image_transform& lhs, const image_transform& rhs);
+
+struct audio_transform final
+{
+       double  volume          = 1.0;
+       bool    is_still        = false;
+       
+       audio_transform& operator*=(const audio_transform &other);
+       audio_transform operator*(const audio_transform &other) const;
+
+       static audio_transform tween(double time, const audio_transform& source, const audio_transform& dest, double duration, const tweener& tween);
+};
+
+bool operator==(const audio_transform& lhs, const audio_transform& rhs);
+bool operator!=(const audio_transform& lhs, const audio_transform& rhs);
+
+//__declspec(align(16)) 
+struct frame_transform final
+{
+public:
+       frame_transform();
+       
+       core::image_transform image_transform;
+       core::audio_transform audio_transform;
+
+       //char padding[(sizeof(core::image_transform) + sizeof(core::audio_transform)) % 16];
+       
+       frame_transform& operator*=(const frame_transform &other);
+       frame_transform operator*(const frame_transform &other) const;
+
+       static frame_transform tween(double time, const frame_transform& source, const frame_transform& dest, double duration, const tweener& tween);
+};
+
+bool operator==(const frame_transform& lhs, const frame_transform& rhs);
+bool operator!=(const frame_transform& lhs, const frame_transform& rhs);
+
+class tweened_transform
+{
+       frame_transform source_;
+       frame_transform dest_;
+       int duration_;
+       int time_;
+       tweener tweener_;
+public:        
+       tweened_transform()
+               : duration_(0)
+               , time_(0)
+       {
+               dest_.image_transform.use_mipmap = env::properties().get(L"configuration.mixer.mipmapping_default_on", false);
+       }
+
+       tweened_transform(const frame_transform& source, const frame_transform& dest, int duration, const tweener& tween)
+               : source_(source)
+               , dest_(dest)
+               , duration_(duration)
+               , time_(0)
+               , tweener_(tween)
+       {
+       }
+
+       const frame_transform& dest() const
+       {
+               return dest_;
+       }
+       
+       frame_transform fetch()
+       {
+               return time_ == duration_ ? dest_ : frame_transform::tween(static_cast<double>(time_), source_, dest_, static_cast<double>(duration_), tweener_);
+       }
+
+       frame_transform fetch_and_tick(int num)
+       {                                               
+               time_ = std::min(time_+num, duration_);
+               return fetch();
+       }
+};
+
+chroma::type get_chroma_mode(const std::wstring& str);
+std::wstring get_chroma_mode(chroma::type type);
+
+namespace detail {
+
+void set_current_aspect_ratio(double aspect_ratio);
+double get_current_aspect_ratio();
+
+}}}