@@ -47,19 +47,21 @@ static inline float JXLGetDistance(const int quality)
4747 if (quality == 0 )
4848 return (1 .0f );
4949 float distance = quality >= 100 ? 0.0
50- : quality >= 30
51- ? 0.1 + (100 - quality) * 0.09
52- : 53.0 / 3000.0 * quality * quality -
53- 23.0 / 20.0 * quality + 25.0 ;
50+ : quality >= 30
51+ ? 0.1 + (100 - quality) * 0.09
52+ : 53.0 / 3000.0 * quality * quality -
53+ 23.0 / 20.0 * quality + 25.0 ;
5454 return distance;
5555}
5656
5757@implementation JxlInternalCoder
5858- (nullable NSData *)encode : (nonnull JXLSystemImage *)platformImage
59- colorSpace : (JXLColorSpace)colorSpace
60- compressionOption : (JXLCompressionOption)compressionOption
61- effort : (int )effort
62- quality : (int )quality error : (NSError * _Nullable *_Nullable)error {
59+ colorSpace : (JXLColorSpace)colorSpace
60+ compressionOption : (JXLCompressionOption)compressionOption
61+ effort : (int )effort
62+ quality : (int )quality
63+ decodingSpeed : (JXLEncoderDecodingSpeed)decodingSpeed
64+ error : (NSError * _Nullable *_Nullable)error {
6365 try {
6466 if (quality < 0 || quality > 100 ) {
6567 *error = [[NSError alloc ] initWithDomain: @" JXLCoder" code: 500 userInfo: @{ NSLocalizedDescriptionKey : @" Quality must be clamped in 0...100" }];
@@ -117,7 +119,9 @@ - (nullable NSData *)encode:(nonnull JXLSystemImage *)platformImage
117119 }
118120
119121 JXLDataWrapper<uint8_t >* wrapper = new JXLDataWrapper<uint8_t >();
120- auto encoded = EncodeJxlOneshot (pixels, width, height, &wrapper->data , jColorspace, jCompressionOption, JXLGetDistance (quality), effort);
122+ auto encoded = EncodeJxlOneshot (pixels, width, height, &wrapper->data ,
123+ jColorspace, jCompressionOption, JXLGetDistance (quality),
124+ effort, (int )decodingSpeed);
121125 if (!encoded) {
122126 delete wrapper;
123127 *error = [[NSError alloc ] initWithDomain: @" JXLCoder" code: 500 userInfo: @{ NSLocalizedDescriptionKey : @" Cannot encode JXL image" }];
@@ -135,8 +139,8 @@ - (nullable NSData *)encode:(nonnull JXLSystemImage *)platformImage
135139 return data;
136140 } catch (std::bad_alloc &err) {
137141 *error = [[NSError alloc ] initWithDomain: @" JXLCoder"
138- code: 500
139- userInfo: @{ NSLocalizedDescriptionKey : [NSString stringWithFormat: @" Encoding image memory error: %s " , err.what ()] }];
142+ code: 500
143+ userInfo: @{ NSLocalizedDescriptionKey : [NSString stringWithFormat: @" Encoding image memory error: %s " , err.what ()] }];
140144 return nullptr ;
141145 }
142146}
@@ -191,11 +195,11 @@ - (CGSize)getSize:(nonnull NSInputStream *)inputStream error:(NSError *_Nullable
191195}
192196
193197- (nullable JXLSystemImage *)decode : (nonnull NSInputStream *)inputStream
194- rescale : (CGSize)rescale
195- pixelFormat : (JXLPreferredPixelFormat)preferredPixelFormat
196- sampler : (JxlSampler)sampler
197- scale : (int )scale
198- error : (NSError *_Nullable * _Nullable)error {
198+ rescale : (CGSize)rescale
199+ pixelFormat : (JXLPreferredPixelFormat)preferredPixelFormat
200+ sampler : (JxlSampler)sampler
201+ scale : (int )scale
202+ error : (NSError *_Nullable * _Nullable)error {
199203 try {
200204 int buffer_length = 30196 ;
201205 std::vector<uint8_t > buffer;
@@ -311,8 +315,8 @@ - (nullable JXLSystemImage *)decode:(nonnull NSInputStream *)inputStream
311315 }
312316
313317 auto scaleResult = [RgbaScaler scaleData: outputData width: (int )xSize height: (int )ySize
314- newWidth: (int )rescale.width newHeight: (int )rescale.height
315- components: components pixelFormat: useFloats ? kF16 : kU8 sampler: xSampler];
318+ newWidth: (int )rescale.width newHeight: (int )rescale.height
319+ components: components pixelFormat: useFloats ? kF16 : kU8 sampler: xSampler];
316320 if (!scaleResult) {
317321 *error = [[NSError alloc ] initWithDomain: @" JXLCoder" code: 500 userInfo: @{ NSLocalizedDescriptionKey : @" Rescale image has failed" }];
318322 return nil ;
@@ -382,17 +386,17 @@ - (nullable JXLSystemImage *)decode:(nonnull NSInputStream *)inputStream
382386 return NULL ;
383387 }
384388 JXLSystemImage *image = nil ;
385- #if JXL_PLUGIN_MAC
389+ #if JXL_PLUGIN_MAC
386390 image = [[NSImage alloc ] initWithCGImage: imageRef size: CGSizeZero];
387- #else
391+ #else
388392 image = [UIImage imageWithCGImage: imageRef scale: scale orientation: UIImageOrientationUp];
389- #endif
393+ #endif
390394
391395 return image;
392396 } catch (std::bad_alloc &err) {
393- *error = [[NSError alloc ] initWithDomain: @" JXLCoder"
394- code: 500
395- userInfo: @{ NSLocalizedDescriptionKey : [NSString stringWithFormat: @" Decoding image memory error: %s " , err.what ()] }];
397+ *error = [[NSError alloc ] initWithDomain: @" JXLCoder"
398+ code: 500
399+ userInfo: @{ NSLocalizedDescriptionKey : [NSString stringWithFormat: @" Decoding image memory error: %s " , err.what ()] }];
396400 return nullptr ;
397401 }
398402}
0 commit comments