field rendering and alignment for composite, bugfixes for luma, pixbuf and pango
[melted] / src / modules / gtk2 / producer_pixbuf.c
index 63817f7..9150e36 100644 (file)
 static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int index );
 static void producer_close( mlt_producer parent );
 
-typedef enum
-{
-       SIGNAL_FORMAT_PAL,
-       SIGNAL_FORMAT_NTSC
-} mlt_signal_format;
-
 static int filter_files( const struct dirent *de )
 {
        if ( de->d_name[ 0 ] != '.' )
@@ -48,7 +42,6 @@ static int filter_files( const struct dirent *de )
                return 0;
 }
 
-
 mlt_producer producer_pixbuf_init( char *filename )
 {
        producer_pixbuf this = calloc( sizeof( struct producer_pixbuf_s ), 1 );
@@ -56,12 +49,13 @@ mlt_producer producer_pixbuf_init( char *filename )
        {
                mlt_producer producer = &this->parent;
 
-               producer->get_frame = producer_get_frame;
-               producer->close = producer_close;
-
                // Get the properties interface
                mlt_properties properties = mlt_producer_properties( &this->parent );
        
+               // Callback registration
+               producer->get_frame = producer_get_frame;
+               producer->close = producer_close;
+
                // Set the default properties
                mlt_properties_set( properties, "resource", filename );
                mlt_properties_set_int( properties, "ttl", 25 );
@@ -89,7 +83,7 @@ mlt_producer producer_pixbuf_init( char *filename )
                                        gap ++;
                                }
                        } 
