| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2007-07-20 |
| 7 |
* Description : Loader for thumbnails |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com> |
| 10 |
* SPDX-FileCopyrightText: 2003-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 11 |
* SPDX-FileCopyrightText: 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> |
| 12 |
* |
| 13 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 14 |
* |
| 15 |
* ============================================================ */ |
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
// Qt includes |
| 20 |
|
| 21 |
#include <QString> |
| 22 |
#include <QPixmap> |
| 23 |
#include <QImage> |
| 24 |
|
| 25 |
// Local includes |
| 26 |
|
| 27 |
#include "drawdecoding.h" |
| 28 |
#include "digikam_export.h" |
| 29 |
#include "thumbnailinfo.h" |
| 30 |
|
| 31 |
namespace Digikam |
| 32 |
{ |
| 33 |
|
| 34 |
class IccProfile; |
| 35 |
class DImgLoaderObserver; |
| 36 |
class DMetadata; |
| 37 |
class ThumbnailImage; |
| 38 |
class ThumbsDbInfo; |
| 39 |
|
| 40 |
class DIGIKAM_EXPORT ThumbnailCreator |
| 41 |
{ |
| 42 |
public: |
| 43 |
|
| 44 |
enum StorageMethod |
| 45 |
{ |
| 46 |
NoThumbnailStorage, |
| 47 |
FreeDesktopStandard, |
| 48 |
ThumbnailDatabase |
| 49 |
}; |
| 50 |
|
| 51 |
public: |
| 52 |
|
| 53 |
/** |
| 54 |
* Create a thumbnail creator object. |
| 55 |
* You must call setThumbnailSize before load. |
| 56 |
*/ |
| 57 |
explicit ThumbnailCreator(StorageMethod method); |
| 58 |
|
| 59 |
/** |
| 60 |
* Create a thumbnail creator object, and set the thumbnail size. |
| 61 |
*/ |
| 62 |
ThumbnailCreator(int thumbnailSize, StorageMethod method); |
| 63 |
~ThumbnailCreator(); |
| 64 |
|
| 65 |
/** |
| 66 |
* Create a thumbnail for the specified file. |
| 67 |
*/ |
| 68 |
QImage load(const ThumbnailIdentifier& identifier, bool onlyStorage = false) const; |
| 69 |
|
| 70 |
/** |
| 71 |
* Creates a thumbnail for the specified detail of the file. |
| 72 |
* A suitable custom identifier (for cache key etc.) is inserted as image.text("customIdentifier"). |
| 73 |
*/ |
| 74 |
QImage loadDetail(const ThumbnailIdentifier& identifier, |
| 75 |
const QRect& detailRect, |
| 76 |
bool onlyStorage = false) const; |
| 77 |
|
| 78 |
/** |
| 79 |
* Ensures that the thumbnail is pregenerated in the database, but does not load it from there. |
| 80 |
*/ |
| 81 |
void pregenerate(const ThumbnailIdentifier& identifier) const; |
| 82 |
void pregenerateDetail(const ThumbnailIdentifier& identifier, |
| 83 |
const QRect& detailRect) const; |
| 84 |
|
| 85 |
/** |
| 86 |
* Sets the thumbnail size. This is the maximum size of the QImage |
| 87 |
* returned by load. |
| 88 |
*/ |
| 89 |
void setThumbnailSize(int thumbnailSize); |
| 90 |
|
| 91 |
/** |
| 92 |
* If you plan to load thumbnail from the context of the threadimageio framework, |
| 93 |
* you can specify the relevant parameters. They will be passed if a thumbnail |
| 94 |
* is created by loading with DImg. |
| 95 |
* Note that DImg is not used in most cases (Raw files, JPEG) |
| 96 |
*/ |
| 97 |
void setLoadingProperties(DImgLoaderObserver* const observer, |
| 98 |
const DRawDecoding& settings); |
| 99 |
|
| 100 |
/** |
| 101 |
* Set the Exif rotation property. |
| 102 |
* If exifRotate is true, the thumbnail will be rotated according |
| 103 |
* to the Exif information. |
| 104 |
* Default value is true. |
| 105 |
*/ |
| 106 |
void setExifRotate(bool rotate); |
| 107 |
|
| 108 |
/** |
| 109 |
* If you enable this property, the thumbnail creator will create only large |
| 110 |
* thumbnails on disk (256x256 as described in FreeDesktop paper). |
| 111 |
* Normally, for requested sizes below 128, thumbnails of 128x128 will be cached on disk. |
| 112 |
* Default value is false. |
| 113 |
*/ |
| 114 |
void setOnlyLargeThumbnails(bool onlyLarge); |
| 115 |
|
| 116 |
/** |
| 117 |
* If you enable this property, the returned QImage objects will not have an alpha channel. |
| 118 |
* Images with transparency will be blended over an opaque background. |
| 119 |
*/ |
| 120 |
void setRemoveAlphaChannel(bool removeAlpha); |
| 121 |
|
| 122 |
/** |
| 123 |
* Set a ThumbnailInfoProvider to provide custom ThumbnailInfos |
| 124 |
*/ |
| 125 |
void setThumbnailInfoProvider(ThumbnailInfoProvider* const provider); |
| 126 |
|
| 127 |
/** |
| 128 |
* Return the thumbnail size, the maximum size of the QImage |
| 129 |
* returned by load. |
| 130 |
*/ |
| 131 |
int thumbnailSize() const; |
| 132 |
|
| 133 |
/** |
| 134 |
* Return the stored image size, the size of the image that is stored on disk |
| 135 |
* (according to Storage Method). |
| 136 |
* This size is possibly larger than thumbnailSize. |
| 137 |
* Possible values: 128 or 256. |
| 138 |
*/ |
| 139 |
int storedSize() const; |
| 140 |
|
| 141 |
/** |
| 142 |
* Store the given image as thumbnail of the given path. |
| 143 |
* Image should at least have storedSize(). |
| 144 |
*/ |
| 145 |
void store(const QString& path, const QImage& image) const; |
| 146 |
|
| 147 |
void storeDetailThumbnail(const QString& path, |
| 148 |
const QRect& detailRect, |
| 149 |
const QImage& image) const; |
| 150 |
|
| 151 |
/** |
| 152 |
* Returns the last error that occurred. |
| 153 |
* It is valid if load returned a null QImage object. |
| 154 |
*/ |
| 155 |
QString errorString() const; |
| 156 |
|
| 157 |
/** |
| 158 |
* Deletes all available thumbnails from the on-disk thumbnail cache. |
| 159 |
* A subsequent call to load() will recreate the thumbnail. |
| 160 |
*/ |
| 161 |
void deleteThumbnailsFromDisk(const QString& filePath) const; |
| 162 |
|
| 163 |
/** |
| 164 |
* Creates a default ThumbnailInfo for the given path using QFileInfo only |
| 165 |
*/ |
| 166 |
static ThumbnailInfo fileThumbnailInfo(const QString& path); |
| 167 |
|
| 168 |
/** |
| 169 |
* Returns the customIdentifier for the detail thumbnail |
| 170 |
*/ |
| 171 |
static QString identifierForDetail(const ThumbnailInfo& info, |
| 172 |
const QRect& rect); |
| 173 |
|
| 174 |
private: |
| 175 |
|
| 176 |
void initialize(); |
| 177 |
|
| 178 |
ThumbnailImage createThumbnail(const ThumbnailInfo& info, |
| 179 |
const QRect& detailRect = QRect()) const; |
| 180 |
|
| 181 |
QImage load(const ThumbnailIdentifier& id, |
| 182 |
const QRect& rect, |
| 183 |
bool pregenerate, |
| 184 |
bool onlyStorage = false) const; |
| 185 |
QImage loadWithDImgScaled(const QString& path, |
| 186 |
IccProfile* const profile) const; |
| 187 |
QImage loadImageDetail(const ThumbnailInfo& info, |
| 188 |
const DMetadata& metadata, |
| 189 |
const QRect& detailRect, |
| 190 |
IccProfile* const profile) const; |
| 191 |
QImage loadImagePreview(const DMetadata& metadata) const; |
| 192 |
QImage loadPNG(const QString& path) const; |
| 193 |
|
| 194 |
QImage handleAlphaChannel(const QImage& thumb) const; |
| 195 |
int exifOrientation(const ThumbnailInfo& info, |
| 196 |
const DMetadata& metadata, |
| 197 |
bool fromEmbeddedPreview, |
| 198 |
bool fromDetail) const; |
| 199 |
QImage exifRotate(const QImage& thumb, int orientation) const; |
| 200 |
|
| 201 |
void store(const QString& path, |
| 202 |
const QImage& i, |
| 203 |
const QRect& rect) const; |
| 204 |
|
| 205 |
ThumbnailInfo makeThumbnailInfo(const ThumbnailIdentifier& identifier, |
| 206 |
const QRect& rect) const; |
| 207 |
QImage scaleForStorage(const QImage& qimage) const; |
| 208 |
|
| 209 |
void storeInDatabase(const ThumbnailInfo& info, |
| 210 |
const ThumbnailImage& image) const; |
| 211 |
ThumbsDbInfo loadThumbsDbInfo(const ThumbnailInfo& info) const; |
| 212 |
ThumbnailImage loadFromDatabase(const ThumbnailInfo& info) const; |
| 213 |
bool isInDatabase(const ThumbnailInfo& info) const; |
| 214 |
void deleteFromDatabase(const ThumbnailInfo& info) const; |
| 215 |
|
| 216 |
void storeFreedesktop(const ThumbnailInfo& info, const ThumbnailImage& image) const; |
| 217 |
ThumbnailImage loadFreedesktop(const ThumbnailInfo& info) const; |
| 218 |
void deleteFromDiskFreedesktop(const QString& filePath) const; |
| 219 |
|
| 220 |
void initThumbnailDirs(); |
| 221 |
QString thumbnailPath(const QString& uri) const; |
| 222 |
|
| 223 |
// implementations in thumbnailbasic.cpp |
| 224 |
|
| 225 |
static QString normalThumbnailDir(); |
| 226 |
static QString largeThumbnailDir(); |
| 227 |
static QString thumbnailPath(const QString& filePath, const QString& basePath); |
| 228 |
static QString thumbnailUri(const QString& filePath); |
| 229 |
static QString thumbnailPathFromUri(const QString& uri, const QString& basePath); |
| 230 |
|
| 231 |
private: |
| 232 |
|
| 233 |
/// @note disabled |
| 234 |
ThumbnailCreator(const ThumbnailCreator&) = delete; |
| 235 |
ThumbnailCreator& operator=(const ThumbnailCreator&) = delete; |
| 236 |
|
| 237 |
private: |
| 238 |
|
| 239 |
class Private; |
| 240 |
Private* const d = nullptr; |
| 241 |
}; |
| 242 |
|
| 243 |
} // namespace Digikam |