static void crop( uint8_t *src, uint8_t *dest, int bpp, int width, int height, int left, int right, int top, int bottom )
{
- int stride = ( width - left - right ) * bpp;
- // Copy an extra line because sometimes the downstream filters (scaler?) access it.
- int y = height - top - bottom + 2;
- uint8_t *s = &src[ ( ( top * width ) + left ) * bpp ];
+ int src_stride = ( width ) * bpp;
+ int dest_stride = ( width - left - right ) * bpp;
+ int y = height - top - bottom + 1;
+ src += top * src_stride + left * bpp;
while ( --y )
{
- memcpy( dest, s, stride );
- dest += stride;
- s += stride + ( right + left ) * bpp;
+ memcpy( dest, src, dest_stride );
+ dest += dest_stride;
+ src += src_stride;
}
}
mlt_properties_set_int( properties, "rescale_width", mlt_properties_get_int( properties, "crop.original_width" ) );
mlt_properties_set_int( properties, "rescale_height", mlt_properties_get_int( properties, "crop.original_height" ) );
}
-
+
+ // Subsampled YUV is messy and less precise.
+ if ( *format == mlt_image_yuv422 )
+ *format = mlt_image_rgb24;
+
// Now get the image
error = mlt_frame_get_image( this, image, format, width, height, writable );
{
int bpp;
+ mlt_log_debug( NULL, "[filter crop] %s %dx%d -> %dx%d\n", mlt_image_format_name(*format),
+ *width, *height, owidth, oheight);
switch ( *format )
{
case mlt_image_yuv422:
}
}
- left -= left % 2;
- right -= right % 2;
+ // Coerce the output to an even width because subsampled YUV with odd widths is too
+ // risky for downstream processing to handle correctly.
+ left += ( width - left - right ) & 1;
if ( width - left - right < 8 )
left = right = 0;
if ( height - top - bottom < 8 )