File indexing completed on 2024-04-28 15:25:45
0001 /* 0002 SPDX-FileCopyrightText: 2022 Albert Astals Cid <aacid@kde.org> 0003 SPDX-FileCopyrightText: 2022 Mirco Miranda <mircomir@outlook.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef UTIL_P_H 0009 #define UTIL_P_H 0010 0011 #include <limits> 0012 0013 #include <QImage> 0014 0015 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 0016 #include <QImageIOHandler> 0017 #endif 0018 0019 // QVector uses some extra space for stuff, hence the 32 here suggested by Thiago Macieira 0020 static constexpr int kMaxQVectorSize = std::numeric_limits<int>::max() - 32; 0021 0022 // On Qt 6 to make the plugins fail to allocate if the image size is greater than QImageReader::allocationLimit() 0023 // it is necessary to allocate the image with QImageIOHandler::allocateImage(). 0024 inline QImage imageAlloc(const QSize &size, const QImage::Format &format) 0025 { 0026 QImage img; 0027 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0028 img = QImage(size, format); 0029 #else 0030 if (!QImageIOHandler::allocateImage(size, format, &img)) { 0031 img = QImage(); // paranoia 0032 } 0033 #endif 0034 return img; 0035 } 0036 0037 inline QImage imageAlloc(qint32 width, qint32 height, const QImage::Format &format) 0038 { 0039 return imageAlloc(QSize(width, height), format); 0040 } 0041 0042 #endif // UTIL_P_H