]> git.sesse.net Git - casparcg/blob - core/video_format.cpp
b58e1f199a968d9bcb565a5600ee87211ea6fc85
[casparcg] / core / video_format.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: Robert Nagy, ronag89@gmail.com
20 */
21
22 #include "StdAfx.h"
23
24 #include "video_format.h"
25
26 #include <boost/algorithm/string.hpp>
27
28 namespace caspar { namespace core {
29         
30         const std::vector<video_format_desc> format_descs = {
31                 { video_format::pal,          720,  576,  1024, 576,  field_mode::upper,       25000, 1000, L"PAL",          { 1920                         } },
32                 { video_format::ntsc,         720,  486,  720,  540,  field_mode::lower,       30000, 1001, L"NTSC",         { 1602, 1601, 1602, 1601, 1602 } },
33                 { video_format::x576p2500,    720,  576,  1024, 576,  field_mode::progressive, 25000, 1000, L"576p2500",     { 1920                         } },
34                 { video_format::x720p2398,    1280, 720,  1280, 720,  field_mode::progressive, 24000, 1001, L"720p2398",     { 2002                         } },
35                 { video_format::x720p2400,    1280, 720,  1280, 720,  field_mode::progressive, 24000, 1000, L"720p2400",     { 2000                         } },
36                 { video_format::x720p2500,    1280, 720,  1280, 720,  field_mode::progressive, 25000, 1000, L"720p2500",     { 1920                         } },
37                 { video_format::x720p5000,    1280, 720,  1280, 720,  field_mode::progressive, 50000, 1000, L"720p5000",     { 960                          } },
38                 { video_format::x720p2997,    1280, 720,  1280, 720,  field_mode::progressive, 30000, 1001, L"720p2997",     { 1602, 1601, 1602, 1601, 1602 } },
39                 { video_format::x720p5994,    1280, 720,  1280, 720,  field_mode::progressive, 60000, 1001, L"720p5994",     { 801,  800,  801,  801,  801  } },
40                 { video_format::x720p3000,    1280, 720,  1280, 720,  field_mode::progressive, 30000, 1000, L"720p3000",     { 1600                         } },
41                 { video_format::x720p6000,    1280, 720,  1280, 720,  field_mode::progressive, 60000, 1000, L"720p6000",     { 800                          } },
42                 { video_format::x1080p2398,   1920, 1080, 1920, 1080, field_mode::progressive, 24000, 1001, L"1080p2398",    { 2002                         } },
43                 { video_format::x1080p2400,   1920, 1080, 1920, 1080, field_mode::progressive, 24000, 1000, L"1080p2400",    { 2000                         } },
44                 { video_format::x1080i5000,   1920, 1080, 1920, 1080, field_mode::upper,       25000, 1000, L"1080i5000",    { 1920                         } },
45                 { video_format::x1080i5994,   1920, 1080, 1920, 1080, field_mode::upper,       30000, 1001, L"1080i5994",    { 1602, 1601, 1602, 1601, 1602 } },
46                 { video_format::x1080i6000,   1920, 1080, 1920, 1080, field_mode::upper,       30000, 1000, L"1080i6000",    { 1600                         } },
47                 { video_format::x1080p2500,   1920, 1080, 1920, 1080, field_mode::progressive, 25000, 1000, L"1080p2500",    { 1920                         } },
48                 { video_format::x1080p2997,   1920, 1080, 1920, 1080, field_mode::progressive, 30000, 1001, L"1080p2997",    { 1602, 1601, 1602, 1601, 1602 } },
49                 { video_format::x1080p3000,   1920, 1080, 1920, 1080, field_mode::progressive, 30000, 1000, L"1080p3000",    { 1600                         } },
50                 { video_format::x1080p5000,   1920, 1080, 1920, 1080, field_mode::progressive, 50000, 1000, L"1080p5000",    { 960                          } },
51                 { video_format::x1080p5994,   1920, 1080, 1920, 1080, field_mode::progressive, 60000, 1001, L"1080p5994",    { 801,  800,  801,  801,  801  } },
52                 { video_format::x1080p6000,   1920, 1080, 1920, 1080, field_mode::progressive, 60000, 1000, L"1080p6000",    { 800                          } },
53                 { video_format::x1556p2398,   2048, 1556, 2048, 1556, field_mode::progressive, 24000, 1001, L"1556p2398",    { 2002                         } },
54                 { video_format::x1556p2400,   2048, 1556, 2048, 1556, field_mode::progressive, 24000, 1000, L"1556p2400",    { 2000                         } },
55                 { video_format::x1556p2500,   2048, 1556, 2048, 1556, field_mode::progressive, 25000, 1000, L"1556p2500",    { 1920                         } },
56                 { video_format::dci1080p2398, 2048, 1080, 2048, 1080, field_mode::progressive, 24000, 1001, L"dci1080p2398", { 2002                         } },
57                 { video_format::dci1080p2400, 2048, 1080, 2048, 1080, field_mode::progressive, 24000, 1000, L"dci1080p2400", { 2000                         } },
58                 { video_format::dci1080p2500, 2048, 1080, 2048, 1080, field_mode::progressive, 25000, 1000, L"dci1080p2500", { 1920                         } },
59                 { video_format::x2160p2398,   3840, 2160, 3840, 2160, field_mode::progressive, 24000, 1001, L"2160p2398",    { 2002                         } },
60                 { video_format::x2160p2400,   3840, 2160, 3840, 2160, field_mode::progressive, 24000, 1000, L"2160p2400",    { 2000                         } },
61                 { video_format::x2160p2500,   3840, 2160, 3840, 2160, field_mode::progressive, 25000, 1000, L"2160p2500",    { 1920                         } },
62                 { video_format::x2160p2997,   3840, 2160, 3840, 2160, field_mode::progressive, 30000, 1001, L"2160p2997",    { 1602, 1601, 1602, 1601, 1602 } },
63                 { video_format::x2160p3000,   3840, 2160, 3840, 2160, field_mode::progressive, 30000, 1000, L"2160p3000",    { 1600                         } },
64                 { video_format::dci2160p2398, 4096, 2160, 4096, 2160, field_mode::progressive, 24000, 1001, L"dci2160p2398", { 2002                         } },
65                 { video_format::dci2160p2400, 4096, 2160, 4096, 2160, field_mode::progressive, 24000, 1000, L"dci2160p2400", { 2000                         } },
66                 { video_format::dci2160p2500, 4096, 2160, 4096, 2160, field_mode::progressive, 25000, 1000, L"dci2160p2500", { 1920                         } },
67                 { video_format::invalid,      0,    0,    0,    0,    field_mode::progressive, 1,     1,    L"invalid",      { 1                            } }
68         };
69
70 video_format_desc::video_format_desc(
71                 video_format format,
72                 int width,
73                 int height,
74                 int square_width,
75                 int square_height,
76                 core::field_mode field_mode,
77                 int time_scale,
78                 int duration,
79                 const std::wstring& name,
80                 const std::vector<int>& audio_cadence)
81         : format(format)
82         , width(width)
83         , height(height)
84         , square_width(square_width)
85         , square_height(square_height)
86         , field_mode(field_mode)
87         , fps(static_cast<double>(time_scale) / static_cast<double>(duration))
88         , time_scale(time_scale)
89         , duration(duration)
90         , field_count(field_mode == core::field_mode::progressive ? 1 : 2)
91         , size(width*height*4)
92         , name(name)
93         , audio_sample_rate(48000)
94         , audio_cadence(audio_cadence)
95 {
96 }
97
98 video_format_desc::video_format_desc(video_format format)
99         : format(video_format::invalid)
100         , field_mode(core::field_mode::empty)
101 {
102         *this = format_descs.at(static_cast<int>(format));
103 }
104
105 video_format_desc::video_format_desc(const std::wstring& name)
106         : format(video_format::invalid)
107         , field_mode(core::field_mode::empty)
108 {       
109         *this = video_format_desc(video_format::invalid);
110         for(auto it = std::begin(format_descs); it != std::end(format_descs)-1; ++it)
111         {
112                 if(boost::iequals(it->name, name))
113                 {
114                         *this = *it;
115                         break;
116                 }
117         }
118 }
119
120 bool operator==(const video_format_desc& lhs, const video_format_desc& rhs)
121 {                                                                                       
122         return lhs.format == rhs.format;
123 }
124
125 bool operator!=(const video_format_desc& lhs, const video_format_desc& rhs)
126 {
127         return !(lhs == rhs);
128 }
129
130 std::wostream& operator<<(std::wostream& out, const video_format_desc& format_desc)
131 {
132         out << format_desc.name.c_str();
133         return out;
134 }
135
136
137 }}
138