Bug 447293

Summary: Setting blending modes/opacity/position/names of multiple output layers is not managed
Product: [Applications] krita Reporter: David Tschumperlé <David.Tschumperle>
Component: G'Mic for KritaAssignee: amyspark <amy>
Status: RESOLVED FIXED    
Severity: normal CC: amy, thetwo222
Priority: NOR    
Version: 5.0.0-beta5   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: What filter Drop Water produces
What it should produce

Description David Tschumperlé 2021-12-20 15:45:59 UTC
SUMMARY

A few filters of the G'MIC plug-in produce multi-layer output, with sometimes "information" passed to the host software in order to set the blending mode, opacity, name and position of each output layer.
With the same kind of information, a G'MIC filter should have access to the blending mode, opacity, name and position of the input layers passed to the filter.
Apparently, these "layer information" are not managed by Krita, which made these filter not working as they should.

For instance, filter "Deformations / Drop Shadow" is one example of such a filter : it sets the blending mode and a different name to each output layers, as you can see on the attached screenshot (for GIMP).
See the difference with what you get with Krita (both versions have run the filter with the same image and default parameters).

* How layer information works?

When calling the plugin, the list `images_names` passed to the plug-in function `run()` should contains layer information for each layer, passed as a string formated like this:
`name(STR1),opacity(VALUE2),mode(STR3),pos(VALUE4,VALUE5)`
where : 
- `STR1` is a string that corresponds to the layer name.
- `VALUE2` is a float value between [0,1] that indicates the layer opacity.
-  `STR3` is a string (lowercase) that indicates the blending mode (see https://github.com/c-koi/gmic-qt/blob/master/src/Host/Gimp/host_gimp.cpp#L175 to see how these strings are defined for GIMP). 
- `VALUE4,VALUE5` are the (x,y) coordinates of the layer, relatively to the whole image.

Note that this string may not contain all these fields, but only one or two or three of them, in no particular order.

That's for the filter input. And that's the same for the output : a G'MIC filter that wants to pass those layer information to the host software will name its output layers exactly like this, so that the host software can set the layer name, opacity, blending mode and position accordingly.
As I think there are less blending modes in GIMP than in Krita, feel free to add your own strings in the style of the existing ones, so that G'MIC can manage these extra blending modes.
Comment 1 David Tschumperlé 2021-12-20 15:51:46 UTC
Created attachment 144719 [details]
What filter Drop Water produces
Comment 2 David Tschumperlé 2021-12-20 15:52:14 UTC
Created attachment 144720 [details]
What it should produce
Comment 3 amyspark 2021-12-21 14:56:45 UTC
Plugin comms log says:

> krita.plugins: convertFromGmicFast
> krita.plugins: Layer name:  "name([unnamed] [specular spots]),mode(alpha),opacity(100)"
> krita.plugins: Detected mode:  "alpha"  =>  "normal"
> krita.plugins: Detected opacity:  100
> krita.plugins: Detected layer name:  "[unnamed] [specular spots]"
> krita.plugins: pluginFinished 0

I don't see any obvious bugs here, I'll have to dig into the image conversion code.
Comment 4 amyspark 2021-12-21 16:39:39 UTC
Definitely a bug in our image conversion code. 

Currently, we run the G'MIC->Krita layer name parsing only if there is an existing node that is going to be overwritten (via KisImportQmicProcessingVisitor traversal). In this case, there are more output than input layers, so the previous step (KisQmicSynchronizeLayersCommand) will take care of the excess nodes... except that it never runs the name parsing step, so the appropriate layer modes are not set.

While at it, I found another bug regarding Krita->G'MIC layer naming; when I implemented G'MIC's format for layer names, I actually never packed it inside the "message", so G'MIC returns nodes that use it as "[unnamed]".

I'll address both bugs in the MR.
Comment 6 thetwo 2021-12-22 13:51:59 UTC
Is the error related to "position" fixed? When I use a filter that outputs multiple layers like "decompose channels", it outputs the image to the upper left corner
Comment 7 amyspark 2021-12-23 16:37:52 UTC
Git commit 540942d8086e32fad496780d18f76addf97cf22e by L. E. Segovia.
Committed on 23/12/2021 at 16:36.
Pushed by lsegovia into branch 'master'.

Use the G'MIC formatted layer name for Krita->G'MIC comms
Related: bug 429851

M  +1    -1    plugins/extensions/qmic/kis_qmic_interface.cpp

https://invent.kde.org/graphics/krita/commit/540942d8086e32fad496780d18f76addf97cf22e
Comment 8 amyspark 2021-12-23 16:38:01 UTC
Git commit a1dbad405f55fd352e0d45c9df09c2bfc9abeeec by L. E. Segovia.
Committed on 23/12/2021 at 16:36.
Pushed by lsegovia into branch 'master'.

Fix blending modes missing from G'MIC filters

The layer name parsing must be applied also to excess nodes (and not
only those parsed by the visitor).

M  +2    -0    plugins/extensions/qmic/kis_qmic_synchronize_layers_command.cpp

https://invent.kde.org/graphics/krita/commit/a1dbad405f55fd352e0d45c9df09c2bfc9abeeec
Comment 9 amyspark 2021-12-23 16:42:13 UTC
Git commit e003f328f73c438818ef749ec2239ddfbe81cacb by L. E. Segovia.
Committed on 23/12/2021 at 16:38.
Pushed by lsegovia into branch 'krita/5.0'.

Use the G'MIC formatted layer name for Krita->G'MIC comms
Related: bug 429851
(cherry picked from commit 540942d8086e32fad496780d18f76addf97cf22e)

M  +1    -1    plugins/extensions/qmic/kis_qmic_interface.cpp

https://invent.kde.org/graphics/krita/commit/e003f328f73c438818ef749ec2239ddfbe81cacb
Comment 10 amyspark 2021-12-23 16:42:29 UTC
Git commit 37d49dc6b9144760c0d4872dda4fb61af541b6bb by L. E. Segovia.
Committed on 23/12/2021 at 16:38.
Pushed by lsegovia into branch 'krita/5.0'.

Fix blending modes missing from G'MIC filters

The layer name parsing must be applied also to excess nodes (and not
only those parsed by the visitor).
(cherry picked from commit a1dbad405f55fd352e0d45c9df09c2bfc9abeeec)

M  +2    -0    plugins/extensions/qmic/kis_qmic_synchronize_layers_command.cpp

https://invent.kde.org/graphics/krita/commit/37d49dc6b9144760c0d4872dda4fb61af541b6bb