39 bool read_file =
false;
46 QFile inputFile(
path.c_str());
47 if (inputFile.open(QIODevice::ReadOnly))
49 QTextStream in(&inputFile);
52 QString line = in.readLine();
54 if (line.length() <= 0)
58 QStringList parts = line.split(
"=" );
59 std::string setting = parts[0].toStdString();
60 std::string value = parts[1].toStdString();
64 if (setting ==
"description") {
67 else if (setting ==
"frame_rate_num") {
68 std::stringstream(value) >> value_int;
71 else if (setting ==
"frame_rate_den") {
72 std::stringstream(value) >> value_int;
75 else if (setting ==
"width") {
76 std::stringstream(value) >> value_int;
79 else if (setting ==
"height") {
80 std::stringstream(value) >> value_int;
83 else if (setting ==
"progressive") {
84 std::stringstream(value) >> value_int;
87 else if (setting ==
"sample_aspect_num") {
88 std::stringstream(value) >> value_int;
91 else if (setting ==
"sample_aspect_den") {
92 std::stringstream(value) >> value_int;
95 else if (setting ==
"display_aspect_num") {
96 std::stringstream(value) >> value_int;
99 else if (setting ==
"display_aspect_den") {
100 std::stringstream(value) >> value_int;
103 else if (setting ==
"colorspace") {
104 std::stringstream(value) >> value_int;
113 catch (
const std::exception& e)
116 throw InvalidFile(
"Profile could not be found or loaded (or is invalid).",
path);
122 throw InvalidFile(
"Profile could not be found or loaded (or is invalid).",
path);
126 std::string Profile::formattedFPS(
bool include_decimal) {
129 std::stringstream fps_string;
132 fps_string << std::fixed << std::setprecision(0) << fps;
135 fps_string << std::fixed << std::setprecision(2) << fps;
137 if (!include_decimal) {
138 QString fps_qstring = QString::fromStdString(fps_string.str());
139 fps_qstring.replace(
".",
"");
140 fps_string.str(fps_qstring.toStdString());
143 return fps_string.str();
148 std::stringstream output;
149 std::string progressive_str =
"p";
151 progressive_str =
"i";
153 std::string fps_string = formattedFPS(
false);
154 output << std::setfill(
'0') << std::setw(5) <<
info.
width << std::setfill(
'\0') <<
"x";
155 output << std::setfill(
'0') << std::setw(4) <<
info.
height << std::setfill(
'\0') << progressive_str;
156 output << std::setfill(
'0') << std::setw(4) << fps_string << std::setfill(
'\0') <<
"_";
157 output << std::setfill(
'0') << std::setw(2) <<
info.
display_ratio.
num << std::setfill(
'\0') <<
"-";
164 std::stringstream output;
165 std::string progressive_str =
"p";
167 progressive_str =
"i";
169 std::string fps_string = formattedFPS(
true);
176 std::stringstream output;
177 std::string progressive_str =
"p";
179 progressive_str =
"i";
181 std::string fps_string = formattedFPS(
true);
189 std::stringstream output;
190 std::string progressive_str =
"p";
192 progressive_str =
"i";
194 std::string fps_string = formattedFPS(
true);
202 std::ofstream file(file_path);
203 if (!file.is_open()) {
204 throw std::ios_base::failure(
"Failed to save profile.");
208 file <<
"frame_rate_num=" <<
info.
fps.
num <<
"\n";
209 file <<
"frame_rate_den=" <<
info.
fps.
den <<
"\n";
238 root[
"fps"] = Json::Value(Json::objectValue);
241 root[
"pixel_ratio"] = Json::Value(Json::objectValue);
244 root[
"display_ratio"] = Json::Value(Json::objectValue);
263 catch (
const std::exception& e)
266 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
273 if (!root[
"description"].isNull())
275 if (!root[
"height"].isNull())
277 if (!root[
"width"].isNull())
279 if (!root[
"pixel_format"].isNull())
281 if (!root[
"fps"].isNull()) {
285 if (!root[
"pixel_ratio"].isNull()) {
290 if (!root[
"display_ratio"].isNull()) {
295 if (!root[
"progressive"].isNull())