File indexing completed on 2024-04-28 03:54:46

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 #include <QImageIOHandler>
0015 
0016 // QList uses some extra space for stuff, hence the 32 here suggested by Thiago Macieira
0017 static constexpr int kMaxQVectorSize = std::numeric_limits<int>::max() - 32;
0018 
0019 // On Qt 6 to make the plugins fail to allocate if the image size is greater than QImageReader::allocationLimit()
0020 // it is necessary to allocate the image with QImageIOHandler::allocateImage().
0021 inline QImage imageAlloc(const QSize &size, const QImage::Format &format)
0022 {
0023     QImage img;
0024     if (!QImageIOHandler::allocateImage(size, format, &img)) {
0025         img = QImage(); // paranoia
0026     }
0027     return img;
0028 }
0029 
0030 inline QImage imageAlloc(qint32 width, qint32 height, const QImage::Format &format)
0031 {
0032     return imageAlloc(QSize(width, height), format);
0033 }
0034 
0035 #endif // UTIL_P_H