Bug 427153 - Some self made .png patterns not read correctly in subtract alpha mode
Summary: Some self made .png patterns not read correctly in subtract alpha mode
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Brush engines (show other bugs)
Version: 4.4.0-beta2
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords: regression, release_blocker
Depends on:
Blocks:
 
Reported: 2020-09-30 14:01 UTC by Wojtek Trybus
Modified: 2020-10-07 09:47 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
bundle with one of the presets that stopped working. I would add the image too, but I guess I can have only one attachment? (3.01 MB, application/zip)
2020-09-30 14:01 UTC, Wojtek Trybus
Details
Image showing difference of the bahaviour (329.06 KB, image/png)
2020-09-30 14:17 UTC, Wojtek Trybus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wojtek Trybus 2020-09-30 14:01:10 UTC
Created attachment 132023 [details]
bundle with one of the presets that stopped working. I would add the image too, but I guess I can have only one attachment?

SUMMARY
I found out that presets from my brushpack are still not working the same way they did in 4.3 (even after fixing the cut-off bug). Subtract pattern behaviour changed, though the difference seems to be only on one of the .png patterns I made myself, and not on the default ones. I tried really hard to tell exactly which part of the pattern settings works differently, but couldn't find a direct answer.

STEPS TO REPRODUCE
1. import the bundle I attached (contains one preset with a brushtip and pattern)
2. compare the result on krita 4.3 and 4.4b2

OBSERVED RESULT
The pattern is barely visible in 4.4. It isn't subtracting most of the pixels. The preview on brush editor seems fine.

EXPECTED RESULT
No change in the same mode from 4.3 to 4.4

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: kubuntu 20.04
(available in About System)
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8

ADDITIONAL INFORMATION
Comment 1 Halla Rempt 2020-09-30 14:07:58 UTC
You can add as many attachments as you want, one by one.
Comment 2 Wojtek Trybus 2020-09-30 14:17:48 UTC
Created attachment 132024 [details]
Image showing difference of the bahaviour
Comment 3 Dmitry Kazakov 2020-10-05 08:58:15 UTC
Yes, I can confirm the regression since 4.3.0. The brush also started to work extremely slower.
Comment 4 Dmitry Kazakov 2020-10-05 08:59:01 UTC
Add Peter Schatz as CC
Comment 5 voronwe13 2020-10-05 16:27:22 UTC
I haven't had a chance to load the preset in either version yet, but I looked at the pattern file, and I suspect the issue is caused by the fact that the pattern in your bundle is pure black and uses alpha instead of grayscale for the value.  The new version leaves alpha in the original pattern, and converts it to grayscale when using it in Subtract or Multiply modes.  I'll take a look at both versions and see if I can figure out why it's converting it to grayscale differently between the two versions.
Comment 6 Wojtek Trybus 2020-10-05 16:47:20 UTC
Big thanks for handling this issue!
Yes, this would explain why I couldn't reproduce this change with any other pattern. All the default ones are in grayscale, while I always found it easier to draw a pattern on a new layer and use clipboard to move it to patterns. This results in black on transparent instead of grayscale. At least now I know how to fix my pattern in case the transparent/grayscale ones are to be differed.

Sorry for the bundle not working - I had a lot of problems with it, and I don't know any other way to create it. Wish you luck on the issue, and thanks for all your work.
Comment 7 Dmitry Kazakov 2020-10-06 14:02:55 UTC
I have a feeling like the bug happens in KisTextureProperties::apply(). 

After the texture patches, line 

KisPaintDeviceSP mask = m_maskInfo->mask(); 

started to return RGBA device instead of alpha8. It makes the texture fill differently. I will not be able to look further until the evening.
Comment 8 voronwe13 2020-10-06 16:19:23 UTC
(In reply to Dmitry Kazakov from comment #7)
> I have a feeling like the bug happens in KisTextureProperties::apply(). 
> 
> After the texture patches, line 
> 
> KisPaintDeviceSP mask = m_maskInfo->mask(); 
> 
> started to return RGBA device instead of alpha8. It makes the texture fill
> differently. I will not be able to look further until the evening.

You're probably right.  I'm going to test making the KisTextureMaskInfo have a "preserve alpha" option which only gets set in Lightness and Gradient modes, so the mask is converted to grayscale when it's created if it's not in one of those modes.  Also, I'm going to fix Gradient mode so it actually uses the alpha in the texture if it's there.  Currently running a build; I'll post a merge request as soon as I have it working.
Comment 9 Bug Janitor Service 2020-10-06 23:43:28 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/518
Comment 10 Dmitry Kazakov 2020-10-07 08:55:59 UTC
Git commit 6e7e3d7a05055389e8e1d49c7c81edb571747345 by Dmitry Kazakov, on behalf of Peter Schatz.
Committed on 07/10/2020 at 08:55.
Pushed by dkazakov into branch 'krita/4.3'.

Fix texture modes for textures with alpha channel

This fixes subtract and multiply alpha modes for brush textures when the
texture file has an alpha channel.  Also fixes gradient map mode so it
respects alpha in textures that have it.

M  +27   -13   plugins/paintops/libpaintop/KisTextureMaskInfo.cpp
M  +2    -1    plugins/paintops/libpaintop/KisTextureMaskInfo.h
M  +10   -5    plugins/paintops/libpaintop/kis_texture_option.cpp

https://invent.kde.org/graphics/krita/commit/6e7e3d7a05055389e8e1d49c7c81edb571747345
Comment 11 Dmitry Kazakov 2020-10-07 09:02:59 UTC
Git commit 42878ab1c502388fc5d9f627411b42055f4e6041 by Dmitry Kazakov, on behalf of Peter Schatz.
Committed on 07/10/2020 at 09:02.
Pushed by dkazakov into branch 'krita/4.4.0'.

Fix texture modes for textures with alpha channel

This fixes subtract and multiply alpha modes for brush textures when the
texture file has an alpha channel.  Also fixes gradient map mode so it
respects alpha in textures that have it.

M  +27   -13   plugins/paintops/libpaintop/KisTextureMaskInfo.cpp
M  +2    -1    plugins/paintops/libpaintop/KisTextureMaskInfo.h
M  +10   -5    plugins/paintops/libpaintop/kis_texture_option.cpp

https://invent.kde.org/graphics/krita/commit/42878ab1c502388fc5d9f627411b42055f4e6041
Comment 12 Dmitry Kazakov 2020-10-07 09:47:21 UTC
Git commit d5afac0eb5968cf1074a9f79fdbbdd2f9499debc by Dmitry Kazakov.
Committed on 07/10/2020 at 09:47.
Pushed by dkazakov into branch 'master'.

Fix texture modes for textures with alpha channel

This fixes subtract and multiply alpha modes for brush textures when the
texture file has an alpha channel.  Also fixes gradient map mode so it
respects alpha in textures that have it.

# Conflicts:
#	plugins/paintops/libpaintop/kis_texture_option.cpp

M  +27   -13   plugins/paintops/libpaintop/KisTextureMaskInfo.cpp
M  +2    -1    plugins/paintops/libpaintop/KisTextureMaskInfo.h
M  +9    -5    plugins/paintops/libpaintop/kis_texture_option.cpp

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