40 bool read_file =
false;
58 QFile inputFile(
path.c_str());
59 if (inputFile.open(QIODevice::ReadOnly))
61 QTextStream in(&inputFile);
64 QString line = in.readLine();
66 if (line.length() <= 0)
70 QStringList parts = line.split(
"=" );
71 std::string setting = parts[0].toStdString();
72 std::string value = parts[1].toStdString();
76 if (setting ==
"description") {
79 else if (setting ==
"frame_rate_num") {
80 std::stringstream(value) >> value_int;
83 else if (setting ==
"frame_rate_den") {
84 std::stringstream(value) >> value_int;
87 else if (setting ==
"width") {
88 std::stringstream(value) >> value_int;
91 else if (setting ==
"height") {
92 std::stringstream(value) >> value_int;
95 else if (setting ==
"progressive") {
96 std::stringstream(value) >> value_int;
99 else if (setting ==
"sample_aspect_num") {
100 std::stringstream(value) >> value_int;
103 else if (setting ==
"sample_aspect_den") {
104 std::stringstream(value) >> value_int;
107 else if (setting ==
"display_aspect_num") {
108 std::stringstream(value) >> value_int;
111 else if (setting ==
"display_aspect_den") {
112 std::stringstream(value) >> value_int;
115 else if (setting ==
"colorspace") {
116 std::stringstream(value) >> value_int;
119 else if (setting ==
"spherical") {
120 std::stringstream(value) >> value_int;
129 catch (
const std::exception& e)
132 throw InvalidFile(
"Profile could not be found or loaded (or is invalid).",
path);
138 throw InvalidFile(
"Profile could not be found or loaded (or is invalid).",
path);
142 std::string Profile::formattedFPS(
bool include_decimal) {
145 std::stringstream fps_string;
148 fps_string << std::fixed << std::setprecision(0) << fps;
151 fps_string << std::fixed << std::setprecision(2) << fps;
153 if (!include_decimal) {
154 QString fps_qstring = QString::fromStdString(fps_string.str());
155 fps_qstring.replace(
".",
"");
156 fps_string.str(fps_qstring.toStdString());
159 return fps_string.str();
164 std::stringstream output;
165 std::string progressive_str =
"p";
167 progressive_str =
"i";
169 std::string fps_string = formattedFPS(
false);
170 output << std::setfill(
'0') << std::setw(5) <<
info.
width << std::setfill(
'\0') <<
"x";
171 output << std::setfill(
'0') << std::setw(4) <<
info.
height << std::setfill(
'\0') << progressive_str;
172 output << std::setfill(
'0') << std::setw(4) << fps_string << std::setfill(
'\0') <<
"_";
173 output << std::setfill(
'0') << std::setw(2) <<
info.
display_ratio.
num << std::setfill(
'\0') <<
"-";
186 std::stringstream output;
187 std::string progressive_str =
"p";
189 progressive_str =
"i";
191 std::string fps_string = formattedFPS(
true);
204 std::stringstream output;
205 std::string progressive_str =
"p";
207 progressive_str =
"i";
209 std::string fps_string = formattedFPS(
true);
223 std::stringstream output;
224 std::string progressive_str =
"p";
226 progressive_str =
"i";
228 std::string fps_string = formattedFPS(
true);
243 std::ofstream file(file_path);
244 if (!file.is_open()) {
245 throw std::ios_base::failure(
"Failed to save profile.");
249 file <<
"frame_rate_num=" <<
info.
fps.
num <<
"\n";
250 file <<
"frame_rate_den=" <<
info.
fps.
den <<
"\n";
280 root[
"fps"] = Json::Value(Json::objectValue);
283 root[
"pixel_ratio"] = Json::Value(Json::objectValue);
286 root[
"display_ratio"] = Json::Value(Json::objectValue);
306 catch (
const std::exception& e)
309 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
316 if (!root[
"description"].isNull())
318 if (!root[
"height"].isNull())
320 if (!root[
"width"].isNull())
322 if (!root[
"pixel_format"].isNull())
324 if (!root[
"fps"].isNull()) {
328 if (!root[
"pixel_ratio"].isNull()) {
333 if (!root[
"display_ratio"].isNull()) {
338 if (!root[
"progressive"].isNull())
340 if (!root[
"spherical"].isNull())