]> git.sesse.net Git - kdenlive/blobdiff - src/kthumb.cpp
Make 2 pass option available to custom profiles
[kdenlive] / src / kthumb.cpp
index 413f7bf968e89356df35102ecc83cf9f410dbf95..809036689a300f4a5de2aef03ab4af4c2dff2950 100644 (file)
@@ -38,7 +38,7 @@
 #include <QImage>
 #include <QApplication>
 #include <QtConcurrentRun>
-
+#include <QVarLengthArray>
 
 KThumb::KThumb(ClipManager *clipManager, KUrl url, const QString &id, const QString &hash, QObject * parent, const char */*name*/) :
     QObject(parent),
@@ -193,6 +193,32 @@ QImage KThumb::getFrame(Mlt::Producer *producer, int framepos, int width, int he
     delete frame;
     return p;
 }
+
+
+//static
+uint KThumb::imageVariance(QImage image )
+{
+    uint delta=0;
+    uint avg=0;
+    uint bytes=image.numBytes();
+    uint STEPS=bytes/2;
+    QVarLengthArray<uchar> pivot(STEPS);
+    uchar *bits=image.bits();
+    // First pass: get pivots and taking average
+    for( uint i=0; i<STEPS ; i++ ){
+        pivot[i]=bits[i*(bytes/STEPS)];
+        avg+=pivot[i];
+    }
+    avg=avg/STEPS;
+    // Second Step: calculate delta (average?)
+    for (uint i=0; i<STEPS; i++)
+    {
+        int curdelta=abs(int(avg-pivot[i]));
+        delta+=curdelta;
+    }
+    return delta/STEPS;
+}
+
 /*
 void KThumb::getImage(KUrl url, int frame, int width, int height)
 {
@@ -340,14 +366,18 @@ void KThumb::getAudioThumbs(int channel, double frame, double frameLength, int a
 
 void KThumb::slotCreateAudioThumbs()
 {
+    Mlt::Profile prof((char*) KdenliveSettings::current_profile().toUtf8().data());
+    Mlt::Producer m_producer(prof, m_url.path().toUtf8().data());
+    if (!m_producer.is_valid()) {
+        kDebug() << "++++++++  INVALID CLIP: " << m_url.path();
+        return;
+    }
     if (!m_audioThumbFile.open(QIODevice::WriteOnly)) {
         kDebug() << "++++++++  ERROR WRITING TO FILE: " << m_audioThumbFile.fileName();
         kDebug() << "++++++++  DISABLING AUDIO THUMBS";
         KdenliveSettings::setAudiothumbnails(false);
         return;
     }
-    Mlt::Profile prof((char*) KdenliveSettings::current_profile().toUtf8().data());
-    Mlt::Producer m_producer(prof, m_url.path().toUtf8().data());
 
     if (KdenliveSettings::normaliseaudiothumbs()) {
         Mlt::Filter m_convert(prof, "volume");
@@ -357,7 +387,7 @@ void KThumb::slotCreateAudioThumbs()
 
     int last_val = 0;
     int val = 0;
-    kDebug() << "for " << m_frame << " " << m_frameLength << " " << m_producer.is_valid();
+    //kDebug() << "for " << m_frame << " " << m_frameLength << " " << m_producer.is_valid();
     for (int z = (int) m_frame; z < (int)(m_frame + m_frameLength) && m_producer.is_valid(); z++) {
         if (m_stopAudioThumbs) break;
         val = (int)((z - m_frame) / (m_frame + m_frameLength) * 100.0);