]> git.sesse.net Git - casparcg/blob - core/frame/frame_transform.h
Merge branch '2.1.0' of https://github.com/CasparCG/Server into 2.1.0
[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 <core/video_format.h>
26
27 #include <boost/array.hpp>
28
29 namespace caspar { namespace core {
30                         
31 struct levels /* final */
32 {
33         levels() 
34                 : min_input(0.0)
35                 , max_input(1.0)
36                 , gamma(1.0)
37                 , min_output(0.0)
38                 , max_output(1.0)
39         {               
40         }
41         double min_input;
42         double max_input;
43         double gamma;
44         double min_output;
45         double max_output;
46 };
47
48 struct image_transform /* final */
49 {
50 public:
51         image_transform();
52
53         double                                  opacity;
54         double                                  contrast;
55         double                                  brightness;
56         double                                  saturation;
57         boost::array<double, 2> fill_translation; 
58         boost::array<double, 2> fill_scale; 
59         boost::array<double, 2> clip_translation;  
60         boost::array<double, 2> clip_scale;  
61         levels                                  levels;
62
63         field_mode                              field_mode;
64         bool                                    is_key;
65         bool                                    is_mix;
66         bool                                    is_still;
67         
68         image_transform& operator*=(const image_transform &other);
69         image_transform operator*(const image_transform &other) const;
70
71         static image_transform tween(double time, const image_transform& source, const image_transform& dest, double duration, const tweener& tween);
72 };
73
74 bool operator==(const image_transform& lhs, const image_transform& rhs);
75 bool operator!=(const image_transform& lhs, const image_transform& rhs);
76
77 struct audio_transform /* final */
78 {
79 public:
80         audio_transform();
81
82         double  volume;
83         bool    is_still;
84         
85         audio_transform& operator*=(const audio_transform &other);
86         audio_transform operator*(const audio_transform &other) const;
87
88         static audio_transform tween(double time, const audio_transform& source, const audio_transform& dest, double duration, const tweener& tween);
89 };
90
91 bool operator==(const audio_transform& lhs, const audio_transform& rhs);
92 bool operator!=(const audio_transform& lhs, const audio_transform& rhs);
93
94 //__declspec(align(16)) 
95 struct frame_transform /* final */
96 {
97 public:
98         frame_transform();
99         
100         image_transform image_transform;
101         audio_transform audio_transform;
102
103         //char padding[(sizeof(core::image_transform) + sizeof(core::audio_transform)) % 16];
104         
105         frame_transform& operator*=(const frame_transform &other);
106         frame_transform operator*(const frame_transform &other) const;
107
108         static frame_transform tween(double time, const frame_transform& source, const frame_transform& dest, double duration, const tweener& tween);
109 };
110
111 bool operator==(const frame_transform& lhs, const frame_transform& rhs);
112 bool operator!=(const frame_transform& lhs, const frame_transform& rhs);
113
114 class tweened_transform
115 {
116         frame_transform source_;
117         frame_transform dest_;
118         int duration_;
119         int time_;
120         tweener tweener_;
121 public: 
122         tweened_transform()
123                 : duration_(0)
124                 , time_(0)
125         {
126         }
127
128         tweened_transform(const frame_transform& source, const frame_transform& dest, int duration, const tweener& tween)
129                 : source_(source)
130                 , dest_(dest)
131                 , duration_(duration)
132                 , time_(0)
133                 , tweener_(tween)
134         {
135         }
136         
137         frame_transform fetch()
138         {
139                 return time_ == duration_ ? dest_ : frame_transform::tween(static_cast<double>(time_), source_, dest_, static_cast<double>(duration_), tweener_);
140         }
141
142         frame_transform fetch_and_tick(int num)
143         {                                               
144                 time_ = std::min(time_+num, duration_);
145                 return fetch();
146         }
147 };
148
149 }}