@@ -35,27 +35,44 @@ - (void)viewDidLoad {
35
35
self.imageView2 .contentMode = UIViewContentModeScaleAspectFit;
36
36
[self .view addSubview: self .imageView2];
37
37
38
- NSURL *staticURL = [NSURL URLWithString: @" https://jpegxl.info/logo .jxl" ];
39
- NSURL *animatedURL = [NSURL URLWithString: @" https://jpegxl.info/anim_jxl_logo .jxl" ];
38
+ NSURL *staticURL = [NSURL URLWithString: @" https://jpegxl.info/images/dice .jxl" ];
39
+ NSURL *animatedURL = [NSURL URLWithString: @" https://jpegxl.info/images/anim-icos .jxl" ];
40
40
41
41
[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) {
42
42
if (image) {
43
43
NSLog (@" %@ " , @" Static JPEG-XL load success" );
44
44
}
45
- // TODO, JXL encoding
45
+ // static JXL encoding
46
46
dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
47
47
NSUInteger maxFileSize = 4096 ;
48
48
NSData *jxlData = [SDImageJPEGXLCoder.sharedCoder encodedDataWithImage: image format: SDImageFormatJPEGXL options: @{SDImageCoderEncodeMaxFileSize : @(maxFileSize)}];
49
49
if (jxlData) {
50
- NSLog (@" %@ " , @" JPEG-XL encoding success" );
50
+ NSLog (@" Static JPEG-XL encode success, bytes: %lu " , (unsigned long )jxlData.length );
51
+ dispatch_async (dispatch_get_main_queue (), ^{
52
+ UIImage *animatedImage = [UIImage sd_imageWithData: jxlData];
53
+ self.imageView2 .image = animatedImage;
54
+ });
51
55
}
52
56
});
53
57
}];
54
- [self .imageView2 sd_setImageWithURL: animatedURL placeholderImage: nil completed: ^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
55
- if (image) {
56
- NSLog (@" %@ " , @" Animated JPEG-XL load success" );
57
- }
58
- }];
58
+ // [self.imageView2 sd_setImageWithURL:animatedURL placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
59
+ // if (image) {
60
+ // NSLog(@"%@", @"Animated JPEG-XL load success");
61
+ // }
62
+ // // animated JXL encoding
63
+ // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
64
+ // NSData *jxlData = [SDImageJPEGXLCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatJPEGXL options:@{
65
+ // SDImageCoderEncodeJXLDistance : @(3.0),
66
+ // }];
67
+ // if (jxlData) {
68
+ // NSLog(@"Animated JPEG-XL encode success, bytes: %lu", (unsigned long)jxlData.length);
69
+ // dispatch_async(dispatch_get_main_queue(), ^{
70
+ // UIImage *animatedImage = [UIImage sd_imageWithData:jxlData];
71
+ // self.imageView1.image = animatedImage;
72
+ // });
73
+ // }
74
+ // });
75
+ // }];
59
76
60
77
[self testHDREncoding ];
61
78
}
@@ -79,13 +96,13 @@ - (void)testHDREncoding {
79
96
- (void )encodeJXLWithImage : (UIImage *)image {
80
97
NSCParameterAssert (image);
81
98
NSDictionary *frameSetting = @{
82
- @(JXL_ENC_FRAME_SETTING_EFFORT) : @(1 ),
83
- @(JXL_ENC_FRAME_SETTING_BROTLI_EFFORT) : @(0 )
99
+ @(JXL_ENC_FRAME_SETTING_EFFORT) : @(10 ),
100
+ @(JXL_ENC_FRAME_SETTING_BROTLI_EFFORT) : @(11 )
84
101
};
85
102
// fastest encoding speed but largest compressed size, you can adjust options here
86
103
NSData *data = [SDImageJPEGXLCoder.sharedCoder encodedDataWithImage: image format: SDImageFormatJPEGXL options: @{
87
104
// SDImageCoderEncodeCompressionQuality : @0.68,
88
- SDImageCoderEncodeJXLDistance : @(1 .0 ),
105
+ SDImageCoderEncodeJXLDistance : @(3 .0 ),
89
106
SDImageCoderEncodeJXLFrameSetting : frameSetting,
90
107
}];
91
108
NSCParameterAssert (data);
0 commit comments