GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix alpha not applying to tinted image by exponentChoi · Pull Request #3748 · SDWebImage/SDWebImage

Conversation

@exponentChoi

@exponentChoi exponentChoi commented Sep 2, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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.

All reactions
@exponentChoi
Fix alpha not applying to tinted image
c5a355c
[description]
Fix the issue where alpha values do not apply to the image.
@dreampiggy

dreampiggy commented Sep 3, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dreampiggy
dreampiggy reviewed Sep 3, 2024
View reviewed changes
Comment thread SDWebImage/Core/UIImage+Transform.m

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

@dreampiggy dreampiggy Sep 3, 2024

Copy link
Copy Markdown
Contributor

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.

Need new CGBlendMode and fix for CIFilter code path as well.

CI filter: https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dreampiggy dreampiggy mentioned this pull request Sep 3, 2024
[Behavior changes] Add blend mode to UIImage+Transform tint color API, default blend mode changed to sourceIn #3749
Merged
8 tasks
@dreampiggy

dreampiggy commented Sep 3, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dreampiggy dreampiggy added the Behavior Changes label Sep 3, 2024
@dreampiggy

dreampiggy commented Sep 3, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

SourceAtop:

SourceIn

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@exponentChoi

exponentChoi commented Sep 3, 2024

Copy link
Copy Markdown
Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dreampiggy

dreampiggy commented Oct 8, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dreampiggy dreampiggy closed this in #3749 Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dreampiggy dreampiggy dreampiggy left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Behavior Changes

Projects

None yet

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.

2 participants

@exponentChoi @dreampiggy
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.