1 | /* |
2 | SPDX-FileCopyrightText: 2022 Albert Astals Cid <aacid@kde.org> |
3 | SPDX-FileCopyrightText: 2022 Mirco Miranda <mircomir@outlook.com> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef UTIL_P_H |
9 | #define UTIL_P_H |
10 | |
11 | #include <limits> |
12 | |
13 | #include <QImage> |
14 | #include <QImageIOHandler> |
15 | |
16 | // Image metadata keys to use in plugins (so they are consistent) |
17 | #define META_KEY_ALTITUDE "Altitude" |
18 | #define META_KEY_AUTHOR "Author" |
19 | #define "Comment" |
20 | #define META_KEY_COPYRIGHT "Copyright" |
21 | #define META_KEY_CREATIONDATE "CreationDate" |
22 | #define META_KEY_DESCRIPTION "Description" |
23 | #define META_KEY_DIRECTION "Direction" |
24 | #define META_KEY_DOCUMENTNAME "DocumentName" |
25 | #define META_KEY_HOSTCOMPUTER "HostComputer" |
26 | #define META_KEY_LATITUDE "Latitude" |
27 | #define META_KEY_LONGITUDE "Longitude" |
28 | #define META_KEY_MODIFICATIONDATE "ModificationDate" |
29 | #define META_KEY_OWNER "Owner" |
30 | #define META_KEY_SOFTWARE "Software" |
31 | #define META_KEY_TITLE "Title" |
32 | #define META_KEY_XML_GIMP "XML:org.gimp.xml" |
33 | #define META_KEY_XMP_ADOBE "XML:com.adobe.xmp" |
34 | |
35 | // Camera info metadata keys |
36 | #define META_KEY_MANUFACTURER "Manufacturer" |
37 | #define META_KEY_MODEL "Model" |
38 | #define META_KEY_SERIALNUMBER "SerialNumber" |
39 | |
40 | // Lens info metadata keys |
41 | #define META_KEY_LENS_MANUFACTURER "LensManufacturer" |
42 | #define META_KEY_LENS_MODEL "LensModel" |
43 | #define META_KEY_LENS_SERIALNUMBER "LensSerialNumber" |
44 | |
45 | // QList uses some extra space for stuff, hence the 32 here suggested by Thiago Macieira |
46 | static constexpr int kMaxQVectorSize = std::numeric_limits<int>::max() - 32; |
47 | |
48 | // On Qt 6 to make the plugins fail to allocate if the image size is greater than QImageReader::allocationLimit() |
49 | // it is necessary to allocate the image with QImageIOHandler::allocateImage(). |
50 | inline QImage imageAlloc(const QSize &size, const QImage::Format &format) |
51 | { |
52 | QImage img; |
53 | if (!QImageIOHandler::allocateImage(size, format, image: &img)) { |
54 | img = QImage(); // paranoia |
55 | } |
56 | return img; |
57 | } |
58 | |
59 | inline QImage imageAlloc(qint32 width, qint32 height, const QImage::Format &format) |
60 | { |
61 | return imageAlloc(size: QSize(width, height), format); |
62 | } |
63 | |
64 | inline double qRoundOrZero(double d) |
65 | { |
66 | // If the value d is outside the range of int, the behavior is undefined. |
67 | if (d > std::numeric_limits<int>::max()) { |
68 | return 0; |
69 | } |
70 | return qRound(d); |
71 | } |
72 | |
73 | #endif // UTIL_P_H |
74 | |