Boston, MA 02110-1301, USA.
***************************************************************************/
+#include "westleypreview.h"
+
#include <qfile.h>
-#include <qpixmap.h>
#include <qimage.h>
#include <QtCore/QVarLengthArray>
#include <unistd.h>
-#include "westleypreview.h"
#define DBG_AREA
//#include "config.h"
-extern "C" {
+extern "C"
+{
KDE_EXPORT ThumbCreator *new_creator() {
return new WestleyPreview;
}
}
WestleyPreview::WestleyPreview()
- : m_rand(0), m_inigoprocess(0) {
+ : m_rand(0), m_inigoprocess(0)
+{
}
-WestleyPreview::~WestleyPreview() {
+WestleyPreview::~WestleyPreview()
+{
delete m_rand;
delete m_inigoprocess;
}
-bool WestleyPreview::startAndWaitProcess(const QStringList &args) {
+bool WestleyPreview::startAndWaitProcess(const QStringList &args)
+{
kDebug(DBG_AREA) << "westleypreview: starting process with args: " << args << endl;
m_inigoprocess->start(args.join(" "));
if (! m_inigoprocess->waitForStarted()) {
return true;
}
-bool WestleyPreview::create(const QString &path, int width, int height, QImage &img) {
+bool WestleyPreview::create(const QString &path, int width, int /*height*/, QImage &img)
+{
QFileInfo fi(path);
- /*if (fi.suffix().trimmed() != "westley" && fi.suffix().trimmed() != "kdenlive")
- {
- kDebug(DBG_AREA) << "westleypreview: matched extension " << fi.suffix().prepend('.') << "; exiting.\n";
- return false;
- }*/
playerBin = KStandardDirs::findExe("inigo");
if (playerBin.isEmpty()) {
kDebug(DBG_AREA) << "westleypreview: inigo not found, exiting.\n";
KUrl furl(path);
kDebug(DBG_AREA) << "videopreview: url=" << furl << "; local:" << furl.isLocalFile() << endl;
fileinfo.towidth = width;
- fileinfo.toheight = height;
- QPixmap pix;
+ fileinfo.toheight = width * 3 / 4;
+ QImage pix;
// if(furl.isLocalFile())
// {
QStringList args;
fileinfo.seconds = 250;
fileinfo.fps = 25;
- //kDebug(DBG_AREA) << "videopreview: find length=" << fileinfo.seconds << ", fps=" << fileinfo.fps << endl;
-
const int LASTTRY = 3;
for (int i = 0; i <= LASTTRY; i++) {
pix = getFrame(path);
if (!pix.isNull()) {
- uint variance = imageVariance(pix.toImage()/*.bits(),( (width+ 7) & ~0x7), width, height, 1 */);
+ uint variance = imageVariance(pix);
kDebug(DBG_AREA) << "videopreview: " << QFileInfo(path).fileName() << " frame variance: " << variance << "; " <<
((variance <= 40 && (i != LASTTRY - 1)) ? "!!!DROPPING!!!" : "GOOD :-)") << endl;
if (variance > 40 || i == LASTTRY - 1) break;
if (pix.isNull()) {
return false;
}
- img = pix.toImage();
+
+ if (pix.depth() != 32)
+ img = pix.convertToFormat(QImage::Format_RGB32);
+ else img = pix;
return true;
}
-QPixmap WestleyPreview::getFrame(const QString &path) {
+QImage WestleyPreview::getFrame(const QString &path)
+{
QStringList args;
-#define START ((fileinfo.seconds*15)/100)
-#define END ((fileinfo.seconds*70)/100)
+ const int START = 25;
+ const int RANGE = 500;
args.clear();
args << playerBin << "\"" + path + "\"";
- if (fileinfo.towidth > fileinfo.toheight) fileinfo.toheight = -2;
- else fileinfo.towidth = -2;
-// switch( flags ){
-// case random
-// }
- unsigned long start = (unsigned long)(START + (m_rand->getDouble() * (END - START)));
+
+ unsigned long start = (unsigned long)(START + (m_rand->getDouble() * RANGE));
args << QString("in=%1").arg(start) << QString("out=%1").arg(start) << "-consumer";
KTemporaryFile temp;
temp.setSuffix(".png");
temp.open();
args << QString("avformat:%1").arg(temp.fileName()) << "vframes=1" << "f=rawvideo" << "vcodec=png" << QString("s=%1x%2").arg(fileinfo.towidth).arg(fileinfo.toheight);
- if (! startAndWaitProcess(args)) return NULL;
- QPixmap retpix(temp.fileName());
+ if (! startAndWaitProcess(args)) return QImage();
+ QImage retpix(temp.fileName());
temp.close();
return retpix;
}
-uint WestleyPreview::imageVariance(QImage image) {
+uint WestleyPreview::imageVariance(QImage image)
+{
uint delta = 0;
uint avg = 0;
uint bytes = image.numBytes();
return delta / STEPS;
}
-ThumbCreator::Flags WestleyPreview::flags() const {
- return DrawFrame;
+ThumbCreator::Flags WestleyPreview::flags() const
+{
+ return None;
}
+
#include "westleypreview.moc"