Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
feat: Compatible with Nuke9
Browse files Browse the repository at this point in the history
  • Loading branch information
ryokosuge committed Jul 1, 2020
1 parent 288a2a2 commit 55e4450
Show file tree
Hide file tree
Showing 10 changed files with 1,603 additions and 1,588 deletions.
5 changes: 2 additions & 3 deletions Cartfile
@@ -1,3 +1,2 @@
github "kean/Nuke" ~> 8.0
git "https://chromium.googlesource.com/webm/libwebp" "v1.0.0"

github "kean/Nuke" ~> 9.0
git "https://chromium.googlesource.com/webm/libwebp" "v1.1.0"
4 changes: 2 additions & 2 deletions Cartfile.resolved
@@ -1,2 +1,2 @@
git "https://chromium.googlesource.com/webm/libwebp" "v1.0.0"
github "kean/Nuke" "8.0"
git "https://chromium.googlesource.com/webm/libwebp" "v1.1.0"
github "kean/Nuke" "9.1.1"
8 changes: 4 additions & 4 deletions Demo/Podfile.lock
Expand Up @@ -24,15 +24,15 @@ PODS:
- libwebp/core
- libwebp/webp (1.0.0)
- Nuke (8.0)
- Nuke-WebP-Plugin (3.1.0):
- Nuke-WebP-Plugin (4.0.0):
- libwebp (= 1.0.0)
- Nuke (~> 8.0)

DEPENDENCIES:
- Nuke-WebP-Plugin (from `../`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/CocoaPods/Specs.git:
- libwebp
- Nuke

Expand All @@ -43,8 +43,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
libwebp: d7e0c95fe97245c97e08101eba10702ebb0f6101
Nuke: 8d90f1dbf88d27a7ba6ff3934de01693812e5adb
Nuke-WebP-Plugin: 9867fc5813a003f3bd3c870188ad67cee7162e0a
Nuke-WebP-Plugin: 1d582afdee4884da4c8e5237df4e46d8468c4c4d

PODFILE CHECKSUM: 45f08ebfebb93cf65f76314cc9b8d0255dd7ba0e

COCOAPODS: 1.7.4
COCOAPODS: 1.9.3
3,128 changes: 1,570 additions & 1,558 deletions Nuke-WebP-Plugin.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Source/WebP/WebPDataDecoder.h
Expand Up @@ -18,7 +18,7 @@

@interface WebPDataDecoder : NSObject

- (nullable Image *)incrementallyDecodeData:(nonnull NSData *)data isFinal:(BOOL)isFinal;
- (nullable Image *)incrementallyDecodeData:(nonnull NSData *)data;
- (nullable Image *)decodeData:(nonnull NSData *)data;

@end
2 changes: 1 addition & 1 deletion Source/WebP/WebPDataDecoder.m
Expand Up @@ -29,7 +29,7 @@ - (void)dealloc {
}
}

