]> git.sesse.net Git - mlt/commitdiff
* Fix memleaks
authorj-b-m <jb@kdenlive.org>
Fri, 24 Jul 2009 12:46:53 +0000 (14:46 +0200)
committerj-b-m <jb@kdenlive.org>
Fri, 24 Jul 2009 12:46:53 +0000 (14:46 +0200)
* Cleanup
* Reload xml when setting "reload_xml" property
modified:   src/modules/qimage/kdenlivetitle_wrapper.cpp
modified:   src/modules/qimage/kdenlivetitle_wrapper.h
modified:   src/modules/qimage/producer_kdenlivetitle.c

src/modules/qimage/kdenlivetitle_wrapper.cpp
src/modules/qimage/kdenlivetitle_wrapper.h
src/modules/qimage/producer_kdenlivetitle.c

index dfc27397ea123b2931e3f5f006b1752c55796359..4727643c2c5d93f726d75ab92fa30860f80a72e8 100644 (file)
@@ -23,7 +23,6 @@
 #include <QtGui/QApplication>
 #include <QtCore/QDebug>
 #include <QtCore/QFile>
-#include <QtGui/QGraphicsView>
 #include <QtGui/QGraphicsScene>
 #include <QtGui/QGraphicsTextItem>
 #include <QtGui/QGraphicsPolygonItem>
@@ -40,22 +39,28 @@ extern "C"
        {
                titleclass=new Title( QString( c ) );
        }
-       void refresh_kdenlivetitle( uint8_t* buffer, int width, int height , double position, char *templatexml, char *templatetext )
+       void refresh_kdenlivetitle( uint8_t* buffer, int width, int height , double position, char *templatexml, char *templatetext, int force_refresh )
        {
+               if (force_refresh) titleclass->reloadXml(templatexml, templatetext);
                titleclass->drawKdenliveTitle( buffer, width, height, position, templatexml, templatetext );
        }
 }
-Title::Title( const QString& filename ):m_filename( filename ),m_scene( NULL )
+
+Title::Title( const QString& filename ):m_filename( filename ), sceneLoaded( false )
 {
        //must be extracted from kdenlive title
-       start =new QGraphicsPolygonItem( QPolygonF( QRectF( 100, 100, 600, 600 ) ) );
-       ;
-       end=new QGraphicsPolygonItem( QPolygonF( QRectF( 0, 0, 300, 300 ) ) );
-       ;
+       /*m_start( QPolygonF( QRectF( 100, 100, 600, 600 ) ) );
+       m_end( QPolygonF( QRectF( 0, 0, 300, 300 ) ) );*/
+}
+
+void Title::reloadXml(char *templatexml, char *templatetext)
+{
+       loadDocument( m_filename, QString( templatexml ), QString( templatetext ) );
 }
+
 void Title::drawKdenliveTitle( uint8_t * buffer, int width, int height, double position, char *templatexml, char *templatetext )
 {
-       if ( !m_scene )
+       if ( !sceneLoaded )
        {
                int argc=0;
                char* argv[1];
@@ -63,21 +68,26 @@ void Title::drawKdenliveTitle( uint8_t * buffer, int width, int height, double p
                if ( ! QApplication::activeWindow() )
                        //if (!app)
                        app=new QApplication( argc,argv );
-               m_scene=new QGraphicsScene;
-               loadDocument( m_filename, start, end, QString( templatexml ), QString( templatetext ) );
+               loadDocument( m_filename, QString( templatexml ), QString( templatetext ) );
        }
        //must be extracted from kdenlive title
 
        QImage *img=new QImage( width,height,QImage::Format_ARGB32 );
        img->fill( 0 );
-       QRectF rstart=start->boundingRect();
-       QRectF rend=end->boundingRect();
-       QPointF topleft=rstart.topLeft()+( rend.topLeft()-rstart.topLeft() )*position;
-       QPointF bottomRight=rstart.bottomRight()+( rend.bottomRight()-rstart.bottomRight() )*position;
        QPainter p1;
        p1.begin( img );
        p1.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing );//|QPainter::SmoothPixmapTransform );
-       m_scene->render( &p1,QRect( 0,0,width,height ),QRectF( topleft,bottomRight ) );
+       
+       if (m_start.polygon().isEmpty() && m_end.polygon().isEmpty()) {
+           m_scene.render( &p1,QRect( 0, 0, width, height ) );
+       }
+       else {
+           QRectF rstart=m_start.boundingRect();
+           QRectF rend=m_end.boundingRect();
+           QPointF topleft=rstart.topLeft()+( rend.topLeft()-rstart.topLeft() )*position;
+           QPointF bottomRight=rstart.bottomRight()+( rend.bottomRight()-rstart.bottomRight() )*position;
+           m_scene.render( &p1,QRect( 0,0,width,height ),QRectF( topleft,bottomRight ) );
+       }
        p1.end();
        uint8_t *pointer=img->bits();
        QRgb* src = ( QRgb* ) pointer;
@@ -91,11 +101,11 @@ void Title::drawKdenliveTitle( uint8_t * buffer, int width, int height, double p
        }
        delete img;
 }
