]> git.sesse.net Git - mlt/commitdiff
split refresh_qimage() into refresh_qiamge() and refresh_image()
authorDan Dennedy <dan@dennedy.org>
Fri, 2 Mar 2012 07:56:43 +0000 (23:56 -0800)
committerDan Dennedy <dan@dennedy.org>
Fri, 2 Mar 2012 07:56:43 +0000 (23:56 -0800)
src/modules/qimage/producer_qimage.c
src/modules/qimage/qimage_wrapper.cpp
src/modules/qimage/qimage_wrapper.h

index ed041c1af3d9ef875603e687fe3c9b2e2f7a91bd..68f5faa094894283cade07db41510658438a90fa 100644 (file)
@@ -72,7 +72,7 @@ mlt_producer producer_qimage_init( mlt_profile profile, mlt_service_type type, c
                                mlt_properties_set_data( frame_properties, "producer_qimage", self, 0, NULL, NULL );
                                mlt_frame_set_position( frame, mlt_producer_position( producer ) );
                                mlt_properties_set_position( frame_properties, "qimage_position", mlt_producer_position( producer ) );
-                               refresh_qimage( self, frame, 0, 0 );
+                               refresh_qimage( self, frame );
                                mlt_frame_close( frame );
                        }
                }
@@ -81,8 +81,6 @@ mlt_producer producer_qimage_init( mlt_profile profile, mlt_service_type type, c
                        producer_close( producer );
                        producer = NULL;
                }
-               if ( producer )
-                       pthread_mutex_init( &self->mutex, NULL );
                return producer;
        }
        free( self );
@@ -152,11 +150,10 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
 {
        int error = 0;
        
-       // Obtain properties of frame
+       // Obtain properties of frame and producer
        mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
-
-       // Obtain the producer for this frame
        producer_qimage self = mlt_properties_get_data( properties, "producer_qimage", NULL );
+       mlt_producer producer = &self->parent;
 
        *width = mlt_properties_get_int( properties, "rescale_width" );
        *height = mlt_properties_get_int( properties, "rescale_height" );
@@ -164,7 +161,11 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        mlt_service_lock( MLT_PRODUCER_SERVICE( &self->parent ) );
 
        // Refresh the image
-       refresh_qimage( self, frame, *width, *height );
+       self->qimage_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.qimage" );
+       self->qimage = mlt_cache_item_data( self->qimage_cache, NULL );
+       self->image_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.image" );
+       self->current_image = mlt_cache_item_data( self->image_cache, NULL );
+       refresh_image( self, frame, *width, *height );
 
        // Get width and height (may have changed during the refresh)
        *width = mlt_properties_get_int( properties, "width" );
@@ -192,7 +193,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        }
 
        // Release references and locks
-       pthread_mutex_unlock( &self->mutex );
+       mlt_cache_item_close( self->qimage_cache );
        mlt_cache_item_close( self->image_cache );
        mlt_service_unlock( MLT_PRODUCER_SERVICE( &self->parent ) );
 
@@ -228,7 +229,10 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
                mlt_properties_set_position( properties, "qimage_position", mlt_producer_position( producer ) );
 
                // Refresh the image
-               refresh_qimage( self, *frame, 0, 0 );
+               self->qimage_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.qimage" );
+               self->qimage = mlt_cache_item_data( self->qimage_cache, NULL );
+               refresh_qimage( self, *frame );
+               mlt_cache_item_close( self->qimage_cache );
 
                // Set producer-specific frame properties
                mlt_properties_set_int( properties, "progressive", mlt_properties_get_int( producer_properties, "progressive" ) );
@@ -251,7 +255,6 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
 static void producer_close( mlt_producer parent )
 {
        producer_qimage self = parent->child;
-       pthread_mutex_destroy( &self->mutex );
        parent->close = NULL;
        mlt_service_cache_purge( MLT_PRODUCER_SERVICE(parent) );
        mlt_producer_close( parent );
index a6dfd58c93a6f3ad7ef135c5912a88dc30e8514f..f2cb722f19cd145cef4a94dd4d75bdf53ea1a637 100644 (file)
@@ -70,8 +70,6 @@ static void qimage_delete( void *data )
 #endif
 }
 
