]> git.sesse.net Git - casparcg/blob - core/producer/frame/frame_transform.cpp
60d93a1aaa8b4424efc63701ff65b646c93f74d0
[casparcg] / core / producer / frame / frame_transform.cpp
1 /*\r
2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 *  This file is part of CasparCG.\r
5 *\r
6 *    CasparCG is free software: you can redistribute it and/or modify\r
7 *    it under the terms of the GNU General Public License as published by\r
8 *    the Free Software Foundation, either version 3 of the License, or\r
9 *    (at your option) any later version.\r
10 *\r
11 *    CasparCG is distributed in the hope that it will be useful,\r
12 *    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 *    GNU General Public License for more details.\r
15 \r
16 *    You should have received a copy of the GNU General Public License\r
17 *    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 */\r
20 // TODO: Move layer specific stuff out of frame related classes.\r
21 #include "../../stdafx.h"\r
22 \r
23 #include "frame_transform.h"\r
24 \r
25 #include <common/utility/assert.h>\r
26 \r
27 namespace caspar { namespace core {\r
28                 \r
29 frame_transform::frame_transform() \r
30         : volume(1.0)\r
31         , opacity(1.0)\r
32         , brightness(1.0)\r
33         , contrast(1.0)\r
34         , saturation(1.0)\r
35         , field_mode(field_mode::progressive)\r
36         , is_key(false)\r
37 {\r
38         std::fill(fill_translation.begin(), fill_translation.end(), 0.0);\r
39         std::fill(fill_scale.begin(), fill_scale.end(), 1.0);\r
40         std::fill(clip_translation.begin(), clip_translation.end(), 0.0);\r
41         std::fill(clip_scale.begin(), clip_scale.end(), 1.0);\r
42 }\r
43 \r
44 frame_transform& frame_transform::operator*=(const frame_transform &other)\r
45 {\r
46         volume                                  *= other.volume;\r
47         opacity                                 *= other.opacity;       \r
48         brightness                              *= other.brightness;\r
49         contrast                                *= other.contrast;\r
50         saturation                              *= other.saturation;\r
51         fill_translation[0]             += other.fill_translation[0]*fill_scale[0];\r
52         fill_translation[1]             += other.fill_translation[1]*fill_scale[1];\r
53         fill_scale[0]                   *= other.fill_scale[0];\r
54         fill_scale[1]                   *= other.fill_scale[1];\r
55         clip_translation[0]             += other.clip_translation[0]*clip_scale[0];\r
56         clip_translation[1]             += other.clip_translation[1]*clip_scale[1];\r
57         clip_scale[0]                   *= other.clip_scale[0];\r
58         clip_scale[1]                   *= other.clip_scale[1];\r
59         levels.min_input                 = std::max(levels.min_input,  other.levels.min_input);\r
60         levels.max_input                 = std::min(levels.max_input,  other.levels.max_input); \r
61         levels.min_output                = std::max(levels.min_output, other.levels.min_output);\r
62         levels.max_output                = std::min(levels.max_output, other.levels.max_output);\r
63         levels.gamma                    *= other.levels.gamma;\r
64         field_mode                               = static_cast<field_mode::type>(field_mode & other.field_mode);\r
65         is_key                                  |= other.is_key;\r
66         return *this;\r
67 }\r
68 \r
69 frame_transform frame_transform::operator*(const frame_transform &other) const\r
70 {\r
71         return frame_transform(*this) *= other;\r
72 }\r
73 \r
74 frame_transform tween(double time, const frame_transform& source, const frame_transform& dest, double duration, const tweener_t& tweener)\r
75 {       \r
76         auto do_tween = [](double time, double source, double dest, double duration, const tweener_t& tweener)\r
77         {\r
78                 return tweener(time, source, dest-source, duration);\r
79         };\r
80         \r
81         frame_transform result; \r
82         result.volume                           = do_tween(time, source.volume,                                 dest.volume,                            duration, tweener);\r
83         result.brightness                       = do_tween(time, source.brightness,                             dest.brightness,                        duration, tweener);\r
84         result.contrast                         = do_tween(time, source.contrast,                               dest.contrast,                          duration, tweener);\r
85         result.saturation                       = do_tween(time, source.saturation,                             dest.saturation,                        duration, tweener);\r
86         result.opacity                          = do_tween(time, source.opacity,                                dest.opacity,                           duration, tweener);     \r
87         result.fill_translation[0]      = do_tween(time, source.fill_translation[0],    dest.fill_translation[0],       duration, tweener), \r
88         result.fill_translation[1]      = do_tween(time, source.fill_translation[1],    dest.fill_translation[1],       duration, tweener);             \r
89         result.fill_scale[0]            = do_tween(time, source.fill_scale[0],                  dest.fill_scale[0],                     duration, tweener), \r
90         result.fill_scale[1]            = do_tween(time, source.fill_scale[1],                  dest.fill_scale[1],                     duration, tweener);     \r
91         result.clip_translation[0]      = do_tween(time, source.clip_translation[0],    dest.clip_translation[0],       duration, tweener), \r
92         result.clip_translation[1]      = do_tween(time, source.clip_translation[1],    dest.clip_translation[1],       duration, tweener);             \r
93         result.clip_scale[0]            = do_tween(time, source.clip_scale[0],                  dest.clip_scale[0],                     duration, tweener), \r
94         result.clip_scale[1]            = do_tween(time, source.clip_scale[1],                  dest.clip_scale[1],                     duration, tweener);\r
95         result.levels.max_input         = do_tween(time, source.levels.max_input,               dest.levels.max_input,          duration, tweener);\r
96         result.levels.min_input         = do_tween(time, source.levels.min_input,               dest.levels.min_input,          duration, tweener);     \r
97         result.levels.max_output        = do_tween(time, source.levels.max_output,              dest.levels.max_output,         duration, tweener);\r
98         result.levels.min_output        = do_tween(time, source.levels.min_output,              dest.levels.min_output,         duration, tweener);\r
99         result.levels.gamma                     = do_tween(time, source.levels.gamma,                   dest.levels.gamma,                      duration, tweener);\r
100         result.field_mode                       = static_cast<field_mode::type>(source.field_mode & dest.field_mode);\r
101         result.is_key                           = source.is_key | dest.is_key;\r
102         \r
103         return result;\r
104 }\r
105 \r
106 bool operator<(const frame_transform& lhs, const frame_transform& rhs)\r
107 {\r
108         return memcmp(&lhs, &rhs, sizeof(frame_transform)) < 0;\r
109 }\r
110 \r
111 bool operator==(const frame_transform& lhs, const frame_transform& rhs)\r
112 {\r
113         return memcmp(&lhs, &rhs, sizeof(frame_transform)) == 0;\r
114 }\r
115 \r
116 bool operator!=(const frame_transform& lhs, const frame_transform& rhs)\r
117 {\r
118         return !(lhs == rhs);\r
119 }\r
120 \r
121 }}