Bug 418406

Summary: A Rotation Transform around the 'x' or 'y' axis (not 'z' axis) caused loss of off-canvas content
Product: [Applications] krita Reporter: Ahab Greybeard <ahab.greybeard>
Component: Tools/TransformAssignee: Dmitry Kazakov <dimula73>
Status: RESOLVED FIXED    
Severity: normal CC: dimula73, raghu, rebecca
Priority: NOR    
Version First Reported In: nightly build (please specify the git hash!)   
Target Milestone: ---   
Platform: Debian stable   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: off canvas content due to 'y' axis rotation
lost off-canvas content due to 'y' axis rotatiob

Description Ahab Greybeard 2020-03-02 17:18:07 UTC
Created attachment 126550 [details]
off canvas content due to 'y' axis rotation

SUMMARY
If the Transform tool is used in Rotation mode so that 'x' or 'y' axis rotations can be done and these operations result in off-canvas content, that off-canvas content is lost/discarded.
If a 'z' axis rotation is done, any resulting off-canvas content is preserved.

This has been observed in the Feb 21st 4.3.0-prealpha (git 2b45b5d).
[This is the latest one I've been able to get due to ongoing problems with appimage downloads.]

STEPS TO REPRODUCE
1. Create content and do a 'y' axis rotation to give off-canvas content such as shown in "y-axis-rot-go-off-canvas.png"
2. Apply the transform and use the Move tool to try to bring the off-canvas content back on-canvas.
3. Note that the off-canvas content has been discarded as shown in "y-axis-rot-lost-off-canvas-content.pmg"
4. Repeat with a 'x' axis rotation and note a similar loss of resultign off-canvas content.
5. Repeat with 'z' axis rotation and note that resulting off-canvas content is preserved.

OBSERVED RESULT
See Steps to reproduce

EXPECTED RESULT
Off-canvas content should be preserved.

SOFTWARE/OS VERSIONS
Krita

 Version: 4.3.0-prealpha (git 2b45b5d)
 Languages: en_GB, en, en, en_GB, en
 Hidpi: true

Qt

  Version (compiled): 5.12.5
  Version (loaded): 5.12.5

OS Information

  Build ABI: x86_64-little_endian-lp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: linux
  Kernel Version: 4.19.0-8-amd64
  Pretty Productname: Debian GNU/Linux 10 (buster)
  Product Type: debian
  Product Version: 10

OpenGL Info
 
  Vendor:  "NVIDIA Corporation" 
  Renderer:  "GeForce GTX 750 Ti/PCIe/SSE2" 
  Version:  "4.6.0 NVIDIA 418.74" 
  Shading language:  "4.60 NVIDIA" 
  Requested format:  QSurfaceFormat(version 3.0, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 0, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::CompatibilityProfile) 
  Current format:    QSurfaceFormat(version 4.6, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 0, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::CompatibilityProfile) 
     Version: 4.6
     Supports deprecated functions true 
     is OpenGL ES: false 

QPA OpenGL Detection Info 
  supportsDesktopGL: true 
  supportsOpenGLES: true 
  isQtPreferOpenGLES: false
Comment 1 Ahab Greybeard 2020-03-02 17:19:01 UTC
Created attachment 126551 [details]
lost off-canvas content due to 'y' axis rotatiob
Comment 2 Rebecca Breu 2020-03-02 18:05:36 UTC
I can confirm this for both the 4.2.8 version and today's nightly appimage 4c27cab.
Comment 3 Dmitry Kazakov 2020-08-20 22:31:03 UTC
Well, that is done semi-intentionally. The problem is that perspective transforms can easily grow really large, sometimes to the infinity. So all the perspective transforms limit the result to the bounds of the image.

I'm not sure how to resolve this bug correctly. There should still some limit, though I don't know how big.
Comment 4 Ahab Greybeard 2020-08-21 08:47:24 UTC
@Dmitry re. Comment 3.
I was working with Rotation but I now see that it also happens with a Perspective transform.
There would be a further problem/complication caused by any pre-existing off canvas content (intentional or not) that would be included in the content bounding box for the transform.
For Rotation, you can have transformed content that's beyond infinity (it's behind your head) and that would be a very difficult problem

For the Rotation transform, there is a bug report which is associated with this issue:
https://bugs.kde.org/show_bug.cgi?id=418557
This is classed as Wishlist. I believe that if that bug was dealt with then it would mostly take care of the problem for Rotation transforms for the x/y axis.

It may be possible to determine a 'reasonable working limit' for keeping content but it would be a lot of work and I doubt that many people do x/y rotations of that nature anyway.
For now, there is a possible workaround (for Rotation and Perspective) where you Resize the canvas so that the transformed content stays on canvas and then you can deal with it as needed.

Maybe you could put this on your backburner until all other bugs are fixed :)
Comment 5 Dmitry Kazakov 2021-06-03 07:49:26 UTC
*** Bug 437956 has been marked as a duplicate of this bug. ***
Comment 6 Dmitry Kazakov 2021-06-03 07:52:58 UTC
Git commit db6406a6c27ddf11874a7e72d8e2c066954f3d7e by Dmitry Kazakov.
Committed on 03/06/2021 at 07:52.
Pushed by dkazakov into branch 'master'.

Fix losing off-canvas data when doing perspective trasnform

Basically, off-canvas cropping is needed only for the transform
mask. The transform tool should transform the entire image all the
time.

The only danger of this change is that perspective transform can
easily grow to infinity. But I didn't manage to reproduce this growth
with the transform tool. I guess it is only possible with the transform
mask (when the source layer is moved).

M  +1    -1    libs/image/kis_fill_painter.cc
M  +7    -5    libs/image/kis_perspectivetransform_worker.cpp
M  +3    -2    libs/image/kis_perspectivetransform_worker.h
M  +1    -1    libs/image/kis_transform_mask.cpp
M  +1    -1    libs/image/tests/kis_perspective_transform_worker_test.cpp
M  +1    -1    libs/image/tests/kis_transform_worker_test.cpp
M  +1    -1    plugins/tools/tool_transform2/kis_transform_mask_adapter.cpp
M  +25   -5    plugins/tools/tool_transform2/kis_transform_utils.cpp
M  +5    -0    plugins/tools/tool_transform2/kis_transform_utils.h

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