Skip to content

Conversation

@exponentChoi
Copy link

@exponentChoi exponentChoi commented Sep 2, 2024

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/

[description]
Fix the issue where alpha values do not apply to the image.
@dreampiggy
Copy link
Contributor

dreampiggy commented Sep 3, 2024

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


// blend mode, see https://en.wikipedia.org/wiki/Alpha_compositing
CGBlendMode blendMode = kCGBlendModeSourceAtop;
CGBlendMode blendMode = kCGBlendModeSourceIn;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dreampiggy
Copy link
Contributor

dreampiggy commented Sep 3, 2024

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

@dreampiggy
Copy link
Contributor

dreampiggy commented Sep 3, 2024

SourceAtop:

SourceIn

@exponentChoi
Copy link
Author

Thanks for your reply. I will also take a look at the PR.

@dreampiggy
Copy link
Contributor

dreampiggy commented Oct 8, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants