Bug 502914

Summary: White background on layer paste
Product: [Applications] krita Reporter: Jonas <jonas.peche>
Component: Layer StackAssignee: Krita Bugs <krita-bugs-null>
Status: REPORTED ---    
Severity: normal CC: halla, m-kde
Priority: NOR    
Version First Reported In: 5.2.9   
Target Milestone: ---   
Platform: Manjaro   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Jonas 2025-04-17 07:56:27 UTC
SUMMARY
When copying a selection of a layer from one document to another, I receive a new layer with the dimension of the selection. When copying the entire layer, however, the resulting layer will have a white background.
This behavior feels inconsistent, and I failed to find a way to avoid this. The pasted layer has an alpha channel.


STEPS TO REPRODUCE
1. Create two documents, a small one and a large one.
2. Select the entire small document, copy it, and paste it into the larger one
3. Observe the white background on the entire layer.

OBSERVED RESULT
White background on the pasted layer.

EXPECTED RESULT
No/transparent background.


SOFTWARE/OS VERSIONS
Operating System: Manjaro Linux 
KDE Plasma Version: 6.2.5
KDE Frameworks Version: 6.10.0
Qt Version: 6.8.2
Kernel Version: 6.1.127-2-MANJARO (64-bit)
Graphics Platform: X11
Processors: 12 ร— AMD Ryzen 5 5600X 6-Core Processor
Memory: 31.3 GiB of RAM
Graphics Processor: NVIDIA GeForce RTX 3060/PCIe/SSE2
Comment 1 Halla Rempt 2025-04-17 08:25:09 UTC
I cannot reproduce this with the 5.2.9 appimage. Maybe some steps are missing ?
Comment 2 Jonas 2025-04-17 09:00:32 UTC
(In reply to Halla Rempt from comment #1)
> I cannot reproduce this with the 5.2.9 appimage. Maybe some steps are
> missing ?

I'm using the version on the AUR, but just tried the 5.2.9 appimage as well. I recorded the process, first copying a subset which is working as expected, then copying the whole layer with the white background thingy: https://streamable.com/sbdlep
Comment 3 Bug Janitor Service 2025-04-18 03:47:07 UTC
๐Ÿ›๐Ÿงน Thanks for your comment!

Automatically switching the status to REPORTED so the team can perform further triage.

In the future you may also do this yourself when providing needed information.
Comment 4 Jonas 2025-04-19 08:19:56 UTC
I dug into the source and tracked down what is happening exactly: The default layer has a default pixel with 100% opaque. When copying the full layer, this default pixel is not cleared.

Specifically, here is the check whether a transparent default pixel is required on the copied, trimmed layers: https://github.com/KDE/krita/blob/8345697b0eedfbc1c38617c7344124e0b61557ea/libs/ui/actions/kis_selection_action_factories.cpp#L90

I personally don't think it's expected to copy the default pixel at all when a selection is active, especially when pasting into another document where there is already a background layer.

So basically simplifying it down to
`const bool needsTransparentPixel = selection && hasNonTransparentDefaultPixel;`
such that it only keeps the default pixel when no selection is active (and thus the layer itself is meant to be copied)