Bug 412283 - Layer style application results in alpha-multiplied colors in the output
Summary: Layer style application results in alpha-multiplied colors in the output
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: layer styles (show other bugs)
Version: 4.2.6
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Dmitry Kazakov
URL:
Keywords:
: 373336 382269 409282 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-09-24 14:13 UTC by Andrei Alexeyev
Modified: 2019-10-10 09:17 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
layerstyle-alpha-bug.kra (17.46 KB, application/x-krita)
2019-09-24 14:13 UTC, Andrei Alexeyev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Alexeyev 2019-09-24 14:13:57 UTC
Created attachment 122835 [details]
layerstyle-alpha-bug.kra

SUMMARY
Some (all?) layer styles seem to compute RGB values of translucent pixels incorrectly (they are multiplied by alpha in the result).

I've attached a simple test case that demonstrates the issue. The "Circle" layer contains an anti-aliased circle with translucent edges. The "Disable translucency" filter layer makes all pixels fully opaque to conveniently display their color values. The "Circle" layer has an "Inner Glow" layer style configured in such a way that should add pure red to every pixel.

STEPS TO REPRODUCE
See attached test case

OBSERVED RESULT
The circle's edges are darkened due to bogus alpha-multiplication.

EXPECTED RESULT
The circle should appear completely yellow.

SOFTWARE/OS VERSIONS
Linux distro: openSUSE Tumbleweed 20190920
KDE Plasma Version: 5.16.5
KDE Frameworks Version: 5.61.0
Qt Version: 5.13.1

ADDITIONAL INFORMATION
I don't know if this behavior is consistent with Photoshop or not. However, I believe it's broken and not useful.
Comment 1 wolthera 2019-09-24 14:17:18 UTC
Yeah, Krita has no concept of premultiplied alpha, so this shouldn't happen.
Comment 2 Halla Rempt 2019-09-28 08:06:30 UTC
Dmitry is working on this.
Comment 3 Dmitry Kazakov 2019-10-02 18:38:23 UTC
*** Bug 373336 has been marked as a duplicate of this bug. ***
Comment 4 Dmitry Kazakov 2019-10-02 19:30:41 UTC
*** Bug 409282 has been marked as a duplicate of this bug. ***
Comment 5 Dmitry Kazakov 2019-10-03 15:27:37 UTC
*** Bug 382269 has been marked as a duplicate of this bug. ***
Comment 6 Dmitry Kazakov 2019-10-10 09:17:24 UTC
Git commit 227bd473709b1332f2b52346bb651489b3b5478d by Dmitry Kazakov.
Committed on 02/10/2019 at 19:41.
Pushed by dkazakov into branch 'master'.

Fix blending of layer styles with transparent pixels

Overlay-like layer styles (overlay, inner shadow, inner glow and satin)
seem to be applied in a complicated way:

1) Firstly the copy of the layer-stack projection is created
2) Then a copy of original layer alpha channel is extracted into a
   selection
3) Alpha channel of the layer itself is maxed-out to 1.0
4) The layer and all the layer overlay-like styles are merged into
   the projection
5) The the copy of the original projection from step 1) is
   copied onto the projection again using selection from step 2).

This weird technique is used to ensure that color mixing happens
exactly in full opacity, as if the colors would have no alpha-channel.

M  +4    -3    libs/image/kis_layer.cc
M  +3    -1    libs/image/kis_layer.h
M  +33   -1    libs/image/kis_layer_projection_plane.cpp
M  +8    -0    libs/image/kis_layer_projection_plane.h
M  +5    -0    libs/image/layerstyles/kis_layer_style_filter_projection_plane.cpp
M  +7    -0    libs/image/layerstyles/kis_layer_style_filter_projection_plane.h
M  +97   -64   libs/image/layerstyles/kis_layer_style_projection_plane.cpp
M  +2    -15   libs/image/layerstyles/kis_ls_overlay_filter.cpp
M  +0    -2    libs/image/layerstyles/kis_ls_overlay_filter.h
M  +9    -27   libs/image/layerstyles/kis_ls_satin_filter.cpp
M  +3    -2    libs/image/layerstyles/kis_ls_utils.h
M  +5    -0    libs/image/layerstyles/kis_multiple_projection.cpp
M  +2    -0    libs/image/layerstyles/kis_multiple_projection.h
M  +117  -0    libs/image/tests/kis_layer_style_projection_plane_test.cpp
M  +2    -0    libs/image/tests/kis_layer_style_projection_plane_test.h
M  +2    -1    libs/psd/psd.h

https://invent.kde.org/kde/krita/commit/227bd473709b1332f2b52346bb651489b3b5478d