Bug 319944

Summary: Clipboard brush is aliased when painting on a rotated canvas
Product: [Applications] krita Reporter: Paul Geraskin <paulgeraskin>
Component: Brush enginesAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: dimula73, ghevan, halla, lukast.dev
Priority: NOR    
Version: git master (please specify the git hash!)   
Target Milestone: ---   
Platform: Other   
OS: All   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Brush blur

Description Paul Geraskin 2013-05-17 11:49:50 UTC
Hi devs!

I tested Gimp and Krita pixel brushes. And Krita has very blurry brush. I guess this is a very vital issue which need to be resolved. 
Screenshot to compare: http://i.imgur.com/sY4C5ct.png
Video which shows what i did: https://vimeo.com/66387286
Source file: https://dl.dropboxusercontent.com/u/26887202/blender/ee.psd

I tried to switch off Size, then set Precision=1 - no effect. The krita's brush is still blurry.

Also, i tried to use Sharpness, but it sharpens only Alpha of the brush (Not RGB).  http://i.imgur.com/wDAtzdd.png

Thanks.
Comment 1 Paul Geraskin 2013-05-17 12:19:02 UTC
Also, use your mouse for testing. Or switch size and opacity off for pen pressure.
Comment 2 vanyossi 2013-05-17 16:08:45 UTC
Created attachment 79937 [details]
Brush blur

I can confirm this bug. No modifiers applied, and brush tip had no scale in it.

It seems the bug is related on how the data is transfer to the canvas as the pixelation varies depending on a small threshold. That's what I try to show at the top. I try to align the shape pixel grid to the canvas layer grid without success.

On pixel perfect brushes the effect is very evident even at normal zoom.
Comment 3 vanyossi 2013-05-17 16:10:25 UTC
Confirming in git master.
Comment 4 LukasT 2013-05-27 06:25:54 UTC
We used to do mip-mapping for bitmap brush masks but it was removed (hint to search in git log:slangkamp iirc) to improve performance without side effect. I'm wondering if this is the side effect or not.
Comment 5 Dmitry Kazakov 2013-07-16 11:00:54 UTC
Git commit b9d749eb4e7c6bbc00332c9d1c090c9a2293af74 by Dmitry Kazakov.
Committed on 16/07/2013 at 10:43.
Pushed by dkazakov into branch 'master'.

A significant refactoring in the Predefined Brush engine

This patch ports the predefined brush engine to the new capabilities
of Qt. It removes a huge chunk of hand-written code. Here is a short list
of changes:

1) All the operations are now performed on non-premultiplied RGB values.
   The use of premultiplication resulted in instability of the color,
   which caused artifacts on scaling and rotation of the brushes.

2) Trilinear filtering of the brushes is now substituted with simple
   bilinear filtering from the nearest pyramid level.

   It turned out that trilinear filtering not only impacted the
   performance, but also introduced heavy aliasing artifacts on specific
   zoom levels.

3) After the patch the speed of the dab generation raised 3-5 times. Here
   are the values for 512px brush:
   Before patch:
      Scaling:   34 ms
      Rotation:  19 ms
   After patch:
      Scaling:   6 ms
      Rotation:  9 ms
Related: bug 320368, bug 300665, bug 320651
CCMAIL:kimageshop@kde.org

M  +1    -2    krita/plugins/paintops/libbrush/CMakeLists.txt
M  +0    -1    krita/plugins/paintops/libbrush/kis_abr_brush.cpp
M  +1    -1    krita/plugins/paintops/libbrush/kis_auto_brush.cpp
M  +70   -778  krita/plugins/paintops/libbrush/kis_brush.cpp
M  +3    -26   krita/plugins/paintops/libbrush/kis_brush.h
M  +2    -3    krita/plugins/paintops/libbrush/kis_gbr_brush.cpp
D  +0    -135  krita/plugins/paintops/libbrush/kis_qimage_mask.cpp
D  +0    -138  krita/plugins/paintops/libbrush/kis_qimage_mask.h
A  +196  -0    krita/plugins/paintops/libbrush/kis_qimage_pyramid.cpp     [License: GPL (v2+)]
A  +52   -0    krita/plugins/paintops/libbrush/kis_qimage_pyramid.h     [License: GPL (v2+)]
D  +0    -64   krita/plugins/paintops/libbrush/kis_scaled_brush.cpp
D  +0    -62   krita/plugins/paintops/libbrush/kis_scaled_brush.h
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_0_sc_0.871853_rot_3.55731_sub_0.137199.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_1_sc_0.861342_rot_3.45867_sub_0.20933.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_2_sc_1.80941_rot_4.97706_sub_0.113862.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_3_sc_0.46124_rot_4.18791_sub_0.167627.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_4_sc_0.963137_rot_2.82314_sub_0.444059.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_5_sc_0.592981_rot_0.439579_sub_0.45074.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_6_sc_1.86775_rot_3.12606_sub_0.365777.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_7_sc_1.13937_rot_3.47854_sub_0.458733.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_8_sc_1.53198_rot_3.68719_sub_0.410264.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/brush_masks/_brush_9_sc_1.46566_rot_2.88023_sub_0.474873.png
M  +-    --    krita/plugins/paintops/libbrush/tests/data/result_autobrush_3.png
M  +-    --    krita/plugins/paintops/libbrush/tests/data/result_autobrush_4.png
A  +-    --    krita/plugins/paintops/libbrush/tests/data/testing_brush_512_bars.gbr
M  +24   -28   krita/plugins/paintops/libbrush/tests/kis_auto_brush_test.cpp
M  +91   -17   krita/plugins/paintops/libbrush/tests/kis_brush_test.cpp
M  +7    -2    krita/plugins/paintops/libbrush/tests/kis_brush_test.h
M  +5    -4    krita/plugins/paintops/libbrush/tests/kis_imagepipe_brush_test.cpp

