Bug 431192 - Transparent gap between layer content and stroke layer style
Summary: Transparent gap between layer content and stroke layer style
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: layer styles (show other bugs)
Version: 4.4.1
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Dmitry Kazakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-05 18:44 UTC by San Jacobs
Modified: 2021-08-06 10:19 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Visual comparison of observed (Krita) and expected result (Photoshop). (280.89 KB, image/jpeg)
2021-01-05 18:44 UTC, San Jacobs
Details
Krita file with examples of inside and outside (57.52 KB, application/x-krita)
2021-01-05 18:51 UTC, San Jacobs
Details

Note You need to log in before you can comment on or make changes to this bug.
Description San Jacobs 2021-01-05 18:44:43 UTC
Created attachment 134584 [details]
Visual comparison of observed (Krita) and expected result (Photoshop).

SUMMARY
When using the layer style stroke with position outside, there is a transparent gap between any anti-aliased edges of the layer content and the stroke.

The same, but opposite is true about using the position inside. However, instead of a transparent gap, the original layer's color shines through where the outer edge of the stroke and the layer content meet.

STEPS TO REPRODUCE
0. Create white background layer
1. Create layer with black content with anti-aliased edges to transparency
2. Enable the stroke layer style
3a. Set stroke position to outside with white color
3b. Set stroke position to inside with black color

OBSERVED RESULT
Inside position: An edge where the color of the content and the stroke mix.
Outside position: An edge where the color of the content and the stroke mix.

EXPECTED RESULT
The same color at the edge as in the stroke.


ADDITIONAL INFORMATION
Outside can be solved by rendering the stroke as done with center-position, but double thickness and below the layer in question.
Comment 1 Tiar 2021-01-05 18:47:32 UTC
Can you also please add a simple small test file for Krita? With one layer showing the problem on the inside and another showing the outside. Thanks in advance!
Comment 2 San Jacobs 2021-01-05 18:51:26 UTC
Created attachment 134585 [details]
Krita file with examples of inside and outside
Comment 3 San Jacobs 2021-01-05 18:51:53 UTC
(In reply to Tymond from comment #1)

Yes, definitely!
Comment 4 Tiar 2021-01-05 23:31:47 UTC
Confirmed.
Comment 5 Dmitry Kazakov 2021-08-06 10:19:54 UTC
Git commit 2599be61082982a3d07edb588098f671ecce2ac7 by Dmitry Kazakov.
Committed on 06/08/2021 at 10:19.
Pushed by dkazakov into branch 'master'.

Fix holes in the Stroke layers style

The stroke should be applied on maxed out layer's projection to
make sure knock-out blending works fine.

Stroke merging process is complicated and performs some kind of
"knockout" method. First both, the layer and the stroke, are applied to
the backdrop independently. Then the result is blended together using
the knockout selection (the contour of the stroke).

And to fix the border effects we need to either ceil or floor the
layer's projection's border opacity. It guarantees that the mixing
code mixes the real color, but not it antialiased version.

If we try to find a vague analogy with the PDF specification, then
the knockout selection will be the "shape" of the stroke. And the
opacity value of the layer effect will be "opacity" of the stroke.

Therefore we first blend a 100%-alpha versions of the stroke and
a layer the backdrop using their corresponding opacity*
vallues, and then we blend two results using the "shape" value.

M  +1    -0    libs/image/CMakeLists.txt
M  +10   -17   libs/image/kis_layer_projection_plane.cpp
M  +3    -3    libs/image/kis_layer_projection_plane.h
M  +45   -0    libs/image/krita_utils.cpp
M  +10   -0    libs/image/krita_utils.h
A  +31   -0    libs/image/layerstyles/KisStrokeLayerStyleFilterProjectionPlane.cpp     [License: GPL(v2.0+)]
A  +26   -0    libs/image/layerstyles/KisStrokeLayerStyleFilterProjectionPlane.h     [License: GPL(v2.0+)]
M  +10   -0    libs/image/layerstyles/kis_layer_style_filter_projection_plane.cpp
M  +6    -0    libs/image/layerstyles/kis_layer_style_filter_projection_plane.h
M  +29   -7    libs/image/layerstyles/kis_layer_style_projection_plane.cpp
M  +11   -0    libs/image/layerstyles/kis_ls_stroke_filter.cpp
M  +3    -0    libs/image/layerstyles/kis_ls_stroke_filter.h

https://invent.kde.org/graphics/krita/commit/2599be61082982a3d07edb588098f671ecce2ac7