#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),
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)
{
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");
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);