From e8cf3e59ff04827b3e0e38824040a14527e6ca02 Mon Sep 17 00:00:00 2001 From: Marco Gittler Date: Fri, 10 Jul 2009 19:04:25 +0200 Subject: [PATCH] first work on kdenlive title producer should later read the xml-file from kdenlive and let the title have scroll and zoom --- src/modules/qimage/Makefile | 4 +- src/modules/qimage/factory.c | 3 +- src/modules/qimage/kdenlivetitle_wrapper.cpp | 49 ++++++++ src/modules/qimage/kdenlivetitle_wrapper.h | 32 +++++ src/modules/qimage/producer_kdenlivetitle.c | 119 +++++++++++++++++++ 5 files changed, 204 insertions(+), 3 deletions(-) create mode 100644 src/modules/qimage/kdenlivetitle_wrapper.cpp create mode 100644 src/modules/qimage/kdenlivetitle_wrapper.h create mode 100644 src/modules/qimage/producer_kdenlivetitle.c diff --git a/src/modules/qimage/Makefile b/src/modules/qimage/Makefile index ad3e4fa5..d2d7dd8a 100644 --- a/src/modules/qimage/Makefile +++ b/src/modules/qimage/Makefile @@ -3,8 +3,8 @@ include config.mak TARGET = ../libmltqimage$(LIBSUF) -OBJS = factory.o producer_qimage.o -CPPOBJS = qimage_wrapper.o +OBJS = factory.o producer_qimage.o producer_kdenlivetitle.o +CPPOBJS = qimage_wrapper.o kdenlivetitle_wrapper.o CFLAGS += -I../.. CXXFLAGS += $(CFLAGS) $(QTCXXFLAGS) -Wno-deprecated diff --git a/src/modules/qimage/factory.c b/src/modules/qimage/factory.c index 61cb0ec0..fdcec364 100644 --- a/src/modules/qimage/factory.c +++ b/src/modules/qimage/factory.c @@ -22,8 +22,9 @@ #include extern mlt_producer producer_qimage_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ); +extern mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ); MLT_REPOSITORY { - MLT_REGISTER( producer_type, "qimage", producer_qimage_init ); + MLT_REGISTER( producer_type, "kdenlivetitle", producer_kdenlivetitle_init ); } diff --git a/src/modules/qimage/kdenlivetitle_wrapper.cpp b/src/modules/qimage/kdenlivetitle_wrapper.cpp new file mode 100644 index 00000000..f7d6beb4 --- /dev/null +++ b/src/modules/qimage/kdenlivetitle_wrapper.cpp @@ -0,0 +1,49 @@ +/* + * kdenlivetitle_wrapper.cpp -- kdenlivetitle wrapper + * Copyright (c) 2009 Marco Gittler + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include +#include +#include "kdenlivetitle_wrapper.h" +#include +extern "C" { +void init_qt (const char* c){ + titleclass=new Title(QString(c)); +} +void refresh_kdenlivetitle( void* buffer, int width, int height , double position){ + titleclass->drawKdenliveTitle(buffer,width,height,position); +} +} +Title::Title(const QString& filename){ + int argc=0; + char* argv[1]; + argv[0]=0; + app=new QCoreApplication(argc,argv); +} +void Title::drawKdenliveTitle(void * buffer ,int width,int height,double position){ + //qDebug() << "ja" << width << height << buffer << position << endl; + QImage img((uchar*)buffer,width,height,width*4,QImage::Format_ARGB32); + img.fill(0x22); + QPainter p; + p.begin(&img); + p.setFont(QFont("Arial",40)); + p.setPen(QPen(QColor(255,255,255))); + p.drawText(width*.2+width*20*position,height/2,"test"); + p.end(); +} diff --git a/src/modules/qimage/kdenlivetitle_wrapper.h b/src/modules/qimage/kdenlivetitle_wrapper.h new file mode 100644 index 00000000..dd7690aa --- /dev/null +++ b/src/modules/qimage/kdenlivetitle_wrapper.h @@ -0,0 +1,32 @@ +/* + * kdenlivetitle_wrapper.h -- kdenlivetitle wrapper + * Copyright (c) 2009 Marco Gittler + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +class QCoreApplication; +class QObject; +class Title; +QCoreApplication *app; +Title* titleclass; + +class Title: public QObject { + + public: + Title(const QString &); + void drawKdenliveTitle(void*,int,int,double); +}; diff --git a/src/modules/qimage/producer_kdenlivetitle.c b/src/modules/qimage/producer_kdenlivetitle.c new file mode 100644 index 00000000..f20e03dd --- /dev/null +++ b/src/modules/qimage/producer_kdenlivetitle.c @@ -0,0 +1,119 @@ +/* + * producer_kdenlivetitle.c -- kdenlive producer + * Copyright (c) 2009 Marco Gittler + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +//#include "frei0r_helper.h" +#include +#include +//#include +//#include +extern init_qt(); +extern refresh_kdenlivetitle(void*,int,int,double); + +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 + mlt_properties properties = MLT_FRAME_PROPERTIES( frame ); + + // Obtain the producer for this frame + mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL ); + + // Obtain properties of producer + mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer ); + + // Allocate the image + int size = *width * ( *height + 1 ) * 4; + + // Allocate the image + *buffer = mlt_pool_alloc( size ); + + // Update the frame + mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL ); + mlt_properties_set_int( properties, "width", *width ); + mlt_properties_set_int( properties, "height", *height ); + + *format = mlt_image_rgb24a; + if ( *buffer != NULL ) + { + mlt_position in = mlt_producer_get_in( producer ); + 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); + } + + return 0; +} + +int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index ) +{ + // Generate a frame + *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) ); + + if ( *frame != NULL ) + { + // Obtain properties of frame and producer + mlt_properties properties = MLT_FRAME_PROPERTIES( *frame ); + + // Obtain properties of producer + mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer ); + + // 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 + mlt_frame_set_position( *frame, mlt_producer_position( producer ) ); + + // 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 + mlt_frame_push_get_image( *frame, producer_get_image ); + } + + // Calculate the next timecode + mlt_producer_prepare_next( producer ); + + return 0; +} + +void producer_close( mlt_producer producer ) +{ + producer->close = NULL; + 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 + if ( this != NULL ) + { + // Callback registration + this->get_frame = producer_get_frame; + this->close = ( mlt_destructor )producer_close; + } + init_qt(); + return this; +} + -- 2.39.5