]> git.sesse.net Git - casparcg/blob - core/producer/frame/basic_frame.cpp
2.0.0.2: Reverted and displayed IS_KEY/KEY_DEPTH. Needs more work.
[casparcg] / core / producer / frame / basic_frame.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 #include "../../stdafx.h"\r
21 \r
22 #include "basic_frame.h"\r
23 \r
24 #include "image_transform.h"\r
25 #include "audio_transform.h"\r
26 #include "pixel_format.h"\r
27 #include "../../video_format.h"\r
28 \r
29 #include <boost/range/algorithm.hpp>\r
30 \r
31 namespace caspar { namespace core {\r
32                                                                                                                                                                                                                                                                                                                 \r
33 struct basic_frame::implementation\r
34 {               \r
35         std::vector<safe_ptr<basic_frame>> frames_;\r
36 \r
37         image_transform image_transform_;       \r
38         audio_transform audio_transform_;\r
39         \r
40 public:\r
41         implementation(const std::vector<safe_ptr<basic_frame>>& frames) \r
42                 : frames_(frames) {}\r
43         implementation(std::vector<safe_ptr<basic_frame>>&& frames) \r
44                 : frames_(std::move(frames)){}\r
45         \r
46         void accept(const basic_frame& self, frame_visitor& visitor)\r
47         {\r
48                 visitor.begin(self);\r
49                 BOOST_FOREACH(auto frame, frames_)\r
50                         frame->accept(visitor);\r
51                 visitor.end();\r
52         }       \r
53 };\r
54         \r
55 basic_frame::basic_frame() : impl_(new implementation(std::vector<safe_ptr<basic_frame>>())){}\r
56 basic_frame::basic_frame(std::vector<safe_ptr<basic_frame>>&& frames) : impl_(new implementation(std::move(frames))){}\r
57 basic_frame::basic_frame(const basic_frame& other) : impl_(new implementation(*other.impl_)){}\r
58 basic_frame::basic_frame(const safe_ptr<basic_frame>& frame)\r
59 {\r
60         std::vector<safe_ptr<basic_frame>> frames;\r
61         frames.push_back(frame);\r
62         impl_.reset(new implementation(std::move(frames)));\r
63 }\r
64 basic_frame::basic_frame(safe_ptr<basic_frame>&& frame)\r
65 {\r
66         std::vector<safe_ptr<basic_frame>> frames;\r
67         frames.push_back(std::move(frame));\r
68         impl_.reset(new implementation(std::move(frames)));\r
69 }\r
70 void basic_frame::swap(basic_frame& other){impl_.swap(other.impl_);}\r
71 basic_frame& basic_frame::operator=(const basic_frame& other)\r
72 {\r
73         basic_frame temp(other);\r
74         temp.swap(*this);\r
75         return *this;\r
76 }\r
77 basic_frame::basic_frame(basic_frame&& other) : impl_(std::move(other.impl_)){}\r
78 basic_frame& basic_frame::operator=(basic_frame&& other)\r
79 {\r
80         basic_frame temp(std::move(other));\r
81         temp.swap(*this);\r
82         return *this;\r
83 }\r
84 void basic_frame::accept(frame_visitor& visitor){impl_->accept(*this, visitor);}\r
85 \r
86 const image_transform& basic_frame::get_image_transform() const { return impl_->image_transform_;}\r
87 image_transform& basic_frame::get_image_transform() { return impl_->image_transform_;}\r
88 const audio_transform& basic_frame::get_audio_transform() const { return impl_->audio_transform_;}\r
89 audio_transform& basic_frame::get_audio_transform() { return impl_->audio_transform_;}\r
90 \r
91 safe_ptr<basic_frame> basic_frame::interlace(const safe_ptr<basic_frame>& frame1, const safe_ptr<basic_frame>& frame2, video_mode::type mode)\r
92 {                       \r
93         if(frame1 == basic_frame::empty() && frame2 == basic_frame::empty())\r
94                 return basic_frame::empty();\r
95         \r
96         if(frame1 == basic_frame::eof() && frame2 == basic_frame::eof())\r
97                 return basic_frame::eof();\r
98         \r
99         if(frame1 == frame2 || mode == video_mode::progressive)\r
100                 return frame2;\r
101 \r
102         auto my_frame1 = make_safe<basic_frame>(frame1);\r
103         auto my_frame2 = make_safe<basic_frame>(frame2);\r
104         if(mode == video_mode::upper)\r
105         {\r
106                 my_frame1->get_image_transform().set_mode(video_mode::upper);   \r
107                 my_frame2->get_image_transform().set_mode(video_mode::lower);   \r
108         }                                                                                        \r
109         else                                                                             \r
110         {                                                                                        \r
111                 my_frame1->get_image_transform().set_mode(video_mode::lower);   \r
112                 my_frame2->get_image_transform().set_mode(video_mode::upper);   \r
113         }\r
114 \r
115         std::vector<safe_ptr<basic_frame>> frames;\r
116         frames.push_back(my_frame1);\r
117         frames.push_back(my_frame2);\r
118         return basic_frame(std::move(frames));\r
119 }\r
120 \r
121 safe_ptr<basic_frame> basic_frame::combine(const safe_ptr<basic_frame>& frame1, const safe_ptr<basic_frame>& frame2)\r
122 {\r
123         if(frame1 == basic_frame::empty() && frame2 == basic_frame::empty())\r
124                 return basic_frame::empty();\r
125         \r
126         if(frame1 == basic_frame::eof() && frame2 == basic_frame::eof())\r
127                 return basic_frame::eof();\r
128         \r
129         std::vector<safe_ptr<basic_frame>> frames;\r
130         frames.push_back(frame1);\r
131         frames.push_back(frame2);\r
132         return basic_frame(std::move(frames));\r
133 }\r
134 \r
135 safe_ptr<basic_frame> basic_frame::fill_and_key(const safe_ptr<basic_frame>& fill, const safe_ptr<basic_frame>& key)\r
136 {\r
137         if(fill == basic_frame::empty() && key == basic_frame::empty())\r
138                 return basic_frame::empty();\r
139         \r
140         if(fill == basic_frame::eof() && key == basic_frame::eof())\r
141                 return basic_frame::eof();\r
142 \r
143         if(key == basic_frame::empty() || key == basic_frame::eof())\r
144                 return fill;\r
145 \r
146         std::vector<safe_ptr<basic_frame>> frames;\r
147         key->get_image_transform().set_is_key(true);\r
148         frames.push_back(key);\r
149         frames.push_back(fill);\r
150         return basic_frame(std::move(frames));\r
151 }\r
152         \r
153 }}