Skip to content

Commit b9b7920

Browse files
committed
small fixes
1 parent 71a5ffc commit b9b7920

File tree

6 files changed

+38
-42
lines changed

6 files changed

+38
-42
lines changed

.swiftpm/xcode/xcuserdata/radzivonbartoshyk.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<key>JxlCoder.xcscheme_^#shared#^_</key>
1313
<dict>
1414
<key>orderHint</key>
15-
<integer>6</integer>
15+
<integer>4</integer>
1616
</dict>
1717
<key>jxlcoder.xcscheme_^#shared#^_</key>
1818
<dict>

Jxl Coder.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
D3D2BA072A9BC06500EBB7A9 /* second.jxl in Resources */ = {isa = PBXBuildFile; fileRef = D3D2BA052A9BC06500EBB7A9 /* second.jxl */; };
2929
D3D2BA092A9BD1B600EBB7A9 /* JXLSystemImage.mm in Sources */ = {isa = PBXBuildFile; fileRef = D3D2BA082A9BD1B600EBB7A9 /* JXLSystemImage.mm */; };
3030
D3D2BA102A9BDADA00EBB7A9 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3D2BA0F2A9BDADA00EBB7A9 /* Accelerate.framework */; };
31+
D3D55DAD2AA4D0E800EA7CB0 /* JxlNukePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D55DAC2AA4D0E800EA7CB0 /* JxlNukePlugin.swift */; };
3132
/* End PBXBuildFile section */
3233

3334
/* Begin PBXFileReference section */
@@ -57,6 +58,7 @@
5758
D3D2BA082A9BD1B600EBB7A9 /* JXLSystemImage.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = JXLSystemImage.mm; sourceTree = "<group>"; };
5859
D3D2BA0A2A9BD1C200EBB7A9 /* JXLSystemImage.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = JXLSystemImage.hpp; sourceTree = "<group>"; };
5960
D3D2BA0F2A9BDADA00EBB7A9 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
61+
D3D55DAC2AA4D0E800EA7CB0 /* JxlNukePlugin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = JxlNukePlugin.swift; path = JxlNukePlugin/JxlNukePlugin.swift; sourceTree = "<group>"; };
6062
/* End PBXFileReference section */
6163

