From kde-commits Wed Nov 30 23:13:10 2011 From: Jean-Baptiste Mardelle Date: Wed, 30 Nov 2011 23:13:10 +0000 To: kde-commits Subject: [kdenlive/v0.8.2] src: Cleanup thumbnails (prefer QImage over QPixmap) Message-Id: <20111130231310.CC06EA60A6 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=132269488102467 Git commit 97fd3fa63e521595da2c4e5cc867030900f9b81a by Jean-Baptiste Mardel= le. Committed on 01/12/2011 at 00:11. Pushed by mardelle into branch 'v0.8.2'. Cleanup thumbnails (prefer QImage over QPixmap) M +3 -15 src/docclipbase.cpp M +1 -10 src/docclipbase.h M +2 -2 src/kdenlivedoc.cpp M +1 -2 src/kdenlivedoc.h M +5 -6 src/kthumb.cpp M +1 -1 src/kthumb.h M +2 -2 src/monitor.cpp M +24 -22 src/projectlist.cpp M +0 -2 src/projectlist.h http://commits.kde.org/kdenlive/97fd3fa63e521595da2c4e5cc867030900f9b81a diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 2b36b8b..5d43417 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -251,17 +251,6 @@ void DocClipBase::setAudioThumbCreated(bool isDone) m_audioThumbCreated =3D isDone; } = - -void DocClipBase::setThumbnail(const QPixmap & pixmap) -{ - m_thumbnail =3D pixmap; -} - -const QPixmap & DocClipBase::thumbnail() const -{ - return m_thumbnail; -} - void DocClipBase::updateAudioThumbnail(const audioByteArray& data) { //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA**************************= *******************"; @@ -1193,12 +1182,11 @@ void DocClipBase::slotExtractImage(QList fram= es) m_thumbProd->extractImage(frames); } = -QPixmap DocClipBase::extractImage(int frame, int width, int height) +QImage DocClipBase::extractImage(int frame, int width, int height) { - if (m_thumbProd =3D=3D NULL) return QPixmap(width, height); + if (m_thumbProd =3D=3D NULL) return QImage(); QMutexLocker locker(&m_producerMutex); - QPixmap p =3D m_thumbProd->extractImage(frame, width, height); - return p; + return m_thumbProd->extractImage(frame, width, height); } = = diff --git a/src/docclipbase.h b/src/docclipbase.h index f4f31ce..64b78c1 100644 --- a/src/docclipbase.h +++ b/src/docclipbase.h @@ -161,15 +161,9 @@ Q_OBJECT public: * it uses it as part of it's own composition. */ bool referencesClip(DocClipBase * clip) const; = - /** Sets the thumbnail to be used by this clip */ - void setThumbnail(const QPixmap & pixmap); - /** Returns the thumbnail producer used by this clip */ KThumb *thumbProducer(); = - /** Returns the thumbnail used by this clip */ - const QPixmap & thumbnail() const; - /** Cache for every audio Frame with 10 Bytes */ /** format is frame -> channel ->bytes */ QMap > m_audioFrameCache; @@ -203,7 +197,7 @@ Q_OBJECT public: bool hasAudioCodec(const QString &codec) const; bool checkHash() const; void setPlaceHolder(bool place); - QPixmap extractImage(int frame, int width, int height); + QImage extractImage(int frame, int width, int height); void clearThumbProducer(); void reloadThumbProducer(); void cleanupProducers(); @@ -223,9 +217,6 @@ private: // Private attributes = /** A list of snap markers; these markers are added to a clips snap-to= points, and are displayed as necessary. */ QList < CommentedTime > m_snapMarkers; - - /** A thumbnail for this clip */ - QPixmap m_thumbnail; GenTime m_duration; = KThumb *m_thumbProd; diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index d6b41e8..c716584 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -1377,9 +1377,9 @@ QPoint KdenliveDoc::getTracksCount() const return QPoint(video, audio); } = -void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) c= onst +void KdenliveDoc::cacheImage(const QString &fileId, const QImage &img) con= st { - pix.save(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + fi= leId + ".png"); + img.save(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + fi= leId + ".png"); } = bool KdenliveDoc::checkDocumentClips(QDomNodeList infoproducers) diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index 9bd3ef5..5cab5ad 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -140,8 +140,7 @@ Q_OBJECT public: * The returned duration might differ from the actual track duration! * It is the one stored in the track's TrackInfo. */ int trackDuration(int ix); - - void cachePixmap(const QString &fileId, const QPixmap &pix) const; + void cacheImage(const QString &fileId, const QImage &img) const; void setProjectFolder(KUrl url); void setZone(int start, int end); QPoint zone() const; diff --git a/src/kthumb.cpp b/src/kthumb.cpp index c7dcfeb..3ca94c6 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -122,15 +122,14 @@ void KThumb::getThumb(int frame) emit thumbReady(frame, img); } = -QPixmap KThumb::extractImage(int frame, int width, int height) +QImage KThumb::extractImage(int frame, int width, int height) { if (m_producer =3D=3D NULL) { - QPixmap p(width, height); - p.fill(Qt::black); - return p; + QImage img(width, height, QImage::Format_ARGB32_Premultiplied); + img.fill(Qt::black); + return img; } - QImage img =3D getProducerFrame(frame, (int) (height * m_ratio + 0.5),= width, height); - return QPixmap::fromImage(img); + return getProducerFrame(frame, (int) (height * m_ratio + 0.5), width, = height); } = //static diff --git a/src/kthumb.h b/src/kthumb.h index 415f355..b85e077 100644 --- a/src/kthumb.h +++ b/src/kthumb.h @@ -63,7 +63,7 @@ Q_OBJECT public: void clearProducer(); void updateThumbUrl(const QString &hash); void extractImage(QList frames); - QPixmap extractImage(int frame, int width, int height); + QImage extractImage(int frame, int width, int height); #if KDE_IS_VERSION(4,5,0) /** @brief Request thumbnails for the frame range. */ void queryIntraThumbs(QList missingFrames); diff --git a/src/monitor.cpp b/src/monitor.cpp index 88184ff..f8c214d 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -503,9 +503,9 @@ void Monitor::mouseMoveEvent(QMouseEvent *event) data.append(list.join(";").toUtf8()); mimeData->setData("kdenlive/clip", data); drag->setMimeData(mimeData); - QPixmap pix =3D m_currentClip->thumbnail(); + /*QPixmap pix =3D m_currentClip->thumbnail(); drag->setPixmap(pix); - drag->setHotSpot(QPoint(0, 50)); + drag->setHotSpot(QPoint(0, 50));*/ drag->start(Qt::MoveAction); = //Qt::DropAction dropAction; diff --git a/src/projectlist.cpp b/src/projectlist.cpp index f29f1e7..e2e03e1 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -1754,28 +1754,30 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWid= getItem *it, bool update) return; } QPixmap pix; + QImage img; int height =3D m_listView->iconSize().height(); int swidth =3D (int)(height * m_render->frameRenderWidth() / m_re= nder->renderHeight()+ 0.5); int dwidth =3D (int)(height * m_render->dar() + 0.5); if (clip->clipType() =3D=3D AUDIO) pix =3D KIcon("audio-x-generic").pixmap(QSize(dwidth, height)); else if (clip->clipType() =3D=3D IMAGE) - pix =3D QPixmap::fromImage(KThumb::getFrame(item->referencedCl= ip()->getProducer(), 0, swidth, dwidth, height)); + img =3D KThumb::getFrame(item->referencedClip()->getProducer()= , 0, swidth, dwidth, height); else { - pix =3D item->referencedClip()->extractImage(frame, dwidth, he= ight); + img =3D item->referencedClip()->extractImage(frame, dwidth, he= ight); } = - if (!pix.isNull()) { + if (!pix.isNull() || !img.isNull()) { monitorItemEditing(false); + if (!img.isNull()) pix =3D QPixmap::fromImage(img); it->setData(0, Qt::DecorationRole, pix); monitorItemEditing(true); = - QString clipId =3D item->getClipHash(); - if (!clipId.isEmpty()) { + QString hash =3D item->getClipHash(); + if (!hash.isEmpty() && !img.isNull()) { if (!isSubItem) - m_doc->cachePixmap(clipId, pix); + m_doc->cacheImage(hash, img); else - m_doc->cachePixmap(clipId + '#' + QString::number(fram= e), pix); + m_doc->cacheImage(hash + '#' + QString::number(frame),= img); } } if (update) @@ -1951,26 +1953,26 @@ bool ProjectList::generateImageProxy() const = void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &i= mg) { - QPixmap pix =3D QPixmap::fromImage(img); - setThumbnail(clipId, pix); + ProjectItem *item =3D getItemById(clipId); + if (item && !img.isNull()) { + QPixmap pix =3D QPixmap::fromImage(img); + monitorItemEditing(false); + item->setData(0, Qt::DecorationRole, pix); + monitorItemEditing(true); + QString hash =3D item->getClipHash(); + if (!hash.isEmpty()) m_doc->cacheImage(hash, img); + } } = void ProjectList::slotReplyGetImage(const QString &clipId, const QString &= name, int width, int height) { - QPixmap pix =3D KIcon(name).pixmap(QSize(width, height)); - setThumbnail(clipId, pix); -} - -void ProjectList::setThumbnail(const QString &clipId, const QPixmap &pix) -{ + // For clips that have a generic icon (like audio clips...) ProjectItem *item =3D getItemById(clipId); + QPixmap pix =3D KIcon(name).pixmap(QSize(width, height)); if (item && !pix.isNull()) { monitorItemEditing(false); item->setData(0, Qt::DecorationRole, pix); monitorItemEditing(true); - //update(); - QString clipId =3D item->getClipHash(); - if (!clipId.isEmpty()) m_doc->cachePixmap(clipId, pix); } } = @@ -2167,10 +2169,10 @@ void ProjectList::addClipCut(const QString &id, int= in, int out, const QString d m_listView->scrollToItem(sub); m_listView->editItem(sub, 1); } - QPixmap p =3D clip->referencedClip()->extractImage(in, (int)(sub->= sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2); - sub->setData(0, Qt::DecorationRole, p); - QString clipId =3D clip->getClipHash(); - if (!clipId.isEmpty()) m_doc->cachePixmap(clipId + '#' + QString::= number(in), p); + QImage img =3D clip->referencedClip()->extractImage(in, (int)(sub-= >sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2); + sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img)); + QString hash =3D clip->getClipHash(); + if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::numbe= r(in), img); monitorItemEditing(true); } emit projectModified(); diff --git a/src/projectlist.h b/src/projectlist.h index 29fbd93..cd2086c 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -339,8 +339,6 @@ private: /** @brief Process ffmpeg output to find out process progress. */ void processLogInfo(QList items, int *duration, const Q= String &log); void monitorItemEditing(bool enable); - /** @brief Set thumbnail for a project's clip. */ - void setThumbnail(const QString &clipId, const QPixmap &pix); /** @brief Get cached thumbnail for a project's clip or create it if n= o cache. */ void getCachedThumbnail(ProjectItem *item); void getCachedThumbnail(SubProjectItem *item);