]> git.sesse.net Git - casparcg/blob - core/producer/frame/frame_transform.cpp
2.0.2: Updated file info headers.
[casparcg] / core / producer / frame / frame_transform.cpp
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\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 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "../../stdafx.h"\r
23 \r
24 #include "frame_transform.h"\r
25 \r
26 #include <common/utility/assert.h>\r
27 \r
28 namespace caspar { namespace core {\r
29                 \r
30 frame_transform::frame_transform() \r
31         : volume(1.0)\r
32         , opacity(1.0)\r
33         , brightness(1.0)\r
34         , contrast(1.0)\r
35         , saturation(1.0)\r
36         , field_mode(field_mode::progressive)\r
37         , is_key(false)\r
38         , is_mix(false)\r
39 {\r
40         std::fill(fill_translation.begin(), fill_translation.end(), 0.0);\r
41         std::fill(fill_scale.begin(), fill_scale.end(), 1.0);\r
42         std::fill(clip_translation.begin(), clip_translation.end(), 0.0);\r
43         std::fill(clip_scale.begin(), clip_scale.end(), 1.0);\r
44 }\r
45 \r
46 frame_transform& frame_transform::operator*=(const frame_transform &other)\r
47 {\r
48         volume                                  *= other.volume;\r
49         opacity                                 *= other.opacity;       \r
50         brightness                              *= other.brightness;\r
51         contrast                                *= other.contrast;\r
52         saturation                              *= other.saturation;\r
53         fill_translation[0]             += other.fill_translation[0]*fill_scale[0];\r
54         fill_translation[1]             += other.fill_translation[1]*fill_scale[1];\r
55         fill_scale[0]                   *= other.fill_scale[0];\r
56         fill_scale[1]                   *= other.fill_scale[1];\r
57         clip_translation[0]             += other.clip_translation[0]*clip_scale[0];\r
58         clip_translation[1]             += other.clip_translation[1]*clip_scale[1];\r
59         clip_scale[0]                   *= other.clip_scale[0];\r
60         clip_scale[1]                   *= other.clip_scale[1];\r
61         levels.min_input                 = std::max(levels.min_input,  other.levels.min_input);\r
62         levels.max_input                 = std::min(levels.max_input,  other.levels.max_input); \r
63         levels.min_output                = std::max(levels.min_output, other.levels.min_output);\r
64         levels.max_output                = std::min(levels.max_output, other.levels.max_output);\r
65         levels.gamma                    *= other.levels.gamma;\r
66         field_mode                               = static_cast<field_mode::type>(field_mode & other.field_mode);\r
67         is_key                                  |= other.is_key;\r
68         is_mix                                  |= other.is_mix;\r
69         return *this;\r
70 }\r
71 \r
72 frame_transform frame_transform::operator*(const frame_transform &other) const\r
73 {\r
74         return frame_transform(*this) *= other;\r
75 }\r
76 \r
77 frame_transform tween(double time, const frame_transform& source, const frame_transform& dest, double duration, const tweener_t& tweener)\r
78 {       \r
79         auto do_tween = [](double time, double source, double dest, double duration, const tweener_t& tweener)\r
80         {\r
81                 return tweener(time, source, dest-source, duration);\r
82         };\r
83         \r
84         frame_transform result; \r
85         result.volume                           = do_tween(time, source.volume,                                 dest.volume,                            duration, tweener);\r
86         result.brightness                       = do_tween(time, source.brightness,                             dest.brightness,                        duration, tweener);\r
87         result.contrast                         = do_tween(time, source.contrast,                               dest.contrast,                          duration, tweener);\r
88         result.saturation                       = do_tween(time, source.saturation,                             dest.saturation,                        duration, tweener);\r
89         result.opacity                          = do_tween(time, source.opacity,                                dest.opacity,                           duration, tweener);     \r
90         result.fill_translation[0]      = do_tween(time, source.fill_translation[0],    dest.fill_translation[0],       duration, tweener), \r
91         result.fill_translation[1]      = do_tween(time, source.fill_translation[1],    dest.fill_translation[1],       duration, tweener);             \r
92         result.fill_scale[0]            = do_tween(time, source.fill_scale[0],                  dest.fill_scale[0],                     duration, tweener), \r
93         result.fill_scale[1]            = do_tween(time, source.fill_scale[1],                  dest.fill_scale[1],                     duration, tweener);     \r
94         result.clip_translation[0]      = do_tween(time, source.clip_translation[0],    dest.clip_translation[0],       duration, tweener), \r
95         result.clip_translation[1]      = do_tween(time, source.clip_translation[1],    dest.clip_translation[1],       duration, tweener);             \r
96         result.clip_scale[0]            = do_tween(time, source.clip_scale[0],                  dest.clip_scale[0],                     duration, tweener), \r
97         result.clip_scale[1]            = do_tween(time, source.clip_scale[1],                  dest.clip_scale[1],                     duration, tweener);\r
98         result.levels.max_input         = do_tween(time, source.levels.max_input,               dest.levels.max_input,          duration, tweener);\r
99         result.levels.min_input         = do_tween(time, source.levels.min_input,               dest.levels.min_input,          duration, tweener);     \r
100         result.levels.max_output        = do_tween(time, source.levels.max_output,              dest.levels.max_output,         duration, tweener);\r
101         result.levels.min_output        = do_tween(time, source.levels.min_output,              dest.levels.min_output,         duration, tweener);\r
102         result.levels.gamma                     = do_tween(time, source.levels.gamma,                   dest.levels.gamma,                      duration, tweener);\r
103         result.field_mode                       = static_cast<field_mode::type>(source.field_mode & dest.field_mode);\r
104         result.is_key                           = source.is_key | dest.is_key;\r
105         result.is_mix                           = source.is_mix | dest.is_mix;\r
106         \r
107         return result;\r
108 }\r
109 \r
110 bool operator<(const frame_transform& lhs, const frame_transform& rhs)\r
111 {\r
112         return memcmp(&lhs, &rhs, sizeof(frame_transform)) < 0;\r
113 }\r
114 \r
115 bool operator==(const frame_transform& lhs, const frame_transform& rhs)\r
116 {\r
117         return memcmp(&lhs, &rhs, sizeof(frame_transform)) == 0;\r
118 }\r
119 \r
120 bool operator!=(const frame_transform& lhs, const frame_transform& rhs)\r
121 {\r
122         return !(lhs == rhs);\r
123 }\r
124 \r
125 }}