-                       mlt_properties_set_position( properties, "out", this->count * 25 );
+                       mlt_properties_set_position( properties, "out", this->count * 250 );
                }
                else if ( strstr( filename, "/.all." ) != NULL )
                {
@@ -123,7 +117,7 @@ mlt_producer producer_pixbuf_init( char *filename )
                {
                        this->filenames = realloc( this->filenames, sizeof( char * ) * ( this->count + 1 ) );
                        this->filenames[ this->count ++ ] = strdup( filename );
-                       mlt_properties_set_position( properties, "out", 25 );
+                       mlt_properties_set_position( properties, "out", 250 );
                }
 
                // Initialise gobject types
@@ -144,7 +138,7 @@ static void refresh_image( mlt_frame frame, int width, int height )
        // Obtain properties of frame
        mlt_properties properties = mlt_frame_properties( frame );
 
-       // Obtain the producer pango for this frame
+       // Obtain the producer for this frame
        producer_pixbuf this = mlt_properties_get_data( properties, "producer_pixbuf", NULL );
 
        // Obtain the producer 
@@ -163,19 +157,24 @@ static void refresh_image( mlt_frame frame, int width, int height )
        mlt_frame_set_position( frame, mlt_producer_position( producer ) );
 
     // optimization for subsequent iterations on single picture
-       if ( this->image != NULL && image_idx == this->image_idx )
+       if ( width != 0 && this->image != NULL && image_idx == this->image_idx )
        {
                if ( width != this->width || height != this->height )
                {
                        pixbuf = mlt_properties_get_data( producer_props, "pixbuf", NULL );
+                       free( this->image );
+                       free( this->alpha );
+                       this->image = NULL;
+                       this->alpha = NULL;
                }
        }
-       else 
+       else if ( this->image == NULL || image_idx != this->image_idx )
        {
                free( this->image );
-               this->image = NULL;
                free( this->alpha );
+               this->image = NULL;
                this->alpha = NULL;
+
                this->image_idx = image_idx;
                pixbuf = gdk_pixbuf_new_from_file( this->filenames[ image_idx ], &error );
 
@@ -196,15 +195,28 @@ static void refresh_image( mlt_frame frame, int width, int height )
        // If we have a pixbuf
        if ( pixbuf && width > 0 )
        {
-               // Note - the original pixbuf is already safe and ready for destruction
-               pixbuf = gdk_pixbuf_scale_simple( pixbuf, width, height, GDK_INTERP_HYPER );
+               char *interps = mlt_properties_get( properties, "rescale.interp" );
+               int interp = GDK_INTERP_BILINEAR;
 
-               // Store width and height
-               this->width = gdk_pixbuf_get_width( pixbuf );
-               this->height = gdk_pixbuf_get_height( pixbuf );
+               if ( strcmp( interps, "nearest" ) == 0 )
+                       interp = GDK_INTERP_NEAREST;
+               else if ( strcmp( interps, "tiles" ) == 0 )
+                       interp = GDK_INTERP_TILES;
+               else if ( strcmp( interps, "hyper" ) == 0 )
+                       interp = GDK_INTERP_HYPER;
 
-               // Allocate/define image and alpha
-               uint8_t *image = malloc( this->width * this->height * 2 );
+//             fprintf( stderr, "SCALING PIXBUF from %dx%d to %dx%d was %dx%d\n", gdk_pixbuf_get_width( pixbuf ), gdk_pixbuf_get_height( pixbuf ), width, height, this->width, this->height );
+               
+               // Note - the original pixbuf is already safe and ready for destruction
+               pixbuf = gdk_pixbuf_scale_simple( pixbuf, width, height, interp );
+               
+               // Store width and height
+               this->width = width;
+               this->height = height;
+               
+               // Allocate/define image
+               // IRRIGATE ME
+               uint8_t *image = malloc( width * ( height + 1 ) * 2 );
                uint8_t *alpha = NULL;
 
                // Extract YUV422 and alpha
@@ -231,7 +243,7 @@ static void refresh_image( mlt_frame frame, int width, int height )
                // Finished with pixbuf now
                g_object_unref( pixbuf );
 
-               // Pass alpha and image on properties with or without destructor
+               // Assign images to producer
                this->image = image;
                this->alpha = alpha;
        }
@@ -242,8 +254,8 @@ static void refresh_image( mlt_frame frame, int width, int height )
        mlt_properties_set_int( properties, "real_width", mlt_properties_get_int( producer_props, "real_width" ) );
        mlt_properties_set_int( properties, "real_height", mlt_properties_get_int( producer_props, "real_height" ) );
 
-       // pass the image and alpha data without destructor
-       mlt_properties_set_data( properties, "image", this->image, this->width * this->height * 2, NULL, NULL );
+       // pass the image data without destructor
+       mlt_properties_set_data( properties, "image", this->image, this->width * ( this->height + 1 ) * 2, NULL, NULL );
        mlt_properties_set_data( properties, "alpha", this->alpha, this->width * this->height, NULL, NULL );
 }
 
@@ -252,9 +264,16 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // Obtain properties of frame
        mlt_properties properties = mlt_frame_properties( frame );
 
+       *width = mlt_properties_get_int( properties, "rescale_width" );
+       *height = mlt_properties_get_int( properties, "rescale_height" );
+
        // Refresh the image
        refresh_image( frame, *width, *height );
 
+       // Determine format
+       //mlt_producer this = mlt_properties_get_data( properties, "producer_pixbuf", NULL );
+       //*format = ( mlt_properties_get_int( mlt_producer_properties( this ), "bpp" ) == 4 ) ? mlt_image_rgb24a : mlt_image_rgb24;
+
        // May need to know the size of the image to clone it
        int size = 0;
 
@@ -270,9 +289,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // The fault is not in the design of mlt, but in the implementation of pixbuf...
        //if ( writable )
        {
-               size = *width * *height * 2;
-
                // Clone our image
+               // IRRIGATE ME
                uint8_t *copy = malloc( size );
                memcpy( copy, image, size );
 
@@ -312,9 +330,13 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
        // Set the producer on the frame properties
        mlt_properties_set_data( properties, "producer_pixbuf", this, 0, NULL, NULL );
 
-       // Refresh the pango image
+       // Refresh the image
        refresh_image( *frame, 0, 0 );
 
+       // Set producer-specific frame properties
+       mlt_properties_set_int( properties, "progressive", 1 );
+       mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( properties, "real_width" ) / mlt_properties_get_double( properties, "real_height" ) );
+
        // Set alpha call back
        ( *frame )->get_alpha_mask = producer_get_alpha_mask;
 
@@ -331,7 +353,6 @@ static void producer_close( mlt_producer parent )
 {
        producer_pixbuf this = parent->child;
        free( this->image );
-       free( this->alpha );
        parent->close = NULL;
        mlt_producer_close( parent );
        free( this );