+ auto in_desc = av_pix_fmt_desc_get (_pixel_format);
+ if (!in_desc) {
+ throw PixelFormatError ("crop_scale_window()", _pixel_format);
+ }
+
+ /* Round down so that we crop only the number of pixels that is straightforward
+ * considering any subsampling.
+ */
+ Crop corrected_crop(
+ round_width_for_subsampling(crop.left, in_desc),
+ round_width_for_subsampling(crop.right, in_desc),
+ round_height_for_subsampling(crop.top, in_desc),
+ round_height_for_subsampling(crop.bottom, in_desc)
+ );
+
+ /* Also check that we aren't cropping more image than there actually is */
+ if ((corrected_crop.left + corrected_crop.right) >= (size().width - 4)) {
+ corrected_crop.left = 0;
+ corrected_crop.right = size().width - 4;
+ }
+
+ if ((corrected_crop.top + corrected_crop.bottom) >= (size().height - 4)) {
+ corrected_crop.top = 0;
+ corrected_crop.bottom = size().height - 4;
+ }
+