2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG (www.casparcg.com).
\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
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
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
19 * Author: Robert Nagy, ronag89@gmail.com
\r
22 #include "../stdafx.h"
\r
24 #include "draw_frame.h"
\r
26 #include "data_frame.h"
\r
28 #include "frame_transform.h"
\r
30 #include <boost/foreach.hpp>
\r
32 namespace caspar { namespace core {
\r
34 struct draw_frame::impl
\r
37 std::vector<draw_frame> frames_;
\r
38 std::shared_ptr<spl::unique_ptr<const data_frame>> data_frame_;
\r
40 core::frame_transform frame_transform_;
\r
50 impl(int tag = impl::empty_tag)
\r
55 impl(spl::unique_ptr<const data_frame>&& frame)
\r
57 , data_frame_(new spl::unique_ptr<const data_frame>(std::move(frame)))
\r
61 impl(std::vector<draw_frame> frames)
\r
63 , frames_(std::move(frames))
\r
67 void accept(frame_visitor& visitor) const
\r
69 visitor.push(frame_transform_);
\r
72 visitor.visit(**data_frame_);
\r
76 BOOST_FOREACH(auto frame, frames_)
\r
77 frame.accept(visitor);
\r
82 bool operator==(const impl& other)
\r
84 return tag_ == other.tag_ &&
\r
85 frames_ == other.frames_ &&
\r
86 data_frame_ == other.data_frame_;
\r
90 draw_frame::draw_frame() : impl_(new impl()){}
\r
91 draw_frame::draw_frame(int tag) : impl_(new impl(std::move(tag))){}
\r
92 draw_frame::draw_frame(const draw_frame& other) : impl_(new impl(*other.impl_)){}
\r
93 draw_frame::draw_frame(draw_frame&& other) : impl_(std::move(other.impl_)){}
\r
94 draw_frame::draw_frame(spl::unique_ptr<const data_frame>&& frame) : impl_(new impl(std::move(frame))){}
\r
95 draw_frame::draw_frame(std::vector<draw_frame> frames) : impl_(new impl(frames)){}
\r
96 draw_frame::~draw_frame(){}
\r
97 draw_frame& draw_frame::operator=(draw_frame other)
\r
102 void draw_frame::swap(draw_frame& other){impl_.swap(other.impl_);}
\r
104 const core::frame_transform& draw_frame::transform() const { return impl_->frame_transform_;}
\r
105 core::frame_transform& draw_frame::transform() { return impl_->frame_transform_;}
\r
106 void draw_frame::accept(frame_visitor& visitor) const{impl_->accept(visitor);}
\r
107 bool draw_frame::operator==(const draw_frame& other)const{return *impl_ == *other.impl_;}
\r
108 bool draw_frame::operator!=(const draw_frame& other)const{return !(*this == other);}
\r
110 draw_frame draw_frame::interlace(draw_frame frame1, draw_frame frame2, core::field_mode mode)
\r
112 if(frame1 == draw_frame::eof() || frame2 == draw_frame::eof())
\r
113 return draw_frame::eof();
\r
115 if(frame1 == draw_frame::empty() && frame2 == draw_frame::empty())
\r
116 return draw_frame::empty();
\r
118 if(frame1 == frame2 || mode == field_mode::progressive)
\r
121 if(mode == field_mode::upper)
\r
123 frame1.transform().image_transform.field_mode = field_mode::upper;
\r
124 frame2.transform().image_transform.field_mode = field_mode::lower;
\r
128 frame1.transform().image_transform.field_mode = field_mode::lower;
\r
129 frame2.transform().image_transform.field_mode = field_mode::upper;
\r
132 std::vector<draw_frame> frames;
\r
133 frames.push_back(std::move(frame1));
\r
134 frames.push_back(std::move(frame2));
\r
135 return draw_frame(std::move(frames));
\r
138 draw_frame draw_frame::over(draw_frame frame1, draw_frame frame2)
\r
140 if(frame1 == draw_frame::eof() || frame2 == draw_frame::eof())
\r
141 return draw_frame::eof();
\r
143 if(frame1 == draw_frame::empty() && frame2 == draw_frame::empty())
\r
144 return draw_frame::empty();
\r
146 std::vector<draw_frame> frames;
\r
147 frames.push_back(std::move(frame1));
\r
148 frames.push_back(std::move(frame2));
\r
149 return draw_frame(std::move(frames));
\r
152 draw_frame draw_frame::mask(draw_frame fill, draw_frame key)
\r
154 if(fill == draw_frame::eof() || key == draw_frame::eof())
\r
155 return draw_frame::eof();
\r
157 if(fill == draw_frame::empty() || key == draw_frame::empty())
\r
158 return draw_frame::empty();
\r
160 std::vector<draw_frame> frames;
\r
161 key.transform().image_transform.is_key = true;
\r
162 frames.push_back(std::move(key));
\r
163 frames.push_back(std::move(fill));
\r
164 return draw_frame(std::move(frames));
\r
167 draw_frame draw_frame::still(draw_frame frame)
\r
169 frame.transform().image_transform.is_still = true;
\r
170 frame.transform().audio_transform.volume = 0.0;
\r
174 const draw_frame& draw_frame::eof()
\r
176 static draw_frame frame(impl::eof_tag);
\r
180 const draw_frame& draw_frame::empty()
\r
182 static draw_frame frame(impl::empty_tag);
\r
186 const draw_frame& draw_frame::late()
\r
188 static draw_frame frame(impl::late_tag);
\r