Skip to content

Add new "grow" selection filter that can stop growing at the darkest pixels

This MR implements the "To darkest pixel" option present in the clip studio paint fill/selection tools.

Pinging @rkolemios to see if they can take a look at this.

Explanation

When using a tool like the fill tool, sometimes it is needed to grow the selection so that it looks better (for example growing it so that the semi-transparent pixels are covered):

01

The problem with that is that the selection is grown uniformly on all sides. This can leave to undesired results for example if one tries to fill some lineart that has variable line with:

02

A new button next to the grow slider allows to activate the "stop growing at the darkest or most opaque pixels" option. This will stop the growing of the selection as soon as some pixel is lighter or less opaque than the previous one:

03

Implementation details

This is implemented as a new selection filter. It applies a dilation and uses an additional reference paint device to check if the pixels got lighter or less opaque.

The main problem I found is that it seems that for the correct check of the changes on intensity/opacity, one should grow the selection in severa 1px dilation iterations. With the approach used by the grow filter I could not come up with a solution to that. So I implemented a dilation with a flat square shaped structuring element. That way I can simulate the iterative approach efficiently and correctly check the reference pixels. The square shaped SE looks worst than the disk shaped one used by the grow filter. But since the resulting dilated selection will have the borders "chopped off" I don't think that matters. CSP also uses another simpler SE for this, I think it is a diamond shaped one.

Test Plan

  • Activate the fill, contiguous/similar selection, enclose and fill tools.
  • Set the grow option to some value greater than 0.
  • Check the "stop at darkest pixels" button to the right of the grow slider.
  • Use the tool to fill/select some region surrounded by lineart for example.
  • See if the fill/selection stopped growing at the darkest or most opaque pixels.

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.
Edited by Deif Lou

Merge request reports