Skip to content

Fix issues generating reference image in KisMergeLabeledLayersCommand

This tries to tackle BUG:471896 and BUG:472700 and probably other issues.

The mechanism to get a image from a subset of color-labeled layers to be used as reference for the fill tool (and other similar tools) right now consists on selecting those relevant layers, copy them and put them in a new temporary image. Then that temporary image if flattened so that a single paint device is generated and used by the tools.

Generating a good image from the subset of color-labeled layers can be a bit tricky. Ideally it should resemble as much as possible the look of the real image, but this is not always possible due to the potentially sparse nature of the subset of required layers. Some of the issues are:

  • The selected layers can be far apart in the layer stack, so, if they have some blend mode other than normal, the look of the reference image can be very different from that of the original image. This is because it can be less in-between layers in the reference image. The current approach to solve this is to just override the blend mode of the layers in the reference image, setting it always to normal. Since the layers used as reference usually are simple enough, this seems to not be a problem at the moment. This also seems to allow storing the nodes as a flat list instead of a tree, which reduces complexity on the process.
  • Handling of layers that need other layers. The issue here is mainly with group, clone and filter layers.
    • If a group layer is labeled and added, we also need to add all the children. This is simply achieved by adding the group node. We must ensure that the children of this node are not visited to avoid duplication. If a group is not labeled with a suitable color label, then its children need to be visited to collect the layers that are labeled.
    • If a clone layer is labeled and should be added, we also need the original source layer on the reference image somehow. To simplify this, the clone layer is not used, but a paint layer copy of it. So the clone layer is kind of baked on this new paint layer. This way we don't have to worry about dependencies.
    • If a filter layer is labeled and should be added, in principle we would also need to add all the layers that are bellow this one. One simplification to this problem is to just take the projection and put it on a paint layer, similar to the clone layer case. This is also similar to the group layer case in that this new layer will already contain the contents of all the layers bellow, so those layers can be skipped. To achieve this it is simpler to traverse the nodes from top to bottom (in terms of layer stack).

BUG:471896 BUG:472700

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.

Reminder: the reviewer is responsible for merging the patch, this is to ensure at the least two people can build the patch. In case a patch breaks the build, both the author and the reviewer should be contacted to fix the build. If this is not possible, the commits shall be reverted, and a notification with the reasoning and any relevant logs shall be sent to the mailing list, kimageshop@kde.org.

Edited by Deif Lou

Merge request reports