consumer_westley now only puts in/out as element attributes and not property elements
[melted] / src / modules / gtk2 / producer_pango.c
index a626a9d..11f9285 100644 (file)
@@ -32,6 +32,7 @@ struct producer_pango_s
        int width;
        int height;
        uint8_t *image;
+       uint8_t *alpha;
        char *fgcolor;
        char *bgcolor;
        int   align;
@@ -252,6 +253,11 @@ static void refresh_image( mlt_frame frame, int width, int height )
                rgba_color fgcolor = parse_color( this->fgcolor );
                rgba_color bgcolor = parse_color( this->bgcolor );
 
+               free( this->image );
+               free( this->alpha );
+               this->image = NULL;
+               this->alpha = NULL;
+
                // Render the title
                pixbuf = pango_get_pixbuf( markup, text, font, fgcolor, bgcolor, pad, align );
 
@@ -272,6 +278,11 @@ static void refresh_image( mlt_frame frame, int width, int height )
        }
        else if ( this->image == NULL || width != this->width || height != this->height )
        {
+               free( this->image );
+               free( this->alpha );
+               this->image = NULL;
+               this->alpha = NULL;
+
                pixbuf = mlt_properties_get_data( producer_props, "pixbuf", NULL );
                mlt_properties_set_int( producer_props, "bpp", gdk_pixbuf_get_has_alpha( pixbuf ) ? 4 : 3 );
        }
@@ -281,30 +292,33 @@ static void refresh_image( mlt_frame frame, int width, int height )
        // If we have a pixbuf and a valid width
        if ( pixbuf && width > 0 )
        {
-               int i;
-               
                // Note - the original pixbuf is already safe and ready for destruction
-               pixbuf = gdk_pixbuf_scale_simple( pixbuf, width, height, GDK_INTERP_HYPER );
+               pixbuf = gdk_pixbuf_scale_simple( pixbuf, width, height, GDK_INTERP_NEAREST );
 
                // Store width and height
-               this->width = gdk_pixbuf_get_width( pixbuf );
-               this->height = gdk_pixbuf_get_height( pixbuf );
+               this->width = width;
+               this->height = height;
 
                // Allocate/define image
                // IRRIGATE ME
-               uint8_t *image = malloc( this->width * ( this->height + 1 )* bpp );
+               uint8_t *image = malloc( width * ( height + 1 ) * bpp );
+               uint8_t *alpha = NULL;
+
+               // Allocate the alpha mask
+               alpha = malloc( this->width * this->height );
 
-               for ( i = 0; i < height; i++ )
-                       memcpy( image + i * width * bpp,
-                               gdk_pixbuf_get_pixels( pixbuf ) + i * gdk_pixbuf_get_rowstride( pixbuf ),
-                               gdk_pixbuf_get_width( pixbuf ) * bpp );
+               // Convert the image
+               mlt_convert_rgb24a_to_yuv422( gdk_pixbuf_get_pixels( pixbuf ),
+                                                                         this->width, this->height,
+                                                                         gdk_pixbuf_get_rowstride( pixbuf ),
+                                                                         image, alpha );
 
                // Finished with pixbuf now
                g_object_unref( pixbuf );
                
                // reference the image in the producer
-               free( this->image );
                this->image = image;
+               this->alpha = alpha;
        }
 
        // Set width/height
@@ -315,6 +329,7 @@ static void refresh_image( mlt_frame frame, int width, int height )
 
        // pass the image data without destructor
        mlt_properties_set_data( properties, "image", this->image, this->width * ( this->height + 1 ) * bpp, NULL, NULL );
+       mlt_properties_set_data( properties, "alpha", this->alpha, this->width * this->height, NULL, NULL );
 }
 
 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
@@ -322,12 +337,15 @@ 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_pango", NULL );
-       *format = ( mlt_properties_get_int( mlt_producer_properties( this ), "bpp" ) == 4 ) ? mlt_image_rgb24a : mlt_image_rgb24;
+       //mlt_producer this = mlt_properties_get_data( properties, "producer_pango", 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;
@@ -360,6 +378,15 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        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 );
+}
+
 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
 {
        producer_pango this = producer->child;
@@ -380,6 +407,9 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
        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;
+
        // Stack the get image callback
        mlt_frame_push_get_image( *frame, producer_get_image );
 
@@ -396,6 +426,7 @@ static void producer_close( mlt_producer parent )
 {
        producer_pango this = parent->child;
        free( this->image );
+       free( this->alpha );
        free( this->fgcolor );
        free( this->bgcolor );
        free( this->markup );