diff --git a/Sources/Image+WebP.swift b/Sources/Image+WebP.swift index 76ae123..0f6cf0f 100644 --- a/Sources/Image+WebP.swift +++ b/Sources/Image+WebP.swift @@ -14,6 +14,10 @@ import Foundation import KingfisherWebP_ObjC #endif +#if canImport(AppKit) +import AppKit +#endif + // MARK: - Image Representation extension KingfisherWrapper where Base: KFCrossPlatformImage { /// isLossy (0=lossy , 1=lossless (default)). @@ -37,16 +41,27 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage { /// isLossy (0=lossy , 1=lossless (default)). /// Note that the default values are isLossy= false and quality=75.0f private func animatedWebPRepresentation(isLossy: Bool = false, quality: Float = 75.0) -> Data? { - #if os(macOS) - return nil - #else - guard let images = base.images?.compactMap({ $0.cgImage }) else { + let imageInfo: [CFString: Any] + if let frameSource = frameSource { + let frameCount = frameSource.frameCount + imageInfo = [ + kWebPAnimatedImageFrames: (0.. TimeInterval { return 0 } + func frame(at index: Int, maxSize: CGSize?) -> CGImage? { + KFCrossPlatformImage(data: .init(fileName: "cover.png"))?.kfCGImage + } + } + + let source = RandomFrameSource() + let image = KingfisherWrapper.animatedImage(source: source, options: .init())! + let encoded2 = s.data(with: image, original: nil) + XCTAssertEqual(encoded2, source.data, "Original data should be used") + } + func testEncodingPerformance() { let s = WebPSerializer.default let images = fileNames.compactMap { fileName -> KFCrossPlatformImage? in