Skip to content

Commit a14aa9d

Browse files
committed
update README about codec thumbnail encoding
1 parent 03252bd commit a14aa9d

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ let lossyAVIFData = SDImageAVIFCoder.shared.encodedData(with: image, format: .av
269269

270270
### Thumbnail Encoding (0.12.0+)
271271

272+
Note: only available in aom codec encoder!
273+
272274
+ Objective-C
273275

274276
```objective-c

SDWebImageAVIFCoder/Classes/SDImageAVIFCoder.m

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,21 @@ - (nullable NSData *)encodedDataWithImage:(nullable UIImage *)image format:(SDIm
353353
encoder->quality = quality;
354354
encoder->qualityAlpha = quality;
355355
encoder->maxThreads = 2;
356-
// Check if need to scale pixel size
357-
CGSize scaledSize = [SDImageCoderHelper scaledSizeWithImageSize:CGSizeMake(width, height) scaleSize:maxPixelSize preserveAspectRatio:YES shouldScaleUp:NO];
358-
if (!CGSizeEqualToSize(scaledSize, CGSizeMake(width, height))) {
359-
// Thumbnail Encoding
360-
assert(scaledSize.width <= width);
361-
assert(scaledSize.height <= height);
362-
avifScalingMode scale;
363-
scale.horizontal.n = (int)scaledSize.width;
364-
scale.horizontal.d = (int)width;
365-
scale.vertical.n = (int)scaledSize.height;
366-
scale.vertical.d = (int)height;
367-
encoder->scalingMode = scale;
356+
// Check if need to scale pixel size, currently only available on aom
357+
const char *codecName = avifCodecName(codecChoice, AVIF_CODEC_FLAG_CAN_ENCODE);
358+
if (codecName && strcmp(codecName, "aom") == 0) {
359+
CGSize scaledSize = [SDImageCoderHelper scaledSizeWithImageSize:CGSizeMake(width, height) scaleSize:maxPixelSize preserveAspectRatio:YES shouldScaleUp:NO];
360+
if (!CGSizeEqualToSize(scaledSize, CGSizeMake(width, height))) {
361+
// Thumbnail Encoding
362+
assert(scaledSize.width <= width);
363+
assert(scaledSize.height <= height);
364+
avifScalingMode scale;
365+
scale.horizontal.n = (int)scaledSize.width;
366+
scale.horizontal.d = (int)width;
367+
scale.vertical.n = (int)scaledSize.height;
368+
scale.vertical.d = (int)height;
369+
encoder->scalingMode = scale;
370+
}
368371
}
369372
avifResult result = avifEncoderWrite(encoder, avif, &raw);
370373

0 commit comments

Comments
 (0)