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

[APNG] UIImage RenderingMode is not original at first, I want to render original image at first. #3665

Open
2 tasks done
0k1019 opened this issue Jan 11, 2024 · 15 comments
Open
2 tasks done
Labels
animated image bug device Something related to real device but not simulator

Comments

@0k1019
Copy link

0k1019 commented Jan 11, 2024

New Issue Checklist

Issue Info

Info Value
Platform Name ios
Platform Version
SDWebImage Version 5.18.7
Integration Method SPM
Xcode Version Xcode 15.1
Repro rate only once
Repro with our demo prj e.g. does it happen with our demo project?
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

I have issue with first load APNG file load has <SDAnimatedImage:0x28232ce70 anonymous {480, 400} renderingMode=automatic(original)> So it render with Template with tint color.
Can you share any options for Rendering Mode original always?

image path: https://apng.onevcat.com/assets/elephant.png
image

@dreampiggy
Copy link
Contributor

We have no any design to support tintColor on Animated Image

@dreampiggy
Copy link
Contributor

I don't think it's a common usage case.

Maybe this need much more work than expected. Because for SDAnimatedImageView, the render is hanlded by ourself, not UIImageView UIKit implementation.

We use layer to draw frame

@0k1019
Copy link
Author

0k1019 commented Jan 11, 2024

Yes I know the layer architecture using SDAnimatedImagePlayer.
My question is how can I render with renderingMode alwaysOriginal.
It is not feature request i think...?
You mean It is not intended work process with SDAnimatedImageView?

i just using options below,

SDImageCache.shared.clearMemory()
SDImageCache.shared.clearDisk()
SDWebImageContextOption.imageCoder
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor() { url, options, context in
      var mutableOptions = options
      if let context = context, let _ = context[.animatedImageClass] {
          mutableOptions.insert(.refreshCached)
      } else {
          mutableOptions.insert(.progressiveLoad)
          mutableOptions.insert(.refreshCached)
          
      }
      return SDWebImageOptionsResult(options: mutableOptions, context: context)
  }

and use this method in SDAnimatedImageView sd_setImage(with: url, placeholderImage: placeholderImage, options: [.retryFailed, .preloadAllFrames])

I can load well in second time. as below image.
IMG_60C531279AC2-1

@0k1019 0k1019 changed the title [APNG] UIImage RenderingMode is template only once. [APNG] UIImage RenderingMode is not original at first, I want to render original image at first. Jan 11, 2024
@dreampiggy
Copy link
Contributor

dreampiggy commented Jan 11, 2024

Misundertanding your question. I previouslly think you want alwaysTemplate.

But I think it should correctly render alwaysOriginal ?

Are you change the UIImageView (the super class)'s tintColor to non-nil value? Or using some traitCollection to override this

Check https://developer.apple.com/documentation/uikit/uiimageview/1621059-tintcolor?language=objc

@dreampiggy
Copy link
Contributor

The decoded UIImage (or SDAnimatedImage, the same) actually use the +[UIImage imageFromCGImage:] to create.

Which inherit the UIKit's default value for renderingMode, which is automatic, by design.

We don't override the renderingMode of the SDWebImage decoded UIImage

@0k1019
Copy link
Author

0k1019 commented Jan 11, 2024

Yes it should correctly render alwaysOriginal. I want to know the solution of it.
this video is my situation. it is abnormal.
I set UIImageView tintColor to red for visualize issue.
Above video, I didn't set tintColor
I know this library doesn't override renderingMode. But it happens to me...

@dreampiggy
Copy link
Contributor

I guess your first appear rendering image is from

[super setImage:image]

Since SDAnimatedImage is subclass, UIKit will try to something render.

And then, our player called back with the actual first frame (from APNG) and display directly on CALayer, then render as normal

@0k1019
Copy link
Author

0k1019 commented Jan 12, 2024

It is so wired. It is not reproduce in simulator.
I check this library line by line. there is no rendering mode change code.
It seems to call super class funcions or initialize.
Can you check super class call code for resolve this issue?
Or any suggestions for reduce this problem reproduce?

@dreampiggy
Copy link
Contributor

It is so wired. It is not reproduce in simulator.

Sounds UIKit bug. Provide details about your test environment

OS version
iPhone model
SDWebImage version

@dreampiggy
Copy link
Contributor

Actually I didn't find this issue on our Demo running simulator


A stupid quick hack I guess it to revert the #3459

This will trigger a sync callback after first "setImage:" (after that PR we use async)

Since UIKit only render the last status in the same runloop, the sync callback will override the CALayer contents and should not show that temp tinted image poster.

But this will break SwiftUI integration. And I don't think it's a correct fix, but hide the issue
(there are still two image render result in the single "setImage:" call, wired)

@0k1019
Copy link
Author

0k1019 commented Jan 12, 2024

My environment:

OS version : iOS 16.0.2
iPhone model: iPhone 14
SDWebImage version: 5.18.7, 5.18.10

Thank you for sharing #3459 .
After I change this line

self.needsDisplayWhenImageBecomesAvailable = YES;

to comment(//).

it is not reproduce my issue. it seems to solve my issue

Can you check this line self.needsDisplayWhenImageBecomesAvailable = YES; is mandatory for setupCurrentFrame?
And If it is not mandatory, Can you remove this line in next release?

@dreampiggy
Copy link
Contributor

No.

It hide the issue, but not fix the issue

@0k1019
Copy link
Author

0k1019 commented Jan 15, 2024

Okay thank you for your consider about this issue.
Can you regenerate this issue?

@dreampiggy
Copy link
Contributor

@0k1019 Provide a full demo (archive to zip and upload here)

I'll try to debug with.

Also, this only reproducable in Real Device ? Not simulator, correct ?

@dreampiggy dreampiggy added device Something related to real device but not simulator bug and removed feature request labels Jan 16, 2024
@0k1019
Copy link
Author

0k1019 commented Jan 17, 2024

Real Devices i reproduces

  • iPhone 14, 16.0.2
  • iPhone 12 mini, 15.5

full demo video
video.zip

Thank you for support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
animated image bug device Something related to real device but not simulator
Projects
None yet
Development

No branches or pull requests

2 participants