-static QMutex g_mutex;
-
 #ifdef USE_KDE
 void init_qimage()
 {
@@ -140,30 +138,17 @@ static QImage* reorient_with_exif( producer_qimage self, int image_idx, QImage *
        return qimage;
 }
 
-void refresh_qimage( producer_qimage self, mlt_frame frame, int width, int height )
+int refresh_qimage( producer_qimage self, mlt_frame frame )
 {
-       // Obtain properties of frame
+       // Obtain properties of frame and producer
        mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
-
-       // Obtain the producer 
        mlt_producer producer = &self->parent;
-
-       // Obtain properties of producer
        mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
 
-       // restore QImage
-       pthread_mutex_lock( &self->mutex );
-       mlt_cache_item qimage_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.qimage" );
-       QImage *qimage = static_cast<QImage*>( mlt_cache_item_data( qimage_cache, NULL ) );
-
-       // restore scaled image
-       self->image_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.image" );
-       self->current_image = static_cast<uint8_t*>( mlt_cache_item_data( self->image_cache, NULL ) );
-
        // Check if user wants us to reload the image
        if ( mlt_properties_get_int( producer_props, "force_reload" ) )
        {
-               qimage = NULL;
+               self->qimage = NULL;
                self->current_image = NULL;
                mlt_properties_set_int( producer_props, "force_reload", 0 );
        }
@@ -182,20 +167,15 @@ void refresh_qimage( producer_qimage self, mlt_frame frame, int width, int heigh
        char image_key[ 10 ];
        sprintf( image_key, "%d", image_idx );
 
-       g_mutex.lock();
-
        int disable_exif = mlt_properties_get_int( producer_props, "disable_exif" );
 
-       // optimization for subsequent iterations on single pictur
-       if ( width != 0 && ( image_idx != self->image_idx || width != self->current_width || height != self->current_height ) )
-               self->current_image = NULL;
        if ( image_idx != self->qimage_idx )
-               qimage = NULL;
-
-       if ( !qimage || mlt_properties_get_int( producer_props, "_disable_exif" ) != disable_exif)
+               self->qimage = NULL;
+       if ( !self->qimage || mlt_properties_get_int( producer_props, "_disable_exif" ) != disable_exif )
        {
                self->current_image = NULL;
-               qimage = new QImage( mlt_properties_get_value( self->filenames, image_idx ) );
+               QImage *qimage = new QImage( mlt_properties_get_value( self->filenames, image_idx ) );
+               self->qimage = qimage;
 
                if ( !qimage->isNull( ) )
                {
@@ -203,16 +183,16 @@ void refresh_qimage( producer_qimage self, mlt_frame frame, int width, int heigh
                        if ( !disable_exif )
                                qimage = reorient_with_exif( self, image_idx, qimage );
 
-                       // Store the width/height of the qimage  
-                       self->current_width = qimage->width( );
-                       self->current_height = qimage->height( );
-
                        // Register qimage for destruction and reuse
-                       mlt_cache_item_close( qimage_cache );
+                       mlt_cache_item_close( self->qimage_cache );
                        mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "qimage.qimage", qimage, 0, ( mlt_destructor )qimage_delete );
-                       qimage_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.qimage" );
+                       self->qimage_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.qimage" );
                        self->qimage_idx = image_idx;
 
+                       // Store the width/height of the qimage
+                       self->current_width = qimage->width( );
+                       self->current_height = qimage->height( );
+
                        mlt_events_block( producer_props, NULL );
                        mlt_properties_set_int( producer_props, "_real_width", self->current_width );
                        mlt_properties_set_int( producer_props, "_real_height", self->current_height );
@@ -222,20 +202,43 @@ void refresh_qimage( producer_qimage self, mlt_frame frame, int width, int heigh
                else
                {
                        delete qimage;
-                       qimage = NULL;
+                       self->qimage = NULL;
                }
        }
 
-       // If we have a pixbuf and this request specifies a valid dimension and we haven't already got a cached version...
-       if ( qimage && width > 0 && !self->current_image )
+       // Set width/height of frame
+       mlt_properties_set_int( properties, "width", self->current_width );
+       mlt_properties_set_int( properties, "height", self->current_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" ) );
+
+       return image_idx;
+}
+
+void refresh_image( producer_qimage self, mlt_frame frame, int width, int height )
+{
+       // Obtain properties of frame and producer
+       mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
+       mlt_producer producer = &self->parent;
+
+       // Get index and qimage
+       int image_idx = refresh_qimage( self, frame );
+
+       // optimization for subsequent iterations on single pictur
+       if ( image_idx != self->image_idx || width != self->current_width || height != self->current_height )
+               self->current_image = NULL;
+
+       // If we have a qimage and need a new scaled image
+       if ( self->qimage && !self->current_image )
        {
                char *interps = mlt_properties_get( properties, "rescale.interp" );
                int interp = 0;
+               QImage *qimage = static_cast<QImage*>( self->qimage );
 
                // QImage has two scaling modes - we'll toggle between them here
-               if ( strcmp( interps, "tiles" ) == 0 )
-                       interp = 1;
-               else if ( strcmp( interps, "hyper" ) == 0 )
+               if ( strcmp( interps, "tiles" ) == 0
+                       || strcmp( interps, "hyper" ) == 0
+                       || strcmp( interps, "bicubic" ) == 0 )
                        interp = 1;
 
 #ifdef USE_QT4
@@ -245,6 +248,7 @@ void refresh_qimage( producer_qimage self, mlt_frame frame, int width, int heigh
                        QImage temp = qimage->convertToFormat( QImage::Format_RGB32 );
                        delete qimage;
                        qimage = new QImage( temp );
+                       self->qimage = qimage;
                }
                QImage scaled = interp == 0 ? qimage->scaled( QSize( width, height ) ) :
                        qimage->scaled( QSize(width, height), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
@@ -291,21 +295,9 @@ void refresh_qimage( producer_qimage self, mlt_frame frame, int width, int heigh
                self->image_idx = image_idx;
        }
 
-       // release references no longer needed
-       mlt_cache_item_close( qimage_cache );
-       if ( width == 0 )
-       {
-               pthread_mutex_unlock( &self->mutex );
-               mlt_cache_item_close( self->image_cache );
-       }
-
        // Set width/height of frame
        mlt_properties_set_int( properties, "width", self->current_width );
        mlt_properties_set_int( properties, "height", self->current_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" ) );
-
-       g_mutex.unlock();
 }
 
 extern void make_tempfile( producer_qimage self, const char *xml )
index b66924428900cbd7d60ad1c8e29410d3be83f000..78e933c8d5fc0638b79863152c2d8e7ee05983d8 100644 (file)
@@ -45,12 +45,14 @@ struct producer_qimage_s
        int current_width;
        int current_height;
        mlt_cache_item image_cache;
-       pthread_mutex_t mutex;
+       mlt_cache_item qimage_cache;
+       void *qimage;
 };
 
 typedef struct producer_qimage_s *producer_qimage;
 
-extern void refresh_qimage( producer_qimage, mlt_frame, int width, int height );
+extern int refresh_qimage( producer_qimage self, mlt_frame frame );
+extern void refresh_image( producer_qimage, mlt_frame, int width, int height );
 extern void make_tempfile( producer_qimage, const char *xml );
 
 #ifdef USE_KDE