]> git.sesse.net Git - casparcg/blob - core/frame/geometry.cpp
[ffmpeg] Ported 2.0.7 ffmpeg producer to 2.1.0 while still keeping the usage of the...
[casparcg] / core / frame / geometry.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Niklas P Andersson, niklas.p.andersson@svt.se
20 */
21
22
23 #include "../StdAfx.h"
24
25 #include "geometry.h"
26
27 namespace caspar { namespace core {
28
29 frame_geometry::coord::coord(double vertex_x, double vertex_y, double texture_x, double texture_y)
30         : vertex_x(vertex_x)
31         , vertex_y(vertex_y)
32         , texture_x(texture_x)
33         , texture_y(texture_y)
34 {
35 }
36
37 bool frame_geometry::coord::operator==(const frame_geometry::coord& other) const
38 {
39         return vertex_x         == other.vertex_x
40                 && vertex_y             == other.vertex_y
41                 && texture_x    == other.texture_x
42                 && texture_y    == other.texture_y
43                 && texture_r    == other.texture_r
44                 && texture_q    == other.texture_q;
45 }
46
47 struct frame_geometry::impl
48 {
49         impl(frame_geometry::geometry_type type, std::vector<coord> data)
50                 : type_(type)
51         {
52                 if (type == geometry_type::quad && data.size() != 4)
53                         CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("The number of coordinates needs to be 4"));
54
55                 if (type == geometry_type::quad_list)
56                 {
57                         if (data.size() % 4 != 0)
58                                 CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("The number of coordinates needs to be a multiple of 4"));
59                 }
60
61                 data_ = std::move(data);
62         }
63         
64         frame_geometry::geometry_type   type_;
65         std::vector<coord>                              data_;
66 };
67
68 frame_geometry::frame_geometry(geometry_type type, std::vector<coord> data) : impl_(new impl(type, std::move(data))) {}
69
70 frame_geometry::geometry_type frame_geometry::type() const { return impl_->type_; }
71 const std::vector<frame_geometry::coord>& frame_geometry::data() const
72 {
73         return impl_->data_;
74 }
75         
76 const frame_geometry& frame_geometry::get_default()
77 {
78         static std::vector<frame_geometry::coord> data = {
79         //    vertex    texture
80                 { 0.0, 0.0, 0.0, 0.0 }, // upper left
81                 { 1.0, 0.0, 1.0, 0.0 }, // upper right
82                 { 1.0, 1.0, 1.0, 1.0 }, // lower right
83                 { 0.0, 1.0, 0.0, 1.0 }  // lower left
84         };
85         static const frame_geometry g(frame_geometry::geometry_type::quad, data);
86
87         return g;
88 }
89
90 }}