GeezerVison is showing github.com — Fix alpha not applying to tinted image by exponentChoi · Pull Request #3748 · SDWebImage/SDWebImage
Conversation
exponentChoi
commented
Sep 2, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
New Pull Request Checklist
-
I have read and understood the CONTRIBUTING guide
-
I have read the Documentation
-
I have searched for a similar pull request in the project and found none
-
I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)
-
I have added the required tests to prove the fix/feature I am adding
-
I have updated the documentation (if necessary)
-
I have run the tests and they pass
-
I have run the lint and it passes (pod lib lint)
This merge request fixes / refers to the following issues: ...
Pull Request Description
Fix the issue where alpha values do not apply to the image.
While using SDWebImage, I discovered that the alpha value for the image color was not being applied. The issue was caused by the CGBlendMode setting. When using kCGBlendModeSourceATop as before, the A color was being overwritten. To resolve this, I switched to using kCGBlendModeSourceIn, which effectively replaced the color. This change ensures that the alpha value is applied to the tintColor of UIImage, similar to how it behaves natively. I discovered this issue while testing with SVG images.
Reference
documentation - https://developer.apple.com/documentation/coregraphics/cgblendmode/
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
[description]
Fix the issue where alpha values do not apply to the image.
dreampiggy
commented
Sep 3, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
This is designed behavior. You should add new enum option to control the blend mode. Such as SDBlendMode, or directly use CGBlendMode
I use the Atop for the original use case which mixed the target rect's color, this API is not designed to be the same effect as UIImage.tintColor at my original introduction
there are also maybe use case which need other blend modes
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
// blend mode, see https://en.wikipedia.org/wiki/Alpha_compositing
|
|
|
CGBlendMode blendMode = kCGBlendModeSourceAtop;
|
|
|
CGBlendMode blendMode = kCGBlendModeSourceIn;
|
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
dreampiggy
commented
Sep 3, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
I've created #3749 for this.
You can use blendMode: kCGBlendModeSourceIn to achieve your preferred filter solution.
Note: this tint is wrong word which cause misunderstanding. You think it should be replace the background image with target color, ignore what background image's own color.
But, in my original design, it's more like mix the background color with target color, keep the alpha from the background, but with color from target color, so I choose that sourceAtop as blend mode.
If you really want to change the default blend mode behavior, this may cause behavior break and need at least minor version bump
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
dreampiggy
commented
Sep 3, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
SourceAtop:

SourceIn

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for your reply. I will also take a look at the PR.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
dreampiggy
commented
Oct 8, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
@exponentChoi I decided to follow your idea. Change the default blend mode to sourceIn, match Tint Color naming on iOS
For user who still want the sourceAtop blend mode, they can use the new API param to opt-in
This is a behavior break changes and I'll notify user on release changelog
|
exponentChoi reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|