SVN commit 950517 by gulino: More refactoring M +1 -1 CMakeLists.txt M +3 -0 constants.h M +2 -2 mplayerthumbscfg.h M +7 -3 mplayervideobackend.cpp M +4 -1 mplayervideobackend.h M +19 -0 previewingfile.cpp M +8 -1 previewingfile.h A thumbnail.cpp [License: LGPL (v2)] A thumbnail.h [License: LGPL (v2)] A thumbnailsmap.cpp [License: LGPL (v2)] A thumbnailsmap.h [License: LGPL (v2)] M +5 -1 videobackendiface.h M +14 -57 videopreview.cpp M +2 -2 videopreview.h --- trunk/kdereview/mplayerthumbs/src/CMakeLists.txt #950516:950517 @@ -3,7 +3,7 @@ ########### next target ############### -set(videopreview_PART_SRCS videopreview.cpp mplayervideobackend.cpp videobackendiface.cpp previewingfile.cpp) +set(videopreview_PART_SRCS videopreview.cpp mplayervideobackend.cpp videobackendiface.cpp previewingfile.cpp thumbnail.cpp thumbnailsmap.cpp) kde4_add_kcfg_files(videopreview_PART_SRCS mplayerthumbs.kcfgc) --- trunk/kdereview/mplayerthumbs/src/constants.h #950516:950517 @@ -1,4 +1,7 @@ /* + Copyright (C) 2006-2009 + by Marco Gulino + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. --- trunk/kdereview/mplayerthumbs/src/mplayerthumbscfg.h #950516:950517 @@ -1,6 +1,6 @@ /*************************************************************************** - Copyright (C) 2006-2008 - by Marco Gulino + Copyright (C) 2006-2009 + by Marco Gulino This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by --- trunk/kdereview/mplayerthumbs/src/mplayervideobackend.cpp #950516:950517 @@ -1,4 +1,7 @@ /* + Copyright (C) 2006-2009 + by Marco Gulino + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. @@ -25,6 +28,7 @@ #include #include #include "previewingfile.h" +#include "thumbnail.h" MPlayerVideoBackend::MPlayerVideoBackend(PreviewingFile *previewingfile, MPlayerThumbsCfg* cfg) : VideoBackendIFace(previewingfile, cfg) @@ -73,7 +77,7 @@ -QPixmap MPlayerVideoBackend::getVideoFrame(int flags) { +Thumbnail *MPlayerVideoBackend::preview(int flags) { QStringList args; kDebug(DBG_AREA) << "videopreview: using flags " << flags << endl; #define START ((previewingFile->getSecondsLength()*15)/100) @@ -118,8 +122,8 @@ QString lastframe=QDir(tmpDirPath ).entryList( QStringList("*.jpg") ).last(); kDebug(DBG_AREA) << "videopreview: LastFrame==" << lastframe << endl; - QPixmap retpix(tmpDirPath.append( lastframe )); - return retpix; + QPixmap *retpix = new QPixmap(tmpDirPath.append( lastframe )); + return new Thumbnail(retpix, previewingFile); } --- trunk/kdereview/mplayerthumbs/src/mplayervideobackend.h #950516:950517 @@ -1,4 +1,7 @@ /* + Copyright (C) 2006-2009 + by Marco Gulino + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. @@ -27,7 +30,7 @@ public: MPlayerVideoBackend(PreviewingFile *previewingFile, MPlayerThumbsCfg* cfg); virtual ~MPlayerVideoBackend(); - virtual QPixmap getVideoFrame(int flags); + virtual Thumbnail* preview(int flags); virtual bool playerCannotPreview(); virtual bool readStreamInformation(); --- trunk/kdereview/mplayerthumbs/src/previewingfile.cpp #950516:950517 @@ -1,4 +1,7 @@ /* + Copyright (C) 2006-2009 + by Marco Gulino + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. @@ -18,6 +21,9 @@ #include "constants.h" #include #include +#include "thumbnail.h" +#include "thumbnailsmap.h" +#include "videobackendiface.h" PreviewingFile::PreviewingFile(const QString& filePath, uint scalingWidth, uint scalingHeight, QObject* parent) : QObject(parent), fileInfo(filePath) { @@ -42,6 +48,17 @@ this->secondsLength=secondsLength; } +Thumbnail* PreviewingFile::getPreview(VideoBackendIFace* videoBackend, uint minVariance, unsigned int maxTries) { + ThumbnailsMap thumbnailsMap; + Preview::frameflags flags; + while(thumbnailsMap.hasAGoodImageOrSurrenders(minVariance, maxTries)) { + flags=(thumbnailsMap.size()>=maxTries) ? Preview::framestart : Preview::framerandom; + thumbnailsMap.addThumbnail(videoBackend->preview(flags) ); + } + return thumbnailsMap.getBestThumbnail(); +} + + unsigned int PreviewingFile::getFPS() { return this->fps; } @@ -66,6 +83,8 @@ return this->scalingWidth; } +#include "previewingfile.moc" + --- trunk/kdereview/mplayerthumbs/src/previewingfile.h #950516:950517 @@ -1,4 +1,7 @@ /* + Copyright (C) 2006-2009 + by Marco Gulino + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. @@ -18,8 +21,11 @@ #define PREVIEWINGFILE_H #include #include +class Thumbnail; +class VideoBackendIFace; class PreviewingFile : public QObject { +Q_OBJECT public: PreviewingFile(const QString &filePath, uint scalingWidth, uint scalingHeight, QObject *parent = 0); bool isBlacklisted(const QStringList &blacklistedExtensions); @@ -30,13 +36,14 @@ bool isWide(); uint getScalingWidth(); uint getScalingHeight(); + Thumbnail *getPreview(VideoBackendIFace *videoBackend, uint minVariance, uint maxTries); + private: QFileInfo fileInfo; uint fps; uint secondsLength; uint scalingWidth; uint scalingHeight; - }; #endif // PREVIEWINGFILE_H --- trunk/kdereview/mplayerthumbs/src/videobackendiface.h #950516:950517 @@ -1,4 +1,7 @@ /* + Copyright (C) 2006-2009 + by Marco Gulino + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. @@ -22,11 +25,12 @@ class PreviewingFile; class MPlayerThumbsCfg; +class Thumbnail; class VideoBackendIFace { public: VideoBackendIFace(PreviewingFile *previewingFile, MPlayerThumbsCfg* cfg); - virtual QPixmap getVideoFrame(int flags) = 0; + virtual Thumbnail *preview(int flags) = 0; bool cannotPreview(); virtual bool readStreamInformation() = 0; virtual ~VideoBackendIFace(); --- trunk/kdereview/mplayerthumbs/src/videopreview.cpp #950516:950517 @@ -1,6 +1,6 @@ /*************************************************************************** - Copyright (C) 2006-2008 - by Marco Gulino + Copyright (C) 2006-2009 + by Marco Gulino This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ #include "mplayervideobackend.h" #include "mplayerthumbs.h" #include "previewingfile.h" +#include "thumbnail.h" extern "C" { @@ -64,52 +65,35 @@ delete videoBackend; return false; } + + Thumbnail *thumbnail=previewingFile->getPreview(videoBackend, 40, 3); + if(!thumbnail || ! thumbnail->pixmapIsValid() ) return false; - QPixmap pix; - int flags=Preview::framerandom; - #define LASTTRY 3 - for(int i=0; i<=LASTTRY; i++) - { - kDebug(DBG_AREA) << "videopreview: try " << i << endl; - flags=((igetVideoFrame(flags); - if(!pix.isNull()) { - uint variance=imageVariance(pix.toImage()/*.bits(),( (width+ 7) & ~0x7), width, height, 1 */); - kDebug(DBG_AREA) << "videopreview: " << previewingFile->getFilePath() << " frame variance: " << variance << "; " << - ((variance<=40 && ( i!=LASTTRY-1))? "!!!DROPPING!!!" : "GOOD :-)" ) << endl; - if(variance>40 || i==LASTTRY-1 ) break; - } - } + delete videoBackend; - delete videoBackend; - - if(pix.isNull() ) - return false; - /** From videocreator.cpp - xine_artsplugin + /* From videocreator.cpp - xine_artsplugin Copyright (C) 2002 Simon MacMullen Copyright (C) 2003 Ewald Snel * */ -// QPixmap pix( createThumbnail( &frame, width, height ) ); -//#ifdef STRIPS_SUPPORT + QPixmap *pix=thumbnail->getPixmap(); if(cfg->createStrips() ) { - QPainter painter( &pix ); + QPainter painter( pix ); QPixmap sprocket; kDebug(DBG_AREA) << "videopreview: using strip image sprocket: " << KStandardDirs::locate( "data", "videothumbnail/sprocket-small.png" ) << endl; - if (pix.height() < 60) + if (pix->height() < 60) sprocket = QPixmap(KStandardDirs::locate( "data", "videothumbnail/sprocket-small.png" )); - else if (pix.height() < 90) + else if (pix->height() < 90) sprocket = QPixmap(KStandardDirs::locate( "data", "videothumbnail/sprocket-medium.png" )); else sprocket = QPixmap(KStandardDirs::locate( "data", "videothumbnail/sprocket-large.png" )); - for (int y = 0; y < pix.height() + sprocket.height(); y += sprocket.height()) { + for (int y = 0; y < pix->height() + sprocket.height(); y += sprocket.height()) { painter.drawPixmap( 0, y, sprocket ); } } // End of xine-artsplugin code -//#endif - img = pix.toImage(); + img = pix->toImage(); return true; } @@ -119,32 +103,5 @@ return (Flags)(DrawFrame); } - -uint VideoPreview::imageVariance(QImage image ) -{ - uint delta=0; - uint avg=0; - uint bytes=image.numBytes(); - uint STEPS=bytes/2; - QVarLengthArray pivot(STEPS); - kDebug(DBG_AREA) << "Using " << STEPS << " steps\n"; - uchar *bits=image.bits(); - // First pass: get pivots and taking average - for( uint i=0; i + Copyright (C) 2006-2009 + by Marco Gulino This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by