digiKam
thumbnailcreator.h
Go to the documentation of this file.
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  * Copyright (C) 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com>
10  * Copyright (C) 2003-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_THUMB_NAIL_CREATOR_H
27 #define DIGIKAM_THUMB_NAIL_CREATOR_H
28 
29 // Qt includes
30 
31 #include <QString>
32 #include <QPixmap>
33 #include <QImage>
34 
35 // Local includes
36 
37 #include "drawdecoding.h"
38 #include "digikam_export.h"
39 #include "thumbnailinfo.h"
40 
41 namespace Digikam
42 {
43 
44 class IccProfile;
45 class DImgLoaderObserver;
46 class DMetadata;
47 class ThumbnailImage;
48 class ThumbsDbInfo;
49 
50 class DIGIKAM_EXPORT ThumbnailCreator
51 {
52 public:
53 
55  {
57  ThumbnailDatabase
58  };
59 
60 public:
61 
66  explicit ThumbnailCreator(StorageMethod method);
67 
71  ThumbnailCreator(int thumbnailSize, StorageMethod method);
73 
77  QImage load(const ThumbnailIdentifier& identifier) const;
78 
83  QImage loadDetail(const ThumbnailIdentifier& identifier,
84  const QRect& detailRect) const;
85 
89  void pregenerate(const ThumbnailIdentifier& identifier) const;
90  void pregenerateDetail(const ThumbnailIdentifier& identifier,
91  const QRect& detailRect) const;
92 
97  void setThumbnailSize(int thumbnailSize);
98 
105  void setLoadingProperties(DImgLoaderObserver* const observer,
106  const DRawDecoding& settings);
107 
114  void setExifRotate(bool rotate);
115 
122  void setOnlyLargeThumbnails(bool onlyLarge);
123 
128  void setRemoveAlphaChannel(bool removeAlpha);
129 
133  void setThumbnailInfoProvider(ThumbnailInfoProvider* const provider);
134 
139  int thumbnailSize() const;
140 
147  int storedSize() const;
148 
153  void store(const QString& path, const QImage& image) const;
154 
155  void storeDetailThumbnail(const QString& path,
156  const QRect& detailRect,
157  const QImage& image) const;
158 
163  QString errorString() const;
164 
169  void deleteThumbnailsFromDisk(const QString& filePath) const;
170 
174  static ThumbnailInfo fileThumbnailInfo(const QString& path);
175 
179  static QString identifierForDetail(const ThumbnailInfo& info,
180  const QRect& rect);
181 
182 private:
183 
184  void initialize();
185 
186  ThumbnailImage createThumbnail(const ThumbnailInfo& info,
187  const QRect& detailRect = QRect()) const;
188 
189  QImage load(const ThumbnailIdentifier& id,
190  const QRect& rect,
191  bool pregenerate) const;
192  QImage loadWithDImgScaled(const QString& path,
193  IccProfile* const profile) const;
194  QImage loadImageDetail(const ThumbnailInfo& info,
195  const DMetadata& metadata,
196  const QRect& detailRect,
197  IccProfile* const profile) const;
198  QImage loadImagePreview(const DMetadata& metadata) const;
199  QImage loadPNG(const QString& path) const;
200 
201  QImage handleAlphaChannel(const QImage& thumb) const;
202  int exifOrientation(const ThumbnailInfo& info,
203  const DMetadata& metadata,
204  bool fromEmbeddedPreview,
205  bool fromDetail) const;
206  QImage exifRotate(const QImage& thumb, int orientation) const;
207 
208  void store(const QString& path,
209  const QImage& i,
210  const QRect& rect) const;
211 
212  ThumbnailInfo makeThumbnailInfo(const ThumbnailIdentifier& identifier,
213  const QRect& rect) const;
214  QImage scaleForStorage(const QImage& qimage) const;
215 
216  void storeInDatabase(const ThumbnailInfo& info,
217  const ThumbnailImage& image) const;
218  ThumbsDbInfo loadThumbsDbInfo(const ThumbnailInfo& info) const;
219  ThumbnailImage loadFromDatabase(const ThumbnailInfo& info) const;
220  bool isInDatabase(const ThumbnailInfo& info) const;
221  void deleteFromDatabase(const ThumbnailInfo& info) const;
222 
223  void storeFreedesktop(const ThumbnailInfo& info, const ThumbnailImage& image) const;
224  ThumbnailImage loadFreedesktop(const ThumbnailInfo& info) const;
225  void deleteFromDiskFreedesktop(const QString& filePath) const;
226 
227  void initThumbnailDirs();
228  QString thumbnailPath(const QString& uri) const;
229 
230  // implementations in thumbnailbasic.cpp
231 
232  static QString normalThumbnailDir();
233  static QString largeThumbnailDir();
234  static QString thumbnailPath(const QString& filePath, const QString& basePath);
235  static QString thumbnailUri(const QString& filePath);
236  static QString thumbnailPathFromUri(const QString& uri, const QString& basePath);
237 
238 private:
239 
240  // Disable
241  ThumbnailCreator(const ThumbnailCreator&) = delete;
242  ThumbnailCreator& operator=(const ThumbnailCreator&) = delete;
243 
244 private:
245 
246  class Private;
247  Private* const d;
248 };
249 
250 } // namespace Digikam
251 
252 #endif // DIGIKAM_THUMB_NAIL_CREATOR_H
Definition: dimgloaderobserver.h:41
Definition: dmetadata.h:55
Definition: drawdecoding.h:48
Definition: iccprofile.h:43
Definition: thumbnailcreator.h:51
StorageMethod
Definition: thumbnailcreator.h:55
@ FreeDesktopStandard
Definition: thumbnailcreator.h:56
Definition: thumbnailinfo.h:40
Definition: thumbnailcreator_p.h:83
Definition: thumbnailinfo.h:112
Definition: thumbnailinfo.h:58
Definition: thumbsdb.h:62
Definition: datefolderview.cpp:43