Skip to content

Commit 9546f3c

Browse files
committed
initial release
1 parent 9291589 commit 9546f3c

File tree

5 files changed

+75
-63
lines changed

5 files changed

+75
-63
lines changed

JxlCoder.podspec

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
Pod::Spec.new do |s|
2-
s.name = 'JxlCoder'
3-
s.version = '1.0.0'
4-
s.summary = 'JXL coder for iOS and MacOS'
5-
s.description = 'Provides support for JXL files in iOS and MacOS'
6-
s.homepage = 'https://github.com/awxkee/jxl-coder-swift'
7-
s.license = { :type => 'BSD-3', :file => 'LICENSE' }
8-
s.author = { 'username' => '[email protected]' }
9-
s.source = { :git => 'https://github.com/awxkee/jxl-coder-swift', :tag => "#{s.version}" }
10-
s.ios.deployment_target = '11.0'
11-
s.osx.deployment_target = '11.0'
12-
s.source_files = 'Sources/jxlc/*.{swift,h,m,cpp,mm,hpp}', "Sources/JxlCoder/*.swift", 'Sources/Module/JxlCoder.h', 'Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers/**/*.h'
13-
s.swift_version = "5.4"
14-
s.frameworks = "Foundation", "CoreGraphics", "Accelerate"
15-
s.ios.vendored_frameworks = 'Sources/Frameworks/libbrotlicommon.xcframework', 'Sources/Frameworks/libbrotlidec.xcframework', 'Sources/Frameworks/libbrotlienc.xcframework', 'Sources/Frameworks/libhwy.xcframework', 'Sources/Frameworks/libjxl.xcframework', 'Sources/Frameworks/libjxl_threads.xcframework'
16-
s.osx.vendored_frameworks = 'Sources/Frameworks/libbrotlicommon.xcframework', 'Sources/Frameworks/libbrotlidec.xcframework', 'Sources/Frameworks/libbrotlienc.xcframework', 'Sources/Frameworks/libhwy.xcframework', 'Sources/Frameworks/libjxl.xcframework', 'Sources/Frameworks/libjxl_threads.xcframework'
17-
#s.module_map = 'Sources/Module/module.modulemap'
18-
s.public_header_files = 'Sources/jxlc/**.h', 'Sources/jxlc/**.hpp', 'Headers/**/*.h'
19-
s.project_header_files = 'Sources/jxlc/jxl_worker.hpp'
20-
s.pod_target_xcconfig = {
21-
'OTHER_CXXFLAGS' => '$(inherited) -std=c++20',
22-
'HEADER_SEARCH_PATHS' => '$(inherited) "$(PODS_TARGET_SRCROOT)/Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers"',
23-
'OTHER_CPLUSPLUSFLAGS' => '$(inherited) -fmodules -fcxx-modules'
24-
}
25-
s.preserve_paths = "Sources/Frameworks/*.xcframework", "Sources/Frameworks/*.xcframework/**/Headers", "Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers/jxl", "Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers/jpegli"
26-
s.libraries = 'c++'
27-
s.requires_arc = true
2+
s.name = 'JxlCoder'
3+
s.version = '1.0.0'
4+
s.summary = 'JXL coder for iOS and MacOS'
5+
s.description = 'Provides support for JXL files in iOS and MacOS'
6+
s.homepage = 'https://github.com/awxkee/jxl-coder-swift'
7+
s.license = { :type => 'BSD-3', :file => 'LICENSE' }
8+
s.author = { 'username' => '[email protected]' }
9+
s.source = { :git => 'https://github.com/awxkee/jxl-coder-swift.git', :tag => "#{s.version}" }
10+
s.ios.deployment_target = '11.0'
11+
s.osx.deployment_target = '11.0'
12+
s.source_files = 'Sources/jxlc/*.{swift,h,m,cpp,mm,hpp}', "Sources/JxlCoder/*.swift", 'Sources/Module/JxlCoder.h', 'Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers/**/*.h'
13+
s.swift_version = ["5.3", "5.4", "5.5"]
14+
s.frameworks = "Foundation", "CoreGraphics", "Accelerate"
15+
s.ios.vendored_frameworks = 'Sources/Frameworks/libbrotlicommon.xcframework', 'Sources/Frameworks/libbrotlidec.xcframework', 'Sources/Frameworks/libbrotlienc.xcframework', 'Sources/Frameworks/libhwy.xcframework', 'Sources/Frameworks/libjxl.xcframework', 'Sources/Frameworks/libjxl_threads.xcframework'
16+
s.osx.vendored_frameworks = 'Sources/Frameworks/libbrotlicommon.xcframework', 'Sources/Frameworks/libbrotlidec.xcframework', 'Sources/Frameworks/libbrotlienc.xcframework', 'Sources/Frameworks/libhwy.xcframework', 'Sources/Frameworks/libjxl.xcframework', 'Sources/Frameworks/libjxl_threads.xcframework'
17+
#s.module_map = 'Sources/Module/module.modulemap'
18+
s.public_header_files = 'Sources/jxlc/**.h', 'Sources/jxlc/**.hpp', 'Headers/**/*.h'
19+
s.project_header_files = 'Sources/jxlc/jxl_worker.hpp'
20+
s.pod_target_xcconfig = {
21+
'OTHER_CXXFLAGS' => '$(inherited) -std=c++20',
22+
'HEADER_SEARCH_PATHS' => '$(inherited) "$(PODS_TARGET_SRCROOT)/Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers"',
23+
'OTHER_CPLUSPLUSFLAGS' => '$(inherited) -fmodules -fcxx-modules'
24+
}
25+
s.preserve_paths = "Sources/Frameworks/*.xcframework", "Sources/Frameworks/*.xcframework/**/Headers", "Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers/jxl", "Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers/jpegli"
26+
s.libraries = 'c++'
27+
s.requires_arc = true
2828
end

