Bug 456357

Summary: Selecting with wand and then doing an invert selection, breaks Trim with Selection
Product: [Applications] krita Reporter: DonnyV <donnyv>
Component: Tools/SelectionAssignee: Krita Bugs <krita-bugs-null>
Status: CONFIRMED ---    
Severity: normal CC: ghevan, ginoba, spamless.9v5xj
Priority: NOR    
Version First Reported In: 5.0.6   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Other   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description DonnyV 2022-07-05 15:11:21 UTC
SUMMARY
If you have a photo in the middle of the canvas and the canvas is bigger than the photo. You then use the selection wand to select the area around the photo and then do a an inverse selection. The photo should now be selected. If you use the "Trim with Selection" tool, nothing happens. 

I see this was an issue back in 2019 also.
https://forum.kde.org/viewtopic.php?f=139&t=161075

OBSERVED RESULT
Nothing happens

EXPECTED RESULT
Expecting the photo to be cropped based on the inverted selection. 

SOFTWARE/OS VERSIONS
Windows: Win 10
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 vanyossi 2022-07-05 17:04:30 UTC
Tested in master (c65b9e93e5) 

This happens after "invert selection" is used, trim to selection does not work as expected. It appears to be triming as if the selection before invert is added to the inverted selection. To test this:

1. Select a frame half image and half outside the image
2. Invert selection, this selects all inside the image but the half previously selected.
3. Trim selection

To the user the selection should crop, but instead the trimming makes the canvas grow.
Comment 2 Deif Lou 2022-07-05 20:40:35 UTC
I think that after inverting the small portion inside the image is selected, but also the entire area outside the image, since the default pixel is changed to full selected value. The area selected due to the default pixel being fully selected is not marked with the marching ants (since it is nor really part of the selection pixels).

To see this one can:
1. select the area around the object of interest with the contiguous selection tool
2. invert the selection
3. change the canvas dimensions to a bigger size
4. fill the selection
5. some area in the borders (the area that is new after resizing the canvas) is also filled but it is not marked with the marching ants.

Maybe one solution is to intersect the selection with the image rect before trimming.