]> git.sesse.net Git - mlt/commitdiff
Rescale title when they are played with a different profile
authorj-b-m <jb@kdenlive.org>
Fri, 31 Jul 2009 07:37:10 +0000 (09:37 +0200)
committerj-b-m <jb@kdenlive.org>
Fri, 31 Jul 2009 07:37:10 +0000 (09:37 +0200)
modified:   kdenlivetitle_wrapper.cpp
modified:   kdenlivetitle_wrapper.h
modified:   producer_kdenlivetitle.c

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

index 08204bfcaa5f045ffc194eb1e56c92198385e4a1..1c18b4647f7bee5df4942a8204b63a9b98d05fe7 100644 (file)
@@ -45,7 +45,7 @@ extern "C"
                }
                drawKdenliveTitle( producer, buffer, width, height, position );
        }
-       
+
        static void qscene_delete( void *data )
        {
                QGraphicsScene *scene = ( QGraphicsScene * )data;
@@ -80,7 +80,7 @@ void drawKdenliveTitle( mlt_producer producer, uint8_t * buffer, int width, int
                loadFromXml( producer, scene, mlt_properties_get( producer_props, "xmldata" ), mlt_properties_get( producer_props, "templatetext" ) );
                mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "qscene", scene, 0, ( mlt_destructor )qscene_delete );
        }
-       
+
        g_mutex.unlock();
        
        //must be extracted from kdenlive title
@@ -90,19 +90,22 @@ void drawKdenliveTitle( mlt_producer producer, uint8_t * buffer, int width, int
        p1.begin( &img );
        p1.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing );
        //| QPainter::SmoothPixmapTransform );
-       
-       QRectF m_start = stringToRect( QString( mlt_properties_get( producer_props, "startrect" ) ) );
-       QRectF m_end = stringToRect( QString( mlt_properties_get( producer_props, "endrect" ) ) );
-       
-       if (m_start.isNull() && m_end.isNull()) {
-           scene->render( &p1 );
+
+       const QRectF start = stringToRect( QString( mlt_properties_get( producer_props, "startrect" ) ) );
+       const QRectF end = stringToRect( QString( mlt_properties_get( producer_props, "endrect" ) ) );
+       const QRectF source( 0, 0, width, height );
+
+       if (end.isNull()) {
+               if (start.isNull())
+                       scene->render( &p1 );
+               else
+                       scene->render( &p1, start, source );
        }
        else {
-           QPointF topleft=m_start.topLeft()+( m_end.topLeft()-m_start.topLeft() )*position;
-           QPointF bottomRight=m_start.bottomRight()+( m_end.bottomRight()-m_start.bottomRight() )*position;
-           const QRectF r1( 0, 0, width, height );
-           const QRectF r2( topleft, bottomRight );
-           scene->render( &p1, r1, r2 );
+           QPointF topleft = start.topLeft() + ( end.topLeft() - start.topLeft() ) * position;
+           QPointF bottomRight = start.bottomRight() + ( end.bottomRight() - start.bottomRight() ) * position;
+           const QRectF r1( topleft, bottomRight );
+           scene->render( &p1, r1, source );
        }
        p1.end();
        uint8_t *pointer=img.bits();
@@ -131,7 +134,14 @@ void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *temp
        QString replacementText = QString::fromUtf8(templateText);
        doc.setContent(data);
        QDomNodeList titles = doc.elementsByTagName( "kdenlivetitle" );
-       int maxZValue = 0;
+       QTransform transform;
+       if ( doc.documentElement().hasAttribute("width") ) {
+           int originalWidth = doc.documentElement().attribute("width").toInt();
+           int originalHeight = doc.documentElement().attribute("height").toInt();
+           if (originalWidth != scene->width() || originalHeight != scene->height()) {
+                   transform = QTransform::fromScale ( scene->width() / originalWidth, scene->height() / originalHeight);
+           }
+       }
        if ( titles.size() )
        {
 
@@ -237,11 +247,12 @@ void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *temp
                        {
                                QPointF p( items.item( i ).namedItem( "position" ).attributes().namedItem( "x" ).nodeValue().toDouble(),
                                           items.item( i ).namedItem( "position" ).attributes().namedItem( "y" ).nodeValue().toDouble() );
+                               if ( transform != QTransform() ) p = QPointF(p.x() * transform.m11(), p.y() * transform.m22());
                                gitem->setPos( p );
                                gitem->setTransform( stringToTransform( items.item( i ).namedItem( "position" ).firstChild().firstChild().nodeValue() ) );
                                int zValue = items.item( i ).attributes().namedItem( "z-index" ).nodeValue().toInt();
-                               if ( zValue > maxZValue ) maxZValue = zValue;
                                gitem->setZValue( zValue );
+                               if ( transform != QTransform() ) gitem->setTransform( transform, true );
                                //gitem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
                        }
                        if ( items.item( i ).nodeName() == "background" )
@@ -261,19 +272,32 @@ void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *temp
                        else if ( items.item( i ).nodeName() == "startviewport" )
                        {
                                QString rect = items.item( i ).attributes().namedItem( "rect" ).nodeValue();
-                               
+                               if ( transform != QTransform() ) {
+                                   rect = rectTransform( rect, transform );
+                               }
                                mlt_properties_set( producer_props, "startrect", rect.toUtf8().data() );
                        }
                        else if ( items.item( i ).nodeName() == "endviewport" )
                        {
                                QString rect = items.item( i ).attributes().namedItem( "rect" ).nodeValue();
+                               if ( transform != QTransform() ) {
+                                   rect = rectTransform( rect, transform );
+                               }
                                mlt_properties_set( producer_props, "endrect", rect.toUtf8().data() );
                        }
                }
        }
