@@ -31,38 +31,6 @@ static void FreeImageData(void *info, const void *data, size_t size) {
31
31
free ((void *)data);
32
32
}
33
33
34
- // / Calculate the actual thumnail pixel size
35
- static CGSize SDCalculateThumbnailSize (CGSize fullSize, BOOL preserveAspectRatio, CGSize thumbnailSize) {
36
- CGFloat width = fullSize.width ;
37
- CGFloat height = fullSize.height ;
38
- CGFloat resultWidth;
39
- CGFloat resultHeight;
40
-
41
- if (width == 0 || height == 0 || thumbnailSize.width == 0 || thumbnailSize.height == 0 || (width <= thumbnailSize.width && height <= thumbnailSize.height )) {
42
- // Full Pixel
43
- resultWidth = width;
44
- resultHeight = height;
45
- } else {
46
- // Thumbnail
47
- if (preserveAspectRatio) {
48
- CGFloat pixelRatio = width / height;
49
- CGFloat thumbnailRatio = thumbnailSize.width / thumbnailSize.height ;
50
- if (pixelRatio > thumbnailRatio) {
51
- resultWidth = thumbnailSize.width ;
52
- resultHeight = ceil (thumbnailSize.width / pixelRatio);
53
- } else {
54
- resultHeight = thumbnailSize.height ;
55
- resultWidth = ceil (thumbnailSize.height * pixelRatio);
56
- }
57
- } else {
58
- resultWidth = thumbnailSize.width ;
59
- resultHeight = thumbnailSize.height ;
60
- }
61
- }
62
-
63
- return CGSizeMake (resultWidth, resultHeight);
64
- }
65
-
66
34
@implementation SDImageJPEGXLCoder
67
35
68
36
+ (instancetype )sharedCoder {
@@ -334,12 +302,19 @@ - (nullable CGImageRef)sd_createJXLImageWithDec:(JxlDecoder *)dec info:(JxlBasic
334
302
CGDataProviderRef provider = CGDataProviderCreateWithData (NULL , buffer, bufferSize, FreeImageData);
335
303
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault ;
336
304
BOOL shouldInterpolate = YES ;
337
- CGImageRef imageRef = CGImageCreate (width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpace, bitmapInfo, provider, NULL , shouldInterpolate, renderingIntent);
305
+ CGImageRef originImageRef = CGImageCreate (width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpace, bitmapInfo, provider, NULL , shouldInterpolate, renderingIntent);
338
306
CGDataProviderRelease (provider);
339
307
340
- if (!imageRef ) {
308
+ if (!originImageRef ) {
341
309
return nil ;
342
310
}
311
+ // TODO: In SDWebImage 6.0 API, coder can choose `whether I supports thumbnail decoding`
312
+ // if return false, we provide a common implementation `after the full image is decoded`
313
+ // do not repeat code in each coder plugin repo :(
314
+ CGSize scaledSize = [SDImageCoderHelper scaledSizeWithImageSize: CGSizeMake (width, height) scaleSize: thumbnailSize preserveAspectRatio: preserveAspectRatio shouldScaleUp: NO ];
315
+ CGImageRef imageRef = [SDImageCoderHelper CGImageCreateScaled: originImageRef size: scaledSize];
316
+ CGImageRelease (originImageRef);
317
+
343
318
return imageRef;
344
319
}
345
320
0 commit comments