X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fcore%2Ffilter_rescale.c;h=0305db4174026f9d14811fccd1cd26dab1170b37;hb=4b72d1071d80828a599085618bbba67a18d14e56;hp=dfbec8fb7b8917eb59d5ccfb912a6eceaad77e29;hpb=79d3c5ad4272c5bfd36dcb5e9a1a77bc04338983;p=melted diff --git a/src/modules/core/filter_rescale.c b/src/modules/core/filter_rescale.c index dfbec8f..0305db4 100644 --- a/src/modules/core/filter_rescale.c +++ b/src/modules/core/filter_rescale.c @@ -31,7 +31,7 @@ typedef int ( *image_scaler )( mlt_frame this, uint8_t **image, mlt_image_format static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format iformat, mlt_image_format oformat, int iwidth, int iheight, int owidth, int oheight ) { // Get the properties - mlt_properties properties = mlt_frame_properties( this ); + mlt_properties properties = MLT_FRAME_PROPERTIES( this ); // Get the rescaling interpolsation char *interps = mlt_properties_get( properties, "rescale.interp" ); @@ -108,19 +108,78 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format iform return 0; } +static void scale_alpha( mlt_frame this, int iwidth, int iheight, int owidth, int oheight ) +{ + int size = 0; + uint8_t *input = mlt_properties_get_data( MLT_FRAME_PROPERTIES( this ), "alpha", &size ); + + if ( input != NULL && ( ( size == iwidth * iheight ) || size == ( iwidth * ( iheight + 1 ) ) ) ) + { + uint8_t *output = mlt_pool_alloc( owidth * oheight ); + + // Derived coordinates + int dy, dx; + + // Calculate ranges + int out_x_range = owidth / 2; + int out_y_range = oheight / 2; + int in_x_range = iwidth / 2; + int in_y_range = iheight / 2; + + // Output pointers + register uint8_t *out_line = output; + register uint8_t *out_ptr; + + // Calculate a middle pointer + uint8_t *in_middle = input + iwidth * in_y_range + in_x_range; + uint8_t *in_line; + + // Generate the affine transform scaling values + register int scale_width = ( iwidth << 16 ) / owidth; + register int scale_height = ( iheight << 16 ) / oheight; + register int base = 0; + + int outer = out_x_range * scale_width; + int bottom = out_y_range * scale_height; + + // Loop for the entirety of our output height. + for ( dy = - bottom; dy < bottom; dy += scale_height ) + { + // Start at the beginning of the line + out_ptr = out_line; + + // Pointer to the middle of the input line + in_line = in_middle + ( dy >> 16 ) * iwidth; + + // Loop for the entirety of our output row. + for ( dx = - outer; dx < outer; dx += scale_width ) + { + base = dx >> 15; + *out_ptr ++ = *( in_line + base ); + } + + // Move to next output line + out_line += owidth; + } + + this->get_alpha_mask = NULL; + mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", output, 0, mlt_pool_release, NULL ); + } +} + /** Do it :-). */ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { // Get the frame properties - mlt_properties properties = mlt_frame_properties( this ); + mlt_properties properties = MLT_FRAME_PROPERTIES( this ); // Get the filter from the stack mlt_filter filter = mlt_frame_pop_service( this ); // Get the filter properties - mlt_properties filter_properties = mlt_filter_properties( filter ); + mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter ); // Get the image scaler method image_scaler scaler_method = mlt_properties_get_data( filter_properties, "method", NULL ); @@ -133,7 +192,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * } // There can be problems with small images - avoid them (by hacking - gah) - if ( *width >= 2 && *height >= 6 ) + if ( *width >= 6 && *height >= 6 ) { int iwidth = *width; int iheight = *height; @@ -145,7 +204,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * // Default from the scaler if not specifed on the frame if ( interps == NULL ) { - interps = mlt_properties_get( mlt_filter_properties( filter ), "interpolation" ); + interps = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "interpolation" ); mlt_properties_set( properties, "rescale.interp", interps ); } @@ -166,12 +225,12 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * { // When no scaling is requested, revert the requested dimensions if possible mlt_properties_set_int( properties, "rescale_width", ( iwidth / 2 ) * 2 ); - mlt_properties_set_int( properties, "rescale_height", ( iheight / 2 ) * 2 ); + mlt_properties_set_int( properties, "rescale_height", iheight ); } // Get the image as requested mlt_frame_get_image( this, image, format, &iwidth, &iheight, writable ); - + // Get rescale interpretation again, in case the producer wishes to override scaling interps = mlt_properties_get( properties, "rescale.interp" ); @@ -189,6 +248,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * scaler_method( this, image, *format, mlt_image_yuv422, iwidth, iheight, owidth, oheight ); *width = owidth; *height = oheight; + + // Scale the alpha + scale_alpha( this, iwidth, iheight, owidth, oheight ); } else if ( *format == mlt_image_rgb24 && wanted_format == mlt_image_rgb24 ) { @@ -198,6 +260,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * // Return the output *width = owidth; *height = oheight; + + // Scale the alpha + scale_alpha( this, iwidth, iheight, owidth, oheight ); } else if ( *format == mlt_image_rgb24 || *format == mlt_image_rgb24a ) { @@ -208,6 +273,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * *format = mlt_image_yuv422; *width = owidth; *height = oheight; + + // Scale the alpha + scale_alpha( this, iwidth, iheight, owidth, oheight ); } else { @@ -239,15 +307,6 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * return 0; } -static uint8_t *producer_get_alpha_mask( mlt_frame this ) -{ - // Obtain properties of frame - mlt_properties properties = mlt_frame_properties( this ); - - // Return the alpha mask - return mlt_properties_get_data( properties, "alpha", NULL ); -} - /** Filter processing. */ @@ -259,9 +318,6 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) // Push the get image method mlt_frame_push_service( frame, filter_get_image ); - // Set alpha call back - frame->get_alpha_mask = producer_get_alpha_mask; - return frame; } @@ -277,7 +333,7 @@ mlt_filter filter_rescale_init( char *arg ) if ( this != NULL ) { // Get the properties - mlt_properties properties = mlt_filter_properties( this ); + mlt_properties properties = MLT_FILTER_PROPERTIES( this ); // Set the process method this->process = filter_process;