Skip to content

Commit 2459b68

Browse files
committed
added loseless JPEG transcoding, reconstruction JPEG from JXL, jpegli compression
1 parent 22a62f7 commit 2459b68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1992
-108
lines changed

JxlCoder.podspec

+7-4
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.6.0'
3+
s.version = '1.7.0'
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'
@@ -12,13 +12,16 @@ Pod::Spec.new do |s|
1212
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'
1313
s.swift_version = ["5.3", "5.4", "5.5"]
1414
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', 'Sources/Frameworks/libjxl_cms.xcframework', 'Sources/Frameworks/libskcms.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', 'Sources/Frameworks/libjxl_cms.xcframework', 'Sources/Frameworks/libskcms.xcframework'
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', 'Sources/Frameworks/libjxl_cms.xcframework', 'Sources/Frameworks/libskcms.xcframework',
16+
'Sources/Frameworks/libjpegli.xcframework'
17+
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', 'Sources/Frameworks/libjxl_cms.xcframework', 'Sources/Frameworks/libskcms.xcframework',
18+
'Sources/Frameworks/libjpegli.xcframework'
1719
s.public_header_files = 'Sources/jxlc/**.h', 'Sources/jxlc/**.hpp', 'Headers/**/*.h'
1820
s.project_header_files = 'Sources/jxlc/JxlWorker.hpp'
1921
s.pod_target_xcconfig = {
22+
'OTHER_CFLAGS' => '$(inherited) -DHWY_COMPILE_ONLY_STATIC=1',
2023
'OTHER_CXXFLAGS' => '$(inherited) -std=c++20 -ffast-math',
21-
'HEADER_SEARCH_PATHS' => '$(inherited) "$(PODS_TARGET_SRCROOT)/Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers" "$(PODS_TARGET_SRCROOT)/Sources/Frameworks/libhwy.xcframework/ios-arm64/Headers"',
24+
'HEADER_SEARCH_PATHS' => '$(inherited) "$(PODS_TARGET_SRCROOT)/Sources/Frameworks/libjxl.xcframework/ios-arm64/Headers" "$(PODS_TARGET_SRCROOT)/Sources/Frameworks/libhwy.xcframework/ios-arm64/Headers" "$(PODS_TARGET_SRCROOT)/Sources/Frameworks/libjpegli.xcframework/ios-arm64/Headers"',
2225
'OTHER_CPLUSPLUSFLAGS' => '$(inherited) -fmodules -fcxx-modules -std=c++20 -ffast-math'
2326
}
2427
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",

