| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2007-06-05 |
| 7 |
* Description : Thumbnail loading - private containers |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> |
| 10 |
* SPDX-FileCopyrightText: 2005-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 11 |
* SPDX-FileCopyrightText: 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com> |
| 12 |
* |
| 13 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 14 |
* |
| 15 |
* ============================================================ */ |
| 16 |
|
| 17 |
#include "thumbnailloadthread_p.h" |
| 18 |
|
| 19 |
namespace Digikam |
| 20 |
{ |
| 21 |
|
| 22 |
bool ThumbnailLoadThread::Private::hasHighlightingBorder() const |
| 23 |
{ |
| 24 |
return (highlight && (size >= 10)); |
| 25 |
} |
| 26 |
|
| 27 |
int ThumbnailLoadThread::Private::pixmapSizeForThumbnailSize(int thumbnailSize) const |
| 28 |
{ |
| 29 |
if (hasHighlightingBorder()) |
| 30 |
{ |
| 31 |
return (thumbnailSize + 2); |
| 32 |
} |
| 33 |
|
| 34 |
return thumbnailSize; |
| 35 |
} |
| 36 |
|
| 37 |
int ThumbnailLoadThread::Private::thumbnailSizeForPixmapSize(int pixmapSize) const |
| 38 |
{ |
| 39 |
// Bug #206666: Do not cut off one-pixel line for highlighting border |
| 40 |
|
| 41 |
if (hasHighlightingBorder()) |
| 42 |
{ |
| 43 |
return (pixmapSize - 2); |
| 44 |
} |
| 45 |
|
| 46 |
return pixmapSize; |
| 47 |
} |
| 48 |
|
| 49 |
bool ThumbnailLoadThread::Private::checkDescription(const LoadingDescription& description) |
| 50 |
{ |
| 51 |
QString cacheKey = description.cacheKey(); |
| 52 |
|
| 53 |
{ |
| 54 |
LoadingCache* const cache = LoadingCache::cache(); |
| 55 |
LoadingCache::CacheLock lock(cache); |
| 56 |
|
| 57 |
if (cache->hasThumbnailPixmap(cacheKey)) |
| 58 |
{ |
| 59 |
return false; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
{ |
| 64 |
QMutexLocker lock(&resultsMutex); |
| 65 |
|
| 66 |
if (collectedResults.contains(cacheKey)) |
| 67 |
{ |
| 68 |
return false; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
return true; |
| 73 |
} |
| 74 |
|
| 75 |
QList<LoadingDescription> ThumbnailLoadThread::Private::makeDescriptions(const QList<ThumbnailIdentifier>& identifiers, int size) |
| 76 |
{ |
| 77 |
QList<LoadingDescription> descriptions; |
| 78 |
{ |
| 79 |
LoadingDescription description = createLoadingDescription(ThumbnailIdentifier(), size, false); |
| 80 |
|
| 81 |
for (const ThumbnailIdentifier& identifier : std::as_const(identifiers)) |
| 82 |
{ |
| 83 |
description.filePath = identifier.filePath; |
| 84 |
description.previewParameters.storageReference = identifier.id; |
| 85 |
|
| 86 |
if (!checkDescription(description)) |
| 87 |
{ |
| 88 |
continue; |
| 89 |
} |
| 90 |
|
| 91 |
descriptions << description; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
lastDescriptions = descriptions; |
| 96 |
|
| 97 |
return descriptions; |
| 98 |
} |
| 99 |
|
| 100 |
QList<LoadingDescription> ThumbnailLoadThread::Private::makeDescriptions(const QList<QPair<ThumbnailIdentifier, QRect> >& identifiersAndRects, int size) |
| 101 |
{ |
| 102 |
QList<LoadingDescription> descriptions; |
| 103 |
{ |
| 104 |
LoadingDescription description = createLoadingDescription(ThumbnailIdentifier(), size, QRect(1, 1, 1, 1), false); |
| 105 |
typedef QPair<ThumbnailIdentifier, QRect> IdRectPair; |
| 106 |
|
| 107 |
for (const IdRectPair& pair : std::as_const(identifiersAndRects)) |
| 108 |
{ |
| 109 |
description.filePath = pair.first.filePath; |
| 110 |
description.previewParameters.storageReference = pair.first.id; |
| 111 |
|
| 112 |
if (!checkDescription(description)) |
| 113 |
{ |
| 114 |
continue; |
| 115 |
} |
| 116 |
|
| 117 |
description.previewParameters.extraParameter = pair.second; |
| 118 |
descriptions << description; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
lastDescriptions = descriptions; |
| 123 |
|
| 124 |
return descriptions; |
| 125 |
} |
| 126 |
|
| 127 |
void ThumbnailImageCatcher::Private::reset() |
| 128 |
{ |
| 129 |
intermediate.clear(); |
| 130 |
tasks.clear(); |
| 131 |
|
| 132 |
if (active) |
| 133 |
{ |
| 134 |
state = Accepting; |
| 135 |
} |
| 136 |
else |
| 137 |
{ |
| 138 |
state = Inactive; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
void ThumbnailImageCatcher::Private::harvest(const LoadingDescription& description, const QImage& image) |
| 143 |
{ |
| 144 |
// called under lock |
| 145 |
|
| 146 |
bool finished = true; |
| 147 |
|
| 148 |
for (int i = 0 ; i < tasks.size() ; ++i) |
| 149 |
{ |
| 150 |
Private::CatcherResult& task = tasks[i]; |
| 151 |
|
| 152 |
if (task.description == description) |
| 153 |
{ |
| 154 |
task.image = image; |
| 155 |
task.received = true; |
| 156 |
} |
| 157 |
|
| 158 |
finished = (finished && task.received); |
| 159 |
} |
| 160 |
|
| 161 |
// cppcheck-suppress knownConditionTrueFalse |
| 162 |
if (finished) |
| 163 |
{ |
| 164 |
state = Quitting; |
| 165 |
condVar.wakeOne(); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
} // namespace Digikam |