[graphics/krita/krita/5.2] /: [string freeze exception] [feature] Add Unify Layers Color Space action
Dmitry Kazakov
null at kde.org
Fri Nov 22 10:03:21 GMT 2024
Git commit 2b9407b26ea462973062d544dc7975c0e377b434 by Dmitry Kazakov.
Committed on 22/11/2024 at 10:03.
Pushed by dkazakov into branch 'krita/5.2'.
[string freeze exception] [feature] Add Unify Layers Color Space action
Sometimes the user may end up with the image consisting of layers in different color
spaces, e.g. sRGB vs Adobe RGB. That might significantly decrease the speed,
with which Krita renders the image, making it almost unusable to work with
(if the size of the image is like 50 layers in 4k in float16 space).
The patch implement a simple hot-fix for this issue. When triggered,
"Unify Layers Color Space" walks through all the layers in the document
and converts them into the image color space. It may increase the rendering speed
up to 2x times(!) in some circumstances.
The action is not present in menus (to not break xmlgui for our users). To trigger the action
use the "Search Action" shortcut:
1) Press Cltr+Enter
2) Type "Unify" to find the action
3) Confirm with Enter key
CC:kimageshop at kde.org
CC:kde-i18n-doc at kde.org
M +12 -0 krita/krita.action
M +24 -0 libs/image/kis_image.cc
M +8 -0 libs/image/kis_image.h
M +10 -0 plugins/extensions/colorspaceconversion/colorspaceconversion.cc
M +1 -1 plugins/extensions/colorspaceconversion/colorspaceconversion.h
https://invent.kde.org/graphics/krita/-/commit/2b9407b26ea462973062d544dc7975c0e377b434
diff --git a/krita/krita.action b/krita/krita.action
index 9ae968f0fbc..70103daa3b9 100644
--- a/krita/krita.action
+++ b/krita/krita.action
@@ -3419,6 +3419,18 @@
<isCheckable>false</isCheckable>
<statusTip/>
</Action>
+ <Action name="unifylayerscolorspace">
+ <icon/>
+ <text>Unify Layers Color Space</text>
+ <whatsThis/>
+ <toolTip>Convert all the layers into the image color space (if they happen to have a different color space)</toolTip>
+ <iconText>Unify Layers Color Space</iconText>
+ <activationFlags>100000</activationFlags>
+ <activationConditions>1</activationConditions>
+ <shortcut/>
+ <isCheckable>false</isCheckable>
+ <statusTip/>
+ </Action>
<Action name="merge_layer">
<icon>merge-layer-below</icon>
<text>&Merge with Layer Below</text>
diff --git a/libs/image/kis_image.cc b/libs/image/kis_image.cc
index 73ab97ab395..4bdeda941f7 100644
--- a/libs/image/kis_image.cc
+++ b/libs/image/kis_image.cc
@@ -1379,6 +1379,30 @@ void KisImage::convertImageProjectionColorSpace(const KoColorSpace *dstColorSpac
KoColorConversionTransformation::internalConversionFlags());
}
+void KisImage::unifyLayersColorSpace()
+{
+ const KUndo2MagicString actionName = kundo2_i18n("Unify Layers Color Space");
+
+ KisImageSignalVector emitSignals;
+
+ KisProcessingApplicator::ProcessingFlags flags =
+ KisProcessingApplicator::NO_UI_UPDATES | KisProcessingApplicator::RECURSIVE;
+
+ KisProcessingApplicator applicator(this, m_d->rootLayer,
+ flags,
+ emitSignals, actionName);
+
+ // src and dst color spaces coincide, since we should just unify
+ // all our layers
+ applicator.applyVisitor(
+ new KisConvertColorSpaceProcessingVisitor(
+ m_d->colorSpace, m_d->colorSpace,
+ KoColorConversionTransformation::internalRenderingIntent(),
+ KoColorConversionTransformation::internalConversionFlags()),
+ KisStrokeJobData::CONCURRENT);
+
+ applicator.end();
+}
bool KisImage::assignLayerProfile(KisNodeSP node, const KoColorProfile *profile)
{
diff --git a/libs/image/kis_image.h b/libs/image/kis_image.h
index 452f5c1af1c..7eda5051c05 100644
--- a/libs/image/kis_image.h
+++ b/libs/image/kis_image.h
@@ -372,6 +372,14 @@ public:
KoColorConversionTransformation::Intent renderingIntent,
KoColorConversionTransformation::ConversionFlags conversionFlags);
+ /**
+ * Unify layers color space
+ *
+ * If any of the layers have color space different from the image color space,
+ * convert them into the image color space.
+ */
+ void unifyLayersColorSpace();
+
/**
* Convert layer and all its child layers to dstColorSpace
*/
diff --git a/plugins/extensions/colorspaceconversion/colorspaceconversion.cc b/plugins/extensions/colorspaceconversion/colorspaceconversion.cc
index 4bc2a0692ea..04bdfdff55d 100644
--- a/plugins/extensions/colorspaceconversion/colorspaceconversion.cc
+++ b/plugins/extensions/colorspaceconversion/colorspaceconversion.cc
@@ -45,6 +45,9 @@ ColorSpaceConversion::ColorSpaceConversion(QObject *parent, const QVariantList &
action = viewManager()->actionManager()->createAction("layercolorspaceconversion");
connect(action, SIGNAL(triggered()), this, SLOT(slotLayerColorSpaceConversion()));
+
+ action = viewManager()->actionManager()->createAction("unifylayerscolorspace");
+ connect(action, SIGNAL(triggered()), this, SLOT(slotUnifyLayersColorSpace()));
}
ColorSpaceConversion::~ColorSpaceConversion()
@@ -102,4 +105,11 @@ void ColorSpaceConversion::slotLayerColorSpaceConversion()
delete dlgColorSpaceConversion;
}
+void ColorSpaceConversion::slotUnifyLayersColorSpace()
+{
+ KisImageSP image = viewManager()->image().toStrongRef();
+ if (!image) return;
+ image->unifyLayersColorSpace();
+}
+
#include "colorspaceconversion.moc"
diff --git a/plugins/extensions/colorspaceconversion/colorspaceconversion.h b/plugins/extensions/colorspaceconversion/colorspaceconversion.h
index 237c7eb84c8..76348d7e543 100644
--- a/plugins/extensions/colorspaceconversion/colorspaceconversion.h
+++ b/plugins/extensions/colorspaceconversion/colorspaceconversion.h
@@ -24,9 +24,9 @@ public:
~ColorSpaceConversion() override;
private Q_SLOTS:
-
void slotImageColorSpaceConversion();
void slotLayerColorSpaceConversion();
+ void slotUnifyLayersColorSpace();
};
#endif // COLORSPACECONVERSION_H
More information about the kimageshop
mailing list