JxlNukePlugin.swift

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,17 @@ public final class JxlNukePlugin: Nuke.ImageDecoding {
1616
public init() {
1717
}
1818

19-
public func decode(_ data: Data) throws -> ImageContainer {
20-
guard try JXLCoder.isJXL(data: data) else { throw JxlNukePluginDecodeError(failureReason: "Provided data is not JXL") }
21-
let image = try JXLCoder.decode(data: data)
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+
}
2224
return ImageContainer(image: image)
2325
}
2426

2527
public func decodePartiallyDownloadedData(_ data: Data) -> ImageContainer? {
2628
return nil
2729
}
28-
29-
public struct JxlNukePluginDecodeError: LocalizedError, CustomNSError {
30-
public var errorDescription: String {
31-
"JXL file cannot be decoded"
32-
}
33-
34-
public var failureReason: String
35-
36-
public var errorUserInfo: [String : Any] {
37-
[NSLocalizedDescriptionKey: "JXL file cannot be decoded", NSLocalizedFailureErrorKey: failureReason]
38-
}
39-
}
4030
}
4131

4232
// MARK: - check JXL format data.

JxlSDWebImageCoder.podspec

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Pod::Spec.new do |s|
2+
s.name = 'JxlSDWebImageCoder'
3+
s.version = '1.0.0'
4+
s.summary = 'JXL encoder and decoder for SDWebImage'
5+
s.description = 'JXL encoder and decoder for SDWebImage in iOS and MacOS'
6+
s.homepage = 'https://github.com/awxkee/jxl-coder-swift'
7+
s.license = { :type => 'BSD-3', :file => 'LICENSE' }
8+
s.author = { 'username' => '[email protected]' }
9+
s.source = { :git => 'https://github.com/awxkee/jxl-coder-swift.git', :tag => "#{s.version}" }
10+
s.ios.deployment_target = '11.0'
11+
s.osx.deployment_target = '11.0'
12+
s.source_files = 'JxlSDWebImageCoder/JxlSDWebImageCoder.swift'
13+
s.swift_version = ["5.3", "5.4", "5.5"]
14+
s.frameworks = "Foundation", "CoreGraphics"
15+
s.dependency = 'SDWebImage', 'JxlCoder'
16+
s.requires_arc = true
17+
end

JxlSDWebImageCoder.swift renamed to JxlSDWebImageCoder/JxlSDWebImageCoder.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,31 @@ import Foundation
1010
import JxlCoder
1111
#endif
1212
import SDWebImage
13+
import UIKit
1314

