[graphics/krita/krita/5.2] libs/flake: Force SVG gradients to work in premultiplied alpha mode

Dmitry Kazakov null at kde.org
Thu Jan 15 12:34:23 GMT 2026


Git commit c82e28995d4a0d8e712b1c6f275fc99b75266b55 by Dmitry Kazakov.
Committed on 15/01/2026 at 12:34.
Pushed by dkazakov into branch 'krita/5.2'.

Force SVG gradients to work in premultiplied alpha mode

WARNING: That is against SVG2 specification!

All internal Krita structures, including GUI editor, expect the gradients to work
in premultiplied alpha mode. The change that happened in SvgParser in 2021
changed the behavior of the loading code only. All GUI controls still create
premultiplied gradients, which caused inconsistencies when loading gradients
created in Krita.

What we need to do is to implement a proper support of non-premultiplied
gradients. That includes the following:

1) All GUI controls should support switching the two modes:

   * Stop Gradient Editor
   * Segment Gradient Editor

2) A proper backward compatibility should be present when loading
    gradients from external buffers:

    * SVG gradients (it is a part of .kra format)
    * ASL gradients (questionable)
    * Gimp gradients (questionable)
    *  XML gradietns saved in Fill Layers and Filters

3) Raster gradients painted with KoMixOp should also support
    non-premultiplied mode

4) FgToTransparent auto-gradient should  properly handle the
    "FgTransparent" option.

CC:kimageshop at kde.org
BUG:502118

M  +5    -3    libs/flake/svg/SvgParser.cpp
M  +2    -0    libs/flake/tests/TestSvgParser.cpp

https://invent.kde.org/graphics/krita/-/commit/c82e28995d4a0d8e712b1c6f275fc99b75266b55

diff --git a/libs/flake/svg/SvgParser.cpp b/libs/flake/svg/SvgParser.cpp
index 0acb67a113d..8938926bc09 100644
--- a/libs/flake/svg/SvgParser.cpp
+++ b/libs/flake/svg/SvgParser.cpp
@@ -1101,9 +1101,11 @@ QGradient* prepareGradientForShape(const SvgGradientHelper *gradient,
         }
     }
 
-    // NOTE: this is an internal API in Qt. SVG specs specify that we
-    // shouldn't interpolate in pre-multiplied space.
-    resultGradient->setInterpolationMode(QGradient::ComponentInterpolation);
+    // TODO: all gradients in Krita are rendered in a premultiplied-alpha
+    //       mode, which is against SVG standard. We need to fix that. Though
+    //       it requires deepeer changes, than just mere setting of the
+    //       QGradient's interpolation mode on loading.
+    // resultGradient->setInterpolationMode(QGradient::ComponentInterpolation);
 
     return resultGradient;
 }
diff --git a/libs/flake/tests/TestSvgParser.cpp b/libs/flake/tests/TestSvgParser.cpp
index fa0f468a776..6d10062fb41 100644
--- a/libs/flake/tests/TestSvgParser.cpp
+++ b/libs/flake/tests/TestSvgParser.cpp
@@ -1417,6 +1417,7 @@ void TestSvgParser::testRenderFillLinearGradientTransparent()
 
     SvgRenderTester t(data);
     t.setCheckQImagePremultiplied(true);
+    QEXPECT_FAIL("", "TODO: Krita forces all gradients to work in premultiplied space, which is against SVG spec", Abort);
     t.test_standard_30px_72ppi("fill_gradient_transparent", false);
 }
 
@@ -1484,6 +1485,7 @@ void TestSvgParser::testRenderFillRadialGradientTransparent()
     SvgRenderTester t(data);
     t.setFuzzyThreshold(1);
     t.setCheckQImagePremultiplied(true);
+    QEXPECT_FAIL("", "TODO: Krita forces all gradients to work in premultiplied space, which is against SVG spec", Abort);
     t.test_standard_30px_72ppi("fill_gradient_radial_transparent", false);
 }
 


More information about the kimageshop mailing list