Package.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ let package = Package(
1818
path: "Sources/JxlCoder"),
1919
.target(name: "jxlc",
2020
dependencies: ["libbrotlicommon", "libbrotlidec", "libbrotlienc", "libhwy",
21-
"libjxl_threads", "libjxl", "libjxl_cms", "libskcms"],
21+
"libjxl_threads", "libjxl", "libjxl_cms", "libskcms",
22+
"libjpegli"],
2223
publicHeadersPath: "include",
23-
cSettings: [.headerSearchPath("./algo")],
24+
cSettings: [
25+
.headerSearchPath("./algo"),
26+
.define("HWY_COMPILE_ONLY_STATIC", to: "1")],
2427
cxxSettings: [.headerSearchPath("./algo")],
2528
linkerSettings: [
2629
.linkedFramework("Accelerate")
@@ -32,7 +35,8 @@ let package = Package(
3235
.binaryTarget(name: "libjxl_threads", path: "Sources/Frameworks/libjxl_threads.xcframework"),
3336
.binaryTarget(name: "libjxl", path: "Sources/Frameworks/libjxl.xcframework"),
3437
.binaryTarget(name: "libjxl_cms", path: "Sources/Frameworks/libjxl_cms.xcframework"),
35-
.binaryTarget(name: "libskcms", path: "Sources/Frameworks/libskcms.xcframework")
38+
.binaryTarget(name: "libskcms", path: "Sources/Frameworks/libskcms.xcframework"),
39+
.binaryTarget(name: "libjpegli", path: "Sources/Frameworks/libjpegli.xcframework")
3640
],
3741
cxxLanguageStandard: .cxx20
3842
)

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ try! animEncoder.add(frame: frameToAnimate, duration: 150)
6767
let animationJxlData = try! animEncoder.finish()
6868
```
6969

70+
## Loseless JPEG transcoding
71+
72+
```swift
73+
let transcoded = try! JXLCoder.transcode(jpegData: Data())
74+
let jpegData: Data = try! JXLCoder.inverse(jxlData: Data())
75+
```
76+
77+
## Jpegli encoding
78+
79+
```swift
80+
let encoded: Data = try! JpegLiEncoder.encode(image: UIImage())
81+
```
82+
7083
## Nuke Plugin
7184

7285
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>AvailableLibraries</key>
6+
<array>
7+
<dict>
8+
<key>BinaryPath</key>
9+
<string>libjpegli.a</string>
10+
<key>HeadersPath</key>
11+
<string>Headers</string>
12+
<key>LibraryIdentifier</key>
13+
<string>ios-arm64_x86_64-simulator</string>
14+
<key>LibraryPath</key>
15+
<string>libjpegli.a</string>
16+
<key>SupportedArchitectures</key>
17+
<array>
18+
<string>arm64</string>
19+
<string>x86_64</string>
20+
</array>
21+
<key>SupportedPlatform</key>
22+
<string>ios</string>
23+
<key>SupportedPlatformVariant</key>
24+
<string>simulator</string>
25+
</dict>
26+
<dict>
27+
<key>BinaryPath</key>
28+
<string>libjpegli.a</string>
29+
<key>HeadersPath</key>
30+
<string>Headers</string>
31+
<key>LibraryIdentifier</key>
32+
<string>macos-arm64_x86_64</string>
33+
<key>LibraryPath</key>
34+
<string>libjpegli.a</string>
35+
<key>SupportedArchitectures</key>
36+
<array>
37+
<string>arm64</string>
38+
<string>x86_64</string>
39+
</array>
40+
<key>SupportedPlatform</key>
41+
<string>macos</string>
42+
</dict>
43+
<dict>
44+
<key>BinaryPath</key>
45+
<string>libjpegli.a</string>
46+
<key>HeadersPath</key>
47+
<string>Headers</string>
48+
<key>LibraryIdentifier</key>
49+
<string>ios-arm64</string>
50+
<key>LibraryPath</key>
51+
<string>libjpegli.a</string>
52+
<key>SupportedArchitectures</key>
53+
<array>
54+
<string>arm64</string>
55+
</array>
56+
<key>SupportedPlatform</key>
57+
<string>ios</string>
58+
</dict>
59+
</array>
60+
<key>CFBundlePackageType</key>
61+
<string>XFWK</string>
62+
<key>XCFrameworkFormatVersion</key>
63+
<string>1.0</string>
64+
</dict>
65+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) the JPEG XL Project Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
//
6+
// This file contains the C API of the common encoder/decoder part of libjpegli
7+
// library, which is based on the C API of libjpeg, with the function names
8+
// changed from jpeg_* to jpegli_*, while compressor and decompressor object
9+
// definitions are included directly from jpeglib.h
10+
//
11+
// Applications can use the libjpegli library in one of the following ways:
12+
//
13+
// (1) Include jpegli/encode.h and/or jpegli/decode.h, update the function
14+
// names of the API and link against libjpegli.
15+
//
16+
// (2) Leave the application code unchanged, but replace the libjpeg.so library
17+
// with the one built by this project that is API- and ABI-compatible with
18+
// libjpeg-turbo's version of libjpeg.so.
19+
20+
#ifndef LIB_JPEGLI_COMMON_H_
21+
#define LIB_JPEGLI_COMMON_H_
22+
23+
/* clang-format off */
24+
#include <stdio.h>
25+
#include "jpeglib.h"
26+
/* clang-format on */
27+
28+
#include "types.h"
29+
30+
#if defined(__cplusplus) || defined(c_plusplus)
31+
extern "C" {
32+
#endif
33+
34+
struct jpeg_error_mgr* jpegli_std_error(struct jpeg_error_mgr* err);
35+
36+
void jpegli_abort(j_common_ptr cinfo);
37+
38+
void jpegli_destroy(j_common_ptr cinfo);
39+
40+
JQUANT_TBL* jpegli_alloc_quant_table(j_common_ptr cinfo);
41+
42+
JHUFF_TBL* jpegli_alloc_huff_table(j_common_ptr cinfo);
43+
44+
#if defined(__cplusplus) || defined(c_plusplus)
45+
} // extern "C"
46+
#endif
47+
48+
#endif // LIB_JPEGLI_COMMON_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright (c) the JPEG XL Project Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
//
6+
// This file contains the C API of the decoder part of the libjpegli library,
7+
// which is based on the C API of libjpeg, with the function names changed from
8+
// jpeg_* to jpegli_*, while decompressor object definitions are included
9+
// directly from jpeglib.h
10+
//
11+
// Applications can use the libjpegli library in one of the following ways:
12+
//
13+
// (1) Include jpegli/encode.h and/or jpegli/decode.h, update the function
14+
// names of the API and link against libjpegli.
15+
//
16+
// (2) Leave the application code unchanged, but replace the libjpeg.so library
17+
// with the one built by this project that is API- and ABI-compatible with
18+
// libjpeg-turbo's version of libjpeg.so.
19+
20+
#ifndef LIB_JPEGLI_DECODE_H_
21+
#define LIB_JPEGLI_DECODE_H_
22+
23+
#include "jpegli/common.h"
24+
25+
#if defined(__cplusplus) || defined(c_plusplus)
26+
extern "C" {
27+
#endif
28+
29+
#define jpegli_create_decompress(cinfo) \
30+
jpegli_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
31+
(size_t)sizeof(struct jpeg_decompress_struct))
32+
33+
void jpegli_CreateDecompress(j_decompress_ptr cinfo, int version,
34+
size_t structsize);
35+
36+
void jpegli_stdio_src(j_decompress_ptr cinfo, FILE *infile);
37+
38+
void jpegli_mem_src(j_decompress_ptr cinfo, const unsigned char *inbuffer,
39+
unsigned long insize);
40+
41+
int jpegli_read_header(j_decompress_ptr cinfo, boolean require_image);
42+
43+
boolean jpegli_start_decompress(j_decompress_ptr cinfo);
44+
45+
JDIMENSION jpegli_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines,
46+
JDIMENSION max_lines);
47+
48+
JDIMENSION jpegli_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines);
49+
50+
void jpegli_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
51+
JDIMENSION *width);
52+
53+
boolean jpegli_finish_decompress(j_decompress_ptr cinfo);
54+
55+
JDIMENSION jpegli_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
56+
JDIMENSION max_lines);
57+
58+
jvirt_barray_ptr *jpegli_read_coefficients(j_decompress_ptr cinfo);
59+
60+
boolean jpegli_has_multiple_scans(j_decompress_ptr cinfo);
61+
62+
boolean jpegli_start_output(j_decompress_ptr cinfo, int scan_number);
63+
64+
boolean jpegli_finish_output(j_decompress_ptr cinfo);
65+
66+
boolean jpegli_input_complete(j_decompress_ptr cinfo);
67+
68+
int jpegli_consume_input(j_decompress_ptr cinfo);
69+
70+
#if JPEG_LIB_VERSION >= 80
71+
void jpegli_core_output_dimensions(j_decompress_ptr cinfo);
72+
#endif
73+
void jpegli_calc_output_dimensions(j_decompress_ptr cinfo);
74+
75+
void jpegli_save_markers(j_decompress_ptr cinfo, int marker_code,
76+
unsigned int length_limit);
77+
78+
void jpegli_set_marker_processor(j_decompress_ptr cinfo, int marker_code,
79+
jpeg_marker_parser_method routine);
80+
81+
boolean jpegli_resync_to_restart(j_decompress_ptr cinfo, int desired);
82+
83+
boolean jpegli_read_icc_profile(j_decompress_ptr cinfo, JOCTET **icc_data_ptr,
84+
unsigned int *icc_data_len);
85+
86+
void jpegli_abort_decompress(j_decompress_ptr cinfo);
87+
88+
void jpegli_destroy_decompress(j_decompress_ptr cinfo);
89+
90+
void jpegli_new_colormap(j_decompress_ptr cinfo);
91+
92+
//
93+
// New API functions that are not available in libjpeg
94+
//
95+
// NOTE: This part of the API is still experimental and will probably change in
96+
// the future.
97+
//
98+
99+
void jpegli_set_output_format(j_decompress_ptr cinfo, JpegliDataType data_type,
100+
JpegliEndianness endianness);
101+
102+
#if defined(__cplusplus) || defined(c_plusplus)
103+
} // extern "C"
104+
#endif
105+
106+
#endif // LIB_JPEGLI_DECODE_H_

0 commit comments

Comments
 (0)