Skip to content

Commit cb7d7de

Browse files
committed
WIP: Try to implemnts the JPEG-XL encoding
Support static image currently Test code need remove
1 parent f302e50 commit cb7d7de

File tree

2 files changed

+405
-17
lines changed

2 files changed

+405
-17
lines changed

Example/SDWebImageJPEGXLCoder/SDViewController.m

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,29 @@ - (void)viewDidLoad {
3737
NSURL *staticURL = [NSURL URLWithString:@"https://jpegxl.info/logo.jxl"];
3838
NSURL *animatedURL = [NSURL URLWithString:@"https://jpegxl.info/anim_jxl_logo.jxl"];
3939

40-
[self.imageView1 sd_setImageWithURL:staticURL placeholderImage:nil options:0 context:nil progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
41-
if (image) {
42-
NSLog(@"%@", @"Static JPEG-XL load success");
43-
}
44-
// TODO, JXL encoding
40+
// [self.imageView1 sd_setImageWithURL:staticURL placeholderImage:nil options:0 context:nil progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
41+
// if (image) {
42+
// NSLog(@"%@", @"Static JPEG-XL load success");
43+
// }
44+
//// TODO, JXL encoding
4545
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
4646
// NSUInteger maxFileSize = 4096;
4747
// NSData *jxlData = [SDImageJPEGXLCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatJPEGXL options:@{SDImageCoderEncodeMaxFileSize : @(maxFileSize)}];
4848
// if (jxlData) {
4949
// NSLog(@"%@", @"JPEG-XL encoding success");
5050
// }
5151
// });
52-
}];
53-
[self.imageView2 sd_setImageWithURL:animatedURL placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
54-
if (image) {
55-
NSLog(@"%@", @"Animated JPEG-XL load success");
56-
}
57-
}];
52+
// }];
53+
// [self.imageView2 sd_setImageWithURL:animatedURL placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
54+
// if (image) {
55+
// NSLog(@"%@", @"Animated JPEG-XL load success");
56+
// }
57+
// }];
58+
59+
// Test JXL Encode
60+
NSData *HDRData = [NSData dataWithContentsOfFile:@"/Users/lizhuoli/Desktop/iso-hdr-demo.jxl"];
61+
UIImage *image = [UIImage imageWithData:HDRData];
62+
[self encodeJXLWithImage:image];
5863
}
5964

6065
- (void)viewWillLayoutSubviews {
@@ -63,6 +68,18 @@ - (void)viewWillLayoutSubviews {
6368
self.imageView2.frame = CGRectMake(0, self.view.bounds.size.height / 2, self.view.bounds.size.width, self.view.bounds.size.height / 2);
6469
}
6570

71+
- (void)encodeJXLWithImage:(UIImage *)image {
72+
NSData *data = [SDImageJPEGXLCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatJPEGXL options:@{
73+
SDImageCoderEncodeCompressionQuality : @0.68
74+
}];
75+
NSCParameterAssert(data);
76+
[data writeToFile:@"/tmp/a.jxl" atomically:YES];
77+
78+
CIImage *ciimage = [CIImage imageWithData:data];
79+
NSString *desc = [ciimage description];
80+
NSLog(@"Encoded JXL CIImage description: %@", desc);
81+
}
82+
6683
- (void)didReceiveMemoryWarning {
6784
[super didReceiveMemoryWarning];
6885
// Dispose of any resources that can be recreated.

0 commit comments

Comments
 (0)