-int Title::loadDocument( const QString& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv, const QString templateXml, const QString templateText )
+
+int Title::loadDocument( const QString& url, const QString templateXml, const QString templateText )
 {
        QDomDocument doc;
-       if ( !m_scene )
-               return -1;
+       sceneLoaded = true;
        if ( !templateXml.isEmpty() )
        {
                doc.setContent( templateXml );
@@ -109,11 +119,12 @@ int Title::loadDocument( const QString& url, QGraphicsPolygonItem* startv, QGrap
                        file.close();
                }
        }
-       return loadFromXml( doc, startv, endv, templateText );
+       return loadFromXml( doc, templateText );
 }
 
-int Title::loadFromXml( QDomDocument doc, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv, const QString templateText )
+int Title::loadFromXml( QDomDocument doc, const QString templateText )
 {
+       m_scene.clear();
        QDomNodeList titles = doc.elementsByTagName( "kdenlivetitle" );
        int maxZValue = 0;
        if ( titles.size() )
@@ -148,9 +159,9 @@ int Title::loadFromXml( QDomDocument doc, QGraphicsPolygonItem* startv, QGraphic
                                        {
                                                QString text = items.item( i ).namedItem( "content" ).firstChild().nodeValue();
                                                text = text.replace( "%s", templateText );
-                                               txt = m_scene->addText( text, font );
+                                               txt = m_scene.addText( text, font );
                                        }
-                                       else txt = m_scene->addText( items.item( i ).namedItem( "content" ).firstChild().nodeValue(), font );
+                                       else txt = m_scene.addText( items.item( i ).namedItem( "content" ).firstChild().nodeValue(), font );
                                        txt->setDefaultTextColor( col );
                                        txt->setTextInteractionFlags( Qt::NoTextInteraction );
                                        if ( txtProperties.namedItem( "alignment" ).isNull() == false )
@@ -183,14 +194,14 @@ int Title::loadFromXml( QDomDocument doc, QGraphicsPolygonItem* startv, QGraphic
                                        QString br_str = items.item( i ).namedItem( "content" ).attributes().namedItem( "brushcolor" ).nodeValue();
                                        QString pen_str = items.item( i ).namedItem( "content" ).attributes().namedItem( "pencolor" ).nodeValue();
                                        double penwidth = items.item( i ).namedItem( "content" ).attributes().namedItem( "penwidth" ).nodeValue().toDouble();
-                                       QGraphicsRectItem *rec = m_scene->addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth ), QBrush( stringToColor( br_str ) ) );
+                                       QGraphicsRectItem *rec = m_scene.addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth ), QBrush( stringToColor( br_str ) ) );
                                        gitem = rec;
                                }
                                else if ( items.item( i ).attributes().namedItem( "type" ).nodeValue() == "QGraphicsPixmapItem" )
                                {
                                        QString url = items.item( i ).namedItem( "content" ).attributes().namedItem( "url" ).nodeValue();
                                        QPixmap pix( url );
-                                       QGraphicsPixmapItem *rec = m_scene->addPixmap( pix );
+                                       QGraphicsPixmapItem *rec = m_scene.addPixmap( pix );
                                        rec->setData( Qt::UserRole, url );
                                        gitem = rec;
                                }
