]> git.sesse.net Git - casparcg/blob - core/producer/frame/image_transform.h
41fa20d4f928ede5f7979402f19b21ea96d3b841
[casparcg] / core / producer / frame / image_transform.h
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 #pragma once\r
21 \r
22 #include <common/utility/tweener.h>\r
23 #include <core/video_format.h>\r
24 \r
25 #include <array>\r
26 #include <type_traits>\r
27 \r
28 namespace caspar { namespace core {\r
29 \r
30 struct pixel_format_desc;\r
31         \r
32 class image_transform \r
33 {\r
34 public:\r
35         \r
36         struct blend_mode\r
37         {\r
38                 enum type \r
39                 {\r
40                         normal = 0,\r
41                         lighten,\r
42                         darken,\r
43                         multiply,\r
44                         average,\r
45                         add,\r
46                         subtract,\r
47                         difference,\r
48                         negation,\r
49                         exclusion,\r
50                         screen,\r
51                         overlay,\r
52                         soft_light,\r
53                         hard_light,\r
54                         color_dodge,\r
55                         color_burn,\r
56                         linear_dodge,\r
57                         linear_burn,\r
58                         linear_light,\r
59                         vivid_light,\r
60                         pin_light,\r
61                         hard_mix,\r
62                         reflect,\r
63                         glow,\r
64                         phoenix,\r
65                         contrast,\r
66                         saturation,\r
67                         color,\r
68                         luminosity,\r
69                         blend_mode_count \r
70                 };\r
71         };\r
72 \r
73         struct alpha_mode\r
74         {\r
75                 enum type \r
76                 {\r
77                         normal = 0,\r
78                 };\r
79         };\r
80 \r
81         struct levels\r
82         {\r
83                 levels() \r
84                         : min_input(0.0)\r
85                         , max_input(1.0)\r
86                         , gamma(1.0)\r
87                         , min_output(0.0)\r
88                         , max_output(1.0)\r
89                 {               \r
90                 }\r
91                 double min_input;\r
92                 double max_input;\r
93                 double gamma;\r
94                 double min_output;\r
95                 double max_output;\r
96         };\r
97 \r
98         image_transform();\r
99 \r
100         void set_opacity(double value);\r
101         double get_opacity() const;\r
102 \r
103         void set_gain(double value);\r
104         double get_gain() const;\r
105 \r
106         void set_brightness(double value);\r
107         double get_brightness() const;\r
108 \r
109         void set_contrast(double value);\r
110         double get_contrast() const;\r
111 \r
112         void set_saturation(double value);\r
113         double get_saturation() const;\r
114         \r
115         void set_levels(const levels& value);\r
116         levels get_levels() const;\r
117         \r
118         void set_fill_translation(double x, double y);\r
119         std::array<double, 2> get_fill_translation() const;\r
120 \r
121         void set_fill_scale(double x, double y);\r
122         std::array<double, 2> get_fill_scale() const;\r
123         \r
124         void set_clip_translation(double x, double y);\r
125         std::array<double, 2> get_clip_translation() const;\r
126 \r
127         void set_clip_scale(double x, double y);\r
128         std::array<double, 2> get_clip_scale() const;\r
129 \r
130         void set_mode(video_mode::type mode);\r
131         video_mode::type get_mode() const;\r
132 \r
133         image_transform& operator*=(const image_transform &other);\r
134         const image_transform operator*(const image_transform &other) const;\r
135 \r
136         void set_is_key(bool value);\r
137         bool get_is_key() const;\r
138 \r
139         void set_deinterlace(bool value);\r
140         bool get_deinterlace() const;\r
141 \r
142         void set_blend_mode(blend_mode::type value);\r
143         blend_mode::type get_blend_mode() const;\r
144         \r
145         void set_alpha_mode(alpha_mode::type value);\r
146         alpha_mode::type get_alpha_mode() const;\r
147 \r
148 private:\r
149         double opacity_;\r
150         double gain_;\r
151         double contrast_;\r
152         double brightness_;\r
153         double saturation_;\r
154         double desaturation_;\r
155         levels levels_;\r
156         std::array<double, 2> fill_translation_; \r
157         std::array<double, 2> fill_scale_; \r
158         std::array<double, 2> clip_translation_; \r
159         std::array<double, 2> clip_scale_; \r
160         video_mode::type mode_;\r
161         bool is_key_;\r
162         bool deinterlace_;\r
163         blend_mode::type blend_mode_;\r
164         alpha_mode::type alpha_mode_;\r
165 };\r
166 \r
167 image_transform::blend_mode::type get_blend_mode(const std::wstring& str);\r
168 image_transform::alpha_mode::type get_alpha_mode(const std::wstring& str);\r
169 \r
170 image_transform tween(double time, const image_transform& source, const image_transform& dest, double duration, const tweener_t& tweener);\r
171 \r
172 inline bool operator==(const image_transform& lhs, const image_transform& rhs)\r
173 {\r
174         return memcmp(&lhs, &rhs, sizeof(image_transform)) == 0;\r
175 }\r
176 \r
177 inline bool operator!=(const image_transform& lhs, const image_transform& rhs)\r
178 {\r
179         return !(lhs == rhs);\r
180 }\r
181 \r
182 }}