From b1948f6a8d43f71243c61d4cdcd0240af9b0f676 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Tue, 15 Mar 2011 15:26:59 +0000 Subject: [PATCH] If fetched thumbnail for new clip is not interesting, try to fetch another one (seek 100 frames and get new thumb): http://kdenlive.org/mantis/view.php?id=2062 svn path=/trunk/kdenlive/; revision=5495 --- src/kthumb.cpp | 28 +++++++++++++++++++++++++++- src/kthumb.h | 4 ++++ src/renderer.cpp | 37 +++++++++++++++++++++++++------------ 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/kthumb.cpp b/src/kthumb.cpp index 90917800..80903668 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -38,7 +38,7 @@ #include #include #include - +#include 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 pivot(STEPS); + uchar *bits=image.bits(); + // First pass: get pivots and taking average + for( uint i=0; iget_image(format, frame_width, frame_height, 0); - QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied); QPixmap pix; - - if (!image.isNull()) { - if (frame_width > (2 * width)) { - // there was a scaling problem, do it manually - QImage scaled = image.scaled(width, imageHeight); - pix = QPixmap::fromImage(scaled.rgbSwapped()); - } else pix = QPixmap::fromImage(image.rgbSwapped()); - } else - pix.fill(Qt::black); - + do { + variance = 100; + uint8_t *data = frame->get_image(format, frame_width, frame_height, 0); + QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied); + + if (!image.isNull()) { + if (frame_width > (2 * width)) { + // there was a scaling problem, do it manually + QImage scaled = image.scaled(width, imageHeight); + pix = QPixmap::fromImage(scaled.rgbSwapped()); + } else pix = QPixmap::fromImage(image.rgbSwapped()); + variance = KThumb::imageVariance(image); + } else + pix.fill(Qt::black); + + if (frameNumber == 0 && variance < 6) { + // Thumbnail is not interesting (for example all black, seek to fetch better thumb + frameNumber = 100; + producer->seek(frameNumber); + delete frame; + frame = producer->get_frame(); + variance = -1; + } + } while (variance == -1); emit replyGetImage(clipId, pix); } else if (frame->get_int("test_audio") == 0) { -- 2.39.2