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 COLORMODELCHECK_H
0008 #define COLORMODELCHECK_H
0009 
0010 #include "KisExportCheckRegistry.h"
0011 #include <KoID.h>
0012 #include <klocalizedstring.h>
0013 #include <kis_image.h>
0014 #include <KoColorSpace.h>
0015 #include <KoColorModelStandardIds.h>
0016 
0017 class ColorModelCheck : public KisExportCheckBase
0018 {
0019 public:
0020 
0021     ColorModelCheck(const KoID &colorModelID, const KoID &colorDepthID, const QString &id, Level level, const QString &customWarning = QString())
0022         : KisExportCheckBase(id, level, customWarning)
0023         , m_colorModelID(colorModelID)
0024         , m_colorDepthID(colorDepthID)
0025     {
0026         Q_ASSERT(!colorModelID.name().isEmpty());
0027         Q_ASSERT(!colorDepthID.name().isEmpty());
0028 
0029         if (customWarning.isEmpty()) {
0030             m_warning = i18nc("image conversion warning",
0031                               "The color model <b>%1</b> or channel depth <b>%2</b> cannot be saved to this format. Your image will be converted.",
0032                               m_colorModelID.name(),
0033                               m_colorDepthID.name());
0034         }
0035     }
0036 
0037     bool checkNeeded(KisImageSP image) const override
0038     {
0039         return (image->colorSpace()->colorModelId() == m_colorModelID && image->colorSpace()->colorDepthId() == m_colorDepthID);
0040     }
0041 
0042     Level check(KisImageSP /*image*/) const override
0043     {
0044         return m_level;
0045     }
0046 
0047     const KoID m_colorModelID;
0048     const KoID m_colorDepthID;
0049 };
0050 
0051 class ColorModelCheckFactory : public KisExportCheckFactory
0052 {
0053 public:
0054 
0055     ColorModelCheckFactory(const KoID &colorModelID, const KoID &colorDepthId)
0056         : m_colorModelID(colorModelID)
0057         , m_colorDepthID(colorDepthId)
0058     {
0059     }
0060 
0061     ~ColorModelCheckFactory() override {}
0062 
0063     KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override
0064     {
0065         return new ColorModelCheck(m_colorModelID, m_colorDepthID, id(), level, customWarning);
0066     }
0067 
0068     QString id() const override {
0069         return "ColorModelCheck/" + m_colorModelID.id() + "/" + m_colorDepthID.id();
0070     }
0071 
0072     const KoID m_colorModelID;
0073     const KoID m_colorDepthID;
0074 };
0075 
0076 #endif // COLORMODELCHECK_H