digiKam
dimg_p.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 : 2005-06-15
7  * Description : digiKam 8/16 bits image management API.
8  * Private data container.
9  *
10  * Copyright (C) 2005 by Renchi Raju <renchi dot raju at gmail dot com>
11  * Copyright (C) 2005-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
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_DIMG_PRIVATE_H
27 #define DIGIKAM_DIMG_PRIVATE_H
28 
29 #include "digikam_config.h"
30 
31 // C ANSI includes
32 
33 #ifndef Q_OS_WIN
34 extern "C"
35 {
36 #endif
37 
38 #include <stdint.h>
39 
40 #ifndef Q_OS_WIN
41 #include <math.h>
42 }
43 #endif
44 
45 // C++ includes
46 
47 #include <cstdio>
48 
49 // Qt includes
50 
51 #include <QCryptographicHash>
52 #include <QSharedData>
53 #include <QString>
54 #include <QByteArray>
55 #include <QVariant>
56 #include <QMap>
57 #include <QFile>
58 #include <QImage>
59 #include <QImageReader>
60 #include <QPaintEngine>
61 #include <QPainter>
62 #include <QPixmap>
63 #include <QSysInfo>
64 #include <QUuid>
65 #include <QScopedPointer>
66 
67 // KDE includes
68 
69 #include <klocalizedstring.h>
70 
71 // Local includes
72 
73 #include "dimg.h"
74 #include "dplugindimg.h"
75 #include "digikam_export.h"
76 #include "digikam_debug.h"
77 #include "dmetadata.h"
78 #include "dimagehistory.h"
79 #include "iccprofile.h"
80 #include "metaengine_rotation.h"
81 #include "drawdecoder.h"
82 #include "loadsavethread.h"
83 #include "filereadwritelock.h"
84 #include "iccmanager.h"
85 #include "icctransform.h"
86 #include "exposurecontainer.h"
87 #include "dimgloaderobserver.h"
88 #include "randomnumbergenerator.h"
89 
94 #define LANCZOS_TABLE_RES 256
95 
100 #define LANCZOS_SUPPORT 2
101 
108 //#define LANCZOS_DATA_FLOAT
109 
110 #ifdef LANCZOS_DATA_FLOAT
111 # define LANCZOS_DATA_TYPE float
112 # define LANCZOS_DATA_ONE 1.0
113 #else
114 # define LANCZOS_DATA_TYPE int
115 # define LANCZOS_DATA_ONE 4096
116 #endif
117 
118 typedef uint64_t ullong; // krazy:exclude=typedefs
119 typedef int64_t llong; // krazy:exclude=typedefs
120 
121 namespace Digikam
122 {
123 
124 class DIGIKAM_EXPORT DImg::Private : public QSharedData
125 {
126 public:
127 
128  explicit Private()
129  : null (true),
130  alpha (false),
131  sixteenBit (false),
132  width (0),
133  height (0),
134  data (nullptr),
135  lanczos_func(nullptr)
136  {
137  }
138 
140  {
141  delete [] data;
142  delete [] lanczos_func;
143  }
144 
145 public:
146 
147  bool null;
148  bool alpha;
150 
151  unsigned int width;
152  unsigned int height;
153 
154  unsigned char* data;
156 
158  QMap<QString, QVariant> attributes;
159  QMap<QString, QString> embeddedText;
162 };
163 
164 // ----------------------------------------------------------------------------
165 
166 class DIGIKAM_EXPORT DImgStaticPriv
167 {
168 public:
169 
170  static DPluginDImg* pluginForFile(const QFileInfo& fileInfo, bool magic)
171  {
172  QMultiMap<int, DPluginDImg*> pluginMap;
173 
174  foreach (DPlugin* const p, DPluginLoader::instance()->allPlugins())
175  {
176  int prio;
177  DPluginDImg* const plug = dynamic_cast<DPluginDImg*>(p);
178 
179  if (plug && ((prio = plug->canRead(fileInfo, magic)) > 0))
180  {
181  /*
182  qCDebug(DIGIKAM_DIMG_LOG) << "File path:" << filePath
183  << "Priority:" << prio
184  << "Loader:" << plug->loaderName();
185  */
186  pluginMap.insert(prio, plug);
187  }
188  }
189 
190  if (pluginMap.isEmpty())
191  {
192  return nullptr;
193  }
194 
195  return pluginMap.first();
196  }
197 
198  static DPluginDImg* pluginForFormat(const QString& format)
199  {
200  QMultiMap<int, DPluginDImg*> pluginMap;
201 
202  if (!format.isNull())
203  {
204  foreach (DPlugin* const p, DPluginLoader::instance()->allPlugins())
205  {
206  int prio;
207  DPluginDImg* const plug = dynamic_cast<DPluginDImg*>(p);
208 
209  if (plug && ((prio = plug->canWrite(format)) > 0))
210  {
211  pluginMap.insert(prio, plug);
212  }
213  }
214  }
215 
216  if (pluginMap.isEmpty())
217  {
218  return nullptr;
219  }
220 
221  return pluginMap.first();
222  }
223 
224  static DImg::FORMAT loaderNameToFormat(const QString& name)
225  {
226  if (name.isNull())
227  {
228  return DImg::NONE;
229  }
230  else if (name == QLatin1String("JPEG"))
231  {
232  return DImg::JPEG;
233  }
234  else if (name == QLatin1String("PNG"))
235  {
236  return DImg::PNG;
237  }
238  else if (name == QLatin1String("TIFF"))
239  {
240  return DImg::TIFF;
241  }
242  else if (name == QLatin1String("RAW"))
243  {
244  return DImg::RAW;
245  }
246  else if (name == QLatin1String("JPEG2000"))
247  {
248  return DImg::JP2K;
249  }
250  else if (name == QLatin1String("PGF"))
251  {
252  return DImg::PGF;
253  }
254  else if (name == QLatin1String("HEIF"))
255  {
256  return DImg::HEIF;
257  }
258 
259  // In others cases, ImageMagick or QImage will be used to try to open file.
260 
261  return DImg::QIMAGE;
262  }
263 
264  static QStringList fileOriginAttributes()
265  {
266  QStringList list;
267  list << QLatin1String("format")
268  << QLatin1String("isReadOnly")
269  << QLatin1String("originalFilePath")
270  << QLatin1String("originalSize")
271  << QLatin1String("originalImageHistory")
272  << QLatin1String("rawDecodingSettings")
273  << QLatin1String("rawDecodingFilterAction")
274  << QLatin1String("uniqueHash")
275  << QLatin1String("uniqueHashV2");
276 
277  return list;
278  }
279 };
280 
281 } // namespace Digikam
282 
283 #endif // DIGIKAM_DIMG_PRIVATE_H
Definition: dimagehistory.h:49
Definition: dimg_p.h:167
static DPluginDImg * pluginForFormat(const QString &format)
Definition: dimg_p.h:198
static DPluginDImg * pluginForFile(const QFileInfo &fileInfo, bool magic)
Definition: dimg_p.h:170
static QStringList fileOriginAttributes()
Definition: dimg_p.h:264
static DImg::FORMAT loaderNameToFormat(const QString &name)
Definition: dimg_p.h:224
unsigned int height
Definition: dimg_p.h:152
LANCZOS_DATA_TYPE * lanczos_func
Definition: dimg_p.h:155
QMap< QString, QString > embeddedText
Definition: dimg_p.h:159
~Private()
Definition: dimg_p.h:139
bool alpha
Definition: dimg_p.h:148
DImageHistory imageHistory
Definition: dimg_p.h:161
MetaEngineData metaData
Definition: dimg_p.h:157
FORMAT
Definition: dimg.h:66
@ NONE
Definition: dimg.h:71
@ TIFF
Definition: dimg.h:74
@ PNG
Definition: dimg.h:73
@ QIMAGE
QImage or ImageMagick.
Definition: dimg.h:80
@ JP2K
Definition: dimg.h:75
@ RAW
Definition: dimg.h:79
@ JPEG
Definition: dimg.h:72
@ HEIF
Definition: dimg.h:77
@ PGF
Definition: dimg.h:76
bool sixteenBit
Definition: dimg_p.h:149
unsigned char * data
Definition: dimg_p.h:154
unsigned int width
Definition: dimg_p.h:151
Private()
Definition: dimg_p.h:128
IccProfile iccProfile
Definition: dimg_p.h:160
QMap< QString, QVariant > attributes
Definition: dimg_p.h:158
Definition: dplugindimg.h:43
virtual int canWrite(const QString &format) const =0
virtual int canRead(const QFileInfo &fileInfo, bool magic) const =0
static DPluginLoader * instance()
instance: returns the singleton of plugin loader
Definition: dpluginloader.cpp:63
Definition: dplugin.h:61
Definition: iccprofile.h:43
Definition: metaengine_data.h:41
uint64_t ullong
Definition: dimg_p.h:118
int64_t llong
Definition: dimg_p.h:119
#define LANCZOS_DATA_TYPE
Definition: dimg_p.h:114
Definition: datefolderview.cpp:43