@@ -198,7 +209,7 @@ int Title::loadFromXml( QDomDocument doc, QGraphicsPolygonItem* startv, QGraphic
                                {
                                        QString url = items.item( i ).namedItem( "content" ).attributes().namedItem( "url" ).nodeValue();
                                        //QGraphicsSvgItem *rec = new QGraphicsSvgItem(url);
-                                       //m_scene->addItem(rec);
+                                       //m_scene.addItem(rec);
                                        //rec->setData(Qt::UserRole, url);
                                        //gitem = rec;
                                }
@@ -219,7 +230,7 @@ int Title::loadFromXml( QDomDocument doc, QGraphicsPolygonItem* startv, QGraphic
                        {
                                QColor color = QColor( stringToColor( items.item( i ).attributes().namedItem( "color" ).nodeValue() ) );
                                //color.setAlpha(items.item(i).attributes().namedItem("alpha").nodeValue().toInt());
-                               QList<QGraphicsItem *> items = m_scene->items();
+                               QList<QGraphicsItem *> items = m_scene.items();
                                for ( int i = 0; i < items.size(); i++ )
                                {
                                        if ( items.at( i )->zValue() == -1100 )
@@ -229,15 +240,15 @@ int Title::loadFromXml( QDomDocument doc, QGraphicsPolygonItem* startv, QGraphic
                                        }
                                }
                        }
-                       else if ( items.item( i ).nodeName() == "startviewport" && startv )
+                       else if ( items.item( i ).nodeName() == "startviewport" )
                        {
                                QString rect = items.item( i ).attributes().namedItem( "rect" ).nodeValue();
-                               startv->setPolygon( stringToRect( rect ) );
+                               m_start.setPolygon( stringToRect( rect ) );
                        }
-                       else if ( items.item( i ).nodeName() == "endviewport" && endv )
+                       else if ( items.item( i ).nodeName() == "endviewport" )
                        {
                                QString rect = items.item( i ).attributes().namedItem( "rect" ).nodeValue();
-                               endv->setPolygon( stringToRect( rect ) );
+                               m_end.setPolygon( stringToRect( rect ) );
                        }
                }
        }
index 31943bf2262fa9f352e58118e13b5b1ec6e36e55..a8b3fe385dfbe3622d4189b1281b9f91b005a0eb 100644 (file)
 #include <QtCore/QString>
 #include <framework/mlt_frame.h>
 #include <QtXml/QDomElement>
+
 class QGraphicsPolygonItem;
 class QCoreApplication;
 class QApplication;
-class QObject;
 class Title;
-class QGraphicsView;
 class QGraphicsScene;
 
 class Title: public QObject
@@ -35,13 +34,14 @@ class Title: public QObject
 public:
        Title( const QString & );
        void drawKdenliveTitle( uint8_t*, int, int, double, char*, char* );
+       void reloadXml(char *templatexml, char *templatetext);
 private:
        QString m_filename;
-       int loadDocument( const QString& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv, const QString templateXml, const QString templateText );
-       int  loadFromXml( QDomDocument doc, QGraphicsPolygonItem* /*startv*/, QGraphicsPolygonItem* /*endv*/, const QString templateText );
-       QGraphicsView *view;
-       QGraphicsScene *m_scene;
-       QGraphicsPolygonItem *start,*end;
+       int loadDocument( const QString& url, const QString templateXml, const QString templateText );
+       int  loadFromXml( QDomDocument doc, const QString templateText );
+       QGraphicsScene m_scene;
+       QGraphicsPolygonItem m_start, m_end;
+       bool sceneLoaded;
        QString colorToString( const QColor& );
        QString rectFToString( const QRectF& );
        QRectF stringToRect( const QString & );
index 44821a3b44be61d1b005336af2562e2958e4e600..7b5ef3fa5bb0149ab06ddf7a1a3f7af543dc3262 100644 (file)
@@ -23,7 +23,7 @@
 
 extern void init_qt();
 
-extern void refresh_kdenlivetitle( uint8_t*, int, int, double, char*, char* );
+extern void refresh_kdenlivetitle( uint8_t*, int, int, double, char*, char*, int );
 
 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
 {
@@ -35,8 +35,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
 
        // Obtain properties of producer
-       // save extra data
-       //mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
+       mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
+       
        // Allocate the image
        int size = *width * ( *height ) * 4;
 
@@ -57,7 +57,11 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                mlt_position out = mlt_producer_get_out( producer );
                mlt_position time = mlt_frame_get_position( frame );
                double position = ( double )( time - in ) / ( double )( out - in + 1 );
-               refresh_kdenlivetitle( *buffer, *width, *height, position, mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "templatexml" ), mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "templatetext" ) );
+               if ( mlt_properties_get_int( producer_props, "force_reload" ) ) {
+                       refresh_kdenlivetitle( *buffer, *width, *height, position, mlt_properties_get( producer_props, "xmldata" ), mlt_properties_get( producer_props, "templatetext" ),  1);
+                       mlt_properties_set_int( producer_props, "force_reload", 0 );
+               }
+               else refresh_kdenlivetitle( *buffer, *width, *height, position, mlt_properties_get( producer_props, "xmldata" ), mlt_properties_get( producer_props, "templatetext" ),  0);
                mlt_log_debug( MLT_PRODUCER_SERVICE( producer ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) );
        }
 
@@ -122,7 +126,6 @@ mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type
                this->close = ( mlt_destructor ) producer_close;
                mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
                mlt_properties_set( properties, "resource", arg );
-
        }
 
        return this;