+       if ( mlt_properties_get( producer_props, "startrect") == mlt_properties_get( producer_props, "endrect") )
+               mlt_properties_set( producer_props, "endrect", "" );
        return;
 }
 
+QString rectTransform( QString s, QTransform t )
+{
+       QStringList l = s.split( ',' );
+       return QString::number(l.at(0).toDouble() * t.m11()) + ',' + QString::number(l.at(1).toDouble() * t.m22()) + ',' + QString::number(l.at(2).toDouble() * t.m11()) + ',' + QString::number(l.at(3).toDouble() * t.m22());
+}
+
 QString colorToString( const QColor& c )
 {
        QString ret = "%1,%2,%3,%4";
index d474e1af347324dc7c15945a0ca6e3e6ccb861d6..775ebe0690a8112e2d0f7158f5535b36133a4d2d 100644 (file)
@@ -33,6 +33,7 @@ class QTransform;
 void drawKdenliveTitle( mlt_producer producer, uint8_t*, int, int, double );
 void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *templateXml, const char *templateText );
 
+QString rectTransform( QString s, QTransform t );
 QString colorToString( const QColor& );
 QString rectFToString( const QRectF& );
 QRectF stringToRect( const QString & );
index 313ffae0dd10a9bba61eff07bdf7cd0d8fbbd6e3..f1db7e70e7a70b91587b1d01ea60341816bf3886 100644 (file)
@@ -56,8 +56,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        /* Obtain properties of producer */
        mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
        
-       *width = mlt_properties_get_int( properties, "rescale_width" );
-       *height = mlt_properties_get_int( properties, "rescale_height" );
+       *width = mlt_properties_get_int( properties, "width" );
+       *height = mlt_properties_get_int( properties, "height" );
        
        /* Allocate the image */
        int size = *width * ( *height ) * 4;
@@ -85,7 +85,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                else refresh_kdenlivetitle( producer, *buffer, *width, *height, position, 0);
                /* Update the frame */
                mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
-               
+
                mlt_log_debug( MLT_PRODUCER_SERVICE( producer ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) );
        }
 
@@ -150,7 +150,7 @@ mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type
                producer->get_frame = producer_get_frame;
                producer->close = ( mlt_destructor )producer_close;
                mlt_properties_set( properties, "resource", filename );
-               mlt_properties_set_int( properties, "aspect_ratio", 1 );
+               //mlt_properties_set_int( properties, "aspect_ratio", 1 );
                read_xml(properties);
                return producer;
        }