[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krita/rempt/impex-refactoring] libs/impex: Add two new checks: imagesize and color model homogeniei
From: Boudewijn Rempt <boud () valdyas ! org>
Date: 2016-09-30 15:24:14
Message-ID: E1bpzfa-0006JX-GC () code ! kde ! org
[Download RAW message or body]
Git commit 5707ab656d7d8d49cf3a7a6b81acc10a97180757 by Boudewijn Rempt.
Committed on 30/09/2016 at 15:17.
Pushed by rempt into branch 'rempt/impex-refactoring'.
Add two new checks: imagesize and color model homogenieity
A +77 -0 libs/impex/CheckImageSize.h [License: LGPL (v2+)]
A +165 -0 libs/impex/ColorModelHomogenousCheck.h [License: LGPL (v2+)]
A +81 -0 libs/impex/ImageSizeCheck.h [License: LGPL (v2+)]
M +9 -0 libs/impex/KisExportCheckRegistry.cpp
http://commits.kde.org/krita/5707ab656d7d8d49cf3a7a6b81acc10a97180757
diff --git a/libs/impex/CheckImageSize.h b/libs/impex/CheckImageSize.h
new file mode 100644
index 0000000..c4c8636
--- /dev/null
+++ b/libs/impex/CheckImageSize.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef CHECKIMAGESIZE_H
+#define CHECKIMAGESIZE_H
+
+#include "KisExportCheckRegistry.h"
+#include <KoID.h>
+#include <klocalizedstring.h>
+#include <kis_image.h>
+#include <kis_image_ImageSize_interface.h>
+#include <KoColorSpace.h>
+
+class ImageSizeCheck : public KisExportCheckBase
+{
+public:
+
+ ImageSizeCheck(int maxWidth, int maxHeight, const QString &id, Level level, \
const QString &customWarning = QString()) + : KisExportCheckBase(id, level, \
customWarning, true) + , m_maxW(maxWidth)
+ , m_maxH(maxHeight)
+ {
+ if (customWarning.isEmpty()) {
+ 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); + \
} + }
+
+ bool checkNeeded(KisImageSP image) const
+ {
+ return image->width() <= m_maxW && image->height() <= m_maxH;
+ }
+
+ Level check(KisImageSP /*image*/) const
+ {
+ return m_level;
+ }
+
+ int m_maxW;
+ int m_maxH;
+};
+
+class ImageSizeCheckFactory : public KisExportCheckFactory
+{
+public:
+
+ ImageSizeCheckFactory() {}
+
+ virtual ~ImageSizeCheckFactory() {}
+
+ KisExportCheckBase *create(int maxWidth, int maxHeight, \
KisExportCheckBase::Level level, const QString &customWarning) + {
+ return new ImageSizeCheck(maxWidth, maxHeight, id(), level, customWarning);
+ }
+
+ QString id() const {
+ return "ImageSizeCheck";
+ }
+};
+
+
+#endif // CHECKIMAGESIZE_H
diff --git a/libs/impex/ColorModelHomogenousCheck.h \
b/libs/impex/ColorModelHomogenousCheck.h new file mode 100644
index 0000000..135d059
--- /dev/null
+++ b/libs/impex/ColorModelHomogenousCheck.h
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef COLORMODELHOMOGENOUSCHECK_H
+#define COLORMODELHOMOGENOUSCHECK_H
+
+#include "KisExportCheckRegistry.h"
+#include <KoID.h>
+#include <klocalizedstring.h>
+#include <kis_image.h>
+#include <KoColorSpace.h>
+#include <KoColorModelStandardIds.h>
+#include <kis_layer.h>
+#include <kis_node_visitor.h>
+#include "kis_node.h"
+#include "kis_paint_layer.h"
+#include "kis_group_layer.h"
+#include "kis_adjustment_layer.h"
+#include "kis_external_layer_iface.h"
+#include "kis_clone_layer.h"
+#include "generator/kis_generator_layer.h"
+
+class KisColorModelHomogenousCheckVisitor : public KisNodeVisitor
+{
+public:
+
+ using KisNodeVisitor::visit;
+
+ KisColorModelHomogenousCheckVisitor(KoID colorModelID, KoID colorDepthID)
+ : m_count(0)
+ , m_colorModelID(colorModelID)
+ , m_colorDepthID(colorDepthID)
+ {
+ }
+
+ quint32 count() {
+ return m_count;
+ }
+
+ bool visit(KisNode* node) {
+ return check(node);
+ }
+
+ bool visit(KisPaintLayer *layer) {
+ return check(layer);
+ }
+
+ bool visit(KisGroupLayer *layer) {
+ return check(layer);
+ }
+
+
+ bool visit(KisAdjustmentLayer *layer) {
+ return check(layer);
+ }
+
+ bool visit(KisExternalLayer *layer) {
+ return check(layer);
+ }
+
+ bool visit(KisCloneLayer *layer) {
+ return check(layer);
+ }
+
+ bool visit(KisGeneratorLayer * layer) {
+ return check(layer);
+ }
+
+ virtual bool visit(KisFilterMask *) {return true;}
+
+ virtual bool visit(KisTransformMask *) {return true;}
+
+ virtual bool visit(KisTransparencyMask *) {return true;}
+
+ virtual bool visit(KisSelectionMask *) {return true;}
+
+ virtual bool visit(KisColorizeMask *) {return true;}
+
+
+private:
+ bool check(KisNode * node)
+ {
+ KisLayer *layer = dynamic_cast<KisLayer*>(node);
+ if (layer) {
+ const KoColorSpace * cs = layer->colorSpace();
+ if (cs->colorModelId() != m_colorModelID && cs->colorDepthId() != \
m_colorDepthID) { + m_count++;
+ }
+ }
+ visitAll(node);
+ return true;
+ }
+
+ quint32 m_count;
+ const KoID m_colorModelID;
+ const KoID m_colorDepthID;
+
+};
+
+class ColorModelHomogenousCheck : public KisExportCheckBase
+{
+public:
+
+ ColorModelHomogenousCheck(const QString &id, Level level, const QString \
&customWarning = QString()) + : KisExportCheckBase(id, level, customWarning, \
true) + {
+ if (customWarning.isEmpty()) {
+ m_warning = i18nc("image conversion warning", "Your image contains \
layers with a color model that is different from the image. The layers will be \
converted."); + }
+ }
+
+ bool checkNeeded(KisImageSP image) const
+ {
+ const KoColorSpace *cs = image->colorSpace();
+ KisColorModelHomogenousCheckVisitor v(cs->colorModelId(), \
cs->colorDepthId()); + image->rootLayer()->accept(v);
+ return (v.count() > 0);
+ }
+
+ Level check(KisImageSP /*image*/) const
+ {
+ return m_level;
+ }
+
+};
+
+class ColorModelHomogenousCheckFactory : public KisExportCheckFactory
+{
+public:
+
+ ColorModelHomogenousCheckFactory()
+ {
+ }
+
+ virtual ~ColorModelHomogenousCheckFactory() {}
+
+ KisExportCheckBase *create(KisExportCheckBase::Level level, const QString \
&customWarning) + {
+ return new ColorModelHomogenousCheck(id(), level, customWarning);
+ }
+
+ QString id() const {
+ return "ColorModelHomogenousCheck";
+ }
+
+};
+
+
+#endif // COLORMODELHOMOGENOUSCHECK_H
diff --git a/libs/impex/ImageSizeCheck.h b/libs/impex/ImageSizeCheck.h
new file mode 100644
index 0000000..e8fcbbb
--- /dev/null
+++ b/libs/impex/ImageSizeCheck.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef CHECKIMAGESIZE_H
+#define CHECKIMAGESIZE_H
+
+#include "KisExportCheckRegistry.h"
+#include <KoID.h>
+#include <klocalizedstring.h>
+#include <kis_image.h>
+#include "kritaimpex_export.h"
+
+class KRITAIMPEX_EXPORT ImageSizeCheck : public KisExportCheckBase
+{
+public:
+
+ ImageSizeCheck(int maxWidth, int maxHeight, const QString &id, Level level, \
const QString &customWarning = QString()) + : KisExportCheckBase(id, level, \
customWarning, true) + , m_maxW(maxWidth)
+ , m_maxH(maxHeight)
+ {
+ if (customWarning.isEmpty()) {
+ 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); + \
} + }
+
+ bool checkNeeded(KisImageSP image) const
+ {
+ return image->width() <= m_maxW && image->height() <= m_maxH;
+ }
+
+ Level check(KisImageSP /*image*/) const
+ {
+ return m_level;
+ }
+
+ int m_maxW;
+ int m_maxH;
+};
+
+class KRITAIMPEX_EXPORT ImageSizeCheckFactory : public KisExportCheckFactory
+{
+public:
+
+ ImageSizeCheckFactory() {}
+
+ virtual ~ImageSizeCheckFactory() {}
+
+ KisExportCheckBase *create( KisExportCheckBase::Level level, const QString \
&customWarning = QString()) + {
+ return new ImageSizeCheck(100000000, 100000000, id(), level, customWarning);
+ }
+
+ KisExportCheckBase *create(int maxWidth, int maxHeight, \
KisExportCheckBase::Level level, const QString &customWarning = QString()) + {
+ return new ImageSizeCheck(maxWidth, maxHeight, id(), level, customWarning);
+ }
+
+ QString id() const {
+ return "ImageSizeCheck";
+ }
+};
+
+
+#endif // CHECKIMAGESIZE_H
diff --git a/libs/impex/KisExportCheckRegistry.cpp \
b/libs/impex/KisExportCheckRegistry.cpp index 4c5df60..b41174c 100644
--- a/libs/impex/KisExportCheckRegistry.cpp
+++ b/libs/impex/KisExportCheckRegistry.cpp
@@ -34,6 +34,8 @@
#include <PSDLayerStylesCheck.h>
#include <sRGBProfileCheck.h>
#include <NodeTypeCheck.h>
+#include <ImageSizeCheck.h>
+#include <ColorModelHomogenousCheck.h>
#include <QGlobalStatic>
@@ -69,6 +71,13 @@ KisExportCheckRegistry::KisExportCheckRegistry ()
chkFactory = new sRGBProfileCheckFactory();
add(chkFactory->id(), chkFactory);
+ // Image size
+ chkFactory = new ImageSizeCheckFactory();
+ add(chkFactory->id(), chkFactory);
+
+ // Do all layer have the image colorspace
+ chkFactory = new ColorModelHomogenousCheckFactory();
+ add(chkFactory->id(), chkFactory);
QList<KoID> allColorModels = \
KoColorSpaceRegistry::instance()->colorModelsList(KoColorSpaceRegistry::AllColorSpaces);
Q_FOREACH(const KoID &colorModelID, allColorModels) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic