]> git.sesse.net Git - kdenlive/blob - src/kthumb.h
Rewrite generation of timeline thumbnails when zooming at frame level, using separate...
[kdenlive] / src / kthumb.h
1 /***************************************************************************
2                          kthumb.h  -  description
3                             -------------------
4    begin                : Fri Nov 22 2002
5    copyright            : (C) 2002 by Jason Wood
6    email                : jasonwood@blueyonder.co.uk
7 ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #ifndef KTHUMB_H
19 #define KTHUMB_H
20
21 #include <QPixmap>
22 #include <QFile>
23 #include <QDomElement>
24 #include <QFuture>
25
26 #include <KUrl>
27 #include <kdeversion.h>
28
29 #include <mlt++/Mlt.h>
30
31
32 /**KRender encapsulates the client side of the interface to a renderer.
33 From Kdenlive's point of view, you treat the KRender object as the
34 renderer, and simply use it as if it was local. Calls are asyncrhonous -
35 you send a call out, and then receive the return value through the
36 relevant signal that get's emitted once the call completes.
37   *@author Jason Wood
38   */
39
40
41 namespace Mlt
42 {
43 class Miracle;
44 class Consumer;
45 class Producer;
46 class Frame;
47 class Profile;
48 };
49
50 class ClipManager;
51
52 class KThumb: public QObject
53 {
54 Q_OBJECT public:
55
56
57     KThumb(ClipManager *clipManager, KUrl url, const QString &id, const QString &hash, QObject * parent = 0, const char *name = 0);
58     ~KThumb();
59     void setProducer(Mlt::Producer *producer);
60     void askForAudioThumbs(const QString &id);
61     bool hasProducer() const;
62     void clearProducer();
63     void updateThumbUrl(const QString &hash);
64     void extractImage(int frame, int frame2);
65     QPixmap extractImage(int frame, int width, int height);
66 #if KDE_IS_VERSION(4,5,0)
67     /** @brief Request thumbnails for the frame range. */
68     void queryIntraThumbs(int start, int end);
69     /** @brief Query cached thumbnail. */
70     QImage findCachedThumb(const QString path);
71 #endif
72
73 public slots:
74     void updateClipUrl(KUrl url, const QString &hash);
75     static QPixmap getImage(KUrl url, int width, int height);
76 //    static QPixmap getImage(QDomElement xml, int frame, int width, int height);
77     /* void getImage(KUrl url, int frame, int width, int height);
78      void getThumbs(KUrl url, int startframe, int endframe, int width, int height);*/
79     void stopAudioThumbs();
80     void removeAudioThumb();
81     void getAudioThumbs(int channel, double frame, double frameLength, int arrayWidth);
82     static QPixmap getImage(KUrl url, int frame, int width, int height);
83     static QImage getFrame(Mlt::Producer *producer, int framepos, int width, int height);
84     /** @brief Calculates image variance, useful to know if a thumbnail is interesting. 
85      *  @return an integer between 0 and 100. 0 means no variance, eg. black image while bigger values mean contrasted image
86      * */
87     static uint imageVariance(QImage image);
88
89 private slots:
90     void slotAudioThumbOver();
91     void slotCreateAudioThumbs();
92 #if KDE_IS_VERSION(4,5,0)
93     /** @brief Fetch all requested frames. */ 
94     void slotGetIntraThumbs();
95 #endif
96
97 private:
98     QFuture<void> m_audioThumbProducer;
99     KUrl m_url;
100     QString m_thumbFile;
101     double m_dar;
102     Mlt::Producer *m_producer;
103     ClipManager *m_clipManager;
104     QString m_id;
105     QList <int> m_requestedThumbs;
106     /** @brief Controls the thumbnails process. */
107     QFuture<void> m_future;
108     /** @brief Controls the intra frames thumbnails process (cached thumbnails). */
109     QFuture<void> m_intra;
110     QFile m_audioThumbFile;
111     bool m_stopAudioThumbs;
112     double m_frame;
113     double m_frameLength;
114     int m_frequency;
115     int m_channels;
116     int m_arrayWidth;
117     /** @brief List of frame numbers from which we want to extract thumbnails. */
118     QList <int> m_intraFramesQueue;
119     void doGetThumbs();
120
121 signals:
122     void thumbReady(int, QImage);
123     void mainThumbReady(const QString &, QPixmap);
124     void audioThumbReady(QMap <int, QMap <int, QByteArray> >);
125     /** @brief We have finished caching all requested thumbs. */
126     void thumbsCached();
127 };
128
129 #endif