Skip to content

Commit 23ad519

Browse files
committed
correctly handle ICC profiles
1 parent 694e0fb commit 23ad519

File tree

7 files changed

+39
-23
lines changed

7 files changed

+39
-23
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
<key>Jxl Coder-Package.xcscheme_^#shared#^_</key>
88
<dict>
99
<key>orderHint</key>
10-
<integer>1</integer>
10+
<integer>0</integer>
11+
</dict>
12+
<key>JxlCoder.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>6</integer>
1116
</dict>
1217
<key>jxlcoder.xcscheme_^#shared#^_</key>
1318
<dict>

Jxl Coder.xcodeproj/project.pbxproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
D341F4CC2A97FC2A003A496C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D341F4CB2A97FC2A003A496C /* Preview Assets.xcassets */; };
1414
D3B84ACC2A9C580800DAFE87 /* Nuke in Frameworks */ = {isa = PBXBuildFile; productRef = D3B84ACB2A9C580800DAFE87 /* Nuke */; };
1515
D3B84ACE2A9C580800DAFE87 /* NukeUI in Frameworks */ = {isa = PBXBuildFile; productRef = D3B84ACD2A9C580800DAFE87 /* NukeUI */; };
16-
D3B84AD02A9C581500DAFE87 /* JxlNukePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3B84ACF2A9C581500DAFE87 /* JxlNukePlugin.swift */; };
1716
D3B84AD32A9C58EB00DAFE87 /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = D3B84AD22A9C58EB00DAFE87 /* SDWebImage */; };
18-
D3B84AD52A9C591600DAFE87 /* JxlSDWebImageCoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3B84AD42A9C591600DAFE87 /* JxlSDWebImageCoder.swift */; };
1917
D3D2B9EB2A9BACF100EBB7A9 /* libjxl_threads.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3D2B9E62A9BACF000EBB7A9 /* libjxl_threads.xcframework */; };
2018
D3D2B9EC2A9BACF100EBB7A9 /* libbrotlidec.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3D2B9E72A9BACF000EBB7A9 /* libbrotlidec.xcframework */; };
2119
D3D2B9EE2A9BACF100EBB7A9 /* libbrotlienc.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3D2B9E92A9BACF100EBB7A9 /* libbrotlienc.xcframework */; };
@@ -38,8 +36,6 @@
3836
D341F4C62A97FC29003A496C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
3937
D341F4C82A97FC2A003A496C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4038
D341F4CB2A97FC2A003A496C /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
41-
D3B84ACF2A9C581500DAFE87 /* JxlNukePlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JxlNukePlugin.swift; sourceTree = "<group>"; };
42-
D3B84AD42A9C591600DAFE87 /* JxlSDWebImageCoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JxlSDWebImageCoder.swift; sourceTree = "<group>"; };
4339
D3B84AD62A9C5FE700DAFE87 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
4440
D3B84AD72A9C636E00DAFE87 /* JXLCoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JXLCoder.h; sourceTree = "<group>"; };
4541
D3D2B9E62A9BACF000EBB7A9 /* libjxl_threads.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = libjxl_threads.xcframework; sourceTree = "<group>"; };
@@ -87,8 +83,6 @@
8783
D341F4B82A97FC29003A496C = {
8884
isa = PBXGroup;
8985
children = (
90-
D3B84AD42A9C591600DAFE87 /* JxlSDWebImageCoder.swift */,
91-
D3B84ACF2A9C581500DAFE87 /* JxlNukePlugin.swift */,
9286
D341F4D22A97FC5A003A496C /* Sources */,
9387
D341F4C32A97FC29003A496C /* Jxl Coder */,
9488
D341F4C22A97FC29003A496C /* Products */,
@@ -290,12 +284,10 @@
290284
files = (
291285
D3D2B9F52A9BAD6A00EBB7A9 /* JXLCPlusCoder.mm in Sources */,
292286
D3D2BA092A9BD1B600EBB7A9 /* JXLSystemImage.mm in Sources */,
293-
D3B84AD52A9C591600DAFE87 /* JxlSDWebImageCoder.swift in Sources */,
294287
D3D2B9FD2A9BAEF300EBB7A9 /* jxl_worker.cpp in Sources */,
295288
D3D2BA002A9BB4AF00EBB7A9 /* JXLCoder.swift in Sources */,
296289
D3D2BA022A9BB50F00EBB7A9 /* JXLSupport.swift in Sources */,
297290
D341F4C72A97FC29003A496C /* ContentView.swift in Sources */,
298-
D3B84AD02A9C581500DAFE87 /* JxlNukePlugin.swift in Sources */,
299291
D341F4C52A97FC29003A496C /* Jxl_CoderApp.swift in Sources */,
300292
);
301293
runOnlyForDeploymentPostprocessing = 0;

