X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fcore%2Ffilter_crop.c;h=8f3b7765042315e8e4f13afbc2329c428b63d3f5;hb=facc6328e46eb0c973c6293390a14258abf071d4;hp=ff91b95290ff08ef5d0f6823fc7f24d7f05069bb;hpb=e508520b21543f7435531a5aef91a321532b16c7;p=mlt diff --git a/src/modules/core/filter_crop.c b/src/modules/core/filter_crop.c index ff91b952..8f3b7765 100644 --- a/src/modules/core/filter_crop.c +++ b/src/modules/core/filter_crop.c @@ -46,18 +46,19 @@ static void crop( uint8_t *src, uint8_t *dest, int bpp, int width, int height, i /** Do it :-). */ -static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) +static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { int error = 0; + mlt_profile profile = mlt_frame_pop_service( frame ); // Get the properties from the frame - mlt_properties properties = MLT_FRAME_PROPERTIES( this ); + mlt_properties properties = MLT_FRAME_PROPERTIES( frame ); // Correct Width/height if necessary if ( *width == 0 || *height == 0 ) { - *width = mlt_properties_get_int( properties, "normalised_width" ); - *height = mlt_properties_get_int( properties, "normalised_height" ); + *width = profile->width; + *height = profile->height; } int left = mlt_properties_get_int( properties, "crop.left" ); @@ -72,12 +73,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * 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 ); + error = mlt_frame_get_image( frame, image, format, width, height, writable ); int owidth = *width - left - right; int oheight = *height - top - bottom; @@ -89,51 +86,34 @@ 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: - bpp = 2; - break; - case mlt_image_rgb24: - bpp = 3; - break; - case mlt_image_rgb24a: - case mlt_image_opengl: - bpp = 4; - break; - default: - // XXX: we only know how to crop packed formats - return 1; - } - - // Provides a manual override for misreported field order - if ( mlt_properties_get( properties, "meta.top_field_first" ) ) + // Subsampled YUV is messy and less precise. + if ( *format == mlt_image_yuv422 && frame->convert_image ) { - mlt_properties_set_int( properties, "top_field_first", mlt_properties_get_int( properties, "meta.top_field_first" ) ); - mlt_properties_set_int( properties, "meta.top_field_first", 0 ); + mlt_image_format requested_format = mlt_image_rgb24; + frame->convert_image( frame, image, format, requested_format ); } + + mlt_log_debug( NULL, "[filter crop] %s %dx%d -> %dx%d\n", mlt_image_format_name(*format), + *width, *height, owidth, oheight); if ( top % 2 ) mlt_properties_set_int( properties, "top_field_first", !mlt_properties_get_int( properties, "top_field_first" ) ); // Create the output image - uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * bpp ); + int size = mlt_image_format_size( *format, owidth, oheight, &bpp ); + uint8_t *output = mlt_pool_alloc( size ); if ( output ) { // Call the generic resize crop( *image, output, bpp, *width, *height, left, right, top, bottom ); // Now update the frame + mlt_frame_set_image( frame, output, size, mlt_pool_release ); *image = output; - mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * bpp, ( mlt_destructor )mlt_pool_release, NULL ); - mlt_properties_set_int( properties, "width", owidth ); - mlt_properties_set_int( properties, "height", oheight ); } // We should resize the alpha too - uint8_t *alpha = mlt_frame_get_alpha_mask( this ); + uint8_t *alpha = mlt_frame_get_alpha_mask( frame ); int alpha_size = 0; mlt_properties_get_data( properties, "alpha", &alpha_size ); if ( alpha && alpha_size >= ( *width * *height ) ) @@ -142,8 +122,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * if ( newalpha ) { crop( alpha, newalpha, 1, *width, *height, left, right, top, bottom ); - mlt_properties_set_data( properties, "alpha", newalpha, owidth * oheight, ( mlt_destructor )mlt_pool_release, NULL ); - this->get_alpha_mask = NULL; + mlt_frame_set_alpha( frame, newalpha, owidth * oheight, mlt_pool_release ); } } *width = owidth; @@ -156,31 +135,41 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * /** Filter processing. */ -static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) +static mlt_frame filter_process( mlt_filter filter, mlt_frame frame ) { - if ( mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "active" ) ) + if ( mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "active" ) ) { // Push the get_image method on to the stack + mlt_frame_push_service( frame, mlt_service_profile( MLT_FILTER_SERVICE( filter ) ) ); mlt_frame_push_get_image( frame, filter_get_image ); } else { - mlt_properties filter_props = MLT_FILTER_PROPERTIES( this ); + mlt_properties filter_props = MLT_FILTER_PROPERTIES( filter ); mlt_properties frame_props = MLT_FRAME_PROPERTIES( frame ); int left = mlt_properties_get_int( filter_props, "left" ); int right = mlt_properties_get_int( filter_props, "right" ); int top = mlt_properties_get_int( filter_props, "top" ); int bottom = mlt_properties_get_int( filter_props, "bottom" ); - int width = mlt_properties_get_int( frame_props, "real_width" ); - int height = mlt_properties_get_int( frame_props, "real_height" ); + int width = mlt_properties_get_int( frame_props, "meta.media.width" ); + int height = mlt_properties_get_int( frame_props, "meta.media.height" ); + int use_profile = mlt_properties_get_int( filter_props, "use_profile" ); + mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) ); + if ( use_profile ) + { + top = top * height / profile->height; + bottom = bottom * height / profile->height; + left = left * width / profile->width; + right = right * width / profile->width; + } if ( mlt_properties_get_int( filter_props, "center" ) ) { double aspect_ratio = mlt_frame_get_aspect_ratio( frame ); if ( aspect_ratio == 0.0 ) - aspect_ratio = mlt_properties_get_double( frame_props, "consumer_aspect_ratio" ); + aspect_ratio = mlt_profile_sar( profile ); double input_ar = aspect_ratio * width / height; - double output_ar = mlt_profile_dar( mlt_service_profile( MLT_FILTER_SERVICE(this) ) ); + double output_ar = mlt_profile_dar( mlt_service_profile( MLT_FILTER_SERVICE(filter) ) ); int bias = mlt_properties_get_int( filter_props, "center_bias" ); if ( input_ar > output_ar ) @@ -188,6 +177,8 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) left = right = ( width - rint( output_ar * height / aspect_ratio ) ) / 2; if ( abs(bias) > left ) bias = bias < 0 ? -left : left; + else if ( use_profile ) + bias = bias * width / profile->width; left -= bias; right += bias; } @@ -196,6 +187,8 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) top = bottom = ( height - rint( aspect_ratio * width / output_ar ) ) / 2; if ( abs(bias) > top ) bias = bias < 0 ? -top : top; + else if ( use_profile ) + bias = bias * height / profile->height; top -= bias; bottom += bias; } @@ -214,8 +207,8 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) mlt_properties_set_int( frame_props, "crop.bottom", bottom ); mlt_properties_set_int( frame_props, "crop.original_width", width ); mlt_properties_set_int( frame_props, "crop.original_height", height ); - mlt_properties_set_int( frame_props, "real_width", width - left - right ); - mlt_properties_set_int( frame_props, "real_height", height - top - bottom ); + mlt_properties_set_int( frame_props, "meta.media.width", width - left - right ); + mlt_properties_set_int( frame_props, "meta.media.height", height - top - bottom ); } return frame; } @@ -225,12 +218,12 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) mlt_filter filter_crop_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { - mlt_filter this = calloc( sizeof( struct mlt_filter_s ), 1 ); - if ( mlt_filter_init( this, this ) == 0 ) + mlt_filter filter = calloc( 1, sizeof( struct mlt_filter_s ) ); + if ( mlt_filter_init( filter, filter ) == 0 ) { - this->process = filter_process; + filter->process = filter_process; if ( arg ) - mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "active", atoi( arg ) ); + mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "active", atoi( arg ) ); } - return this; + return filter; }