-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Use SDWebImageAvoidDecodeImage
to allow user to control force decode feature for individual image request
#2283
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
Use SDWebImageAvoidDecodeImage
to allow user to control force decode feature for individual image request
#2283
Conversation
…e feature for individual image request. Replace all the central control for `decompressImages`
Current break change (Need change code)SDImageCacheConfig.h
SDWebImageDownloader.h
SDWebImageDownloadOperation.h
|
Codecov Report
@@ Coverage Diff @@
## 5.x #2283 +/- ##
======================================
Coverage ? 42.75%
======================================
Files ? 51
Lines ? 6063
Branches ? 0
======================================
Hits ? 2592
Misses ? 3471
Partials ? 0
Continue to review full report at Codecov.
|
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.
👍
SDWebImageAvoidDecodeImage
to allow user to control force decod…SDWebImageAvoidDecodeImage
to allow user to control force decode feature for individual image request
I need central control. Can I set the default Option to SDWebImageAvoidDecodeImage? [[SDImageCache sharedImageCache] setShouldDecompressImages:NO];
[[SDWebImageDownloader sharedDownloader] setShouldDecompressImages:NO]; |
@dreampiggy 呃呃呃,帮忙看看 |
@ripperhe You and @welsonxue have the exact opposite request for this option. 😅 To solve this problem, there are 3 solutions, maybe... Change your codeYou can try build a wrapper category method, which always pass the default option @implementation UIImageView (MyWebCache)
- (void)my_setImageWithURL:(NSURL *)url options:(SDWebImageOption)options {
SDWebImageOption newOptions = SDWebImageAvoidDecodeImage | options;
[self sd_setImageWithURL:url options:newOptions];
}
@end See comment here: #2679. Similar problem. Allows global control to overrideWe can use a global control, which override your This enum can only represent two meaning: SDWebImageManager.sharedManager.avoidDecodeImage = NO;
[imageView sd_setImageWithURL:url option:SDWebImageAvoidDecodeImage];
// What's the final result for this option ? One way for this, it to use the 5.0 new context option, which use a 3-case enum, or can use This may cause API breaking, in my opinion. Or we need to deprecate the old option Add a default options featureWe can introduce a feature called This can also fix other related option where user want to take both global control && per-image-request control like But actually, this feature have one disadvantage, how to solve the problem when some image request don't want the default option, but others want ? SDWebImageManager.sharedManager.defaultOptions = SDWebImageAvoidDecodeImage;
[imageView sd_setImageWithURL:url option:0]; // How to do if I really want this image request, to trun the force decode on?
// Maybe something like this ?
[imageView sd_setImageWithURL:url option:SDWebImageIgnoreDefaultOptions]; // Ignore default options appending, final options result to 0 Which solution to use, need some discussion. You can create a new feature request for this. |
Thank you very much for your reply. I get a rough idea of what you mean. I finally decided to use version There are too many places to use SDWebImage, and I'm not sure what risks there are.I'm looking forward to the next version. |
Moved the discussion and feature request to #2719 |
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 / reffers to the following issues: #1927
Pull Request Description
Reason
This is about that
decompressImages
feature. We all know that whatdecompressImages
will do. It actually callsd_decodedImageWithImage:
in the background, to draw the image from Image/IO on the bitmap context, this can help to force decode the image. Then when we set thisUIImage
on theUIImageView
, it does not cause any lag or blocking on the main queue to wait forCore Animation
firstly decode it.This options is good for performance, and it seems that most of application use this well. However, due to the force decode process, this will consume more memory, especially for huge images. It's a trade-off between Time & Space.
In previous SDWebImage, we have a option to enable/disable this feature. We have these:
SDImageCache
:SDImageCache.config.shouldDecompressImages
SDWebImageDownloader
:SDWebImageDownloader.shouldDecompressImages
SDWebImageDownloadOperation
:SDWebImageDownloadOperation.shouldDecompressImages
But however, they are both central control. Which means if I disable on in shared downloader, or shared cache, this will effect all the image request for this. In most cases, we do not want this. Because if user want to set this option for individual image request, they have no way to do this, except create another
SDImageCache
andSDWebImageDownloader
instance, which is really heavy on usage and cause many problem when syncing for shared cache/downloader.From the real world application experience by our company(Such as Tik Tok), most images are small enough (less than 1000x1000), the force decode process can help to increase nearly 4-5 frame rates on common
UITableView
orUIScrollView
. It's quite rare we need turn it off, unless some huge images which consume much memory.So, we'd better move that option, into
SDWebImageOptions
level, to allow we control it for each image request fromsd_setImageWithURL:
Design
From the description above, we should treat
force decode
ON as the default value. And this options can be used both inmanager
,cache
,downloader
. So we just put it in theSDWebImageOptions
. Naming itSDWebImageAvoidDecodeImage
to specify that you can avoid this force decode feature.There are also the correspond options for
SDImageCacheOptions
andSDWebImageDownloaderOptions
, keep it the same name as usual.Implementation