JxlCoder.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'JxlCoder'
3-
s.version = '1.0.1'
3+
s.version = '1.0.2'
44
s.summary = 'JXL coder for iOS and MacOS'
55
s.description = 'Provides support for JXL files in iOS and MacOS'
66
s.homepage = 'https://github.com/awxkee/jxl-coder-swift'
@@ -25,4 +25,4 @@ Pod::Spec.new do |s|
2525
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"
2626
s.libraries = 'c++'
2727
s.requires_arc = true
28-
end
28+
end

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ let package = Package(
88
platforms: [.iOS(.v11), .macOS(.v11)],
99
products: [
1010
.library(
11-
name: "jxlcoder",
12-
targets: ["jxlcoder"]),
11+
name: "JxlCoder",
12+
targets: ["JxlCoder"]),
1313
],
1414
targets: [
1515
.target(

Sources/jxlc/JXLCPlusCoder.mm

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
#import "jxl_worker.hpp"
1212
#import <Accelerate/Accelerate.h>
1313

14-
static void JXLCGDataProviderReleaseDataCallback(void *info, const void *data, size_t size) {
15-
JXLDataWrapper* dataWrapper = static_cast<JXLDataWrapper*>(info);
14+
static void JXLCGData16ProviderReleaseDataCallback(void *info, const void *data, size_t size) {
15+
auto dataWrapper = static_cast<JXLDataWrapper<uint16_t>*>(info);
1616
delete dataWrapper;
1717
}
1818

19+
static void JXLCGData8ProviderReleaseDataCallback(void *info, const void *data, size_t size) {
20+
auto dataWrapper = static_cast<JXLDataWrapper<uint8_t>*>(info);
21+
delete dataWrapper;
22+
}
23+
24+
1925
std::vector<uint8_t> convertRGBAtoRGB(std::vector<uint8_t> srcVector, int width, int height) {
2026
std::vector<uint8_t> dstVector;
2127
vImage_Buffer src = {
@@ -98,7 +104,7 @@ - (nullable NSData *)encode:(nonnull JXLSystemImage *)platformImage
98104
pixels = resizedVector;
99105
}
100106

101-
JXLDataWrapper* wrapper = new JXLDataWrapper();
107+
JXLDataWrapper<uint8_t>* wrapper = new JXLDataWrapper<uint8_t>();
102108
auto encoded = EncodeJxlOneshot(pixels, width, height, &wrapper->data, jColorspace, jCompressionOption, compressionDistance);
103109
if (!encoded) {
104110
delete wrapper;
@@ -196,7 +202,7 @@ - (nullable JXLSystemImage *)decode:(nonnull NSInputStream *)inputStream error:(
196202
return nil;
197203
}
198204

199-
JXLDataWrapper* dataWrapper = new JXLDataWrapper();
205+
auto dataWrapper = new JXLDataWrapper<uint8_t>();
200206
std::vector<uint8_t> iccProfile;
201207
size_t xSize, ySize;
202208
auto decoded = DecodeJpegXlOneShot(imageData.data(), imageData.size(),
@@ -207,10 +213,22 @@ - (nullable JXLSystemImage *)decode:(nonnull NSInputStream *)inputStream error:(
207213
return nil;
208214
}
209215

210-
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
211-
int flags = (int)kCGBitmapByteOrder32Big | (int)kCGImageAlphaLast;
216+
CGColorSpaceRef colorSpace;
217+
if (iccProfile.size() > 0) {
218+
CFDataRef iccData = CFDataCreate(kCFAllocatorDefault, iccProfile.data(), iccProfile.size());
219+
colorSpace = CGColorSpaceCreateWithICCData(iccData);
220+
CFRelease(iccData);
221+
} else {
222+
colorSpace = CGColorSpaceCreateDeviceRGB();
223+
}
224+
225+
if (!colorSpace) {
226+
colorSpace = CGColorSpaceCreateDeviceRGB();
227+
}
228+
229+
int flags = (int)kCGImageByteOrder32Big | (int)kCGImageAlphaLast;
212230
CGDataProviderRef provider = CGDataProviderCreateWithData(dataWrapper, dataWrapper->data.data(),
213-
dataWrapper->data.size(), JXLCGDataProviderReleaseDataCallback);
231+
dataWrapper->data.size(), JXLCGData8ProviderReleaseDataCallback);
214232
if (!provider) {
215233
delete dataWrapper;
216234
*error = [[NSError alloc] initWithDomain:@"JXLCoder"

Sources/jxlc/jxl_worker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ bool DecodeJpegXlOneShot(const uint8_t *jxl, size_t size,
7777
JxlDecoderImageOutBufferSize(dec.get(), &format, &buffer_size)) {
7878
return false;
7979
}
80-
if (buffer_size != *xsize * *ysize * 4) {
80+
if (buffer_size != *xsize * *ysize * 4 * sizeof(uint8_t)) {
8181
return false;
8282
}
83-
pixels->resize(*xsize * *ysize * 4);
83+
pixels->resize(*xsize * *ysize * 4 * sizeof(uint8_t));
8484
void *pixels_buffer = (void *) pixels->data();
8585
size_t pixels_buffer_size = pixels->size() * sizeof(uint8_t);
8686
if (JXL_DEC_SUCCESS != JxlDecoderSetImageOutBuffer(dec.get(), &format,

Sources/jxlc/jxl_worker.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ bool EncodeJxlOneshot(const std::vector<uint8_t> &pixels, const uint32_t xsize,
3333
jxl_colorspace colorspace, jxl_compression_option compression_option,
3434
float compression_distance);
3535

36+
template <typename DataType>
3637
class JXLDataWrapper {
3738
public:
3839
JXLDataWrapper() {}
39-
std::vector<uint8_t> data;
40+
std::vector<DataType> data;
4041
};
4142
#endif
4243

0 commit comments

Comments
 (0)