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 | // QList uses some extra space for stuff, hence the 32 here suggested by Thiago Macieira |
17 | static constexpr int kMaxQVectorSize = std::numeric_limits<int>::max() - 32; |
18 | |
19 | // On Qt 6 to make the plugins fail to allocate if the image size is greater than QImageReader::allocationLimit() |
20 | // it is necessary to allocate the image with QImageIOHandler::allocateImage(). |
21 | inline QImage imageAlloc(const QSize &size, const QImage::Format &format) |
22 | { |
23 | QImage img; |
24 | if (!QImageIOHandler::allocateImage(size, format, image: &img)) { |
25 | img = QImage(); // paranoia |
26 | } |
27 | return img; |
28 | } |
29 | |
30 | inline QImage imageAlloc(qint32 width, qint32 height, const QImage::Format &format) |
31 | { |
32 | return imageAlloc(size: QSize(width, height), format); |
33 | } |
34 | |
35 | #endif // UTIL_P_H |
36 | |