- (Image *)incrementallyDecodeData:(NSData *)data isFinal:(BOOL)isFinal {
- (Image *)incrementallyDecodeData:(NSData *)data {

if (!_idec) {
_idec = WebPINewRGB(MODE_rgbA, NULL, 0, 0);
Expand Down
14 changes: 10 additions & 4 deletions Source/WebPImage.swift
Expand Up @@ -16,11 +16,16 @@ public class WebPImageDecoder: Nuke.ImageDecoding {
public init() {
}

public func decode(data: Data, isFinal: Bool) -> Image? {
public func decode(_ data: Data) -> ImageContainer? {
guard data.isWebPFormat else { return nil }
guard !isFinal else { return _decode(data) }
guard let image = _decode(data) else { return nil }
return ImageContainer(image: image)
}

return decoder.incrementallyDecode(data, isFinal: isFinal)
public func decodePartiallyDownloadedData(_ data: Data) -> ImageContainer? {
guard data.isWebPFormat else { return nil }
guard let image = decoder.incrementallyDecode(data) else { return nil }
return ImageContainer(image: image)
}

}
Expand All @@ -42,9 +47,10 @@ extension WebPImageDecoder {

// MARK: - private
private let _queue = DispatchQueue(label: "com.github.ryokosuge.Nuke-WebP-Plugin.DataDecoder")

extension WebPImageDecoder {

internal func _decode(_ data: Data) -> Image? {
private func _decode(_ data: Data) -> PlatformImage? {
return _queue.sync {
return decoder.decode(data)
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/WebPDecodeTests.swift
Expand Up @@ -56,15 +56,15 @@ class WebPDecodeTests: XCTestCase {
let webpData = try! Data(contentsOf: self.webpImagePath)
let decoder = NukeWebPPlugin.WebPDataDecoder();
// no image
XCTAssertNil(decoder.incrementallyDecode(webpData[0...500], isFinal: false))
XCTAssertNil(decoder.incrementallyDecode(webpData[0...500]))

// created image
let scan1 = decoder.incrementallyDecode(webpData[0...3702], isFinal: false)
let scan1 = decoder.incrementallyDecode(webpData[0...3702])
XCTAssertNotNil(scan1)
XCTAssertEqual(scan1!.size.width, 320)
XCTAssertEqual(scan1!.size.height, 235)

let scan2 = decoder.incrementallyDecode(webpData, isFinal: true)
let scan2 = decoder.incrementallyDecode(webpData)
XCTAssertNotNil(scan2)
XCTAssertEqual(scan2!.size.width, 320)
XCTAssertEqual(scan2!.size.height, 235)
Expand Down
6 changes: 3 additions & 3 deletions Tests/WebPDecodeTests_MacOS.swift
Expand Up @@ -56,15 +56,15 @@ class WebPDecodeTests: XCTestCase {
let webpData = try! Data(contentsOf: self.webpImagePath)
let decoder = NukeWebPPlugin.WebPDataDecoder();
// no image
XCTAssertNil(decoder.incrementallyDecode(webpData[0...500], isFinal: false))
XCTAssertNil(decoder.incrementallyDecode(webpData[0...500]))

// created image
let scan1 = decoder.incrementallyDecode(webpData[0...3702], isFinal: false)
let scan1 = decoder.incrementallyDecode(webpData[0...3702])
XCTAssertNotNil(scan1)
XCTAssertEqual(scan1!.size.width, 320)
XCTAssertEqual(scan1!.size.height, 235)

let scan2 = decoder.incrementallyDecode(webpData, isFinal: true)
let scan2 = decoder.incrementallyDecode(webpData)
XCTAssertNotNil(scan2)
XCTAssertEqual(scan2!.size.width, 320)
XCTAssertEqual(scan2!.size.height, 235)
Expand Down
16 changes: 7 additions & 9 deletions Tests/WebPImageDecoderTests.swift
Expand Up @@ -34,18 +34,16 @@ class WebPImageDecoderTests: XCTestCase {
let decoder = NukeWebPPlugin.WebPImageDecoder()

// no image
XCTAssertNil(decoder.decode(data: webpData[0...500], isFinal: false))
XCTAssertNil(decoder.decode(webpData[0...500]))

// created image
let scan1 = decoder.decode(data: webpData[0...3702], isFinal: false)
XCTAssertNotNil(scan1)
XCTAssertEqual(scan1!.size.width, 320)
XCTAssertEqual(scan1!.size.height, 235)

let scan2 = decoder.decode(data: webpData, isFinal: true)
let scan1 = decoder.decode(webpData[0...3702])
XCTAssertNil(scan1)

let scan2 = decoder.decode(webpData)
XCTAssertNotNil(scan2)
XCTAssertEqual(scan2!.size.width, 320)
XCTAssertEqual(scan2!.size.height, 235)
XCTAssertEqual(scan2!.image.size.width, 320)
XCTAssertEqual(scan2!.image.size.height, 235)
}

func testsImageDecoderRegistryRegistered() {
Expand Down

0 comments on commit 55e4450

Please sign in to comment.