static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame ); mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); mlt_position position = mlt_frame_get_position( frame ); // Get the image *format = mlt_image_yuv422; int error = mlt_frame_get_image( frame, image, format, width, height, 0 ); // Only process if we have no error and a valid colour space if ( error == 0 ) { double factor = mlt_properties_get_double( properties, "start" ); mlt_position f_pos = mlt_filter_get_position( filter, frame ); mlt_position f_len = mlt_filter_get_length2( filter, frame ); int speed = mlt_properties_anim_get_int( properties, "speed", f_pos, f_len ); int deformX = mlt_properties_anim_get_int( properties, "deformX", f_pos, f_len ); int deformY = mlt_properties_anim_get_int( properties, "deformY", f_pos, f_len ); if ( mlt_properties_get( properties, "end" ) ) { // Determine the time position of this frame in the transition duration double end = fabs( mlt_properties_get_double( MLT_FILTER_PROPERTIES( filter ), "end" ) ); factor += ( end - factor ) * mlt_filter_get_progress( filter, frame ); } // If animated property "wave" is set, use its value. char* wave_property = mlt_properties_get( properties, "wave" ); if ( wave_property ) { factor = mlt_properties_anim_get_double( properties, "wave", f_pos, f_len ); } if (factor != 0) { int image_size = *width * (*height) * 2; uint8_t *dst = mlt_pool_alloc (image_size); DoWave(*image, *width, (*height), dst, position, speed, factor, deformX, deformY); *image = dst; mlt_frame_set_image( frame, *image, image_size, mlt_pool_release ); } } return error; }
static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame ); mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); mlt_position pos = mlt_filter_get_position( filter, frame ); mlt_position len = mlt_filter_get_length2( filter, frame ); *format = mlt_image_yuv422; int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); if ( error == 0 && *image ) { int h = *height; int w = *width; double position = mlt_filter_get_progress( filter, frame ); srand(position*10000); int noise = mlt_properties_anim_get_int( properties, "noise", pos, len ); double contrast = mlt_properties_anim_get_double( properties, "contrast", pos, len ) / 100.0; double brightness = 127.0 * (mlt_properties_anim_get_double( properties, "brightness", pos, len ) -100.0 ) / 100.0; int x = 0,y = 0,pix = 0; for ( x = 0; x < w; x++ ) { for( y = 0; y < h; y++ ) { uint8_t* pixel = (*image + (y) * w * 2 + (x) * 2 ); if (*pixel > 20) { pix = MIN ( MAX ( ( (double)*pixel -127.0 ) * contrast + 127.0 + brightness , 0 ) , 255 ) ; if ( noise > 0 ) pix -= ( rand() % noise - noise ); *pixel = MIN ( MAX ( pix , 0 ) , 255 ); } } } } return error; }
static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { // Get the filter mlt_filter filter = mlt_frame_pop_service( frame ); mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); mlt_position position = mlt_filter_get_position( filter, frame ); mlt_position length = mlt_filter_get_length2( filter, frame ); // Get the image *format = mlt_image_yuv422; int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); // Only process if we have no error and a valid colour space if ( error == 0 ) { // Get the charcoal scatter value int x_scatter = mlt_properties_anim_get_double( properties, "x_scatter", position, length ); int y_scatter = mlt_properties_anim_get_double( properties, "y_scatter", position, length ); float scale = mlt_properties_anim_get_double( properties, "scale" ,position, length); float mix = mlt_properties_anim_get_double( properties, "mix", position, length); int invert = mlt_properties_anim_get_int( properties, "invert", position, length); // We'll process pixel by pixel int x = 0; int y = 0; // We need to create a new frame as this effect modifies the input uint8_t *temp = mlt_pool_alloc( *width * *height * 2 ); uint8_t *p = temp; uint8_t *q = *image; // Calculations are carried out on a 3x3 matrix int matrix[ 3 ][ 3 ]; // Used to carry out the matrix calculations int sum1; int sum2; float sum; int val; // Loop for each row for ( y = 0; y < *height; y ++ ) { // Loop for each pixel for ( x = 0; x < *width; x ++ ) { // Populate the matrix matrix[ 0 ][ 0 ] = get_Y( *image, *width, *height, x - x_scatter, y - y_scatter ); matrix[ 0 ][ 1 ] = get_Y( *image, *width, *height, x , y - y_scatter ); matrix[ 0 ][ 2 ] = get_Y( *image, *width, *height, x + x_scatter, y - y_scatter ); matrix[ 1 ][ 0 ] = get_Y( *image, *width, *height, x - x_scatter, y ); matrix[ 1 ][ 2 ] = get_Y( *image, *width, *height, x + x_scatter, y ); matrix[ 2 ][ 0 ] = get_Y( *image, *width, *height, x - x_scatter, y + y_scatter ); matrix[ 2 ][ 1 ] = get_Y( *image, *width, *height, x , y + y_scatter ); matrix[ 2 ][ 2 ] = get_Y( *image, *width, *height, x + x_scatter, y + y_scatter ); // Do calculations sum1 = (matrix[2][0] - matrix[0][0]) + ( (matrix[2][1] - matrix[0][1]) << 1 ) + (matrix[2][2] - matrix[2][0]); sum2 = (matrix[0][2] - matrix[0][0]) + ( (matrix[1][2] - matrix[1][0]) << 1 ) + (matrix[2][2] - matrix[2][0]); sum = scale * sqrti( sum1 * sum1 + sum2 * sum2 ); // Assign value *p ++ = !invert ? ( sum >= 16 && sum <= 235 ? 251 - sum : sum < 16 ? 235 : 16 ) : ( sum >= 16 && sum <= 235 ? sum : sum < 16 ? 16 : 235 ); q ++; val = 128 + mix * ( *q ++ - 128 ); val = val < 16 ? 16 : val > 240 ? 240 : val; *p ++ = val; } } // Return the created image *image = temp; // Store new and destroy old mlt_frame_set_image( frame, *image, *width * *height * 2, mlt_pool_release ); } return error; }
static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame ); mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); mlt_position pos = mlt_filter_get_position( filter, frame ); mlt_position len = mlt_filter_get_length2( filter, frame ); *format = mlt_image_yuv422; int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); if ( error == 0 && *image ) { int h = *height; int w = *width; int x = 0; int y = 0; double position = mlt_filter_get_progress( filter, frame ); srand( position * 10000); int delta = mlt_properties_anim_get_int( properties, "delta", pos, len ); int every = mlt_properties_anim_get_int( properties, "every", pos, len ); int bdu = mlt_properties_anim_get_int( properties, "brightnessdelta_up", pos, len ); int bdd = mlt_properties_anim_get_int( properties, "brightnessdelta_down", pos, len ); int bevery = mlt_properties_anim_get_int( properties, "brightnessdelta_every", pos, len ); int udu = mlt_properties_anim_get_int( properties, "unevendevelop_up", pos, len ); int udd = mlt_properties_anim_get_int( properties, "unevendevelop_down", pos, len ); int uduration = mlt_properties_anim_get_int( properties, "unevendevelop_duration", pos, len ); int diffpic = 0; if ( delta ) diffpic = rand() % delta * 2 - delta; int brightdelta = 0; if (( bdu + bdd ) != 0 ) brightdelta = rand() % (bdu + bdd) - bdd; if ( rand() % 100 > every ) diffpic = 0; if ( rand() % 100 > bevery) brightdelta = 0; int yend, ydiff; int unevendevelop_delta = 0; if ( uduration > 0 ) { float uval = sinarr[ ( ((int)position) % uduration) * 100 / uduration ]; unevendevelop_delta = uval * ( uval > 0 ? udu : udd ); } if ( diffpic <= 0 ) { y = h; yend = 0; ydiff = -1; } else { y = 0; yend = h; ydiff = 1; } while( y != yend ) { for ( x = 0; x < w; x++ ) { uint8_t* pic = ( *image + y * w * 2 + x * 2 ); int newy = y + diffpic; if ( newy > 0 && newy < h ) { uint8_t oldval= *( pic + diffpic * w * 2 ); if ( ((int) oldval + brightdelta + unevendevelop_delta ) > 255 ) { *pic=255; } else if ( ( (int) oldval + brightdelta + unevendevelop_delta ) <0 ) { *pic=0; } else { *pic = oldval + brightdelta + unevendevelop_delta; } *( pic + 1 ) =* ( pic + diffpic * w * 2 + 1 ); } else { *pic = 0; } } y += ydiff; } } return error; }
static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame ); mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); mlt_position pos = mlt_filter_get_position( filter, frame ); mlt_position len = mlt_filter_get_length2( filter, frame ); int maxdia = mlt_properties_anim_get_int( properties, "maxdiameter", pos, len ); int maxcount = mlt_properties_anim_get_int( properties, "maxcount", pos, len ); *format = mlt_image_yuv422; int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); // Load svg char *factory = mlt_properties_get( properties, "factory" ); char temp[1204] = ""; sprintf( temp, "%s/oldfilm/", mlt_environment( "MLT_DATA" ) ); mlt_properties direntries = mlt_properties_new(); mlt_properties_dir_list( direntries, temp,"dust*.svg",1 ); if (!maxcount) return 0; double position = mlt_filter_get_progress( filter, frame ); srand( position * 10000 ); mlt_service_lock( MLT_FILTER_SERVICE( filter ) ); int im = rand() % maxcount; int piccount = mlt_properties_count( direntries ); while ( im-- && piccount ) { int picnum = rand() % piccount; int y1 = rand() % *height; int x1 = rand() % *width; char resource[1024] = ""; char savename[1024] = "", savename1[1024] = "", cachedy[100]; int dx = ( *width * maxdia / 100); int luma_width, luma_height; uint8_t *luma_image = NULL; uint8_t *alpha = NULL; int updown = rand() % 2; int mirror = rand() % 2; sprintf( resource, "%s", mlt_properties_get_value(direntries,picnum) ); sprintf( savename, "cache-%d-%d", picnum,dx ); sprintf( savename1, "cache-alpha-%d-%d", picnum, dx ); sprintf( cachedy, "cache-dy-%d-%d", picnum,dx ); luma_image = mlt_properties_get_data( properties , savename , NULL ); alpha = mlt_properties_get_data( properties , savename1 , NULL ); if ( luma_image == NULL || alpha == NULL ) { mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) ); mlt_producer producer = mlt_factory_producer( profile, factory, resource ); if ( producer != NULL ) { mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer ); mlt_properties_set( producer_properties, "eof", "loop" ); mlt_frame luma_frame = NULL; if ( mlt_service_get_frame( MLT_PRODUCER_SERVICE( producer ), &luma_frame, 0 ) == 0 ) { mlt_image_format luma_format = mlt_image_yuv422; luma_width = dx; luma_height = luma_width * mlt_properties_get_int( MLT_FRAME_PROPERTIES ( luma_frame ) , "height" ) / mlt_properties_get_int( MLT_FRAME_PROPERTIES ( luma_frame ) , "width" ); mlt_properties_set( MLT_FRAME_PROPERTIES( luma_frame ), "rescale.interp", "best" );// none/nearest/tiles/hyper mlt_frame_get_image( luma_frame, &luma_image, &luma_format, &luma_width, &luma_height, 0 ); alpha = mlt_frame_get_alpha_mask (luma_frame ); uint8_t* savealpha = mlt_pool_alloc( luma_width * luma_height ); uint8_t* savepic = mlt_pool_alloc( luma_width * luma_height * 2); if ( savealpha && savepic ) { memcpy( savealpha, alpha , luma_width * luma_height ); memcpy( savepic, luma_image , luma_width * luma_height * 2 ); mlt_properties_set_data( properties, savename, savepic, luma_width * luma_height * 2, mlt_pool_release, NULL ); mlt_properties_set_data( properties, savename1, savealpha, luma_width * luma_height, mlt_pool_release, NULL ); mlt_properties_set_int( properties, cachedy, luma_height ); overlay_image( *image, *width, *height, luma_image, luma_width, luma_height, alpha, x1, y1, updown, mirror ); } else { if ( savealpha ) mlt_pool_release( savealpha ); if ( savepic ) mlt_pool_release( savepic ); } mlt_frame_close( luma_frame ); } mlt_producer_close( producer ); } } else { overlay_image ( *image, *width, *height, luma_image, dx, mlt_properties_get_int ( properties, cachedy ), alpha, x1, y1, updown, mirror ); } } mlt_service_unlock( MLT_FILTER_SERVICE( filter ) ); if (piccount>0 ) return 0; if ( error == 0 && *image ) { int h = *height; int w = *width; int im = rand() % maxcount; while ( im-- ) { int type = im % 2; int y1 = rand() % h; int x1 = rand() % w; int dx = rand() % maxdia; int dy = rand() % maxdia; int x=0, y=0; double v = 0.0; for ( x = -dx ; x < dx ; x++ ) { for ( y = -dy ; y < dy ; y++ ) { if ( x1 + x < w && x1 + x > 0 && y1 + y < h && y1 + y > 0 ){ uint8_t *pix = *image + (y+y1) * w * 2 + (x + x1) * 2; v=pow((double) x /(double)dx * 5.0, 2.0) + pow((double)y / (double)dy * 5.0, 2.0); if (v>10) v=10; v = 1.0 - ( v / 10.0 ); switch(type) { case 0: *pix -= (*pix) * v; break; case 1: *pix += ( 255-*pix ) * v; break; } } } } } } return error; }