[vlmc-devel] Media: Take snapshot
Yikai Lu
git at videolan.org
Sun Jul 24 11:54:46 CEST 2016
vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Sun Jul 24 18:12:18 2016 +0900| [79a4771767699f698a27736123f6aedf96b0845f] | committer: Yikai Lu
Media: Take snapshot
> https://code.videolan.org/videolan/vlmc/commit/79a4771767699f698a27736123f6aedf96b0845f
---
src/Media/Media.cpp | 19 ++++++++++++++-----
src/Media/Media.h | 1 -
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/Media/Media.cpp b/src/Media/Media.cpp
index a1c9aa9..0c1547a 100644
--- a/src/Media/Media.cpp
+++ b/src/Media/Media.cpp
@@ -62,9 +62,6 @@ Media::Media(const QString &path )
: m_input( nullptr )
, m_fileInfo( nullptr )
, m_baseClip( nullptr )
-#ifdef WITH_GUI
- , m_snapshotImage( nullptr )
-#endif
{
setFilePath( path );
}
@@ -144,7 +141,19 @@ Media::setFilePath( const QString &filePath )
QPixmap&
Media::snapshot()
{
- Media::defaultSnapshot = new QPixmap( ":/images/vlmc" );
- return *Media::defaultSnapshot;
+ if ( Media::defaultSnapshot == nullptr )
+ Media::defaultSnapshot = new QPixmap( ":/images/vlmc" );
+
+ if ( m_snapshot.isNull() == true ) {
+ int height = 200;
+ int width = height * m_input->aspectRatio();
+ m_input->setPosition( m_input->length() / 3 );
+ QImage img( m_input->image( width, height ), width, height,
+ QImage::Format_RGBA8888, []( void* buf ){ delete[] (uchar*) buf; } );
+ m_input->setPosition( 0 );
+ m_snapshot.convertFromImage( img );
+ }
+
+ return m_snapshot.isNull() ? *Media::defaultSnapshot : m_snapshot;
}
#endif
diff --git a/src/Media/Media.h b/src/Media/Media.h
index 4156c25..16b7f1e 100644
--- a/src/Media/Media.h
+++ b/src/Media/Media.h
@@ -123,7 +123,6 @@ protected:
#ifdef WITH_GUI
static QPixmap* defaultSnapshot;
QPixmap m_snapshot;
- QImage* m_snapshotImage;
#endif
signals:
More information about the Vlmc-devel
mailing list