]> git.sesse.net Git - mlt/blobdiff - src/modules/gtk2/producer_pixbuf.c
Fix pango producer from loading with empty string arg.
[mlt] / src / modules / gtk2 / producer_pixbuf.c
index a3c106ee3550528c36c34e0c2cda16db420a6a6c..b12d7811b7412a8f12af802924d86fd5a9d02604 100644 (file)
 #include <framework/mlt_log.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
+#include "config.h"
+
+#ifdef USE_EXIF
+#include <libexif/exif-data.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -118,7 +124,7 @@ static void load_filenames( producer_pixbuf this, mlt_properties producer_proper
        {
                // Generate a temporary file for the svg
                char fullname[ 1024 ] = "/tmp/mlt.XXXXXX";
-               int fd = mkstemp( fullname );
+               int fd = g_mkstemp( fullname );
 
                if ( fd > -1 )
                {
@@ -217,7 +223,7 @@ static void refresh_image( producer_pixbuf this, mlt_frame frame, int width, int
        this->image = mlt_cache_item_data( this->image_cache, NULL );
 
        // Check if user wants us to reload the image
-       if ( mlt_properties_get_int( producer_props, "force_reload" ) || mlt_properties_get_int( producer_props, "_orientation" ) != mlt_properties_get_int( producer_props, "meta.attr.orientation" ) )
+       if ( mlt_properties_get_int( producer_props, "force_reload" ) )
        {
                pixbuf = NULL;
                this->image = NULL;
@@ -266,7 +272,8 @@ static void refresh_image( producer_pixbuf this, mlt_frame frame, int width, int
                                this->image = NULL;
                }
        }
-
+       int disable_exif = mlt_properties_get_int( producer_props, "disable_exif" );
+       
     // optimization for subsequent iterations on single picture
        if ( width != 0 && ( image_idx != this->image_idx || width != this->width || height != this->height ) )
                this->image = NULL;
@@ -274,52 +281,72 @@ static void refresh_image( producer_pixbuf this, mlt_frame frame, int width, int
                pixbuf = NULL;
        mlt_log_debug( MLT_PRODUCER_SERVICE( producer ), "image %p pixbuf %p idx %d image_idx %d pixbuf_idx %d width %d\n",
                this->image, pixbuf, image_idx, this->image_idx, this->pixbuf_idx, width );
-       if ( !pixbuf && !this->image )
+       if ( !pixbuf || mlt_properties_get_int( producer_props, "_disable_exif" ) != disable_exif )
        {
                this->image = NULL;
                pixbuf = gdk_pixbuf_new_from_file( mlt_properties_get_value( this->filenames, image_idx ), &error );
 
                if ( pixbuf )
                {
-                       int exif_orientation = mlt_properties_get_int( producer_props, "meta.attr.orientation" );
-
-                       if ( exif_orientation > 1 )
-                       {
-                             GdkPixbuf *processed;
-                             GdkPixbufRotation matrix = GDK_PIXBUF_ROTATE_NONE;
-
-                             // Rotate image according to exif data
-                             switch ( exif_orientation ) {
-                               case 2:
-                                   processed = gdk_pixbuf_flip ( pixbuf, TRUE );
-                                   break;
-                               case 4:
-                                   processed = gdk_pixbuf_flip ( pixbuf, FALSE );
-                                   break;
-                               case 8:
-                                   matrix = GDK_PIXBUF_ROTATE_CLOCKWISE;
-                                   processed = pixbuf;
-                                   break;
-                               case 3:
-                                   matrix = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
-                                   processed = pixbuf;
-                                   break;
-                               case 6:
-                                   matrix = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
-                                   processed = pixbuf;
-                                   break;
-                               case 5:
-                                   matrix = GDK_PIXBUF_ROTATE_CLOCKWISE;
-                                   processed = gdk_pixbuf_flip ( pixbuf, TRUE );
-                                   break;
-                               case 7:
-                                   matrix = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
-                                   processed = gdk_pixbuf_flip ( pixbuf, TRUE );
-                                   break;
-
-                             }
-                             pixbuf = gdk_pixbuf_rotate_simple( processed, matrix );
+#ifdef USE_EXIF
+                       // Read the exif value for this file
+                       if ( disable_exif == 0) {
+                               ExifData *d = exif_data_new_from_file( mlt_properties_get_value( this->filenames, image_idx ) );
+                               ExifEntry *entry;
+                               int exif_orientation = 0;
+
+                               /* get orientation and rotate image accordingly if necessary */
+                               if (d) {
+                                       if ( ( entry = exif_content_get_entry ( d->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION ) ) )
+                                               exif_orientation = exif_get_short (entry->data, exif_data_get_byte_order (d));
+
+                                       /* Free the EXIF data */
+                                       exif_data_unref(d);
+                               }
+                               
+                               // Remember EXIF value, might be useful for someone
+                               mlt_properties_set_int( producer_props, "_exif_orientation" , exif_orientation );
+
+                               if ( exif_orientation > 1 )
+                               {
+                                       GdkPixbuf *processed = NULL;
+                                       GdkPixbufRotation matrix = GDK_PIXBUF_ROTATE_NONE;
+
+                                       // Rotate image according to exif data
+                                       switch ( exif_orientation ) {
+                                         case 2:
+                                             processed = gdk_pixbuf_flip ( pixbuf, TRUE );
+                                             break;
+                                         case 3:
+                                             matrix = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
+                                             processed = pixbuf;
+                                             break;
+                                         case 4:
+                                             processed = gdk_pixbuf_flip ( pixbuf, FALSE );
+                                             break;
+                                         case 5:
+                                             matrix = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
+                                             processed = gdk_pixbuf_flip ( pixbuf, TRUE );
+                                             break;
+                                         case 6:
+                                             matrix = GDK_PIXBUF_ROTATE_CLOCKWISE;
+                                             processed = pixbuf;
+                                             break;
+                                         case 7:
+                                             matrix = GDK_PIXBUF_ROTATE_CLOCKWISE;
+                                             processed = gdk_pixbuf_flip ( pixbuf, TRUE );
+                                             break;
+                                         case 8:
+                                             matrix = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
+                                             processed = pixbuf;
+                                             break;
+                                       }
+                                       if ( processed )
+                                               pixbuf = gdk_pixbuf_rotate_simple( processed, matrix );
+                               }
                        }
+#endif
+
                        // Register this pixbuf for destruction and reuse
                        mlt_cache_item_close( pixbuf_cache );
                        mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "pixbuf.pixbuf", pixbuf, 0, ( mlt_destructor )g_object_unref );
@@ -329,7 +356,7 @@ static void refresh_image( producer_pixbuf this, mlt_frame frame, int width, int
                        mlt_events_block( producer_props, NULL );
                        mlt_properties_set_int( producer_props, "_real_width", gdk_pixbuf_get_width( pixbuf ) );
                        mlt_properties_set_int( producer_props, "_real_height", gdk_pixbuf_get_height( pixbuf ) );
-                       mlt_properties_set_int( producer_props, "_orientation", exif_orientation );
+                       mlt_properties_set_int( producer_props, "_disable_exif", disable_exif );
                        mlt_events_unblock( producer_props, NULL );
 
                        // Store the width/height of the pixbuf temporarily
@@ -348,7 +375,7 @@ static void refresh_image( producer_pixbuf this, mlt_frame frame, int width, int
                        interp = GDK_INTERP_NEAREST;
                else if ( strcmp( interps, "tiles" ) == 0 )
                        interp = GDK_INTERP_TILES;
-               else if ( strcmp( interps, "hyper" ) == 0 )
+               else if ( strcmp( interps, "hyper" ) == 0 || strcmp( interps, "bicubic" ) == 0 )
                        interp = GDK_INTERP_HYPER;
 
                // Note - the original pixbuf is already safe and ready for destruction
@@ -416,7 +443,7 @@ static void refresh_image( producer_pixbuf this, mlt_frame frame, int width, int
                mlt_properties_set_int( cached_props, "height", this->height );
                mlt_properties_set_int( cached_props, "real_width", mlt_properties_get_int( producer_props, "_real_width" ) );
                mlt_properties_set_int( cached_props, "real_height", mlt_properties_get_int( producer_props, "_real_height" ) );
-               mlt_properties_set_data( cached_props, "image", this->image, this->width * ( this->alpha ? 4 : 3 ) * this->height, mlt_pool_release, NULL );
+               mlt_frame_set_image( cached, this->image, this->width * ( this->alpha ? 4 : 3 ) * this->height, mlt_pool_release );
                mlt_properties_set_int( cached_props, "alpha", this->alpha );
                mlt_properties_set_data( cache, image_key, cached, 0, ( mlt_destructor )mlt_frame_close, NULL );
        }
@@ -437,6 +464,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        *width = mlt_properties_get_int( properties, "rescale_width" );
        *height = mlt_properties_get_int( properties, "rescale_height" );
 
+       mlt_service_lock( MLT_PRODUCER_SERVICE( &this->parent ) );
+
        // Refresh the image
        refresh_image( this, frame, *width, *height );
 
@@ -453,7 +482,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                uint8_t *image_copy = mlt_pool_alloc( image_size );
                memcpy( image_copy, this->image, image_size );
                // Now update properties so we free the copy after
-               mlt_properties_set_data( properties, "image", image_copy, image_size, mlt_pool_release, NULL );
+               mlt_frame_set_image( frame, image_copy, image_size, mlt_pool_release );
                // We're going to pass the copy on
                *buffer = image_copy;
                *format = this->alpha ? mlt_image_rgb24a : mlt_image_rgb24;
@@ -468,6 +497,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // Release references and locks
        pthread_mutex_unlock( &this->mutex );
        mlt_cache_item_close( this->image_cache );
+       mlt_service_unlock( MLT_PRODUCER_SERVICE( &this->parent ) );
 
        return error;
 }
@@ -505,7 +535,12 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
 
                // Set producer-specific frame properties
                mlt_properties_set_int( properties, "progressive", mlt_properties_get_int( producer_properties, "progressive" ) );
-               mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_properties, "aspect_ratio" ) );
+               
+               double force_ratio = mlt_properties_get_double( producer_properties, "force_aspect_ratio" );
+               if ( force_ratio > 0.0 )
+                       mlt_properties_set_double( properties, "aspect_ratio", force_ratio );
+               else
+                       mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_properties, "aspect_ratio" ) );
 
                // Push the get_image method
                mlt_frame_push_get_image( *frame, producer_get_image );