File indexing completed on 2024-05-12 15:59:02

0001 /*
0002  * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef CHECKIMAGESIZE_H
0008 #define CHECKIMAGESIZE_H
0009 
0010 #include "KisExportCheckRegistry.h"
0011 #include <KoID.h>
0012 #include <klocalizedstring.h>
0013 #include <kis_image.h>
0014 #include <kis_image_ImageSize_interface.h>
0015 #include <KoColorSpace.h>
0016 
0017 class ImageSizeCheck : public KisExportCheckBase
0018 {
0019 public:
0020 
0021     ImageSizeCheck(int maxWidth, int maxHeight, const QString &id, Level level, const QString &customWarning = QString())
0022         : KisExportCheckBase(id, level, customWarning, true)
0023         , m_maxW(maxWidth)
0024         , m_maxH(maxHeight)
0025     {
0026         if (customWarning.isEmpty()) {
0027             m_warning = i18nc("image conversion warning", "This image is larger than <b>%1 x %2</b>. Images this size cannot be saved to this format.", m_maxW, m_maxH);
0028         }
0029     }
0030 
0031     bool checkNeeded(KisImageSP image) const
0032     {
0033         return image->width() <= m_maxW && image->height() <= m_maxH;
0034     }
0035 
0036     Level check(KisImageSP /*image*/) const
0037     {
0038         return m_level;
0039     }
0040 
0041     int m_maxW;
0042     int m_maxH;
0043 };
0044 
0045 class ImageSizeCheckFactory : public KisExportCheckFactory
0046 {
0047 public:
0048 
0049     ImageSizeCheckFactory() {}
0050 
0051     virtual ~ImageSizeCheckFactory() {}
0052 
0053     KisExportCheckBase *create(int maxWidth, int maxHeight, KisExportCheckBase::Level level, const QString &customWarning)
0054     {
0055         return new ImageSizeCheck(maxWidth, maxHeight, id(), level, customWarning);
0056     }
0057 
0058     QString id() const {
0059         return "ImageSizeCheck";
0060     }
0061 };
0062 
0063 
0064 #endif // CHECKIMAGESIZE_H