6264
/* Begin PBXFrameworksBuildPhase section */
@@ -83,6 +85,7 @@
8385
D341F4B82A97FC29003A496C = {
8486
isa = PBXGroup;
8587
children = (
88+
D3D55DAC2AA4D0E800EA7CB0 /* JxlNukePlugin.swift */,
8689
D341F4D22A97FC5A003A496C /* Sources */,
8790
D341F4C32A97FC29003A496C /* Jxl Coder */,
8891
D341F4C22A97FC29003A496C /* Products */,
@@ -288,6 +291,7 @@
288291
D3D2BA002A9BB4AF00EBB7A9 /* JXLCoder.swift in Sources */,
289292
D3D2BA022A9BB50F00EBB7A9 /* JXLSupport.swift in Sources */,
290293
D341F4C72A97FC29003A496C /* ContentView.swift in Sources */,
294+
D3D55DAD2AA4D0E800EA7CB0 /* JxlNukePlugin.swift in Sources */,
291295
D341F4C52A97FC29003A496C /* Jxl_CoderApp.swift in Sources */,
292296
);
293297
runOnlyForDeploymentPostprocessing = 0;

JxlNukePlugin.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
1212
s.source_files = 'JxlNukePlugin/JxlNukePlugin.swift'
1313
s.swift_version = ["5.3", "5.4", "5.5"]
1414
s.frameworks = "Foundation", "CoreGraphics"
15-
s.dependency 'Nuke'
15+
s.dependency 'Nuke', '~> 12.0'
1616
s.dependency 'JxlCoder'
1717
s.requires_arc = true
1818
end

JxlNukePlugin/JxlNukePlugin.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,30 @@ import JxlCoder
1212
#endif
1313

1414
public final class JxlNukePlugin: Nuke.ImageDecoding {
15-
16-
public init() {
15+
public func decode(_ data: Data) throws -> Nuke.ImageContainer {
16+
guard try JXLCoder.isJXL(data: data) else { throw JXLNukePluginDecodeError() }
17+
let image = try JXLCoder.decode(data: data)
18+
return ImageContainer(image: image)
1719
}
1820

19-
public func decode(_ data: Data) -> ImageContainer? {
20-
guard (try? JXLCoder.isJXL(data: data)) ?? false else { return nil }
21-
guard let image = try? JXLCoder.decode(data: data) else {
22-
return nil
23-
}
24-
return ImageContainer(image: image)
21+
public init() {
2522
}
2623

2724
public func decodePartiallyDownloadedData(_ data: Data) -> ImageContainer? {
2825
return nil
2926
}
3027
}
3128

29+
public struct JXLNukePluginDecodeError: LocalizedError, CustomNSError {
30+
public var errorDescription: String? {
31+
"JXL file cannot be decoded"
32+
}
33+
34+
public var errorUserInfo: [String : Any] {
35+
[NSLocalizedDescriptionKey: "JXL file cannot be decoded"]
36+
}
37+
}
38+
3239
// MARK: - check JXL format data.
3340
extension JxlNukePlugin {
3441

README.md

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,28 @@ let data: Data = try JXLCoder.encode(data: UIImage())
3434
If you wish to use `JXL` with <a href="https://github.com/kean/Nuke" target="_blank">`Nuke`</a> you may add `JxlCoder` library to project and activate the plugin on app init
3535
### Use code below in your project or add a pod `JxlNukePlugin`
3636
```swift
37-
import Nuke
38-
#if canImport(JxlCoder)
39-
import JxlCoder
40-
#endif
41-
4237
public final class JxlNukePlugin: Nuke.ImageDecoding {
43-
44-
public init() {
38+
public func decode(_ data: Data) throws -> Nuke.ImageContainer {
39+
guard try JXLCoder.isJXL(data: data) else { throw JXLNukePluginDecodeError() }
40+
let image = try JXLCoder.decode(data: data)
41+
return ImageContainer(image: image)
4542
}
4643

47-
public func decode(_ data: Data) -> ImageContainer? {
48-
guard (try? JXLCoder.isJXL(data: data)) ?? false else { return nil }
49-
guard let image = try? JXLCoder.decode(data: data) else {
50-
return nil
51-
}
52-
return ImageContainer(image: image)
44+
public init() {
5345
}
5446

5547
public func decodePartiallyDownloadedData(_ data: Data) -> ImageContainer? {
5648
return nil
5749
}
5850
}
5951

60-
// MARK: - check JXL format data.
61-
extension JxlNukePlugin {
62-
63-
public static func enable() {
64-
Nuke.ImageDecoderRegistry.shared.register { (context) -> ImageDecoding? in
65-
JxlNukePlugin.enable(context: context)
66-
}
52+
public struct JXLNukePluginDecodeError: LocalizedError, CustomNSError {
53+
public var errorDescription: String? {
54+
"JXL file cannot be decoded"
6755
}
6856

69-
public static func enable(context: Nuke.ImageDecodingContext) -> Nuke.ImageDecoding? {
70-
return try? JXLCoder.isJXL(data: context.data) ? JxlNukePlugin() : nil
57+
public var errorUserInfo: [String : Any] {
58+
[NSLocalizedDescriptionKey: "JXL file cannot be decoded"]
7159
}
7260
}
7361

Sources/JxlCoder/JXLCoder.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ import Foundation
1010
import jxlc
1111
#endif
1212

13-
public struct AVIFNukePluginDecodeError: LocalizedError, CustomNSError {
14-
public var errorDescription: String? {
15-
"JXL file cannot be decoded"
16-
}
17-
18-
public var errorUserInfo: [String : Any] {
19-
[NSLocalizedDescriptionKey: "JXL file cannot be decoded"]
20-
}
21-
}
22-
2313
public class JXLCoder {
2414
private static let shared = JXLCPlusCoder()
2515
private static let magic1 = Data([0xFF, 0x0A])
@@ -115,4 +105,11 @@ public class JXLCoder {
115105
let srcStream = InputStream(data: data)
116106
return try getSize(srcStream: srcStream)
117107
}
108+
109+
/**
110+
- Returns: Uniform type identifier
111+
**/
112+
public static func utiIdentifier() -> String {
113+
"dyn.ah62d4rv4ge80y8dq"
114+
}
118115
}

0 commit comments

Comments
 (0)