Bug 396131

Summary: [File Layers] Wrong (up)scaling of File layer when this one has transparency around it.
Product: [Applications] krita Reporter: David REVOY <info>
Component: Layer StackAssignee: Dmitry Kazakov <dimula73>
Status: RESOLVED FIXED    
Severity: normal CC: dimula73, freebox64, halla
Priority: NOR    
Version: git master (please specify the git hash!)   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Video

Description David REVOY 2018-07-03 15:58:26 UTC
To reproduce:
=============
1. Open https://www.peppercarrot.com/extras/forum/256x256_base-canvas.png in Krita.
2. Download https://www.peppercarrot.com/extras/forum/128x128_overlay-center.png on disk
3. Drag'n'Drop 128x128_overlay-center.png over the canvas (256x256_base-canvas.png) and "Insert as a New File Layer"
4. Open the Layer properties(right click on layer>Properties)
5. Select "Scale to Image Size"

Result
======
The 128x128 picture doesn't strecht to the 256x256 image. It even transform without any reason into a 512x512px File Layer.

Interesting fact: if you take a picture without opacity like https://www.peppercarrot.com/extras/forum/128x128_overlay.png ; Krita upscale the picture correctly.
Comment 1 Halla Rempt 2018-07-10 13:35:41 UTC
Hm, here it does scale to 256x256, but it is placed with the top-level corner in the center of the image after setting the scale to image size option.
Comment 2 David REVOY 2018-07-11 08:00:19 UTC
Here I have this result after scaling:
https://www.peppercarrot.com/extras/temp/2018-07-11_screenshot_094840_net.jpg

If I move it/recenter it:
https://www.peppercarrot.com/extras/temp/2018-07-11_screenshot_094945_net.jpg

It looks like Krita autocrop the transparent pixels around the original 128x128 and then upscale the obtained new geometry (the central part) to 256x256, and also move a top-left corner to centerX and centerY of the canvas.

Expected would be:
https://www.peppercarrot.com/extras/temp/2018-07-11_screenshot_095056_net.jpg
...to respect the transparent padding around the original 128x128 picture.
Comment 3 mvowada 2018-09-07 11:21:11 UTC
Created attachment 114823 [details]
Video

Hi, in my case, I'm getting the same behaviour as David (see video - Krita Appimage 4.2.0-pre-alpha (git 65a1598) - Ubuntu 14.04, Unity).
Comment 4 Dmitry Kazakov 2020-08-13 13:58:25 UTC
Git commit 9f4810685ded1d9ee1ac0b654416d7c61b56c42f by Dmitry Kazakov.
Committed on 13/08/2020 at 13:56.
Pushed by dkazakov into branch 'krita/4.3'.

Fix scaling of file layers with transparent background

For upscaling/downscaling the image we should use its physical
size saved in the original file, not just the bounding rect
calculated with exactBounds().

This patch may change the look of existing .kra files, but we
can consider this case inexistent, because the offset of
transparent file layers has always been calculated incorrectly.
I don't think anyone could use the feature for transparent
layers because of that.
CC:kimageshop@kde.org

M  +9    -7    libs/ui/kis_file_layer.cpp
M  +1    -1    libs/ui/kis_file_layer.h
M  +4    -1    libs/ui/kis_safe_document_loader.cpp
M  +1    -1    libs/ui/kis_safe_document_loader.h

https://invent.kde.org/graphics/krita/commit/9f4810685ded1d9ee1ac0b654416d7c61b56c42f
Comment 5 Dmitry Kazakov 2020-08-13 13:59:29 UTC
Git commit ab91d8ee40021a5ce35d4da40191a545996f281e by Dmitry Kazakov.
Committed on 13/08/2020 at 13:59.
Pushed by dkazakov into branch 'master'.

Fix scaling of file layers with transparent background

For upscaling/downscaling the image we should use its physical
size saved in the original file, not just the bounding rect
calculated with exactBounds().

This patch may change the look of existing .kra files, but we
can consider this case inexistent, because the offset of
transparent file layers has always been calculated incorrectly.
I don't think anyone could use the feature for transparent
layers because of that.
CC:kimageshop@kde.org

M  +9    -7    libs/ui/kis_file_layer.cpp
M  +1    -1    libs/ui/kis_file_layer.h
M  +4    -1    libs/ui/kis_safe_document_loader.cpp
M  +1    -1    libs/ui/kis_safe_document_loader.h

https://invent.kde.org/graphics/krita/commit/ab91d8ee40021a5ce35d4da40191a545996f281e