[graphics/krita] /: [string freeze exception] [feature] Add Unify Layers Color Space action

Dmitry Kazakov null at kde.org
Fri Nov 22 09:59:51 GMT 2024


Git commit e0529a5168e3cb8e22b6a9d21418913ec379c7d2 by Dmitry Kazakov.
Committed on 22/11/2024 at 09:59.
Pushed by dkazakov into branch 'master'.

[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

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/e0529a5168e3cb8e22b6a9d21418913ec379c7d2

diff --git a/krita/krita.action b/krita/krita.action
index f0c13796fab..1f8fbd6c326 100644
--- a/krita/krita.action
+++ b/krita/krita.action
@@ -3475,6 +3475,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 97b731f87d4..49627cb82c8 100644
--- a/libs/image/kis_image.cc
+++ b/libs/image/kis_image.cc
@@ -1396,6 +1396,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 881883ec6d3..0e904c8bf09 100644
--- a/libs/image/kis_image.h
+++ b/libs/image/kis_image.h
@@ -377,6 +377,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