digiKam
Loading...
Searching...
No Matches
dimg.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-14
7 * Description : digiKam 8/16 bits image management API
8 *
9 * SPDX-FileCopyrightText: 2005 by Renchi Raju <renchi dot raju at gmail dot com>
10 * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
11 * SPDX-FileCopyrightText: 2006-2013 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 <QExplicitlySharedDataPointer>
22#include <QByteArray>
23#include <QFileInfo>
24#include <QFlags>
25#include <QSize>
26#include <QRect>
27#include <QVariant>
28
29// Local includes
30
31#include "digikam_export.h"
32#include "drawdecoding.h"
33#include "dcolor.h"
34#include "dcolorcomposer.h"
35#include "historyimageid.h"
36#include "iccprofile.h"
37#include "metaengine_data.h"
38
39class QImage;
40class QPixmap;
41
42namespace Digikam
43{
44
45class ExposureSettingsContainer;
46class DImageHistory;
47class FilterAction;
48class IccTransform;
49class DImgLoaderObserver;
50
51class DIGIKAM_EXPORT DImg
52{
53public:
54
55 enum FORMAT
56 {
57 NONE = 0,
64 // Others file formats.
66 QIMAGE
67 };
68
69 enum ANGLE
70 {
71 ROT90 = 0,
74 ROTNONE
75 };
76
77 enum FLIP
78 {
79 HORIZONTAL = 0,
80 VERTICAL
81 };
82
84 {
85 COLORMODELUNKNOWN = 0,
93 COLORMODELRAW
94 };
95
96public:
97
101 static FORMAT fileFormat(const QString& filePath);
102
103 static QString formatToMimeType(FORMAT frm);
104
105public:
106
107 class Private;
108
109public:
110
114 DImg();
115
119 explicit DImg(const QByteArray& filePath, DImgLoaderObserver* const observer = nullptr,
120 const DRawDecoding& rawDecodingSettings = DRawDecoding());
121
125 explicit DImg(const QString& filePath, DImgLoaderObserver* const observer = nullptr,
126 const DRawDecoding& rawDecodingSettings = DRawDecoding());
127
132 DImg(const DImg& image);
133
138 explicit DImg(const QImage& image);
139
147 DImg(uint width, uint height, bool sixteenBit, bool alpha = false, uchar* const data = nullptr, bool copyData = true);
148
149 ~DImg();
150
154 DImg& operator=(const DImg& image);
155
162 void detach();
163
173 bool operator==(const DImg& image) const;
174
179 void putImageData(uint width, uint height, bool sixteenBit, bool alpha, uchar* const data, bool copyData = true);
180
188 void putImageData(uchar* const data, bool copyData = true);
189
193 void reset();
194
198 void resetMetaData();
199
204 uchar* stripImageData();
205
206 bool load(const QString& filePath, DImgLoaderObserver* const observer = nullptr,
207 const DRawDecoding& rawDecodingSettings = DRawDecoding());
208
209 bool load(const QString& filePath,
210 bool loadMetadata, bool loadICCData, bool loadUniqueHash, bool loadHistory,
211 DImgLoaderObserver* const observer = nullptr,
212 const DRawDecoding& rawDecodingSettings = DRawDecoding());
213
214 bool load(const QString& filePath, int loadFlags, DImgLoaderObserver* const observer,
215 const DRawDecoding& rawDecodingSettings = DRawDecoding());
216
217 bool save(const QString& filePath, FORMAT frm, DImgLoaderObserver* const observer = nullptr);
218 bool save(const QString& filePath, const QString& format, DImgLoaderObserver* const observer = nullptr);
219
227 void imageSavedAs(const QString& savePath);
228
234 bool loadItemInfo(const QString& filePath, bool loadMetadata = true,
235 bool loadICCData = true, bool loadUniqueHash = true,
236 bool loadImageHistory = true);
237
238 bool isNull() const;
239 uint width() const;
240 uint height() const;
241 QSize size() const;
242 uchar* copyBits() const;
243 uchar* bits() const;
244 uchar* scanLine(uint i) const;
245 bool hasAlpha() const;
246 bool sixteenBit() const;
247 quint64 numBytes() const;
248 quint64 numPixels() const;
249
253 int bytesDepth() const;
254
258 int bitsDepth() const;
259
264 QString originalFilePath() const;
265
271 QString lastSavedFilePath() const;
272
277 COLORMODEL originalColorModel() const;
278
282 int originalBitDepth() const;
283
287 QSize originalSize() const;
288
293 QSize originalRatioSize() const;
294
304 FORMAT detectedFormat() const;
305
312 QString format() const;
313
321 QString savedFormat() const;
322
327 DRawDecoding rawDecodingSettings() const;
328
335 DColor getPixelColor(uint x, uint y) const;
336 void setPixelColor(uint x, uint y, const DColor& color);
337 void prepareSubPixelAccess();
338 DColor getSubPixelColor(float x, float y) const;
339 DColor getSubPixelColorFast(float x, float y) const;
340
347 bool hasTransparentPixels() const;
348
355 bool isReadOnly() const;
356
360 MetaEngineData getMetadata() const;
361 IccProfile getIccProfile() const;
362 void setMetadata(const MetaEngineData& data);
363 void setIccProfile(const IccProfile& profile);
364
365 void setAttribute(const QString& key, const QVariant& value);
366 QVariant attribute(const QString& key) const;
367 bool hasAttribute(const QString& key) const;
368 void removeAttribute(const QString& key);
369
370 void setEmbeddedText(const QString& key, const QString& text);
371 QString embeddedText(const QString& key) const;
372
373 const DImageHistory& getItemHistory() const;
374 DImageHistory& getItemHistory();
375 void setItemHistory(const DImageHistory& history);
376 bool hasImageHistory() const;
377 DImageHistory getOriginalImageHistory() const;
378 void addFilterAction(const FilterAction& action);
379
388 void setHistoryBranchAfter(const DImageHistory& historyBeforeBranch, bool isBranch = true);
389 void setHistoryBranchForLastSteps(int numberOfLastHistorySteps, bool isBranch = true);
390 void setHistoryBranch(bool isBranch = true);
391
406 {
411 RemoveOldMetadataPreviews = 1 << 0,
415 CreateNewMetadataPreview = 1 << 1,
420 ResetExifOrientationTag = 1 << 2,
425 CreateNewImageHistoryUUID = 1 << 3,
426
427 PrepareMetadataFlagsAll = RemoveOldMetadataPreviews |
428 CreateNewMetadataPreview |
429 ResetExifOrientationTag |
430 CreateNewImageHistoryUUID
431 };
432 Q_DECLARE_FLAGS(PrepareMetadataFlags, PrepareMetadataFlag)
433
434 void prepareMetadataToSave(const QString& intendedDestPath,
435 const QString& destMimeType,
436 const QString& originalFileName = QString(),
437 PrepareMetadataFlags flags = PrepareMetadataFlagsAll);
438
443 void prepareMetadataToSave(const QString& intendedDestPath,
444 const QString& destMimeType,
445 bool resetExifOrientationTag);
446
450 HistoryImageId createHistoryImageId(const QString& filePath, HistoryImageId::Type type);
451
464 HistoryImageId addAsReferredImage(const QString& filePath, HistoryImageId::Type type = HistoryImageId::Intermediate);
465 void addAsReferredImage(const HistoryImageId& id);
466 void insertAsReferredImage(int afterHistoryStep, const HistoryImageId& otherImagesId);
467
473 void addCurrentUniqueImageId(const QString& uuid);
474
479 int exifOrientation(const QString& filePath);
480
498 QVariant fileOriginData() const;
499 void setFileOriginData(const QVariant& data);
500 QVariant lastSavedFileOriginData() const;
501 void switchOriginToLastSaved();
502
506 DImg copy() const;
507
511 DImg copyImageData() const;
512
519 DImg copyMetaData() const;
520
524 DImg copy(const QRect& rect) const;
525 DImg copy(const QRectF& relativeRect) const;
526 DImg copy(int x, int y, int w, int h) const;
527
537 void bitBltImage(const DImg* const src, int dx, int dy);
538 void bitBltImage(const DImg* const src, int sx, int sy, int dx, int dy);
539 void bitBltImage(const DImg* const src, int sx, int sy, int w, int h, int dx, int dy);
540 void bitBltImage(const uchar* const src, int sx, int sy, int w, int h, int dx, int dy,
541 uint swidth, uint sheight, int sdepth);
542
548 void bitBlendImage(DColorComposer* const composer, const DImg* const src,
549 int sx, int sy, int w, int h, int dx, int dy,
550 DColorComposer::MultiplicationFlags multiplicationFlags =
551 DColorComposer::NoMultiplication);
552
558 void bitBlendImageOnColor(DColorComposer* const composer, const DColor& color,
559 int x, int y, int w, int h,
560 DColorComposer::MultiplicationFlags multiplicationFlags =
561 DColorComposer::NoMultiplication);
562 void bitBlendImageOnColor(const DColor& color, int x, int y, int w, int h);
563 void bitBlendImageOnColor(const DColor& color);
564
568 QImage copyQImage() const;
569 QImage copyQImage32() const;
570 QImage copyQImage(const QRect& rect) const;
571 QImage copyQImage(const QRectF& relativeRect) const;
572 QImage copyQImage(int x, int y, int w, int h) const;
573
577 void crop(const QRect& rect);
578 void crop(int x, int y, int w, int h);
579
583 void resize(int w, int h);
584
592 void removeAlphaChannel(const DColor& destColor);
593 void removeAlphaChannel();
594
599 DImg smoothScale(int width, int height, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio) const;
600 DImg smoothScale(const QSize& destSize, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio) const;
601
611 DImg smoothScaleClipped(int width, int height, int clipx, int clipy,
612 int clipwidth, int clipheight, bool smooth = true) const;
613 DImg smoothScaleClipped(const QSize& destSize, const QRect& clip, bool smooth = true) const;
614
619 DImg smoothScaleSection(int sx, int sy, int sw, int sh, int dw, int dh) const;
620 DImg smoothScaleSection(const QRect& sourceRect, const QSize& destSize) const;
621
622 void rotate(ANGLE angle);
623 void flip(FLIP direction);
624
631 bool rotateAndFlip(int orientation);
632
636 bool reverseRotateAndFlip(int orientation);
637
645 bool wasExifRotated();
646 bool exifRotate(const QString& filePath);
647
651 bool reverseExifRotate(const QString& filePath);
652
656 int orientation() const;
657
662 bool transform(int transformAction);
663
664 QPixmap convertToPixmap() const;
665 QPixmap convertToPixmap(IccTransform& monitorICCtrans) const;
666
671 QImage pureColorMask(ExposureSettingsContainer* const expoSettings) const;
672
678 void convertDepth(int depth);
679
683 void convertToSixteenBit();
684 void convertToEightBit();
685 void convertToDepthOfImage(const DImg* const otherImage);
686
691 void fill(const DColor& color);
692
711 QByteArray getUniqueHash();
712 static QByteArray getUniqueHash(const QString& filePath);
713
733 QByteArray getUniqueHashVersion(int version);
734 static QByteArray getUniqueHashVersion(const QString& filePath, int version);
735
744 QByteArray createImageUniqueId();
745
749 static QString colorModelToString(COLORMODEL colorModel);
750
754 static bool isAnimatedImage(const QString& filePath);
755
756private:
757
758 DImg(const DImg& image, uint w, uint h);
759
760 void copyMetaData(const QExplicitlySharedDataPointer<Private>& src);
761 void copyImageData(const QExplicitlySharedDataPointer<Private>& src);
762 void setImageData(bool null, uint width, uint height, bool sixteenBit, bool alpha);
763 void setImageDimension(uint width, uint height);
764 size_t allocateData() const;
765
766 bool clipped(int& x, int& y, int& w, int& h, uint width, uint height) const;
767
768 QDateTime creationDateFromFilesystem(const QFileInfo& fileInfo) const;
769
770 static QByteArray createUniqueHash(const QString& filePath, const QByteArray& ba);
771 static QByteArray createUniqueHashV2(const QString& filePath);
772 static QByteArray createUniqueHashV3(const QString& filePath);
773
774 void bitBlt(const uchar* const src, uchar* const dest,
775 int sx, int sy, int w, int h, int dx, int dy,
776 uint swidth, uint sheight, uint dwidth, uint dheight,
777 bool sixteenBit, int sdepth, int ddepth);
778 void bitBlend(DColorComposer* const composer, uchar* const src, uchar* const dest,
779 int sx, int sy, int w, int h, int dx, int dy,
780 uint swidth, uint sheight, uint dwidth, uint dheight,
781 bool sixteenBit, int sdepth, int ddepth,
782 DColorComposer::MultiplicationFlags multiplicationFlags);
783 void bitBlendOnColor(DColorComposer* const composer, const DColor& color,
784 uchar* data, int x, int y, int w, int h,
785 uint width, uint height, bool sixteenBit, int depth,
786 DColorComposer::MultiplicationFlags multiplicationFlags);
787 bool normalizeRegionArguments(int& sx, int& sy, int& w, int& h, int& dx, int& dy,
788 uint swidth, uint sheight, uint dwidth, uint dheight) const;
789
790private:
791
792 QExplicitlySharedDataPointer<Private> m_priv;
793
794 friend class DImgLoader;
795};
796
797} // namespace Digikam
798
799Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::DImg::PrepareMetadataFlags)
Definition dcolorcomposer.h:26
MultiplicationFlags
Definition dcolorcomposer.h:77
Definition dcolor.h:33
Definition dimagehistory.h:39
Definition dimgloaderobserver.h:31
Definition dimgloader.h:41
Definition dimg.h:52
COLORMODEL
Definition dimg.h:84
@ YCBCR
Definition dimg.h:90
@ CMYK
Definition dimg.h:91
@ INDEXED
Definition dimg.h:89
@ MONOCHROME
Definition dimg.h:88
@ CIELAB
Definition dimg.h:92
@ GRAYSCALE
Definition dimg.h:87
@ RGB
Definition dimg.h:86
ANGLE
Definition dimg.h:70
@ ROT180
Definition dimg.h:72
@ ROT270
Definition dimg.h:73
QString embeddedText(const QString &key) const
PrepareMetadataFlag
Definition dimg.h:406
FORMAT
Definition dimg.h:56
@ TIFF
Definition dimg.h:60
@ PNG
Definition dimg.h:59
@ JP2K
Definition dimg.h:61
@ RAW
Definition dimg.h:65
@ JPEG
Definition dimg.h:58
@ HEIF
Definition dimg.h:63
@ PGF
Definition dimg.h:62
FLIP
Definition dimg.h:78
bool sixteenBit() const
uint width() const
uint height() const
Definition drawdecoding.h:38
Definition exposurecontainer.h:29
Definition filteraction.h:33
Definition historyimageid.h:32
Type
Definition historyimageid.h:36
Definition iccprofile.h:33
Definition icctransform.h:39
Definition metaengine_data.h:31
qulonglong value
Definition itemviewutilities.cpp:585
Definition datefolderview.cpp:34
bool operator==(const SearchTextSettings &a, const SearchTextSettings &b)
Definition searchtextbar.cpp:40