]> git.sesse.net Git - kdenlive/blobdiff - src/kthumb.cpp
Apply patch from P. Fleury to improve jog shuttle speed handling.
[kdenlive] / src / kthumb.cpp
index dcbb27ce7f7a06768549ede2e0c604e822abe8e4..3986e3e53eadbfaa8779b86f685676cf47ca4d49 100644 (file)
@@ -145,6 +145,8 @@ KThumb::~KThumb()
 
 void KThumb::setProducer(Mlt::Producer *producer)
 {
+    m_requestedThumbs.clear();
+    m_future.waitForFinished();
     m_producer = producer;
     // FIXME: the profile() call leaks an object, but trying to free
     // it leads to a double-free in Profile::~Profile()
@@ -169,11 +171,8 @@ void KThumb::updateThumbUrl(const QString &hash)
 void KThumb::updateClipUrl(KUrl url, const QString &hash)
 {
     m_url = url;
-    if (m_producer) {
-        char *tmp = Render::decodedString(url.path());
-        m_producer->set("resource", tmp);
-        delete[] tmp;
-    }
+    if (m_producer)
+        m_producer->set("resource", url.path().toUtf8().constData());
     m_thumbFile = m_clipManager->projectFolder() + "/thumbs/" + hash + ".thumb";
 }
 
@@ -194,8 +193,8 @@ void KThumb::extractImage(int frame, int frame2)
 
 void KThumb::doGetThumbs()
 {
-    const int twidth = (int)(KdenliveSettings::trackheight() * m_dar);
     const int theight = KdenliveSettings::trackheight();
+    const int twidth = FRAME_SIZE;//(int)(theight * m_dar + 0.5);
 
     while (!m_requestedThumbs.isEmpty()) {
         int frame = m_requestedThumbs.takeFirst();
@@ -214,17 +213,13 @@ QPixmap KThumb::extractImage(int frame, int width, int height)
 //static
 QPixmap KThumb::getImage(KUrl url, int frame, int width, int height)
 {
-    char *tmp = Render::decodedString(KdenliveSettings::current_profile());
-    Mlt::Profile profile(tmp);
-    delete[] tmp;
+    Mlt::Profile profile(KdenliveSettings::current_profile().toUtf8().constData());
     QPixmap pix(width, height);
     if (url.isEmpty()) return pix;
 
-    tmp = Render::decodedString(url.path());
     //"<mlt><playlist><producer resource=\"" + url.path() + "\" /></playlist></mlt>");
     //Mlt::Producer producer(profile, "xml-string", tmp);
-    Mlt::Producer *producer = new Mlt::Producer(profile, tmp);
-    delete[] tmp;
+    Mlt::Producer *producer = new Mlt::Producer(profile, url.path().toUtf8().constData());
 
     pix = QPixmap::fromImage(getFrame(producer, frame, width, height));
     delete producer;
@@ -235,7 +230,7 @@ QPixmap KThumb::getImage(KUrl url, int frame, int width, int height)
 //static
 QImage KThumb::getFrame(Mlt::Producer *producer, int framepos, int width, int height)
 {
-    QImage p(width, height, QImage::Format_ARGB32);
+    QImage p(width, height, QImage::Format_ARGB32_Premultiplied);
     if (producer == NULL) {
         p.fill(Qt::red);
         return p;
@@ -257,14 +252,19 @@ QImage KThumb::getFrame(Mlt::Producer *producer, int framepos, int width, int he
     /*Mlt::Producer parentProd(producer->parent());
     Mlt::Service service(parentProd.get_service());
     mlt_service_lock(service.get_service());*/
-
+    int ow = width;
+    int oh = height;
     mlt_image_format format = mlt_image_rgb24a;
-    uint8_t *data = frame->get_image(format, width, height, 0);
-    QImage image((uchar *)data, width, height, QImage::Format_ARGB32);
+    uint8_t *data = frame->get_image(format, ow, oh, 0);
+    QImage image((uchar *)data, ow, oh, QImage::Format_ARGB32_Premultiplied);
     //mlt_service_unlock(service.get_service());
 
     if (!image.isNull()) {
-        p = image.rgbSwapped();
+        if (ow > (2 * width)) {
+            // there was a scaling problem, do it manually
+            QImage scaled = image.scaled(width, height);
+            p = scaled.rgbSwapped();
+        } else p = image.rgbSwapped();
     } else
         p.fill(Qt::red);
 
@@ -276,9 +276,7 @@ void KThumb::getImage(KUrl url, int frame, int width, int height)
 {
     if (url.isEmpty()) return;
     QPixmap image(width, height);
-    char *tmp = KRender::decodedString(url.path());
-    Mlt::Producer m_producer(tmp);
-    delete tmp;
+    Mlt::Producer m_producer(url.path().toUtf8().constData());
     image.fill(Qt::black);
 
     if (m_producer.is_blank()) {
@@ -306,9 +304,7 @@ void KThumb::getThumbs(KUrl url, int startframe, int endframe, int width, int he
 {
     if (url.isEmpty()) return;
     QPixmap image(width, height);
-    char *tmp = KRender::decodedString(url.path());
-    Mlt::Producer m_producer(tmp);
-    delete tmp;
+    Mlt::Producer m_producer(url.path().toUtf8().constData());
     image.fill(Qt::black);
 
     if (m_producer.is_blank()) {
@@ -387,12 +383,20 @@ void KThumb::getAudioThumbs(int channel, double frame, double frameLength, int a
             slotAudioThumbOver();
             return;
         }
+
         kDebug() << "reading audio thumbs from file";
+
+        int h1 = arrayWidth * m_channels;
+        int h2 = (int) frame * h1;
+        int h3;
         for (int z = (int) frame; z < (int)(frame + frameLength); z++) {
+            h2 += h1;
+            h3 = 0;
             for (int c = 0; c < m_channels; c++) {
+                h3 += arrayWidth;
                 QByteArray m_array(arrayWidth, '\x00');
                 for (int i = 0; i < arrayWidth; i++)
-                    m_array[i] = channelarray[z*arrayWidth*m_channels + c*arrayWidth + i];
+                    m_array[i] = channelarray[h2 + h3 + i];
                 storeIn[z][c] = m_array;
             }
         }