14-
class JxlSDWebImageCoder: NSObject, SDImageCoder {
15+
public class JxlSDWebImageCoder: NSObject, SDImageCoder {
1516
public override init() {
1617
}
1718

18-
func canDecode(from data: Data?) -> Bool {
19+
public func canDecode(from data: Data?) -> Bool {
1920
guard let data else {
2021
return false
2122
}
2223
return (try? JXLCoder.isJXL(data: data)) ?? false
2324
}
2425

25-
func decodedImage(with data: Data?, options: [SDImageCoderOption : Any]? = nil) -> UIImage? {
26+
public func decodedImage(with data: Data?, options: [SDImageCoderOption : Any]? = nil) -> UIImage? {
2627
guard let data else {
2728
return nil
2829
}
2930
return try? JXLCoder.decode(data: data)
3031
}
3132

32-
func canEncode(to format: SDImageFormat) -> Bool {
33+
public func canEncode(to format: SDImageFormat) -> Bool {
3334
true
3435
}
3536

36-
func encodedData(with image: UIImage?, format: SDImageFormat, options: [SDImageCoderOption : Any]? = nil) -> Data? {
37+
public func encodedData(with image: UIImage?, format: SDImageFormat, options: [SDImageCoderOption : Any]? = nil) -> Data? {
3738
guard let image else {
3839
return nil
3940
}

README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,31 @@ public final class JxlNukePlugin: Nuke.ImageDecoding {
4343
public init() {
4444
}
4545

46-
public func decode(_ data: Data) throws -> ImageContainer {
47-
guard try JXLCoder.isJXL(data: data) else { throw JxlNukePluginDecodeError(failureReason: "Provided data is not JXL") }
48-
let image = try JXLCoder.decode(data: data)
46+
public func decode(_ data: Data) -> ImageContainer? {
47+
guard (try? JXLCoder.isJXL(data: data)) ?? false else { return nil }
48+
guard let image = try? JXLCoder.decode(data: data) else {
49+
return nil
50+
}
4951
return ImageContainer(image: image)
5052
}
5153

5254
public func decodePartiallyDownloadedData(_ data: Data) -> ImageContainer? {
5355
return nil
5456
}
57+
}
5558

56-
public struct JxlNukePluginDecodeError: LocalizedError, CustomNSError {
57-
public var errorDescription: String {
58-
"JXL file cannot be decoded"
59-
}
60-
61-
public var failureReason: String
59+
// MARK: - check JXL format data.
60+
extension JxlNukePlugin {
6261

63-
public var errorUserInfo: [String : Any] {
64-
[NSLocalizedDescriptionKey: "JXL file cannot be decoded", NSLocalizedFailureErrorKey: failureReason]
62+
public static func enable() {
63+
Nuke.ImageDecoderRegistry.shared.register { (context) -> ImageDecoding? in
64+
JxlNukePlugin.enable(context: context)
6565
}
6666
}
67+
68+
public static func enable(context: Nuke.ImageDecodingContext) -> Nuke.ImageDecoding? {
69+
return try? JXLCoder.isJXL(data: context.data) ? JxlNukePlugin() : nil
70+
}
6771
}
6872

6973
// MARK: - check JXL format data.
@@ -89,29 +93,29 @@ import JxlCoder
8993
#endif
9094
import SDWebImage
9195

92-
class JxlSDWebImageCoder: NSObject, SDImageCoder {
96+
public class JxlSDWebImageCoder: NSObject, SDImageCoder {
9397
public override init() {
9498
}
95-
96-
func canDecode(from data: Data?) -> Bool {
99+
100+
public func canDecode(from data: Data?) -> Bool {
97101
guard let data else {
98102
return false
99103
}
100104
return (try? JXLCoder.isJXL(data: data)) ?? false
101105
}
102106

103-
func decodedImage(with data: Data?, options: [SDImageCoderOption : Any]? = nil) -> UIImage? {
107+
public func decodedImage(with data: Data?, options: [SDImageCoderOption : Any]? = nil) -> UIImage? {
104108
guard let data else {
105109
return nil
106110
}
107111
return try? JXLCoder.decode(data: data)
108112
}
109113

110-
func canEncode(to format: SDImageFormat) -> Bool {
114+
public func canEncode(to format: SDImageFormat) -> Bool {
111115
true
112116
}
113117

114-
func encodedData(with image: UIImage?, format: SDImageFormat, options: [SDImageCoderOption : Any]? = nil) -> Data? {
118+
public func encodedData(with image: UIImage?, format: SDImageFormat, options: [SDImageCoderOption : Any]? = nil) -> Data? {
115119
guard let image else {
116120
return nil
117121
}

0 commit comments

Comments
 (0)