http://commits.kde.org/calligra/b9d749eb4e7c6bbc00332c9d1c090c9a2293af74
Comment 6 Dmitry Kazakov 2013-07-17 13:40:54 UTC
Git commit fac079a40168ea93da50d2951430b07a8a2a9b0f by Dmitry Kazakov.
Committed on 17/07/2013 at 07:56.
Pushed by dkazakov into branch 'master'.

Properly fix the blurred brushes bug

There should be a small fuzzyness when searching for a proper zoom level

M  +7    -1    krita/plugins/paintops/libbrush/kis_qimage_pyramid.cpp
M  +3    -1    krita/plugins/paintops/libbrush/kis_qimage_pyramid.h
M  +37   -1    krita/plugins/paintops/libbrush/tests/kis_brush_test.cpp
M  +1    -0    krita/plugins/paintops/libbrush/tests/kis_brush_test.h

http://commits.kde.org/calligra/fac079a40168ea93da50d2951430b07a8a2a9b0f
Comment 7 Paul Geraskin 2013-07-17 14:29:49 UTC
Now it works cool.

But if I rotate canvas i get such an issue with antialising http://i.imgur.com/xwWlniw.png
Can you check it? Just rotate canvas...
Comment 8 Dmitry Kazakov 2013-07-17 21:02:33 UTC
Hm, I need to check that...
Comment 9 Dmitry Kazakov 2013-07-19 07:18:55 UTC
This happens because Clipboard brush uses exactBounds() and crops the transparent pixels on the border. Later, when doing transformations, the pixels are not filtered, because there are no transparent pixels to blend with. There may be two options to solve the issue:

1) Add a workaround to clipboard brush (add 1px). That is bad approach.
2) Investigate why QPainter doesn't do filtering when there is no transparent pixels on the border of the source image. That is good approach.
Comment 10 Dmitry Kazakov 2013-12-22 14:57:28 UTC
Git commit 48f8f2ce30a73d545a368b88444fb206e8281e98 by Dmitry Kazakov.
Committed on 22/12/2013 at 14:53.
Pushed by dkazakov into branch 'master'.

Fix smooth rotation of the Predefined Brushes

There is a bug in Qt which prevents a QImage from being transformed
smoothly. See a comment in KisQImagePyramid::appendPyramidLevel.

M  +32   -6    krita/plugins/paintops/libbrush/kis_qimage_pyramid.cpp
M  +11   -1    krita/plugins/paintops/libbrush/kis_qimage_pyramid.h
M  +48   -0    krita/plugins/paintops/libbrush/tests/kis_brush_test.cpp
M  +2    -0    krita/plugins/paintops/libbrush/tests/kis_brush_test.h

http://commits.kde.org/calligra/48f8f2ce30a73d545a368b88444fb206e8281e98
Comment 11 Dmitry Kazakov 2013-12-28 14:52:54 UTC
Git commit 896ba64f39f53adc9e56efbe0070cd40e206026e by Dmitry Kazakov.
Committed on 22/12/2013 at 14:53.
Pushed by dkazakov into branch 'calligra/2.8'.

Fix smooth rotation of the Predefined Brushes

There is a bug in Qt which prevents a QImage from being transformed
smoothly. See a comment in KisQImagePyramid::appendPyramidLevel.

M  +32   -6    krita/plugins/paintops/libbrush/kis_qimage_pyramid.cpp
M  +11   -1    krita/plugins/paintops/libbrush/kis_qimage_pyramid.h
M  +48   -0    krita/plugins/paintops/libbrush/tests/kis_brush_test.cpp
M  +2    -0    krita/plugins/paintops/libbrush/tests/kis_brush_test.h

http://commits.kde.org/calligra/896ba64f39f53adc9e56efbe0070cd40e206026e