Fix black borders around the preview in some cases (#2331).
authorCarl Hetherington <cth@carlh.net>
Wed, 14 Sep 2022 23:03:51 +0000 (01:03 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 16 Sep 2022 20:38:05 +0000 (22:38 +0200)
We need to round the container size to the nearest multiple of 2
so that cropping subsampled sources does not leave gaps.  As far
as I can see:

- the direction that you round x in doesn't matter
- it's better to round y up

(if you calculate the error in the resulting ratio in each case).

src/lib/video_content.cc
src/wx/film_viewer.cc

index de3d3f3a2382e887ba31c10087d1c01834f6a598..1d1d010a95662193bc52ab84e5dacb2b8746fb10 100644 (file)
@@ -660,7 +660,7 @@ VideoContent::scaled_size (dcp::Size film_container)
        }
 
        auto size = size_after_crop ();
        }
 
        auto size = size_after_crop ();
-       size.width *= _sample_aspect_ratio.get_value_or(1);
+       size.width = std::lrint(size.width * _sample_aspect_ratio.get_value_or(1));
 
        /* This is what we will return unless there is any legacy stuff to take into account */
        auto auto_size = fit_ratio_within (size.ratio(), film_container);
 
        /* This is what we will return unless there is any legacy stuff to take into account */
        auto auto_size = fit_ratio_within (size.ratio(), film_container);
index b5b2ca972e57aa345856cea8ce28037db1788283..c56e2f5d26f89a3478e3e2385ddd99ee5dd82dd2 100644 (file)
@@ -303,6 +303,16 @@ FilmViewer::calculate_sizes ()
        out_size.width = max (64, out_size.width);
        out_size.height = max (64, out_size.height);
 
        out_size.width = max (64, out_size.width);
        out_size.height = max (64, out_size.height);
 
+       /* Make sure the video container sizes are always a multiple of 2 so that
+        * we don't get gaps with subsampled sources (e.g. YUV420)
+        */
+       if (out_size.width % 2) {
+               out_size.width++;
+       }
+       if (out_size.height % 2) {
+               out_size.height++;
+       }
+
        _player->set_video_container_size (out_size);
 }
 
        _player->set_video_container_size (out_size);
 }