ThumbnailImageProvider.cpp 2.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*****************************************************************************
 * ThumbnailImageProvider.cpp
 *****************************************************************************
 * Copyright (C) 2008-2016 VideoLAN
 *
 * Authors: Yikei Lu    <luyikei.qmltu@gmail.com>
 *          Hugo Beauzée-Luyssen <hugo@beauzee.fr>
 *
 * 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 the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

luyikei's avatar
luyikei committed
24 25
#include "ThumbnailImageProvider.h"

26 27 28
#include "Library/Library.h"
#include "Media/Clip.h"
#include "Media/Media.h"
luyikei's avatar
luyikei committed
29
#include "Main/Core.h"
30 31
#include "Tools/VlmcDebug.h"
#include "Workflow/MainWorkflow.h"
luyikei's avatar
luyikei committed
32 33

ThumbnailImageProvider::ThumbnailImageProvider()
34
    : QQuickImageProvider( QQuickImageProvider::Image )
luyikei's avatar
luyikei committed
35 36 37
{
}

38 39
QImage
ThumbnailImageProvider::requestImage( const QString& id, QSize* size, const QSize& requestedSize )
luyikei's avatar
luyikei committed
40 41 42 43 44
{
    QString tmp = id;
    tmp.replace( "%7B", "{" );
    tmp.replace( "%7D", "}" );

45 46 47 48 49 50 51 52 53 54 55 56 57
    auto infos = tmp.split( '/' );
    auto libraryUuid = infos[0];
    auto clip = Core::instance()->library()->clip( libraryUuid );
    Backend::MLT::MLTInput input( qPrintable( clip->media()->mrl() ) );
    input.setPosition( infos[0].toLongLong() );
    size->setWidth( input.width() );
    size->setHeight( input.height() );
    auto width = requestedSize.width() > 0 ? requestedSize.width() : size->width();
    auto height = requestedSize.height() > 0 ? requestedSize.height() : size->height();
    auto image = input.image( width, height );
    QImage qImg( image, width, height, QImage::Format_RGBA8888,
                 []( void* ptr ){ delete[] (uint8_t*)ptr; } );
    return qImg;
luyikei's avatar
luyikei committed
58
}