void init_qt (const char* c){
titleclass=new Title(QString(c));
}
- void refresh_kdenlivetitle( uint8_t* buffer, int width, int height , double position){
- titleclass->drawKdenliveTitle(buffer,width,height,position);
- int i=0;
- uint8_t* pointer;
- //rotate bytes for correct order in mlt
- for (i=0;i<width*height*4;i+=4){
- pointer=buffer+i;
- uint8_t a=pointer[0],r=pointer[1],g=pointer[2],b=pointer[3];
- pointer[0]=g;//g
- pointer[1]=r;//r
- pointer[2]=b;//b
- pointer[3]=a;//a
- }
+ uint8_t* refresh_kdenlivetitle( uint8_t* buffer, int width, int height , double position){
+ void * cpy=malloc( width*height*4);
+ uint8_t* ret=titleclass->drawKdenliveTitle(buffer,width,height,position);
+ memcpy(cpy,ret,width*height*4);
+ return (uint8_t*)cpy;
}
}
-Title::Title(const QString& filename){
- int argc=0;
+Title::Title(const QString& filename):m_filename(filename),m_scene(NULL){
+ /*int argc=0;
char* argv[1];
argv[0]="xxx";
if (! QApplication::activeWindow())
app=new QApplication(argc,argv);
+ */
//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_scene=new QGraphicsScene;
- loadDocument(filename,start,end);
+ //m_scene=new QGraphicsScene;
+ //loadDocument(filename,start,end);
}
-void Title::drawKdenliveTitle(uint8_t * buffer ,int width,int height,double position){
+uint8_t* Title::drawKdenliveTitle(uint8_t * buffer ,int width,int height,double position){
+ if (!m_scene){
+ int argc=0;
+ char* argv[1];
+ argv[0]="xxx";
+ //if (! QApplication::activeWindow())
+ if (!app)
+ app=new QApplication(argc,argv);
+ m_scene=new QGraphicsScene;
+ loadDocument(m_filename,start,end);
+ }
+ //must be extracted from kdenlive title
+
//qDebug() << width << height;
- QImage img((uchar*)buffer,width,height,width*4,QImage::Format_ARGB32);
- img.fill(Qt::transparent);
+ QImage *img=new QImage(width,height,QImage::Format_ARGB32);
+ //QImage img((uchar*)buffer,width,height,width*4,QImage::Format_ARGB32);
+ img->fill(Qt::transparent);
//img.fill(66);
+ //memset(buffer,127,width*height+4);
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.begin(img);
p1.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing|QPainter::SmoothPixmapTransform );
m_scene->render(&p1,QRect(0,0,width,height),QRectF(topleft,bottomRight));
p1.end();
+ uint8_t* pointer=img->bits();
+ for (int i=0;i<width*height*4;i+=4){
+ pointer=buffer+i;
+ uint8_t a=pointer[0],r=pointer[1],g=pointer[2],b=pointer[3];
+ pointer[0]=g;//g
+ pointer[1]=r;//r
+ pointer[2]=b;//b
+ pointer[3]=a;//a
+ }
+ return img->bits();
//qDebug() << img.hasAlphaChannel();
//img.save("test.png");
}
*/
#include <QtCore/QObject>
+#include <QtCore/QString>
#include <framework/mlt_frame.h>
#include <QtXml/QDomElement>
class QGraphicsPolygonItem;
public:
Title(const QString &);
- void drawKdenliveTitle(uint8_t*,int,int,double);
+ uint8_t* drawKdenliveTitle(uint8_t*,int,int,double);
private:
+ QString m_filename;
int loadFromXml(QDomDocument doc, QGraphicsPolygonItem* /*startv*/, QGraphicsPolygonItem* /*endv*/);
int loadDocument(const QString& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv);
QGraphicsView *view;
//#include <QtCore/QCoreApplication>
//#include <QtGui/QImage>
extern void init_qt();
-extern void refresh_kdenlivetitle(uint8_t*,int,int,double);
+extern uint8_t* refresh_kdenlivetitle(uint8_t*,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 producer
mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
- int size1;
// 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 );
+ //printf("%x %x %x\n",*(buffer),*(buffer+1),*(buffer+2));
+
+ //######### noise
+ // Update the frame
+ mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
+#if 0
+ // Before we write to the image, make sure we have one
+ if ( *buffer != NULL )
+ {
+ // Calculate the end of the buffer
+ uint8_t *p = *buffer + *width * *height * 2;
+
+ // Value to hold a random number
+ uint32_t value;
+
+ // Generate random noise
+ while ( p != *buffer )
+ {
+ value = rand() & 0xff;
+ *( -- p ) = 128;
+ *( -- p ) = value < 16 ? 16 : value > 240 ? 240 : value;
+ }
+ }
+
+
+ printf("%x %x\n", mlt_properties_get_data(properties,"image",NULL),mlt_properties_get_data(producer_props,"image",NULL));
//unchached now
+#else
if ( 1 )
{
// Allocate the image
- uint8_t *image = mlt_pool_alloc( size );
*format = mlt_image_rgb24a;
+ //*format = mlt_image_yuv422;
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( image, *width, *height, position );
+ //uint8_t *pic= mlt_pool_alloc( size);
+ uint8_t* pic1=refresh_kdenlivetitle(*buffer, *width, *height, position );
+
- *buffer=image;
- mlt_properties_set_data( properties, "image", image, size, mlt_pool_release, NULL );
+ memcpy(*buffer,pic1,size);
+
+ /*uint8_t *p = *buffer + *width * *height * 2;
+
+ // Value to hold a random number
+ uint32_t value;
+
+ // Generate random noise
+ while ( p != *buffer )
+ {
+ value = rand() & 0xff;
+ *( -- p ) = 128;
+ *( -- p ) = value < 16 ? 16 : value > 240 ? 240 : value;
+ }
+ */
mlt_log_debug( MLT_PRODUCER_SERVICE(producer), "width:%d height:%d %s\n",*width,*height, mlt_image_format_name( *format ) );
}
-
+#endif
return 0;
}
// Initialise the producer
if ( this != NULL )
{
+ init_qt(arg);
// Callback registration
this->get_frame = producer_get_frame;
this->close = ( mlt_destructor )producer_close;
}
- init_qt(arg);
return this;
}