@@ -1371,6 +1371,33 @@ void Timeline::apply_json_to_timeline(Json::Value change) {
13711371 else if (root_key == " fps" && sub_key == " den" )
13721372 // Set fps.den
13731373 info.fps .den = change[" value" ].asInt ();
1374+ else if (root_key == " display_ratio" && sub_key == " " && change[" value" ].isObject ()) {
1375+ // Set display_ratio fraction
1376+ if (!change[" value" ][" num" ].isNull ())
1377+ info.display_ratio .num = change[" value" ][" num" ].asInt ();
1378+ if (!change[" value" ][" den" ].isNull ())
1379+ info.display_ratio .den = change[" value" ][" den" ].asInt ();
1380+ }
1381+ else if (root_key == " display_ratio" && sub_key == " num" )
1382+ // Set display_ratio.num
1383+ info.display_ratio .num = change[" value" ].asInt ();
1384+ else if (root_key == " display_ratio" && sub_key == " den" )
1385+ // Set display_ratio.den
1386+ info.display_ratio .den = change[" value" ].asInt ();
1387+ else if (root_key == " pixel_ratio" && sub_key == " " && change[" value" ].isObject ()) {
1388+ // Set pixel_ratio fraction
1389+ if (!change[" value" ][" num" ].isNull ())
1390+ info.pixel_ratio .num = change[" value" ][" num" ].asInt ();
1391+ if (!change[" value" ][" den" ].isNull ())
1392+ info.pixel_ratio .den = change[" value" ][" den" ].asInt ();
1393+ }
1394+ else if (root_key == " pixel_ratio" && sub_key == " num" )
1395+ // Set pixel_ratio.num
1396+ info.pixel_ratio .num = change[" value" ].asInt ();
1397+ else if (root_key == " pixel_ratio" && sub_key == " den" )
1398+ // Set pixel_ratio.den
1399+ info.pixel_ratio .den = change[" value" ].asInt ();
1400+
13741401 else if (root_key == " sample_rate" )
13751402 // Set sample rate
13761403 info.sample_rate = change[" value" ].asInt ();
@@ -1380,9 +1407,7 @@ void Timeline::apply_json_to_timeline(Json::Value change) {
13801407 else if (root_key == " channel_layout" )
13811408 // Set channel layout
13821409 info.channel_layout = (ChannelLayout) change[" value" ].asInt ();
1383-
13841410 else
1385-
13861411 // Error parsing JSON (or missing keys)
13871412 throw InvalidJSONKey (" JSON change key is invalid" , change.toStyledString ());
13881413
@@ -1443,7 +1468,14 @@ void Timeline::ClearAllCache() {
14431468// Set Max Image Size (used for performance optimization). Convenience function for setting
14441469// Settings::Instance()->MAX_WIDTH and Settings::Instance()->MAX_HEIGHT.
14451470void Timeline::SetMaxSize (int width, int height) {
1446- // Init max image size (choose the smallest one)
1447- Settings::Instance ()->MAX_WIDTH = min (width, info.width );
1448- Settings::Instance ()->MAX_HEIGHT = min (height, info.height );
1471+ // Maintain aspect ratio regardless of what size is passed in
1472+ QSize display_ratio_size = QSize (info.display_ratio .num * info.pixel_ratio .ToFloat (), info.display_ratio .den * info.pixel_ratio .ToFloat ());
1473+ QSize proposed_size = QSize (min (width, info.width ), min (height, info.height ));
1474+
1475+ // Scale QSize up to proposed size
1476+ display_ratio_size.scale (proposed_size, Qt::KeepAspectRatio);
1477+
1478+ // Set max size
1479+ Settings::Instance ()->MAX_WIDTH = display_ratio_size.width ();
1480+ Settings::Instance ()->MAX_HEIGHT = display_ratio_size.height ();
14491481}
0 commit comments