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