Post

Replies

Boosts

Views

Activity

Reply to Image decompression strategies for performance
(Question continued here due to character limit) Back to potential solutions: Peter Steinberger's useful gist demonstrates one potential solution to pre-loading by creating a bitmap context: gist dot github dot com/steipete/1144242. AlamofireImage also had a similar approach as well: github dot com/Alamofire/AlamofireImage/blob/35623582388a3bfb21338566898ebbaebaef33dd/Source/UIImage%2BAlamofireImage.swift#L117-L146 But AlamofireImage recently switched to the much shorter strategy of fetching CGDataProvider's data to prime the inflation, which is undocumented behavior (at least that I've found): github dot com/Alamofire/AlamofireImage/blob/3e8edbeb75227f8542aa87f90240cf0424d6362f/Source/UIImage%2BAlamofireImage.swift#L113 WWDC 2018 - 219 Image and Graphics Best Practices (https://developer.apple.com/videos/play/wwdc2018/219/) shows a downsampling technique that demonstrates the use of kCGImageSourceShouldCacheImmediately flag, but the options dictionary can only be fed into CGImageSources that are created from a URL, unfortunately. It turns out that, empirically, just calling UIGraphicsBeginImageContextWithOptions and drawing the image without any other flags or options set on the context will cache the image. But I'm afraid that it might not be doing enough to produce a 1-to-1 image for all formats and color spaces. In fact, this was brought up on the previously linked gist: gist dot github dot com/steipete/1144242#gistcomment-817406. Drawing the image using UIGraphicsImageRender also works as a strategy for pre-loading but is found to be too slow (FB7878121). It seems from the examples and from some local profiling that fetching an image's CGDataProvider's data is enough to pre load the image and it's fast. But is this a reliable strategy for all images and formats? Are there other strategies that are better suited for this technique? And what are the disadvantages of pre loading images on a background thread? I'm most concerned with using a technique that's reliable and preserves the image data as best as it can, especially with respect to transparency and color space. Thanks, Mark
Jul ’20