-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PNG images being loaded without premultiplying its alpha channels #682
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments, but looks good.
Bit annoying that only UI expects pre-multiplied alpha currently, but no easy way around it since it has to go through egui.
Also, you need to move the premultiple/unpremultiply template functions to a header (can add imaging.hpp) if you want to use them in serialization.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but can you check CI runs and fix the errors @Yttruire
Codecov Report
@@ Coverage Diff @@
## devel #682 +/- ##
==========================================
+ Coverage 80.56% 80.62% +0.06%
==========================================
Files 257 258 +1
Lines 33046 33135 +89
==========================================
+ Hits 26623 26716 +93
+ Misses 6423 6419 -4
|
CI should be fixed now, seems to have been an issue with visibility of the implemented functions within the header file |
src/core/shards/imaging.cpp
Outdated
@@ -313,10 +397,10 @@ struct Resize { | |||
void registerShards() { | |||
REGISTER_SHARD("Convolve", Convolve); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if it's time to introduce a Image
prefix and change those into like Image.Resize
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yttruire Can you add some add a test case for PremultiplyAlpha & DemultiplyAlpha in the image script (or a new script) |
To be refactored because it currently opens the file twice in order to verify its type
Problem is related to the templates and name resolution in imaging.hpp with the new premultiplyAlpha and demultiplyAlpha template functions
2cabb2d
to
66ffac6
Compare
…eter to LoadImage. Also refactor premultiplying alpha in serialization
…com/fragcolor-xyz/shards into zh/fix-premultiplied-alpha-channels
…/github.com/fragcolor-xyz/shards into zh/fix-premultiplied-alpha-channels" This reverts commit 510e3a5, reversing changes made to 697d170.
…emultiplyAlpha divide by 0
PNG images are guaranteed by the file standards to not contain premultiplied alpha channels, and use straight alpha channels. As a result, PNGs will be rendered wrongly as the un-premultiplied alpha channels are used to render the image.
This PR fixes
LoadImage
. It will now check if the loaded image is a PNG and if so, premultiplies the alpha channels, then flags the image as having a premultiplied alpha channel. If images that are not PNG, it will assume that they are already premultiplied and simply flag them as premultiplied. This PR also adds two shards PremultiplyAlpha and DemultiplyAlpha for manually premultiplying the alpha and demultiplying alpha of an image.Some refactoring is also done for the premultiplying and demultiplying of the alpha channels.
LoadImage
's code for loading byte inputs and files have also been streamlined in the process.Note: Checking image file type for PNG can be done according to the specifications @ http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html
Additional list of file signatures: https://en.wikipedia.org/wiki/List_of_file_signatures
Fixes #671