]> git.sesse.net Git - mlt/blob - src/modules/qimage/kdenlivetitle_wrapper.cpp
Fix wrong type causing bug in titler (kdenlive-2971)
[mlt] / src / modules / qimage / kdenlivetitle_wrapper.cpp
1 /*
2  * kdenlivetitle_wrapper.cpp -- kdenlivetitle wrapper
3  * Copyright (c) 2009 Marco Gittler <g.marco@freenet.de>
4  * Copyright (c) 2009 Jean-Baptiste Mardelle <jb@kdenlive.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "kdenlivetitle_wrapper.h"
22
23 #include <QtGui/QImage>
24 #include <QtGui/QPainter>
25 #include <QtCore/QDebug>
26 #include <QtGui/QApplication>
27 #include <QtCore/QMutex>
28 #include <QtGui/QGraphicsScene>
29 #include <QtGui/QGraphicsTextItem>
30 #include <QtSvg/QGraphicsSvgItem>
31 #include <QtSvg/QSvgRenderer>
32 #include <QtGui/QTextCursor>
33 #include <QtGui/QTextDocument>
34 #include <QtGui/QStyleOptionGraphicsItem>
35
36 #include <QtCore/QString>
37
38 #include <QtXml/QDomElement>
39 #include <QtCore/QRectF>
40 #include <QtGui/QColor>
41 #include <QtGui/QWidget>
42 #include <framework/mlt_log.h>
43
44 #if QT_VERSION >= 0x040600
45 #include <QtGui/QGraphicsEffect>
46 #include <QtGui/QGraphicsBlurEffect>
47 #include <QtGui/QGraphicsDropShadowEffect>
48 #endif
49
50 static QApplication *app = NULL;
51
52 class ImageItem: public QGraphicsItem
53 {
54 public:
55     ImageItem(QImage img)
56     {
57         m_img = img;
58     }
59     QImage m_img;
60
61
62 protected:
63
64 virtual QRectF boundingRect() const
65 {
66     return QRectF(0, 0, m_img.width(), m_img.height());
67 }
68
69 virtual void paint( QPainter *painter,
70                        const QStyleOptionGraphicsItem * /*option*/,
71                        QWidget* )
72
73     painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
74     painter->drawImage(QPoint(), m_img);
75 }
76 };
77
78
79 QRectF stringToRect( const QString & s )
80 {
81
82         QStringList l = s.split( ',' );
83         if ( l.size() < 4 )
84                 return QRectF();
85         return QRectF( l.at( 0 ).toDouble(), l.at( 1 ).toDouble(), l.at( 2 ).toDouble(), l.at( 3 ).toDouble() ).normalized();
86 }
87
88 QColor stringToColor( const QString & s )
89 {
90         QStringList l = s.split( ',' );
91         if ( l.size() < 4 )
92                 return QColor();
93         return QColor( l.at( 0 ).toInt(), l.at( 1 ).toInt(), l.at( 2 ).toInt(), l.at( 3 ).toInt() );
94         ;
95 }
96 QTransform stringToTransform( const QString& s )
97 {
98         QStringList l = s.split( ',' );
99         if ( l.size() < 9 )
100                 return QTransform();
101         return QTransform(
102                    l.at( 0 ).toDouble(), l.at( 1 ).toDouble(), l.at( 2 ).toDouble(),
103                    l.at( 3 ).toDouble(), l.at( 4 ).toDouble(), l.at( 5 ).toDouble(),
104                    l.at( 6 ).toDouble(), l.at( 7 ).toDouble(), l.at( 8 ).toDouble()
105                );
106 }
107
108 static void qscene_delete( void *data )
109 {
110         QGraphicsScene *scene = ( QGraphicsScene * )data;
111         if (scene) delete scene;
112         scene = NULL;
113 }
114
115
116 void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *templateXml, const char *templateText )
117 {
118         scene->clear();
119         mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
120         QDomDocument doc;
121         QString data = QString::fromUtf8(templateXml);
122         QString replacementText = QString::fromUtf8(templateText);
123         doc.setContent(data);
124         QDomElement title = doc.documentElement();
125
126         // Check for invalid title
127         if ( title.isNull() || title.tagName() != "kdenlivetitle" ) return;
128         
129         // Check title locale
130         if ( title.hasAttribute( "LC_NUMERIC" ) ) {
131             QString locale = title.attribute( "LC_NUMERIC" );
132             QLocale::setDefault( locale );
133         }
134         
135         int originalWidth;
136         int originalHeight;
137         if ( title.hasAttribute("width") ) {
138             originalWidth = title.attribute("width").toInt();
139             originalHeight = title.attribute("height").toInt();
140             scene->setSceneRect(0, 0, originalWidth, originalHeight);
141         }
142         else {
143             originalWidth = scene->sceneRect().width();
144             originalHeight = scene->sceneRect().height();
145         }
146         if ( title.hasAttribute( "out" ) ) {
147             mlt_properties_set_position( producer_props, "_animation_out", title.attribute( "out" ).toDouble() );
148         }
149         else {
150             mlt_properties_set_position( producer_props, "_animation_out", mlt_producer_get_out( producer ) );
151         }
152         
153         mlt_properties_set_int( producer_props, "_original_width", originalWidth );
154         mlt_properties_set_int( producer_props, "_original_height", originalHeight );
155
156         QDomNode node;
157         QDomNodeList items = title.elementsByTagName("item");
158         for ( int i = 0; i < items.count(); i++ )
159         {
160                 QGraphicsItem *gitem = NULL;
161                 node = items.item( i );
162                 QDomNamedNodeMap nodeAttributes = node.attributes();
163                 int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt();
164                 if ( zValue > -1000 )
165                 {
166                         if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsTextItem" )
167                         {
168                                 QDomNamedNodeMap txtProperties = node.namedItem( "content" ).attributes();
169                                 QFont font( txtProperties.namedItem( "font" ).nodeValue() );
170                                 QDomNode propsNode = txtProperties.namedItem( "font-bold" );
171                                 if ( !propsNode.isNull() )
172                                 {
173                                         // Old: Bold/Not bold.
174                                         font.setBold( propsNode.nodeValue().toInt() );
175                                 }
176                                 else
177                                 {
178                                         // New: Font weight (QFont::)
179                                         font.setWeight( txtProperties.namedItem( "font-weight" ).nodeValue().toInt() );
180                                 }
181                                 font.setItalic( txtProperties.namedItem( "font-italic" ).nodeValue().toInt() );
182                                 font.setUnderline( txtProperties.namedItem( "font-underline" ).nodeValue().toInt() );
183                                 // Older Kdenlive version did not store pixel size but point size
184                                 if ( txtProperties.namedItem( "font-pixel-size" ).isNull() )
185                                 {
186                                         QFont f2;
187                                         f2.setPointSize( txtProperties.namedItem( "font-size" ).nodeValue().toInt() );
188                                         font.setPixelSize( QFontInfo( f2 ).pixelSize() );
189                                 }
190                                 else
191                                         font.setPixelSize( txtProperties.namedItem( "font-pixel-size" ).nodeValue().toInt() );
192                                 QColor col( stringToColor( txtProperties.namedItem( "font-color" ).nodeValue() ) );
193                                 QString text = node.namedItem( "content" ).firstChild().nodeValue();
194                                 if ( !replacementText.isEmpty() )
195                                 {
196                                         text = text.replace( "%s", replacementText );
197                                 }
198                                 QGraphicsTextItem *txt = scene->addText(text, font);
199                                 if (txtProperties.namedItem("font-outline").nodeValue().toDouble()>0.0){
200                                         qRegisterMetaType<QTextCursor>( "QTextCursor" );
201                                         QTextCursor cursor(txt->document());
202                                         cursor.select(QTextCursor::Document);
203                                         QTextCharFormat format;
204                                         format.setTextOutline(
205                                                         QPen(QColor( stringToColor( txtProperties.namedItem( "font-outline-color" ).nodeValue() ) ),
206                                                         txtProperties.namedItem("font-outline").nodeValue().toDouble(),
207                                                         Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin)
208                                         );
209                                         format.setForeground(QBrush(col));
210
211                                         cursor.mergeCharFormat(format);
212                                 } else {
213                                         txt->setDefaultTextColor( col );
214                                 }
215                                 
216                                 // Effects
217                                 if (!txtProperties.namedItem( "typewriter" ).isNull()) {
218                                         // typewriter effect
219                                         mlt_properties_set_int( producer_props, "_animated", 1 );
220                                         QStringList effetData = QStringList() << "typewriter" << text << txtProperties.namedItem( "typewriter" ).nodeValue();
221                                         txt->setData(0, effetData);
222                                         if ( !txtProperties.namedItem( "textwidth" ).isNull() )
223                                                 txt->setData( 1, txtProperties.namedItem( "textwidth" ).nodeValue() );
224                                 }
225                                 
226                                 if ( txtProperties.namedItem( "alignment" ).isNull() == false )
227                                 {
228                                         txt->setTextWidth( txt->boundingRect().width() );
229                                         QTextOption opt = txt->document()->defaultTextOption ();
230                                         opt.setAlignment(( Qt::Alignment ) txtProperties.namedItem( "alignment" ).nodeValue().toInt() );
231                                         txt->document()->setDefaultTextOption (opt);
232                                 }
233                                         if ( !txtProperties.namedItem( "kdenlive-axis-x-inverted" ).isNull() )
234                                 {
235                                         //txt->setData(OriginXLeft, txtProperties.namedItem("kdenlive-axis-x-inverted").nodeValue().toInt());
236                                 }
237                                 if ( !txtProperties.namedItem( "kdenlive-axis-y-inverted" ).isNull() )
238                                 {
239                                         //txt->setData(OriginYTop, txtProperties.namedItem("kdenlive-axis-y-inverted").nodeValue().toInt());
240                                 }
241                                         gitem = txt;
242                         }
243                         else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsRectItem" )
244                         {
245                                 QString rect = node.namedItem( "content" ).attributes().namedItem( "rect" ).nodeValue();
246                                 QString br_str = node.namedItem( "content" ).attributes().namedItem( "brushcolor" ).nodeValue();
247                                 QString pen_str = node.namedItem( "content" ).attributes().namedItem( "pencolor" ).nodeValue();
248                                 double penwidth = node.namedItem( "content" ).attributes().namedItem( "penwidth") .nodeValue().toDouble();
249                                 QGraphicsRectItem *rec = scene->addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ), QBrush( stringToColor( br_str ) ) );
250                                 gitem = rec;
251                         }
252                         else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsPixmapItem" )
253                         {
254                                 const QString url = node.namedItem( "content" ).attributes().namedItem( "url" ).nodeValue();
255                                 const QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue();
256                                 QImage img;
257                                 if (base64.isEmpty()){
258                                         img.load(url);
259                                 }else{
260                                         img.loadFromData(QByteArray::fromBase64(base64.toAscii()));
261                                 }
262                                 ImageItem *rec = new ImageItem(img);
263                                 scene->addItem( rec );
264                                 gitem = rec;
265                         }
266                         else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsSvgItem" )
267                         {
268                                 QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
269                                 QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue();
270                                 QGraphicsSvgItem *rec = NULL;
271                                 if (base64.isEmpty()){
272                                         rec = new QGraphicsSvgItem(url);
273                                 }else{
274                                         rec = new QGraphicsSvgItem();
275                                         QSvgRenderer *renderer= new QSvgRenderer(QByteArray::fromBase64(base64.toAscii()), rec );
276                                         rec->setSharedRenderer(renderer);
277                                 }
278                                 if (rec){
279                                         scene->addItem(rec);
280                                         gitem = rec;
281                                 }
282                         }
283                 }
284                 //pos and transform
285                 if ( gitem )
286                 {
287                         QPointF p( node.namedItem( "position" ).attributes().namedItem( "x" ).nodeValue().toDouble(),
288                                    node.namedItem( "position" ).attributes().namedItem( "y" ).nodeValue().toDouble() );
289                         gitem->setPos( p );
290                         gitem->setTransform( stringToTransform( node.namedItem( "position" ).firstChild().firstChild().nodeValue() ) );
291                         int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt();
292                         gitem->setZValue( zValue );
293
294 #if QT_VERSION >= 0x040600
295                         // effects
296                         QDomNode eff = items.item(i).namedItem("effect");
297                         if (!eff.isNull()) {
298                                 QDomElement e = eff.toElement();
299                                 if (e.attribute("type") == "blur") {
300                                         QGraphicsBlurEffect *blur = new QGraphicsBlurEffect();
301                                         blur->setBlurRadius(e.attribute("blurradius").toInt());
302                                         gitem->setGraphicsEffect(blur);
303                                 }
304                                 else if (e.attribute("type") == "shadow") {
305                                         QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect();
306                                         shadow->setBlurRadius(e.attribute("blurradius").toInt());
307                                         shadow->setOffset(e.attribute("xoffset").toInt(), e.attribute("yoffset").toInt());
308                                         gitem->setGraphicsEffect(shadow);
309                                 }
310                         }
311 #endif
312                 }
313         }
314
315         QDomNode n = title.firstChildElement("background");
316         if (!n.isNull()) {
317                 QColor color = QColor( stringToColor( n.attributes().namedItem( "color" ).nodeValue() ) );
318                 if (color.alpha() > 0) {
319                         QGraphicsRectItem *rec = scene->addRect(0, 0, scene->width(), scene->height() , QPen( Qt::NoPen ), QBrush( color ) );
320                         rec->setZValue(-1100);
321                 }
322           
323         }
324
325         QString startRect;
326         n = title.firstChildElement( "startviewport" );
327         // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport
328         if (!n.isNull() && !n.toElement().hasAttribute("x"))
329         {
330                 startRect = n.attributes().namedItem( "rect" ).nodeValue();
331         }
332         n = title.firstChildElement( "endviewport" );
333         // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport
334         if (!n.isNull() && !n.toElement().hasAttribute("x"))
335         {
336                 QString rect = n.attributes().namedItem( "rect" ).nodeValue();
337                 if (startRect != rect)
338                         mlt_properties_set( producer_props, "_endrect", rect.toUtf8().data() );
339         }
340         if (!startRect.isEmpty()) {
341                 mlt_properties_set( producer_props, "_startrect", startRect.toUtf8().data() );
342         }
343         return;
344 }
345
346
347 void drawKdenliveTitle( producer_ktitle self, mlt_frame frame, int width, int height, double position, int force_refresh )
348 {
349         // Obtain the producer 
350         mlt_producer producer = &self->parent;
351         mlt_profile profile = mlt_service_profile ( MLT_PRODUCER_SERVICE( producer ) ) ;
352         mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
353
354         // Obtain properties of frame
355         mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
356         
357         pthread_mutex_lock( &self->mutex );
358         
359         // Check if user wants us to reload the image
360         if ( mlt_properties_get( producer_props, "_animated" ) != NULL || force_refresh == 1 || width != self->current_width || height != self->current_height || mlt_properties_get( producer_props, "_endrect" ) != NULL )
361         {
362                 //mlt_cache_item_close( self->image_cache );
363                 self->current_image = NULL;
364                 mlt_properties_set_data( producer_props, "cached_image", NULL, 0, NULL, NULL );
365                 mlt_properties_set_int( producer_props, "force_reload", 0 );
366         }
367         
368         if (self->current_image == NULL) {
369                 // restore QGraphicsScene
370                 QGraphicsScene *scene = static_cast<QGraphicsScene *> (mlt_properties_get_data( producer_props, "qscene", NULL ));
371
372                 if ( force_refresh == 1 && scene )
373                 {
374                         scene = NULL;
375                         mlt_properties_set_data( producer_props, "qscene", NULL, 0, NULL, NULL );
376                 }
377
378                 if ( scene == NULL )
379                 {
380                         int argc = 1;
381                         char* argv[1];
382                         argv[0] = (char*) "xxx";
383                         
384                         // Warning: all Qt graphic objects (QRect, ...) must be initialized AFTER 
385                         // the QApplication is created, otherwise their will be NULL
386                         
387                         if ( app == NULL ) {
388                                 if ( qApp ) {
389                                         app = qApp;
390                                 }
391                                 else {
392 #ifdef linux
393                                         if ( getenv("DISPLAY") == 0 )
394                                         {
395                                                 mlt_log_panic( MLT_PRODUCER_SERVICE( producer ), "Error, cannot render titles without an X11 environment.\nPlease either run melt from an X session or use a fake X server like xvfb:\nxvfb-run -a melt (...)\n" );
396                                                 pthread_mutex_unlock( &self->mutex );
397                                                 return;
398                                         }
399 #endif
400                                         app = new QApplication( argc, argv );                           
401                                         const char *localename = mlt_properties_get_lcnumeric( MLT_SERVICE_PROPERTIES( MLT_PRODUCER_SERVICE( producer ) ) );
402                                         QLocale::setDefault( QLocale( localename ) );
403                                 }
404                         }
405                         scene = new QGraphicsScene();
406                         scene->setItemIndexMethod( QGraphicsScene::NoIndex );
407                         scene->setSceneRect(0, 0, mlt_properties_get_int( properties, "width" ), mlt_properties_get_int( properties, "height" ));
408                         if ( mlt_properties_get( producer_props, "resource" ) && mlt_properties_get( producer_props, "resource" )[0] != '\0' )
409                         {
410                                 // The title has a resource property, so we read all properties from the resource.
411                                 // Do not serialize the xmldata
412                                 loadFromXml( producer, scene, mlt_properties_get( producer_props, "_xmldata" ), mlt_properties_get( producer_props, "templatetext" ) );
413                         }
414                         else
415                         {
416                                 // The title has no resource, all data should be serialized
417                                 loadFromXml( producer, scene, mlt_properties_get( producer_props, "xmldata" ), mlt_properties_get( producer_props, "templatetext" ) );
418                           
419                         }
420                         mlt_properties_set_data( producer_props, "qscene", scene, 0, ( mlt_destructor )qscene_delete, NULL );
421                 }
422                 
423                 QRectF start = stringToRect( QString( mlt_properties_get( producer_props, "_startrect" ) ) );
424                 QRectF end = stringToRect( QString( mlt_properties_get( producer_props, "_endrect" ) ) );
425         
426                 int originalWidth = mlt_properties_get_int( producer_props, "_original_width" );
427                 int originalHeight= mlt_properties_get_int( producer_props, "_original_height" );
428                 const QRectF source( 0, 0, width, height );
429                 if (start.isNull()) {
430                     start = QRectF( 0, 0, originalWidth, originalHeight );
431                 }
432
433                 // Effects
434                 QList <QGraphicsItem *> items = scene->items();
435                 QGraphicsTextItem *titem = NULL;
436                 for (int i = 0; i < items.count(); i++) {
437                     titem = static_cast <QGraphicsTextItem*> ( items.at( i ) );
438                     if (titem && !titem->data( 0 ).isNull()) {
439                             QStringList params = titem->data( 0 ).toStringList();
440                             if (params.at( 0 ) == "typewriter" ) {
441                                     // typewriter effect has 2 param values:
442                                     // the keystroke delay and a start offset, both in frames
443                                     QStringList values = params.at( 2 ).split( ";" );
444                                     int interval = qMax( 0, ( ( int ) position - values.at( 1 ).toInt()) / values.at( 0 ).toInt() );
445                                     qRegisterMetaType<QTextCursor>( "QTextCursor" );
446                                     QTextCursor cursor = titem->textCursor();
447                                     cursor.movePosition(QTextCursor::EndOfBlock);
448                                     // get the font format
449                                     QTextCharFormat format = cursor.charFormat();
450                                     cursor.select(QTextCursor::Document);
451                                     QString txt = params.at( 1 ).left( interval );
452                                     // If the string to insert is empty, insert a space / linebreak so that we don't loose
453                                     // formatting infos for the next iterations
454                                     int lines = params.at( 1 ).count( '\n' );
455                                     QString empty = " ";
456                                     for (int i = 0; i < lines; i++)
457                                             empty.append( "\n " );
458                                     cursor.insertText( txt.isEmpty() ? empty : txt, format );
459                                     if ( !titem->data( 1 ).isNull() )
460                                           titem->setTextWidth( titem->data( 1 ).toDouble() );
461                             }
462                     }
463                 }
464
465                 //must be extracted from kdenlive title
466                 QImage img( width, height, QImage::Format_ARGB32 );
467                 img.fill( 0 );
468                 QPainter p1;
469                 p1.begin( &img );
470                 p1.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing );
471                 //| QPainter::SmoothPixmapTransform );
472                 mlt_position anim_out = mlt_properties_get_position( producer_props, "_animation_out" );
473
474                 if (end.isNull())
475                 {
476                         scene->render( &p1, source, start, Qt::IgnoreAspectRatio );
477                 }
478                 else if ( position > anim_out ) {
479                         scene->render( &p1, source, end, Qt::IgnoreAspectRatio );
480                 }
481                 else {
482                         double percentage = 0;
483                         if ( position && anim_out )
484                                 percentage = position / anim_out;
485                         QPointF topleft = start.topLeft() + ( end.topLeft() - start.topLeft() ) * percentage;
486                         QPointF bottomRight = start.bottomRight() + ( end.bottomRight() - start.bottomRight() ) * percentage;
487                         const QRectF r1( topleft, bottomRight );
488                         scene->render( &p1, source, r1, Qt::IgnoreAspectRatio );
489                         if ( profile && !profile->progressive ){
490                                 int line=0;
491                                 double percentage_next_filed    = ( position + 0.5 ) / anim_out;
492                                 QPointF topleft_next_field = start.topLeft() + ( end.topLeft() - start.topLeft() ) * percentage_next_filed;
493                                 QPointF bottomRight_next_field = start.bottomRight() + ( end.bottomRight() - start.bottomRight() ) * percentage_next_filed;
494                                 const QRectF r2( topleft_next_field, bottomRight_next_field );
495                                 QImage img1( width, height, QImage::Format_ARGB32 );
496                                 img1.fill( 0 );
497                                 QPainter p2;
498                                 p2.begin(&img1);
499                                 p2.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing );
500                                 scene->render(&p2,source,r2,  Qt::IgnoreAspectRatio );
501                                 p2.end();
502                                 int next_field_line = (  mlt_properties_get_int( producer_props, "top_field_first" ) ? 1 : 0 );
503                                 for (line = next_field_line ;line<height;line+=2){
504                                                 memcpy(img.scanLine(line),img1.scanLine(line),img.bytesPerLine());
505                                 }
506
507                         }
508                 }
509                 p1.end();
510
511                 int size = width * height * 4;
512                 uint8_t *pointer=img.bits();
513                 QRgb* src = ( QRgb* ) pointer;
514                 self->current_image = ( uint8_t * )mlt_pool_alloc( size );
515                 uint8_t *dst = self->current_image;
516         
517                 for ( int i = 0; i < width * height * 4; i += 4 )
518                 {
519                         *dst++=qRed( *src );
520                         *dst++=qGreen( *src );
521                         *dst++=qBlue( *src );
522                         *dst++=qAlpha( *src );
523                         src++;
524                 }
525
526                 mlt_properties_set_data( producer_props, "cached_image", self->current_image, size, mlt_pool_release, NULL );
527                 self->current_width = width;
528                 self->current_height = height;
529         }
530
531         pthread_mutex_unlock( &self->mutex );
532         mlt_properties_set_int( properties, "width", self->current_width );
533         mlt_properties_set_int( properties, "height", self->current_height );
534 }
535
536