]> git.sesse.net Git - kdenlive/commitdiff
simplify the getImage methods in kthumb and use it in renderer (to fix random crash...
authorMarco Gittler <marco@gitma.de>
Tue, 18 Mar 2008 16:55:55 +0000 (16:55 +0000)
committerMarco Gittler <marco@gitma.de>
Tue, 18 Mar 2008 16:55:55 +0000 (16:55 +0000)
less debug in initeffect

svn path=/branches/KDE4/; revision=2077

src/initeffects.cpp
src/kthumb.cpp
src/kthumb.h
src/renderer.cpp

index 81435b071644c19b6f526973c47d486d0a213fcf..bbd82d278bb79fd8359d307811cc0fad31b7da64 100644 (file)
@@ -329,7 +329,7 @@ QDomDocument initEffects::createDescriptionFromMlt(Mlt::Repository* repository,
 
     QDomDocument ret;
     Mlt::Properties *metadata = repository->metadata(filter_type, filtername.toAscii().data());
-    kDebug() << filtername;
+    //kDebug() << filtername;
     if (metadata && metadata->is_valid()) {
         if (metadata->get("title") && metadata->get("identifier")) {
             QDomElement eff = ret.createElement("effect");
@@ -387,10 +387,10 @@ QDomDocument initEffects::createDescriptionFromMlt(Mlt::Repository* repository,
             ret.appendChild(eff);
         }
     }
-    QString outstr;
-    QTextStream str(&outstr);
-    ret.save(str, 2);
-    kDebug() << outstr;
+    /* QString outstr;
+     QTextStream str(&outstr);
+     ret.save(str, 2);
+     kDebug() << outstr;*/
     return ret;
 }
 
index ec137979dfda05ba2cbe28334894859123df24db..12b8403202b5a6c1f0d5c6eb6abf71d5c7d1bd66 100644 (file)
@@ -154,7 +154,7 @@ KThumb::~KThumb() {
 //static
 QPixmap KThumb::getImage(KUrl url, int width, int height) {
     if (url.isEmpty()) return QPixmap();
-    QPixmap pix(width, height);
+    /*QPixmap pix(width, height);
     kDebug() << "+++++++++++  GET THMB IMG FOR: " << url;
     char *tmp = Render::decodedString(url.path());
     Mlt::Profile prof((char*) KdenliveSettings::current_profile().data());
@@ -180,51 +180,71 @@ QPixmap KThumb::getImage(KUrl url, int width, int height) {
         } else pix.fill(Qt::black);
     }
     if (m_frame) delete m_frame;
-    return pix;
+    return pix;*/
+    return getImage(url, 0, width, height);
 }
 
 void KThumb::extractImage(int frame, int frame2) {
     if (m_url.isEmpty()) return;
-    QPixmap pix(m_width, m_height);
+
     char *tmp = Render::decodedString(m_url.path());
     Mlt::Producer m_producer(*m_profile, tmp);
     delete[] tmp;
 
+    QPixmap pix(m_width, m_height);
     if (m_producer.is_blank()) {
+        QPixmap pix(m_width, m_height);
         pix.fill(Qt::black);
         emit thumbReady(frame, pix);
         return;
     }
-    Mlt::Frame * m_frame;
-    mlt_image_format format = mlt_image_rgb24a;
-    Mlt::Filter m_convert(*m_profile, "avcolour_space");
-    m_convert.set("forced", mlt_image_rgb24a);
-    m_producer.attach(m_convert);
     if (frame != -1) {
-        m_producer.seek(frame);
-        m_frame = m_producer.get_frame();
-        if (m_frame && m_frame->is_valid()) {
-            uint8_t *thumb = m_frame->get_image(format, m_width, m_height);
-            QImage image(thumb, m_width, m_height, QImage::Format_ARGB32);
-            if (!image.isNull()) {
-                pix = pix.fromImage(image);
-            } else pix.fill(Qt::black);
-        }
-        if (m_frame) delete m_frame;
+        QPixmap pix = getFrame(&m_producer, frame, m_width, m_height);
         emit thumbReady(frame, pix);
     }
-    if (frame2 == -1) return;
-    m_producer.seek(frame2);
-    m_frame = m_producer.get_frame();
+    if (frame2 != -1) {
+        QPixmap pix = getFrame(&m_producer, frame2, m_width, m_height);
+        emit thumbReady(frame2, pix);
+    }
+
+}
+
+QPixmap KThumb::getImage(KUrl url, int frame, int width, int height) {
+    Mlt::Profile profile((char*) KdenliveSettings::current_profile().data());
+    QPixmap pix(width, height);
+    if (url.isEmpty()) return pix;
+    char *tmp = Render::decodedString(url.path());
+    Mlt::Producer producer(profile, tmp);
+    delete[] tmp;
+
+    if (producer.is_blank()) {
+
+        pix.fill(Qt::black);
+        return pix;
+    }
+    return getFrame(&producer, frame, width, height);
+
+}
+
+QPixmap KThumb::getFrame(Mlt::Producer* producer, int frame, int width, int height) {
+    Mlt::Profile profile((char*) KdenliveSettings::current_profile().data());
+    Mlt::Filter m_convert(profile, "avcolour_space");
+    m_convert.set("forced", mlt_image_rgb24a);
+    producer->attach(m_convert);
+
+    producer->seek(frame);
+    Mlt::Frame * m_frame = producer->get_frame();
+    mlt_image_format format = mlt_image_rgb24a;
+    QPixmap pix(width, height);
     if (m_frame && m_frame->is_valid()) {
-        uint8_t *thumb = m_frame->get_image(format, m_width, m_height);
-        QImage image(thumb, m_width, m_height, QImage::Format_ARGB32);
+        uint8_t *thumb = m_frame->get_image(format, width, height);
+        QImage image(thumb, width, height, QImage::Format_ARGB32);
         if (!image.isNull()) {
             pix = pix.fromImage(image);
         } else pix.fill(Qt::black);
     }
     if (m_frame) delete m_frame;
-    emit thumbReady(frame2, pix);
+    return pix;
 
 }
 /*
index a0255210178858285c1bd9b6de2db549b8325f19..a8637e90145bceaf03cf5d43936bf0d7df6b7663 100644 (file)
@@ -83,7 +83,8 @@ public slots:
     void stopAudioThumbs();
     void removeAudioThumb();
     void getAudioThumbs(int channel, double frame, double frameLength, int arrayWidth);
-
+    static QPixmap getImage(KUrl url, int frame, int width, int height);
+    static QPixmap getFrame(Mlt::Producer* producer, int frame, int width, int height);
 protected:
     virtual void customEvent(QEvent * event);
 
index c7b0c109c6ab437d6a3425656638e5b6b51d79b5..2ddad7c2d0eb1d681db47b07f059b15e5849dd52 100644 (file)
@@ -40,6 +40,7 @@ extern "C" {
 
 #include "renderer.h"
 #include "kdenlivesettings.h"
+#include "kthumb.h"
 
 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
     // detect if the producer has finished playing. Is there a better way to do it ?
@@ -402,7 +403,7 @@ void Render::getFileProperties(const QDomElement &xml, int clipId) {
                 filePropertyMap["type"] = "video";
 
             // Generate thumbnail for this frame
-            QPixmap pixmap = frameThumbnail(frame, width, height, true);
+            QPixmap pixmap = KThumb::getImage(url, 0, width, height);
 
             emit replyGetImage(clipId, 0, pixmap, width, height);