]> git.sesse.net Git - casparcg/blob - core/frame/frame_transform.h
[general] Added cg_producer_registry as dependency in frame_producer_dependencies
[casparcg] / core / frame / frame_transform.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Robert Nagy, ronag89@gmail.com
20 */
21
22 #pragma once
23
24 #include <common/tweener.h>
25 #include <common/env.h>
26
27 #include <core/video_format.h>
28 #include <core/mixer/image/blend_modes.h>
29
30 #include <boost/array.hpp>
31 #include <boost/optional.hpp>
32 #include <boost/property_tree/ptree.hpp>
33
34 namespace caspar { namespace core {
35
36 struct chroma
37 {
38         enum class legacy_type
39         {
40                 none,
41                 green,
42                 blue
43         };
44
45         bool            enable                          = false;
46         bool            show_mask                       = false;
47         double          target_hue                      = 0.0;
48         double          hue_width                       = 0.0;
49         double          min_saturation          = 0.0;
50         double          min_brightness          = 0.0;
51         double          softness                        = 0.0;
52         double          spill                           = 1.0;
53         double          spill_darken            = 0.0;
54 };
55
56 struct levels final
57 {
58         double min_input        = 0.0;
59         double max_input        = 1.0;
60         double gamma            = 1.0;
61         double min_output       = 0.0;
62         double max_output       = 1.0;
63 };
64
65 struct corners final
66 {
67         boost::array<double, 2> ul = boost::array<double, 2> { { 0.0, 0.0 } };
68         boost::array<double, 2> ur = boost::array<double, 2> { { 1.0, 0.0 } };
69         boost::array<double, 2> lr = boost::array<double, 2> { { 1.0, 1.0 } };
70         boost::array<double, 2> ll = boost::array<double, 2> { { 0.0, 1.0 } };
71 };
72
73 struct rectangle final
74 {
75         boost::array<double, 2> ul = boost::array<double, 2> { { 0.0, 0.0 } };
76         boost::array<double, 2> lr = boost::array<double, 2> { { 1.0, 1.0 } };
77 };
78
79 struct image_transform final
80 {
81         double                                  opacity                         = 1.0;
82         double                                  contrast                        = 1.0;
83         double                                  brightness                      = 1.0;
84         double                                  saturation                      = 1.0;
85
86         // A bug in VS 2013 prevents us from writing:
87         // boost::array<double, 2> fill_translation = { { 0.0, 0.0 } };
88         // See http://blogs.msdn.com/b/vcblog/archive/2014/08/19/the-future-of-non-static-data-member-initialization.aspx
89         boost::array<double, 2> anchor                          = boost::array<double, 2> { { 0.0, 0.0 } };
90         boost::array<double, 2> fill_translation        = boost::array<double, 2> { { 0.0, 0.0 } };
91         boost::array<double, 2> fill_scale                      = boost::array<double, 2> { { 1.0, 1.0 } };
92         boost::array<double, 2> clip_translation        = boost::array<double, 2> { { 0.0, 0.0 } };
93         boost::array<double, 2> clip_scale                      = boost::array<double, 2> { { 1.0, 1.0 } };
94         double                                  angle                           = 0.0;
95         rectangle                               crop;
96         corners                                 perspective;
97         core::levels                    levels;
98         core::chroma                    chroma;
99
100         core::field_mode                field_mode                      = core::field_mode::progressive;
101         bool                                    is_key                          = false;
102         bool                                    is_mix                          = false;
103         bool                                    is_still                        = false;
104         bool                                    use_mipmap                      = false;
105         core::blend_mode                blend_mode                      = core::blend_mode::normal;
106         int                                             layer_depth                     = 0;
107
108         image_transform& operator*=(const image_transform &other);
109         image_transform operator*(const image_transform &other) const;
110
111         static image_transform tween(double time, const image_transform& source, const image_transform& dest, double duration, const tweener& tween);
112 };
113
114 bool operator==(const image_transform& lhs, const image_transform& rhs);
115 bool operator!=(const image_transform& lhs, const image_transform& rhs);
116
117 struct audio_transform final
118 {
119         double  volume          = 1.0;
120         bool    is_still        = false;
121
122         audio_transform& operator*=(const audio_transform &other);
123         audio_transform operator*(const audio_transform &other) const;
124
125         static audio_transform tween(double time, const audio_transform& source, const audio_transform& dest, double duration, const tweener& tween);
126 };
127
128 bool operator==(const audio_transform& lhs, const audio_transform& rhs);
129 bool operator!=(const audio_transform& lhs, const audio_transform& rhs);
130
131 //__declspec(align(16))
132 struct frame_transform final
133 {
134 public:
135         frame_transform();
136
137         core::image_transform image_transform;
138         core::audio_transform audio_transform;
139
140         //char padding[(sizeof(core::image_transform) + sizeof(core::audio_transform)) % 16];
141
142         frame_transform& operator*=(const frame_transform &other);
143         frame_transform operator*(const frame_transform &other) const;
144
145         static frame_transform tween(double time, const frame_transform& source, const frame_transform& dest, double duration, const tweener& tween);
146 };
147
148 bool operator==(const frame_transform& lhs, const frame_transform& rhs);
149 bool operator!=(const frame_transform& lhs, const frame_transform& rhs);
150
151 class tweened_transform
152 {
153         frame_transform source_;
154         frame_transform dest_;
155         int duration_;
156         int time_;
157         tweener tweener_;
158 public:
159         tweened_transform()
160                 : duration_(0)
161                 , time_(0)
162         {
163                 dest_.image_transform.use_mipmap = env::properties().get(L"configuration.mixer.mipmapping-default-on", false);
164         }
165
166         tweened_transform(const frame_transform& source, const frame_transform& dest, int duration, const tweener& tween)
167                 : source_(source)
168                 , dest_(dest)
169                 , duration_(duration)
170                 , time_(0)
171                 , tweener_(tween)
172         {
173         }
174
175         const frame_transform& dest() const
176         {
177                 return dest_;
178         }
179
180         frame_transform fetch()
181         {
182                 return time_ == duration_ ? dest_ : frame_transform::tween(static_cast<double>(time_), source_, dest_, static_cast<double>(duration_), tweener_);
183         }
184
185         frame_transform fetch_and_tick(int num)
186         {
187                 time_ = std::min(time_+num, duration_);
188                 return fetch();
189         }
190 };
191
192 boost::optional<chroma::legacy_type> get_chroma_mode(const std::wstring& str);
193
194 namespace detail {
195
196 void set_current_aspect_ratio(double aspect_ratio);
197 double get_current_aspect_ratio();
198
199 }}}