* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "kdenlivetitle_wrapper.h"
+#include <framework/mlt_producer.h>
+
#include <QtGui/QImage>
#include <QtGui/QPainter>
-#include <QtCore/QCoreApplication>
+#include <QtCore/QDebug>
#include <QtGui/QApplication>
#include <QtCore/QFile>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsTextItem>
-#include <QtGui/QGraphicsPolygonItem>
#include <QtGui/QTextCursor>
-#include "kdenlivetitle_wrapper.h"
-#include <framework/mlt_producer.h>
-static Title* titleclass;
-static QApplication *app;
+static Title* titleclass = NULL;
+static QApplication *app = NULL;
extern "C"
{
void init_qt( const char* c )
{
- titleclass=new Title( QString( c ) );
+ titleclass=new Title( c );
}
void close_qt()
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);
+ if (force_refresh) titleclass->loadFromXml( templatexml, QString( templatetext ) );
titleclass->drawKdenliveTitle( buffer, width, height, position, templatexml, templatetext );
}
}
-Title::Title( const QString& filename ):m_filename( filename ), m_scene( NULL )
-{
-}
-Title::~Title()
+Title::Title( const char *filename ):m_filename( filename ), m_scene( NULL )
{
- if (m_scene) delete m_scene;
- if (app) delete app;
}
-void Title::reloadXml(char *templatexml, char *templatetext)
+Title::~Title()
{
- if (m_scene == NULL) return;
- loadDocument( m_filename, QString( templatexml ), QString( templatetext ) );
+ if (m_scene) {
+ m_scene->clear();
+ delete m_scene;
+ }
}
-void Title::drawKdenliveTitle( uint8_t * buffer, int width, int height, double position, char *templatexml, char *templatetext )
+void Title::drawKdenliveTitle( uint8_t * buffer, int width, int height, double position, const char *templatexml, const char *templatetext )
{
if ( m_scene == NULL )
{
- int argc=0;
+ int argc = 1;
char* argv[1];
- argv[0]="xxx";
- if ( ! QApplication::activeWindow() )
- //if (!app)
- app=new QApplication( argc,argv );
- m_scene = new QGraphicsScene(app);
- loadDocument( m_filename, QString( templatexml ), QString( templatetext ) );
+ argv[0] = "xxx";
+ if (qApp) {
+ app = qApp;
+ }
+ else {
+ app=new QApplication( argc,argv );
+ }
+ m_scene = new QGraphicsScene(0, 0, (qreal) width, (qreal) height, app);
+ loadFromXml( templatexml, QString( templatetext ) );
}
//must be extracted from kdenlive title
-
- QImage *img=new QImage( width,height,QImage::Format_ARGB32 );
+ QImage *img = new QImage( width,height,QImage::Format_ARGB32 );
img->fill( 0 );
QPainter p1;
p1.begin( img );
p1.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing );//|QPainter::SmoothPixmapTransform );
-
if (m_start.isNull() && m_end.isNull()) {
- m_scene->render( &p1,QRect( 0, 0, width, height ) );
+ m_scene->render( &p1 );
}
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;
- m_scene->render( &p1,QRect( 0,0,width,height ),QRectF( topleft,bottomRight ) );
+ const QRectF r1( 0, 0, width, height );
+ const QRectF r2( topleft, bottomRight );
+ m_scene->render( &p1, r1, r2 );
}
p1.end();
uint8_t *pointer=img->bits();
QRgb* src = ( QRgb* ) pointer;
- for ( int i=0;i<width*height*4;i+=4 )
+ for ( int i = 0; i < width * height * 4; i += 4 )
{
*buffer++=qRed( *src );
*buffer++=qGreen( *src );
delete img;
}
-int Title::loadDocument( const QString& url, const QString templateXml, const QString templateText )
-{
- if (m_scene == NULL) return 0;
- QDomDocument doc;
- if ( !templateXml.isEmpty() )
- {
- doc.setContent( templateXml );
- }
- else
- {
- QFile file( url );
- if ( file.open( QIODevice::ReadOnly ) )
- {
- doc.setContent( &file, false );
- file.close();
- }
- }
- return loadFromXml( doc, templateText );
-}
-
-int Title::loadFromXml( QDomDocument doc, const QString templateText )
+void Title::loadFromXml( const char *templateXml, const QString templateText )
{
+ if (m_scene == NULL) return;
m_scene->clear();
+ QDomDocument doc;
+ QString data(templateXml);
+ doc.setContent(data);
QDomNodeList titles = doc.elementsByTagName( "kdenlivetitle" );
int maxZValue = 0;
if ( titles.size() )
}
}
}
- return maxZValue;
+ return;
}
QString Title::colorToString( const QColor& c )
#include <stdlib.h>
#include <string.h>
+
extern void init_qt();
extern void close_qt();
extern void refresh_kdenlivetitle( uint8_t*, int, int, double, char*, char*, int );
+void read_xml(mlt_properties properties)
+{
+ FILE *f = fopen( mlt_properties_get( properties, "resource" ), "r");
+ if ( f != NULL )
+ {
+ int size = 0;
+ long lSize;
+
+ fseek (f , 0 , SEEK_END);
+ lSize = ftell (f);
+ rewind (f);
+
+ char *infile = (char*) mlt_pool_alloc(lSize);
+ size=fread(infile,1,lSize,f);
+ infile[size] = '\0';
+ fclose(f);
+ mlt_properties_set(properties, "xmldata", infile);
+ mlt_pool_release( infile );
+ }
+}
+
static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
{
- // Obtain properties of frame
+ /* Obtain properties of frame */
mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
- // Obtain the producer for this frame
+ /* Obtain the producer for this frame */
mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
- // Obtain properties of producer
+ /* Obtain properties of producer */
mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
- // Allocate the image
+ /* Allocate the image */
int size = *width * ( *height ) * 4;
*buffer = mlt_pool_alloc( size );
- // Update the frame
+
mlt_properties_set_int( properties, "width", *width );
mlt_properties_set_int( properties, "height", *height );
- // Update the frame
- mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
- //cache later ??
+
+
+ /* cache later ?? */
if ( 1 )
{
- // Allocate the image
+ /* Allocate the image */
*format = mlt_image_rgb24a;
mlt_position in = mlt_producer_get_in( producer );
mlt_position out = mlt_producer_get_out( producer );
mlt_position time = mlt_producer_position( producer );
double position = ( double )( time - in ) / ( double )( out - in + 1 );
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);
+ read_xml(producer_props);
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);
+ refresh_kdenlivetitle( *buffer, *width, *height, position, mlt_properties_get( producer_props, "xmldata" ), mlt_properties_get( producer_props, "templatetext" ), 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 ) );
}
return 0;
}
-int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
{
- // Generate a frame
+ /* Generate a frame */
*frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
if ( *frame != NULL )
{
- // Obtain properties of frame and producer
+ /* Obtain properties of frame and producer */
mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
- // Obtain properties of producer
+ /* Obtain properties of producer */
mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
- // Set the producer on the frame properties
+ /* Set the producer on the frame properties */
mlt_properties_set_data( properties, "producer_kdenlivetitle", producer, 0, NULL, NULL );
- // Update timecode on the frame we're creating
+ /* Update timecode on the frame we're creating */
mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
- // Set producer-specific frame properties
+ /* Set producer-specific frame properties */
mlt_properties_set_int( properties, "progressive", 1 );
mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) );
- // Push the get_image method
+ /* Push the get_image method */
mlt_frame_push_get_image( *frame, producer_get_image );
}
- // Calculate the next timecode
+ /* Calculate the next timecode */
mlt_producer_prepare_next( producer );
return 0;
}
-void producer_close( mlt_producer producer )
+static void producer_close( mlt_producer producer )
{
+ fprintf(stderr, "000000000000000000000000 CLOSING\n");
producer->close = NULL;
- mlt_producer_close( producer );
close_qt();
+ mlt_producer_close( producer );
free( producer );
}
-mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
-{
- // Create a new producer object
- mlt_producer this = mlt_producer_new( );
- // Initialise the producer
+mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *filename )
+{
+ fprintf(stderr, "\n\n,,,,,,,,, CREATE 1 TITLE\n");
+ /* Create a new producer object */
- if ( this != NULL )
+ mlt_producer producer = calloc( 1, sizeof( struct mlt_producer_s ) );
+ if ( producer != NULL && mlt_producer_init( producer, NULL ) == 0 )
{
- init_qt( arg );
- // Callback registration
- this->get_frame = producer_get_frame;
- this->close = ( mlt_destructor ) producer_close;
- mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
- mlt_properties_set( properties, "resource", arg );
+ /* Get the properties interface */
+ mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
+ /* Callback registration */
+ 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 );
+ read_xml(properties);
+ init_qt( filename );
+ return producer;
}
-
- return this;
+ free( producer );
+ return NULL;
}