Created
November 17, 2019 21:36
-
-
Save dmytro-anokhin/9711f9886b73fa35b094652a17ac9d57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func createFrameImage(at index: Int, subsamplingLevel: SubsamplingLevel = .default, decodingOptions: DecodingOptions = .default) -> CGImage? { | |
| guard index < frameCount else { | |
| return nil | |
| } | |
| let image: CGImage? | |
| let options: CFDictionary | |
| switch decodingOptions.mode { | |
| case .asynchronous: | |
| // Don't consider the subsamplingLevel when comparing the image native size with sizeForDrawing. | |
| guard var size = frameSize(at: index) else { | |
| return nil | |
| } | |
| if let sizeForDrawing = decodingOptions.sizeForDrawing { | |
| // See which size is smaller: the image native size or the sizeForDrawing. | |
| if sizeForDrawing.width * sizeForDrawing.height < size.width * size.height { | |
| size = sizeForDrawing | |
| } | |
| } | |
| options = imageSourceAsyncOptions(sizeForDrawing: size, subsamplingLevel: subsamplingLevel) | |
| image = CGImageSourceCreateThumbnailAtIndex(imageSource, index, options) | |
| case .synchronous: | |
| options = imageSourceOptions(with: subsamplingLevel) | |
| image = CGImageSourceCreateImageAtIndex(imageSource, index, options) | |
| } | |
| // WebKit has support for xbm images but we don't | |
| return image | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment