Skip to content
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

Introduce the hacky workaround for iOS 17 ImageIO indexed color png decode (Apple's bug) #3634

Conversation

dreampiggy
Copy link
Contributor

@dreampiggy dreampiggy commented Nov 10, 2023

Changes

This use the runtime detection instead of available check, more stable

When we detect the ImageIO is buggy, we will change the correct alpha info with non-premultiplied

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

This is the ultimate solution for Apple's bug #3605

Workaround steps

  1. Use a sample (only 1x1 pixel), decode its pixel values at runtime.
  2. If the R, G, and B values of this sample are not equal to 50, consider ImageIO to be in Buggy mode.
  3. In Buggy mode, all instances where CGImageGetUTType() == UTTypePNG, and CGImageGetAlphaInfo == AlphaLast or AlphaFirst, are forcefully treated as AlphaPremultipliedLast or AlphaPremultipliedFirst.
  4. Optionally, an @available iOS 17 check can be added at the outermost level.

…ode bug

This use the runtime detection instead of available check, more stable

When we detect the ImageIO is buggy, we will change the correct alpha info with non-premultiplied
@dreampiggy dreampiggy force-pushed the bugfix/workaround_hacky_imageio_png_indexed_color branch from 9f88940 to d5dccae Compare November 10, 2023 10:45
@dreampiggy dreampiggy changed the title Introduce the hacky workaround for iOS 17 ImageIO indexed color png code bug Introduce the hacky workaround for iOS 17 ImageIO indexed color png decode (Apple's bug) Nov 10, 2023
@dreampiggy
Copy link
Contributor Author

dreampiggy commented Nov 10, 2023

Update:

From Apple's feedback, this issue seem been fixed in iOS 17.1

There were some late changes that went into the final release version of iOS 17. This issue should be fixed in the shipping version.

Please verify this issue with iOS 17.1 and update your bug report with your results by logging into ​https://feedbackassistant.apple.com/ or by using the Feedback Assistant app.

iOS 17.1 (Build: 21B74 | 21B80)
https://developer.apple.com/download/
Posted Date: October 25, 2023

@dreampiggy dreampiggy added fix apple bug apple's bug cause our framework author's pain png PNG image related labels Nov 10, 2023
return SDCGImageCreateMutableCopy(image, CGImageGetBitmapInfo(image));
}

static BOOL SDLoadOnePixelBitmapBuffer(CGImageRef imageRef, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this useful for other thing ? May consider to expose to public API like +[SDImageCoderHelper CGImageGetRGBA]

@dreampiggy dreampiggy merged commit 213be11 into SDWebImage:master Nov 15, 2023
3 of 4 checks passed
@dreampiggy dreampiggy added this to the 5.18.5 milestone Nov 15, 2023
@dreampiggy
Copy link
Contributor Author

Note the PR changes is not correct and complete. Must use the code from #3637 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apple bug apple's bug cause our framework author's pain fix png PNG image related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants