]> git.sesse.net Git - mlt/commitdiff
Fix bugs with odd width YUV processing.
authorDan Dennedy <dan@dennedy.org>
Sun, 12 Sep 2010 19:51:23 +0000 (12:51 -0700)
committerDan Dennedy <dan@dennedy.org>
Sun, 12 Sep 2010 19:51:23 +0000 (12:51 -0700)
By preferring to crop on RGB and output an even width in case it
eventually needs to be converted to YUV, which is usually the case.

src/modules/core/filter_crop.c

index f5ba7e5e7c1713e45c53ad1adfd17b36e8310c63..ff91b95290ff08ef5d0f6823fc7f24d7f05069bb 100644 (file)
 
 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, sstride );
-               dest += stride;
-               s += stride + ( right + left ) * bpp;
+               memcpy( dest, src, dest_stride );
+               dest += dest_stride;
+               src += src_stride;
        }
 }
 
@@ -71,7 +71,11 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                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 );
 
@@ -85,6 +89,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
        {
                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:
@@ -195,8 +201,9 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
                        }
                }               
 
-               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 )