X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fcore%2Ftransition_luma.c;h=167d4cfebd6a6af465b1912496d4270e7ce1ed83;hb=1e4bb58474abd58fd4285c70abd2a61d3b13db9b;hp=6c57339257a1f85dbc8007e6e5a4dcd1e730b3f4;hpb=d7f9be0634acea4a311066054258d2b0f6b4b7a5;p=melted diff --git a/src/modules/core/transition_luma.c b/src/modules/core/transition_luma.c index 6c57339..167d4cf 100644 --- a/src/modules/core/transition_luma.c +++ b/src/modules/core/transition_luma.c @@ -34,7 +34,7 @@ typedef struct struct mlt_transition_s parent; char *filename; int width; - int height; + int height; float *bitmap; } transition_luma; @@ -59,99 +59,60 @@ static inline float smoothstep( float edge1, float edge2, float a ) return ( a * a * ( 3 - 2 * a ) ); } -static int frame_composite_yuv( mlt_frame this, mlt_frame that, int x, int y, float weight, int *width, int *height ) -{ - int ret = 0; - int width_src = *width, height_src = *height; - int width_dest = *width, height_dest = *height; - mlt_image_format format_src = mlt_image_yuv422, format_dest = mlt_image_yuv422; - uint8_t *p_src, *p_dest; - int i, j; - int stride_src; - int stride_dest; - int x_src = 0, y_src = 0; - - // optimization point - no work to do - if ( ( x < 0 && -x >= width_src ) || ( y < 0 && -y >= height_src ) ) - return ret; - - format_src = mlt_image_yuv422; - format_dest = mlt_image_yuv422; - - mlt_frame_get_image( this, &p_dest, &format_dest, &width_dest, &height_dest, 1 /* writable */ ); - mlt_frame_get_image( that, &p_src, &format_src, &width_src, &height_src, 0 /* writable */ ); +/** Calculate the position for this frame. +*/ - stride_src = width_src * 2; - stride_dest = width_dest * 2; - - // crop overlay off the left edge of frame - if ( x < 0 ) - { - x_src = -x; - width_src -= x_src; - x = 0; - } - - // crop overlay beyond right edge of frame - else if ( x + width_src > width_dest ) - width_src = width_dest - x; +static float position_calculate( mlt_transition this, mlt_frame frame ) +{ + // Get the in and out position + mlt_position in = mlt_transition_get_in( this ); + mlt_position out = mlt_transition_get_out( this ); - // crop overlay off the top edge of the frame - if ( y < 0 ) - { - y_src = -y; - height_src -= y_src; - } - // crop overlay below bottom edge of frame - else if ( y + height_src > height_dest ) - height_src = height_dest - y; + // Get the position of the frame + mlt_position position = mlt_frame_get_position( frame ); - // offset pointer into overlay buffer based on cropping - p_src += x_src * 2 + y_src * stride_src; + // Now do the calcs + return ( float )( position - in ) / ( float )( out - in + 1 ); +} - // offset pointer into frame buffer based upon positive, even coordinates only! - p_dest += ( x < 0 ? 0 : x ) * 2 + ( y < 0 ? 0 : y ) * stride_dest; +/** Calculate the field delta for this frame - position between two frames. +*/ - // Get the alpha channel of the overlay - uint8_t *p_alpha = mlt_frame_get_alpha_mask( that ); +static float delta_calculate( mlt_transition this, mlt_frame frame ) +{ + // Get the in and out position + mlt_position in = mlt_transition_get_in( this ); + mlt_position out = mlt_transition_get_out( this ); - // offset pointer into alpha channel based upon cropping - if ( p_alpha ) - p_alpha += x_src + y_src * stride_src / 2; + // Get the position of the frame + mlt_position position = mlt_frame_get_position( frame ); - uint8_t *p = p_src; - uint8_t *q = p_dest; - uint8_t *o = p_dest; - uint8_t *z = p_alpha; + // Now do the calcs + float x = ( float )( position - in ) / ( float )( out - in + 1 ); + position++; + float y = ( float )( position - in ) / ( float )( out - in + 1 ); - uint8_t Y; - uint8_t UV; - uint8_t a; - float value; + return ( y - x ) / 2.0; +} - // now do the compositing only to cropped extents - for ( i = 0; i < height_src; i++ ) - { - p = p_src; - q = p_dest; - o = p_dest; - z = p_alpha; +static inline int dissolve_yuv( mlt_frame this, mlt_frame that, float weight, int width, int height ) +{ + int ret = 0; + int width_src = width, height_src = height; + mlt_image_format format = mlt_image_yuv422; + uint8_t *p_src, *p_dest; + float weight_complement = 1 - weight; + uint8_t *p; + uint8_t *limit; - for ( j = 0; j < width_src; j ++ ) - { - Y = *p ++; - UV = *p ++; - a = ( z == NULL ) ? 255 : *z ++; - value = ( weight * ( float ) a / 255.0 ); - *o ++ = (uint8_t)( Y * value + *q++ * ( 1 - value ) ); - *o ++ = (uint8_t)( UV * value + *q++ * ( 1 - value ) ); - } + mlt_frame_get_image( this, &p_dest, &format, &width, &height, 1 /* writable */ ); + mlt_frame_get_image( that, &p_src, &format, &width_src, &height_src, 0 /* writable */ ); + + p = p_dest; + limit = p_dest + height_src * width_src * 2; - p_src += stride_src; - p_dest += stride_dest; - if ( p_alpha ) - p_alpha += stride_src / 2; - } + while ( p < limit ) + *p_dest++ = ( uint8_t )( *p_src++ * weight + *p++ * weight_complement ); return ret; } @@ -243,13 +204,16 @@ static int transition_get_image( mlt_frame this, uint8_t **image, mlt_image_form mlt_properties b_props = mlt_frame_properties( b_frame ); // Arbitrary composite defaults - float frame_delta = 1 / mlt_properties_get_double( b_props, "fps" ); float mix = mlt_properties_get_double( b_props, "image.mix" ); + float frame_delta = mlt_properties_get_double( b_props, "luma.delta" ); int luma_width = mlt_properties_get_int( b_props, "luma.width" ); int luma_height = mlt_properties_get_int( b_props, "luma.height" ); float *luma_bitmap = mlt_properties_get_data( b_props, "luma.bitmap", NULL ); float luma_softness = mlt_properties_get_double( b_props, "luma.softness" ); - int progressive = mlt_properties_get_int( b_props, "progressive" ) || mlt_properties_get_int( a_props, "consumer_progressive" ); + int progressive = mlt_properties_get_int( b_props, "progressive" ) || + mlt_properties_get_int( a_props, "consumer_progressive" ) || + mlt_properties_get_int( b_props, "luma.progressive" ); + int top_field_first = mlt_properties_get_int( b_props, "top_field_first" ); int reverse = mlt_properties_get_int( b_props, "luma.reverse" ); @@ -260,6 +224,7 @@ static int transition_get_image( mlt_frame this, uint8_t **image, mlt_image_form // Honour the reverse here mix = reverse ? 1 - mix : mix; + frame_delta *= reverse ? -1.0 : 1.0; // Ensure we get scaling on the b_frame mlt_properties_set( b_props, "rescale.interp", "nearest" ); @@ -270,7 +235,7 @@ static int transition_get_image( mlt_frame this, uint8_t **image, mlt_image_form luma_softness, progressive ? -1 : top_field_first, width, height ); else // Dissolve the frames using the time offset for mix value - frame_composite_yuv( this, b_frame, 0, 0, mix, width, height ); + dissolve_yuv( this, b_frame, mix, *width, *height ); // Extract the a_frame image info *width = mlt_properties_get_int( a_props, "width" ); @@ -285,6 +250,7 @@ static int transition_get_image( mlt_frame this, uint8_t **image, mlt_image_form static void luma_read_pgm( FILE *f, float **map, int *width, int *height ) { + void *release = NULL; uint8_t *data = NULL; while (1) { @@ -339,8 +305,7 @@ static void luma_read_pgm( FILE *f, float **map, int *width, int *height ) bpp = maxval > 255 ? 2 : 1; // allocate temporary storage for the raw data - // IRRIGATE ME - data = malloc( *width * *height * bpp ); + data = mlt_pool_allocate( *width * *height * bpp, &release ); if ( data == NULL ) break; @@ -350,6 +315,7 @@ static void luma_read_pgm( FILE *f, float **map, int *width, int *height ) // allocate the luma bitmap // IRRIGATE ME + // Difficult here - need to change the function prototype.... *map = p = (float*) malloc( *width * *height * sizeof( float ) ); if ( *map == NULL ) break; @@ -366,8 +332,8 @@ static void luma_read_pgm( FILE *f, float **map, int *width, int *height ) break; } - if ( data != NULL ) - free( data ); + if ( release != NULL ) + mlt_pool_release( release ); } @@ -401,14 +367,9 @@ static mlt_frame transition_process( mlt_transition transition, mlt_frame a_fram } } - // Determine the time position of this frame in the transition duration - mlt_position in = mlt_transition_get_in( transition ); - mlt_position out = mlt_transition_get_out( transition ); - mlt_position time = mlt_frame_get_position( b_frame ); - float pos = ( float )( time - in ) / ( float )( out - in + 1 ); - // Set the b frame properties - mlt_properties_set_double( b_props, "image.mix", pos ); + mlt_properties_set_double( b_props, "image.mix", position_calculate( transition, b_frame ) ); + mlt_properties_set_double( b_props, "luma.delta", delta_calculate( transition, b_frame ) ); mlt_properties_set_int( b_props, "luma.width", this->width ); mlt_properties_set_int( b_props, "luma.height", this->height ); mlt_properties_set_data( b_props, "luma.bitmap", this->bitmap, 0, NULL, NULL );