diff --git a/src/library/coverart.h b/src/library/coverart.h index d93140e66748..76c87fce43ce 100644 --- a/src/library/coverart.h +++ b/src/library/coverart.h @@ -83,11 +83,10 @@ class CoverArt : public CoverInfo { : resizedToWidth(0) { } - CoverArt(const CoverInfo& base, const QImage& img, int rtw, double devicePixelRatio) + CoverArt(const CoverInfo& base, const QImage& img, int rtw) : CoverInfo(base), image(img), - resizedToWidth(rtw), - devicePixelRatio(devicePixelRatio) { + resizedToWidth(rtw) { } // all-default memory management @@ -103,7 +102,6 @@ class CoverArt : public CoverInfo { // outside the GUI thread QImage image; int resizedToWidth; - double devicePixelRatio; }; QDebug operator<<(QDebug dbg, const CoverArt& art); diff --git a/src/library/coverartcache.cpp b/src/library/coverartcache.cpp index 730c665b4cb7..e86e69150824 100644 --- a/src/library/coverartcache.cpp +++ b/src/library/coverartcache.cpp @@ -13,9 +13,9 @@ namespace { mixxx::Logger kLogger("CoverArtCache"); -QString pixmapCacheKey(quint16 hash, int actualWidth) { +QString pixmapCacheKey(quint16 hash, int width) { return QString("CoverArtCache_%1_%2") - .arg(QString::number(hash)).arg(actualWidth); + .arg(QString::number(hash)).arg(width); } // The transformation mode when scaling images @@ -47,14 +47,13 @@ CoverArtCache::~CoverArtCache() { QPixmap CoverArtCache::requestCover(const CoverInfo& requestInfo, const QObject* pRequestor, - const int deviceIndependentWidth, - const double devicePixelRatio, + const int desiredWidth, const bool onlyCached, const bool signalWhenDone) { if (sDebug) { kLogger.debug() << "requestCover" << requestInfo << pRequestor << - deviceIndependentWidth << onlyCached << signalWhenDone; + desiredWidth << onlyCached << signalWhenDone; } if (requestInfo.type == CoverInfo::NONE) { @@ -77,11 +76,10 @@ QPixmap CoverArtCache::requestCover(const CoverInfo& requestInfo, // column). It's very important to keep the cropped covers in cache because // it avoids having to rescale+crop it ALWAYS (which brings a lot of // performance issues). - QString cacheKey = pixmapCacheKey(requestInfo.hash, deviceIndependentWidth * devicePixelRatio); + QString cacheKey = pixmapCacheKey(requestInfo.hash, desiredWidth); QPixmap pixmap; if (QPixmapCache::find(cacheKey, &pixmap)) { - pixmap.setDevicePixelRatio(devicePixelRatio); if (sDebug) { kLogger.debug() << "CoverArtCache::requestCover cover found in cache" << requestInfo << signalWhenDone; } @@ -106,7 +104,7 @@ QPixmap CoverArtCache::requestCover(const CoverInfo& requestInfo, QFutureWatcher* watcher = new QFutureWatcher(this); QFuture future = QtConcurrent::run( this, &CoverArtCache::loadCover, requestInfo, pRequestor, - deviceIndependentWidth, devicePixelRatio, signalWhenDone); + desiredWidth, signalWhenDone); connect(watcher, SIGNAL(finished()), this, SLOT(coverLoaded())); watcher->setFuture(future); return QPixmap(); @@ -114,23 +112,22 @@ QPixmap CoverArtCache::requestCover(const CoverInfo& requestInfo, //static void CoverArtCache::requestCover(const Track& track, - const QObject* pRequestor, double devicePixelRatio) { + const QObject* pRequestor) { CoverArtCache* pCache = CoverArtCache::instance(); if (pCache == nullptr) return; CoverInfo info = track.getCoverInfoWithLocation(); - pCache->requestCover(info, pRequestor, 0, devicePixelRatio, false, true); + pCache->requestCover(info, pRequestor, 0, false, true); } CoverArtCache::FutureResult CoverArtCache::loadCover( const CoverInfo& info, const QObject* pRequestor, - const int deviceIndependentWidth, - const double devicePixelRatio, + const int desiredWidth, const bool signalWhenDone) { if (sDebug) { kLogger.debug() << "loadCover" - << info << deviceIndependentWidth << signalWhenDone; + << info << desiredWidth << signalWhenDone; } QImage image = CoverArtUtils::loadCover(info); @@ -142,13 +139,13 @@ CoverArtCache::FutureResult CoverArtCache::loadCover( // Adjust the cover size according to the request or downsize the image for // efficiency. - if (!image.isNull() && deviceIndependentWidth > 0) { - image = resizeImageWidth(image, deviceIndependentWidth * devicePixelRatio); + if (!image.isNull() && desiredWidth > 0) { + image = resizeImageWidth(image, desiredWidth); } FutureResult res; res.pRequestor = pRequestor; - res.cover = CoverArt(info, image, deviceIndependentWidth, devicePixelRatio); + res.cover = CoverArt(info, image, desiredWidth); res.signalWhenDone = signalWhenDone; return res; @@ -182,10 +179,9 @@ void CoverArtCache::coverLoaded() { // we have to be sure that res.cover.hash is unique // because insert replaces the images with the same key QString cacheKey = pixmapCacheKey( - res.cover.hash, res.cover.resizedToWidth * res.cover.devicePixelRatio); + res.cover.hash, res.cover.resizedToWidth); QPixmapCache::insert(cacheKey, pixmap); } - pixmap.setDevicePixelRatio(res.cover.devicePixelRatio); m_runningRequests.remove(qMakePair(res.pRequestor, res.cover.hash)); diff --git a/src/library/coverartcache.h b/src/library/coverartcache.h index 11203c851789..89e9efd5a109 100644 --- a/src/library/coverartcache.h +++ b/src/library/coverartcache.h @@ -26,13 +26,11 @@ class CoverArtCache : public QObject, public Singleton { QPixmap requestCover(const CoverInfo& info, const QObject* pRequestor, const int desiredWidth, - const double devicePixelRatio, const bool onlyCached, const bool signalWhenDone); static void requestCover(const Track& track, - const QObject* pRequestor, - const double devicePixelRatio); + const QObject* pRequestor); // Guesses the cover art for the provided tracks by searching the tracks' // metadata and folders for image files. All I/O is done in a separate @@ -69,7 +67,6 @@ class CoverArtCache : public QObject, public Singleton { FutureResult loadCover(const CoverInfo& coverInfo, const QObject* pRequestor, const int desiredWidth, - const double devicePixelRatio, const bool emitSignals); // Guesses the cover art for each track. diff --git a/src/library/coverartdelegate.cpp b/src/library/coverartdelegate.cpp index fa294927aac1..7d032dac28d8 100644 --- a/src/library/coverartdelegate.cpp +++ b/src/library/coverartdelegate.cpp @@ -110,8 +110,9 @@ void CoverArtDelegate::paintItem(QPainter *painter, double scaleFactor = getDevicePixelRatioF(dynamic_cast(parent())); // We listen for updates via slotCoverFound above and signal to // BaseSqlTableModel when a row's cover is ready. - QPixmap pixmap = pCache->requestCover(info, this, option.rect.width(), - scaleFactor, m_bOnlyCachedCover, true); + QPixmap pixmap = pCache->requestCover(info, this, option.rect.width() * scaleFactor, + m_bOnlyCachedCover, true); + pixmap.setDevicePixelRatio(scaleFactor); if (!pixmap.isNull()) { int width = math_min(pixmap.width(), option.rect.width()) * scaleFactor; int height = math_min(pixmap.height(), option.rect.height()) * scaleFactor; diff --git a/src/library/dlgcoverartfullsize.cpp b/src/library/dlgcoverartfullsize.cpp index afa39f051936..f0143dc35a31 100644 --- a/src/library/dlgcoverartfullsize.cpp +++ b/src/library/dlgcoverartfullsize.cpp @@ -103,7 +103,7 @@ void DlgCoverArtFullSize::slotLoadTrack(TrackPointer pTrack) { void DlgCoverArtFullSize::slotTrackCoverArtUpdated() { if (m_pLoadedTrack != nullptr) { - CoverArtCache::requestCover(*m_pLoadedTrack, this, getDevicePixelRatioF(this)); + CoverArtCache::requestCover(*m_pLoadedTrack, this); } } @@ -134,6 +134,7 @@ void DlgCoverArtFullSize::slotCoverFound(const QObject* pRequestor, } QPixmap resizedPixmap = m_pixmap.scaled(size() * getDevicePixelRatioF(this), Qt::KeepAspectRatio, Qt::SmoothTransformation); + resizedPixmap.setDevicePixelRatio(getDevicePixelRatioF(this)); coverArt->setPixmap(resizedPixmap); // center the window setGeometry(QStyle::alignedRect( @@ -184,6 +185,7 @@ void DlgCoverArtFullSize::resizeEvent(QResizeEvent* event) { // qDebug() << "DlgCoverArtFullSize::resizeEvent" << size(); QPixmap resizedPixmap = m_pixmap.scaled(size() * getDevicePixelRatioF(this), Qt::KeepAspectRatio, Qt::SmoothTransformation); + resizedPixmap.setDevicePixelRatio(getDevicePixelRatioF(this)); coverArt->setPixmap(resizedPixmap); } diff --git a/src/library/dlgtrackinfo.cpp b/src/library/dlgtrackinfo.cpp index 6faaba967c22..b8cd18079594 100644 --- a/src/library/dlgtrackinfo.cpp +++ b/src/library/dlgtrackinfo.cpp @@ -180,7 +180,7 @@ void DlgTrackInfo::populateFields(const Track& track) { m_pWCoverArtLabel->setCoverArt(m_loadedCoverInfo, QPixmap()); CoverArtCache* pCache = CoverArtCache::instance(); if (pCache != NULL) { - pCache->requestCover(m_loadedCoverInfo, this, 0, getDevicePixelRatioF(this), false, true); + pCache->requestCover(m_loadedCoverInfo, this, 0, false, true); } } @@ -254,7 +254,7 @@ void DlgTrackInfo::slotCoverInfoSelected(const CoverInfoRelative& coverInfo) { m_loadedCoverInfo = CoverInfo(coverInfo, m_pLoadedTrack->getLocation()); CoverArtCache* pCache = CoverArtCache::instance(); if (pCache) { - pCache->requestCover(m_loadedCoverInfo, this, 0, getDevicePixelRatioF(this), false, true); + pCache->requestCover(m_loadedCoverInfo, this, 0, false, true); } } diff --git a/src/widget/wcoverart.cpp b/src/widget/wcoverart.cpp index 0444612fa6f9..3e4b490a3a3c 100644 --- a/src/widget/wcoverart.cpp +++ b/src/widget/wcoverart.cpp @@ -143,7 +143,7 @@ void WCoverArt::slotReset() { void WCoverArt::slotTrackCoverArtUpdated() { if (m_loadedTrack) { - CoverArtCache::requestCover(*m_loadedTrack, this, getDevicePixelRatioF(this)); + CoverArtCache::requestCover(*m_loadedTrack, this); } } @@ -191,7 +191,11 @@ QPixmap WCoverArt::scaledCoverArt(const QPixmap& normal) { if (normal.isNull()) { return QPixmap(); } - return normal.scaled(size() * getDevicePixelRatioF(this), Qt::KeepAspectRatio, Qt::SmoothTransformation); + QPixmap scaled; + scaled = normal.scaled(size() * getDevicePixelRatioF(this), + Qt::KeepAspectRatio, Qt::SmoothTransformation); + scaled.setDevicePixelRatio(getDevicePixelRatioF(this)); + return scaled; } void WCoverArt::paintEvent(QPaintEvent* /*unused*/) { diff --git a/src/widget/wcoverartlabel.cpp b/src/widget/wcoverartlabel.cpp index 8636276abad3..0c37c12aef2a 100644 --- a/src/widget/wcoverartlabel.cpp +++ b/src/widget/wcoverartlabel.cpp @@ -40,15 +40,15 @@ void WCoverArtLabel::setCoverArt(const CoverInfo& coverInfo, QPixmap px) { qDebug() << "WCoverArtLabel::setCoverArt" << coverInfo << px.size(); - m_loadedCover = px; + m_loadedCover = px.scaled(s_labelDisplaySize * getDevicePixelRatioF(this), + Qt::KeepAspectRatio, Qt::SmoothTransformation); + m_loadedCover.setDevicePixelRatio(getDevicePixelRatioF(this)); m_pCoverMenu->setCoverArt(coverInfo); - - if (px.isNull()) { + if (m_loadedCover.isNull()) { setPixmap(m_defaultCover); } else { - setPixmap(px.scaled(s_labelDisplaySize * getDevicePixelRatioF(this), Qt::KeepAspectRatio, - Qt::SmoothTransformation)); + setPixmap(m_loadedCover); } QSize frameSize = pixmap()->size() / getDevicePixelRatioF(this); diff --git a/src/widget/wspinny.cpp b/src/widget/wspinny.cpp index cf70cdbb9a3a..c9d23f38495b 100644 --- a/src/widget/wspinny.cpp +++ b/src/widget/wspinny.cpp @@ -263,7 +263,7 @@ void WSpinny::slotLoadingTrack(TrackPointer pNewTrack, TrackPointer pOldTrack) { void WSpinny::slotTrackCoverArtUpdated() { if (m_loadedTrack) { - CoverArtCache::requestCover(*m_loadedTrack, this, getDevicePixelRatioF(this)); + CoverArtCache::requestCover(*m_loadedTrack, this); } } @@ -406,7 +406,10 @@ QPixmap WSpinny::scaledCoverArt(const QPixmap& normal) { if (normal.isNull()) { return QPixmap(); } - return normal.scaled(size() * getDevicePixelRatioF(this), Qt::KeepAspectRatio, Qt::SmoothTransformation); + QPixmap scaled = normal.scaled(size() * getDevicePixelRatioF(this), + Qt::KeepAspectRatio, Qt::SmoothTransformation); + scaled.setDevicePixelRatio(getDevicePixelRatioF(this)); + return scaled; } void WSpinny::resizeEvent(QResizeEvent* /*unused*/) {