Krita Source Code Documentation
Loading...
Searching...
No Matches
ColorModelHomogenousCheck.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef COLORMODELHOMOGENOUSCHECK_H
8#define COLORMODELHOMOGENOUSCHECK_H
9
11#include <KoID.h>
12#include <klocalizedstring.h>
13#include <kis_image.h>
14#include <KoColorSpace.h>
16#include <kis_layer.h>
17#include <kis_node_visitor.h>
18#include "kis_node.h"
19#include "kis_paint_layer.h"
20#include "kis_group_layer.h"
23#include "kis_clone_layer.h"
25
27{
28public:
29
31
32 KisColorModelHomogenousCheckVisitor(KoID colorModelID, KoID colorDepthID)
33 : m_count(0)
34 , m_colorModelID(colorModelID)
35 , m_colorDepthID(colorDepthID)
36 {
37 }
38
39 quint32 count() {
40 return m_count;
41 }
42
43 bool visit(KisNode* node) override {
44 return check(node);
45 }
46
47 bool visit(KisPaintLayer *layer) override {
48 return check(layer);
49 }
50
51 bool visit(KisGroupLayer *layer) override {
52 return check(layer);
53 }
54
55
56 bool visit(KisAdjustmentLayer *layer) override {
57 return check(layer);
58 }
59
60 bool visit(KisExternalLayer *layer) override {
61 return check(layer);
62 }
63
64 bool visit(KisCloneLayer *layer) override {
65 return check(layer);
66 }
67
68 bool visit(KisGeneratorLayer * layer) override {
69 return check(layer);
70 }
71
72 bool visit(KisFilterMask *) override {return true;}
73
74 bool visit(KisTransformMask *) override {return true;}
75
76 bool visit(KisTransparencyMask *) override {return true;}
77
78 bool visit(KisSelectionMask *) override {return true;}
79
80 bool visit(KisColorizeMask *) override {return true;}
81
82
83private:
84 bool check(KisNode * node)
85 {
86 KisLayer *layer = dynamic_cast<KisLayer*>(node);
87 if (layer && !layer->isFakeNode()) {
88
89 const KoColorSpace * cs = layer->colorSpace();
90 if (cs->colorModelId() != m_colorModelID || cs->colorDepthId() != m_colorDepthID) {
91 m_count++;
92 }
93 }
94 visitAll(node);
95 return true;
96 }
97
98 quint32 m_count;
101
102};
103
105{
106public:
107
108 ColorModelHomogenousCheck(const QString &id, Level level, const QString &customWarning = QString())
109 : KisExportCheckBase(id, level, customWarning, true)
110 {
111 if (customWarning.isEmpty()) {
112 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.");
113 }
114 }
115
116 bool checkNeeded(KisImageSP image) const override
117 {
118 const KoColorSpace *cs = image->colorSpace();
120 image->rootLayer()->accept(v);
121 return (v.count() > 0);
122 }
123
124 Level check(KisImageSP /*image*/) const override
125 {
126 return m_level;
127 }
128
129};
130
132{
133public:
134
138
140
141 KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override
142 {
143 return new ColorModelHomogenousCheck(id(), level, customWarning);
144 }
145
146 QString id() const override {
147 return "ColorModelHomogenousCheck";
148 }
149
150};
151
152
153#endif // COLORMODELHOMOGENOUSCHECK_H
qreal v
KisExportCheckBase * create(KisExportCheckBase::Level level, const QString &customWarning) override
Level check(KisImageSP) const override
bool checkNeeded(KisImageSP image) const override
ColorModelHomogenousCheck(const QString &id, Level level, const QString &customWarning=QString())
bool visit(KisGeneratorLayer *layer) override
bool visit(KisExternalLayer *layer) override
bool visit(KisPaintLayer *layer) override
bool visit(KisSelectionMask *) override
bool visit(KisAdjustmentLayer *layer) override
KisColorModelHomogenousCheckVisitor(KoID colorModelID, KoID colorDepthID)
bool visit(KisTransparencyMask *) override
bool visit(KisColorizeMask *) override
bool visit(KisCloneLayer *layer) override
bool visit(KisGroupLayer *layer) override
bool visit(KisTransformMask *) override
The KisExportCheckBase class defines the interface of the individual checks of an export filter's cap...
virtual QString id() const
KisGroupLayerSP rootLayer() const
const KoColorSpace * colorSpace() const
virtual bool visit(KisNode *node)=0
bool visitAll(KisNode *node, bool breakOnFail=false)
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
Definition KoID.h:30
virtual bool isFakeNode() const
bool accept(KisNodeVisitor &v) override
const KoColorSpace * colorSpace() const override
returns the image's colorSpace or null, if there is no image
Definition kis_layer.cc:225