]> git.sesse.net Git - casparcg/blob - core/video_format.cpp
ec0c5a099092e5465a49e9ec64a79801af2b4662
[casparcg] / core / video_format.cpp
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\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 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "StdAfx.h"\r
23 \r
24 #include "video_format.h"\r
25 \r
26 #include <boost/algorithm/string.hpp>\r
27 #include <boost/assign.hpp>\r
28 \r
29 namespace caspar { namespace core {\r
30         \r
31 const std::vector<video_format_desc> format_descs = boost::assign::list_of\r
32         (video_format_desc(video_format::pal,                    720,  576, 1024, 576,  field_mode::upper,                         25,     1, L"PAL",           boost::assign::list_of<int>(3840)))\r
33         (video_format_desc(video_format::ntsc,                   720,  486,  720, 540,  field_mode::lower,                      30000,  1001, L"NTSC",          boost::assign::list_of<int>(3204)(3202)(3204)(3202)(3204)))\r
34         (video_format_desc(video_format::x576p2500,              720,  576,  720, 576,  field_mode::progressive,           25,     1, L"576p2500",      boost::assign::list_of<int>(3840)                                               ))\r
35         (video_format_desc(video_format::x720p2500,             1280,  720, 1280, 720,  field_mode::progressive,           25,     1, L"720p2500",      boost::assign::list_of<int>(3840)                                               )) \r
36         (video_format_desc(video_format::x720p5000,             1280,  720, 1280, 720,  field_mode::progressive,           50,     1, L"720p5000",      boost::assign::list_of<int>(1920)                                               )) \r
37         (video_format_desc(video_format::x720p5994,             1280,  720, 1280, 720,  field_mode::progressive,        60000,  1001, L"720p5994",      boost::assign::list_of<int>(1602)(1601)(1602)(1601)(1602)))\r
38         (video_format_desc(video_format::x720p6000,             1280,  720, 1280, 720,  field_mode::progressive,           60,     1, L"720p6000",      boost::assign::list_of<int>(1600)                                               ))\r
39         (video_format_desc(video_format::x1080p2397,    1920, 1080, 1920, 1080, field_mode::progressive,        24000,  1001, L"1080p2398",     boost::assign::list_of<int>(4004)                                               ))\r
40         (video_format_desc(video_format::x1080p2400,    1920, 1080, 1920, 1080, field_mode::progressive,           24,     1, L"1080p2400",     boost::assign::list_of<int>(4000)                                               ))\r
41         (video_format_desc(video_format::x1080i5000,    1920, 1080, 1920, 1080, field_mode::upper,                         25,     1, L"1080i5000",     boost::assign::list_of<int>(3840)                                               ))\r
42         (video_format_desc(video_format::x1080i5994,    1920, 1080, 1920, 1080, field_mode::upper,                      30000,  1001, L"1080i5994",     boost::assign::list_of<int>(3204)(3202)(3204)(3202)(3204)))\r
43         (video_format_desc(video_format::x1080i6000,    1920, 1080, 1920, 1080, field_mode::upper,                         30,     1, L"1080i6000",     boost::assign::list_of<int>(3200)                                               ))\r
44         (video_format_desc(video_format::x1080p2500,    1920, 1080, 1920, 1080, field_mode::progressive,           25,     1, L"1080p2500",     boost::assign::list_of<int>(3840)                                               ))\r
45         (video_format_desc(video_format::x1080p2997,    1920, 1080, 1920, 1080, field_mode::progressive,        30000,  1001, L"1080p2997",     boost::assign::list_of<int>(3204)(3202)(3204)(3202)(3204)))\r
46         (video_format_desc(video_format::x1080p3000,    1920, 1080, 1920, 1080, field_mode::progressive,           30,     1, L"1080p3000",     boost::assign::list_of<int>(3200)                                               ))\r
47         (video_format_desc(video_format::x1080p5000,    1920, 1080, 1920, 1080, field_mode::progressive,           50,     1, L"1080p5000",     boost::assign::list_of<int>(1920)                                               ))\r
48         (video_format_desc(video_format::invalid,                  0,    0,    0,        0, field_mode::progressive,        1,     1, L"invalid",       boost::assign::list_of<int>(1)                                                  ));\r
49 \r
50 video_format_desc::video_format_desc(video_format format,\r
51                                         int width,\r
52                                         int height,\r
53                                         int square_width,\r
54                                         int square_height,\r
55                                         core::field_mode field_mode,\r
56                                         int time_scale,\r
57                                         int duration,\r
58                                         const std::wstring& name,\r
59                                         const std::vector<int>& audio_cadence)\r
60         : format(format)\r
61         , width(width)\r
62         , height(height)\r
63         , square_width(square_width)\r
64         , square_height(square_height)\r
65         , field_mode(field_mode)\r
66         , fps((double)time_scale/(double)duration)\r
67         , time_scale(time_scale)\r
68         , duration(duration)\r
69         , field_count(field_mode == field_mode::progressive ? 1 : 2)\r
70         , size(width*height*4)\r
71         , name(name)\r
72         , audio_sample_rate(48000)\r
73         , audio_channels(2)\r
74         , audio_cadence(audio_cadence)\r
75 {\r
76 }\r
77 \r
78 video_format_desc::video_format_desc(video_format format)\r
79         : format(video_format::invalid)\r
80         , field_mode(field_mode::empty)\r
81 {\r
82         *this = format_descs.at(format.value());\r
83 }\r
84 \r
85 video_format_desc::video_format_desc(const std::wstring& name)\r
86         : format(video_format::invalid)\r
87         , field_mode(field_mode::empty)\r
88 {       \r
89         *this = video_format_desc(video_format::invalid);\r
90         for(auto it = std::begin(format_descs); it != std::end(format_descs)-1; ++it)\r
91         {\r
92                 if(boost::iequals(it->name, name))\r
93                 {\r
94                         *this = *it;\r
95                         break;\r
96                 }\r
97         }\r
98 }\r
99 \r
100 bool operator==(const video_format_desc& lhs, const video_format_desc& rhs)\r
101 {                                                                                       \r
102         return lhs.format == rhs.format;\r
103 }\r
104 \r
105 bool operator!=(const video_format_desc& lhs, const video_format_desc& rhs)\r
106 {\r
107         return !(lhs == rhs);\r
108 }\r
109 \r
110 std::wostream& operator<<(std::wostream& out, const video_format_desc& format_desc)\r
111 {\r
112         out << format_desc.name.c_str();\r
113         return out;\r
114 }\r
115 \r
116 \r
117 }}\r
118 \r