Skip to content

Add "propagate colors" filter

Deif Lou requested to merge deiflou/krita:deiflou/propagate_colors_filter into master

This filter expands the colors of an image into the transparent areas.

The original idea came up after BUG:471871 (and relevant MR by Dmitry !1860 (merged)). That bug report required propagating the colors into the transparent areas, but leaving the alpha channel untouched. This can be useful when displaying the images with bilinear filtering that does not pre-multiply the colors, as in the case of the bug report.

Now, there was a thread on KA about implementing a related feature. In this case the propagation of the colors is used to fill the transparent regions on a UV map, avoiding unwanted "spills" of the transparent regions when texturing the models.

Both cases share the fundamental solution, which is propagating the colors into the transparent areas, but the former retains the original alpha channel and the latter also expands it. This filter covers both use cases.

There are a few options:

  • Expansion pattern: The propagation is like a dilation filter although here it is implemented using a distance transform algorithm. This option allows choosing the distance metric for the transform, which can be considered analogous to the dilation kernel shape: rectangle (chessboard metric), diamond (city block metric), octagon (pseudo euclidean, just an approximation due to the distances being propagated locally).

    propagate_colors_01.png

    From left to right: original image; rectangle shaped expansion; diamond shaped expansion; octagon shaped expansion. Note that the octagon approximates better the true euclidean distance, giving a voronoi diagram feel.

  • Expansion distance: The expansion can be restricted to a given distance (think dilation radius), or be unrestricted, so that it covers all the transparent area.

    propagate_colors_02.png

    From left to right: original image; expanded image with unrestricted distance; expanded image with restricted distance.

  • Transparency behavior: One can choose if the alpha channel should be expanded or remain untouched.

    propagate_colors_03.png

    From left to right: the original image; the expanded image with expanded alpha channel; the expanded image preserving the alpha channel (note that it looks like the original one, although the color components were propagated into the transparent areas); the third image after applying a levels filter that makes the transparent areas semi-opaque to clearly see how the colors were truly propagated.

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.
  • Does the patch add a user-visible feature? If yes, is there a documentation MR ready for it at Krita Documentation Repository?

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