Skip to content

Commit 5221681

Browse files
authored
Merge pull request #4 from SDWebImage/upgrade_avif_v3
Upgrade libavif to 0.3.0, support dav1d instead aom for decoding, which is faster
2 parents e75bb2b + c8ed433 commit 5221681

File tree

7 files changed

+46
-16
lines changed

7 files changed

+46
-16
lines changed

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
github "SDWebImage/SDWebImage" ~> 5.0
2-
github "SDWebImage/libavif-Xcode" ~> 0.2.0
2+
github "SDWebImage/libavif-Xcode" ~> 0.3.0

Cartfile.resolved

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
github "SDWebImage/SDWebImage" "5.1.0"
1+
github "SDWebImage/SDWebImage" "5.2.2"
22
github "SDWebImage/libaom-Xcode" "1.0.1"
3-
github "SDWebImage/libavif-Xcode" "0.2.0"
3+
github "SDWebImage/libavif-Xcode" "0.3.0"

Example/Podfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
target 'SDWebImageAVIFCoder_Example' do
44
platform :ios, '8.0'
55
pod 'SDWebImageAVIFCoder', :path => '../'
6+
pod 'libavif', :subspecs => ['libaom', 'libdav1d']
67

78
target 'SDWebImageAVIFCoder_Tests' do
89
inherit! :search_paths
@@ -14,4 +15,5 @@ end
1415
target 'SDWebImageAVIFCoder_Example macOS' do
1516
platform :osx, '10.10'
1617
pod 'SDWebImageAVIFCoder', :path => '../'
18+
pod 'libavif', :subspecs => ['libaom', 'libdav1d']
1719
end

Example/Podfile.lock

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
PODS:
22
- libaom (1.0.1)
3-
- libavif (0.2.0):
3+
- libavif (0.3.0):
4+
- libavif/libaom (= 0.3.0)
5+
- libavif/libaom (0.3.0):
46
- libaom (>= 1.0.1)
5-
- SDWebImage (5.1.0):
6-
- SDWebImage/Core (= 5.1.0)
7-
- SDWebImage/Core (5.1.0)
8-
- SDWebImageAVIFCoder (0.2.1):
9-
- libavif (~> 0.2.0)
7+
- libavif/libdav1d (0.3.0):
8+
- libavif/libaom
9+
- libdav1d (>= 0.4.0)
10+
- libdav1d (0.4.0)
11+
- SDWebImage (5.2.2):
12+
- SDWebImage/Core (= 5.2.2)
13+
- SDWebImage/Core (5.2.2)
14+
- SDWebImageAVIFCoder (0.3.0):
15+
- libavif (~> 0.3.0)
1016
- SDWebImage (~> 5.0)
1117

1218
DEPENDENCIES:
19+
- libavif/libaom
20+
- libavif/libdav1d
1321
- SDWebImageAVIFCoder (from `../`)
1422

1523
SPEC REPOS:
1624
https://github.com/cocoapods/specs.git:
1725
- libaom
1826
- libavif
27+
- libdav1d
1928
- SDWebImage
2029

2130
EXTERNAL SOURCES:
@@ -24,10 +33,11 @@ EXTERNAL SOURCES:
2433

2534
SPEC CHECKSUMS:
2635
libaom: 1e48c68559b8d6191c1a9f266e0bee83b2dd21fd
27-
libavif: 251b8a20baa5b05467cc64c3b844eaa7b5cf3a62
28-
SDWebImage: fb387001955223213dde14bc08c8b73f371f8d8f
29-
SDWebImageAVIFCoder: 0cc05dc868739b68d6b61856ef11e1aea6af68eb
36+
libavif: 8ae7eca52a4ba56592c63991a30697a9a24244e7
37+
libdav1d: 097f791c93d050b1cb6c0788fbe6c9024ceb3d7e
38+
SDWebImage: 5fcdb02cc35e05fc35791ec514b191d27189f872
39+
SDWebImageAVIFCoder: f994b0bf9e8748a837bd18ec8491228690c16612
3040

31-
PODFILE CHECKSUM: cb60778bff8fb5ce4fbc8792f6079317b7a897be
41+
PODFILE CHECKSUM: 1daaa635bd369cbbf21bf2dd090f9adae3a762dc
3242

3343
COCOAPODS: 1.7.5

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ AVIF image spec is still in evolve. And the current upstream AVIF codec is a sim
2020

2121
Since we rely on the external codec libavif. We may periodically update the dependency and bump version. Make sure you're using the latest version as possible as you can :)
2222

23+
## aom && dav1d
24+
25+
libavif is a still image codec. But AVIF is based on the AV1 Video standard. So it need a AV1 codec for support. This relationship is just like HEIF(image) and HEVC(video) codec.
26+
27+
By default, libavif is built with [aom](https://aomedia.googlesource.com/aom/) codec support. aom is the first AV1 codec during the standard draft implementation.
28+
29+
[dav1d](https://github.com/videolan/dav1d) is the new and next generation AV1 codec, focused on speed and correctness.
30+
31+
From v0.3.0, libavif can built with dav1d. For CocoaPods user, you can simply use the subspec for this. Carthage for optional dav1d codec is not supported currently.
32+
2333
## Requirements
2434

2535
+ iOS 8
@@ -37,6 +47,13 @@ it, simply add the following line to your Podfile:
3747
pod 'SDWebImageAVIFCoder'
3848
```
3949

50+
Note: From version 0.4.0, if you want to use dav1d instead aom for libavif which we dependent on, control the subspec of libavif instead:
51+
52+
```ruby
53+
pod 'SDWebImageAVIFCoder'
54+
pod 'libavif/libdav1d'
55+
```
56+
4057
Note: From version 0.2.0, the dependency libavif and libaom use the portable C implementation to works on Apple platforms. If you need the pre-built library with SIMD/AVX and assembly optimization, try the 0.1.0 version.
4158

4259
#### Carthage

SDWebImageAVIFCoder.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ Which is built based on the open-sourced libavif codec.
3636
s.source_files = 'SDWebImageAVIFCoder/Classes/**/*', 'SDWebImageAVIFCoder/Module/SDWebImageAVIFCoder.h'
3737

3838
s.dependency 'SDWebImage', '~> 5.0'
39-
s.dependency 'libavif', '~> 0.2.0'
39+
s.dependency 'libavif', '~> 0.3.0'
4040
end

SDWebImageAVIFCoder/Classes/SDImageAVIFCoder.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,12 @@ - (nullable NSData *)encodedDataWithImage:(nullable UIImage *)image format:(SDIm
278278
if (options[SDImageCoderEncodeCompressionQuality]) {
279279
compressionQuality = [options[SDImageCoderEncodeCompressionQuality] doubleValue];
280280
}
281-
int rescaledQuality = AVIF_WORST_QUALITY - (int)((compressionQuality) * AVIF_WORST_QUALITY);
281+
int rescaledQuality = AVIF_QUANTIZER_WORST_QUALITY - (int)((compressionQuality) * AVIF_QUANTIZER_WORST_QUALITY);
282282

283283
avifRawData raw = AVIF_RAW_DATA_EMPTY;
284284
avifEncoder *encoder = avifEncoderCreate();
285-
encoder->quality = rescaledQuality;
285+
encoder->minQuantizer = rescaledQuality;
286+
encoder->maxQuantizer = rescaledQuality;
286287
encoder->maxThreads = 2;
287288
avifResult result = avifEncoderWrite(encoder, avif, &raw);
288289

0 commit comments

Comments
 (0)