diff --git a/Package.swift b/Package.swift index 89ed365..8b289b0 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,7 @@ let package = Package( .library(name: "NukeUI", targets: ["NukeUI"]) ], dependencies: [ - .package(url: "https://github.com/kean/Nuke.git", from: "10.3.0"), + .package(url: "https://github.com/kean/Nuke.git", from: "10.5.0"), .package(url: "https://github.com/kaishin/Gifu", from: "3.0.0") ], targets: [ diff --git a/Sources/LazyImage.swift b/Sources/LazyImage.swift index 919c7f7..c1fd788 100644 --- a/Sources/LazyImage.swift +++ b/Sources/LazyImage.swift @@ -251,9 +251,6 @@ public struct LazyImage: View { } private func load(_ request: HashableRequest?) { - #if !os(watchOS) - ImageDecoders.Video.register() - #endif model.load(request?.request) } diff --git a/Sources/LazyImageView.swift b/Sources/LazyImageView.swift index bfb3bbb..59117f3 100644 --- a/Sources/LazyImageView.swift +++ b/Sources/LazyImageView.swift @@ -251,10 +251,6 @@ public final class LazyImageView: _PlatformBaseView { private func load(_ request: ImageRequestConvertible?) { assert(Thread.isMainThread, "Must be called from the main thread") - if imageView.isVideoRenderingEnabled { - ImageDecoders.Video.register() - } - cancel() if isResetEnabled { diff --git a/Sources/VideoImageDecoder.swift b/Sources/VideoImageDecoder.swift deleted file mode 100644 index 8f95810..0000000 --- a/Sources/VideoImageDecoder.swift +++ /dev/null @@ -1,86 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2015-2021 Alexander Grebenyuk (github.com/kean). - - -#if !os(watchOS) - -import Foundation -import Nuke -import AVKit - -extension ImageType { - public static let mp4: ImageType = "public.mp4" -} - -extension ImageDecoders { - final class Video: ImageDecoding, ImageDecoderRegistering { - private var didProducePreview = false - - var isAsynchronous: Bool { - false - } - - init?(data: Data, context: ImageDecodingContext) { - guard Video.isVideo(data) else { return nil } - } - - init?(partiallyDownloadedData data: Data, context: ImageDecodingContext) { - guard Video.isVideo(data) else { return nil } - } - - static func isVideo(_ data: Data) -> Bool { - match(data, offset: 4, [0x66, 0x74, 0x79, 0x70]) - } - - func decode(_ data: Data) -> ImageContainer? { - ImageContainer(image: _PlatformImage(), type: .mp4, data: data) - } - - func decodePartiallyDownloadedData(_ data: Data) -> ImageContainer? { - guard !didProducePreview else { - return nil // We only need one preview - } - guard let preview = makePreview(for: data) else { - return nil - } - didProducePreview = true - return ImageContainer(image: preview, type: .mp4, isPreview: true, data: data) - } - - private static var isRegistered: Bool = false - - static func register() { - guard !isRegistered else { return } - isRegistered = true - - ImageDecoderRegistry.shared.register(ImageDecoders.Video.self) - } - } -} - -private func makePreview(for data: Data) -> _PlatformImage? { - let asset = AVDataAsset(data: data) - let generator = AVAssetImageGenerator(asset: asset) - guard let cgImage = try? generator.copyCGImage(at: CMTime(value: 0, timescale: 1), actualTime: nil) else { - return nil - } - #if os(macOS) - return _PlatformImage(cgImage: cgImage, size: .zero) - #else - return _PlatformImage(cgImage: cgImage) - #endif -} - -// TODO: extened support for other image formats -// ftypisom - ISO Base Media file (MPEG-4) v1 -// There are a bunch of other ways to create MP4 -// https://www.garykessler.net/library/file_sigs.html -private func match(_ data: Data, offset: Int = 0, _ numbers: [UInt8]) -> Bool { - guard data.count >= numbers.count + offset else { return false } - return !zip(numbers.indices, numbers).contains { (index, number) in - data[index + offset] != number - } -} - -#endif