Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libavif #1381

Merged
merged 24 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
47f8746
Update libavif (v1.0.0-main)
aryanpingle Sep 14, 2023
f8804b1
Update libavif (v1.0.1-main)
aryanpingle Sep 15, 2023
82658c7
Refactor variable names for clarity
aryanpingle Sep 15, 2023
642ac6d
Update libaom (v3.7.0)
aryanpingle Sep 28, 2023
96da59f
Add checks for API return values
aryanpingle Oct 17, 2023
a5a3f63
Rename variables for readability
aryanpingle Oct 17, 2023
f1f4030
Minor patches in logic
aryanpingle Oct 17, 2023
3ed34e1
Minor patches in lossless calculation
aryanpingle Oct 18, 2023
625eee2
Add chroma subsampling options to AVIF
aryanpingle Oct 18, 2023
1b3f791
Add skeleton for sharp downsampling param
aryanpingle Oct 23, 2023
f27d524
Try to use libsharpyuv
surma Oct 23, 2023
47cd47e
Encoder working, decoder isnt
surma Oct 25, 2023
25ea8b9
Make sure sharpyuv is disabled for decoder
surma Oct 25, 2023
0413c66
Add AVIF_LOCAL flags for sharp yuv
aryanpingle Oct 27, 2023
ab79caf
Get AVIF sharp YUV working
aryanpingle Oct 27, 2023
41c4b30
Clean up AVIF makefiles
aryanpingle Oct 28, 2023
faa1467
AVIF: Make sharpyuv conditional on subsample
aryanpingle Oct 28, 2023
fd53823
AVIF: Flags to speed up sharpyuv build
aryanpingle Oct 30, 2023
aad51d3
AVIF: Minor refactoring in enc.cpp
aryanpingle Oct 30, 2023
699b9e0
AVIF: Minor refactoring & renaming
aryanpingle Oct 30, 2023
4cdc246
AVIF: Use smart pointers to prevent memory leaks
aryanpingle Oct 31, 2023
7099d5e
AVIF: Minor refactoring
aryanpingle Nov 3, 2023
aa89d7c
AVIF: Revert defaultoptions logic change
aryanpingle Nov 3, 2023
795e395
Merge branch 'dev' into avif-update
jakearchibald Jan 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codecs/avif/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# libavif and libaom versions are from
# google3/third_party/libavif/METADATA
CODEC_URL = https://github.com/AOMediaCodec/libavif/archive/647c3c208cf152395d777c1bf7240d2ecf7df5a9.tar.gz
CODEC_URL = https://github.com/AOMediaCodec/libavif/archive/d1c26facaf5a8a97919ceee06814d05d10e25622.tar.gz
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
CODEC_PACKAGE = node_modules/libavif.tar.gz

LIBAOM_URL = https://aomedia.googlesource.com/aom/+archive/v3.6.0.tar.gz
Expand Down
Binary file modified codecs/avif/dec/avif_dec.wasm
Binary file not shown.
Binary file modified codecs/avif/dec/avif_node_dec.wasm
Binary file not shown.
21 changes: 7 additions & 14 deletions codecs/avif/enc/avif_enc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using namespace emscripten;

struct AvifOptions {
// [0 - 63]
// 0 = lossless
// 63 = worst quality
// [0 - 100]
// 0 = worst quality
// 100 = lossless
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
int cqLevel;
// As above, but -1 means 'use cqLevel'
int cqAlphaLevel;
Expand Down Expand Up @@ -81,23 +81,16 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
avifEncoder* encoder = avifEncoderCreate();

if (lossless) {
encoder->minQuantizer = AVIF_QUANTIZER_LOSSLESS;
encoder->maxQuantizer = AVIF_QUANTIZER_LOSSLESS;
encoder->minQuantizerAlpha = AVIF_QUANTIZER_LOSSLESS;
encoder->maxQuantizerAlpha = AVIF_QUANTIZER_LOSSLESS;
encoder->quality = AVIF_QUALITY_LOSSLESS;
encoder->qualityAlpha = AVIF_QUALITY_LOSSLESS;
} else {
encoder->minQuantizer = AVIF_QUANTIZER_BEST_QUALITY;
encoder->maxQuantizer = AVIF_QUANTIZER_WORST_QUALITY;
encoder->minQuantizerAlpha = AVIF_QUANTIZER_BEST_QUALITY;
encoder->maxQuantizerAlpha = AVIF_QUANTIZER_WORST_QUALITY;
avifEncoderSetCodecSpecificOption(encoder, "end-usage", "q");
avifEncoderSetCodecSpecificOption(encoder, "cq-level", std::to_string(options.cqLevel).c_str());
avifEncoderSetCodecSpecificOption(encoder, "sharpness",
std::to_string(options.sharpness).c_str());

encoder->quality = options.cqLevel;
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
if (options.cqAlphaLevel != -1) {
avifEncoderSetCodecSpecificOption(encoder, "alpha:cq-level",
std::to_string(options.cqAlphaLevel).c_str());
encoder->qualityAlpha = options.cqAlphaLevel;
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
}

if (options.tune == 2 || (options.tune == 0 && options.cqLevel <= 32)) {
Expand Down
2 changes: 1 addition & 1 deletion codecs/avif/enc/avif_enc.js

Large diffs are not rendered by default.

Binary file modified codecs/avif/enc/avif_enc.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion codecs/avif/enc/avif_enc_mt.js

Large diffs are not rendered by default.

Binary file modified codecs/avif/enc/avif_enc_mt.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion codecs/avif/enc/avif_node_enc.js

Large diffs are not rendered by default.

Binary file modified codecs/avif/enc/avif_node_enc.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion codecs/avif/enc/avif_node_enc_mt.js

Large diffs are not rendered by default.

Binary file modified codecs/avif/enc/avif_node_enc_mt.wasm
Binary file not shown.
31 changes: 19 additions & 12 deletions src/features/encoders/avif/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ interface State {
tune: AVIFTune;
}

const maxQuant = 63;
const maxSpeed = 10;
/**
* AVIF quality ranges from 0 (worst) to 100 (lossless).
* Since lossless is a separate checkbox, we cap user-inputted quality at 99
*
* AVIF speed ranges from 0 (slowest) to 10 (fastest).
* We display it as 'effort' to the user since it conveys the speed-size tradeoff
* much better: speed = 10 - effort
*/
const MAX_EFFORT = 10;
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved

export class Options extends Component<Props, State> {
static getDerivedStateFromProps(
Expand All @@ -67,18 +74,18 @@ export class Options extends Component<Props, State> {
return {
options,
lossless,
quality: maxQuant - cqLevel,
quality: cqLevel,
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
separateAlpha,
alphaQuality:
maxQuant -
(separateAlpha ? options.cqAlphaLevel : defaultOptions.cqLevel),
alphaQuality: separateAlpha
? options.cqAlphaLevel
: defaultOptions.cqLevel,
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
subsample:
options.subsample === 0 || lossless
? defaultOptions.subsample
: options.subsample,
tileRows: options.tileRowsLog2,
tileCols: options.tileColsLog2,
effort: maxSpeed - options.speed,
effort: MAX_EFFORT - options.speed,
chromaDeltaQ: options.chromaDeltaQ,
sharpness: options.sharpness,
denoiseLevel: options.denoiseLevel,
Expand Down Expand Up @@ -120,16 +127,16 @@ export class Options extends Component<Props, State> {
};

const newOptions: EncodeOptions = {
cqLevel: optionState.lossless ? 0 : maxQuant - optionState.quality,
cqLevel: optionState.lossless ? 100 : optionState.quality,
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
cqAlphaLevel:
optionState.lossless || !optionState.separateAlpha
? -1
: maxQuant - optionState.alphaQuality,
: optionState.alphaQuality,
// Always set to 4:4:4 if lossless
subsample: optionState.lossless ? 3 : optionState.subsample,
tileColsLog2: optionState.tileCols,
tileRowsLog2: optionState.tileRows,
speed: maxSpeed - optionState.effort,
speed: MAX_EFFORT - optionState.effort,
chromaDeltaQ: optionState.chromaDeltaQ,
sharpness: optionState.sharpness,
denoiseLevel: optionState.denoiseLevel,
Expand Down Expand Up @@ -183,7 +190,7 @@ export class Options extends Component<Props, State> {
<div class={style.optionOneCell}>
<Range
min="0"
max="63"
max="99"
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
value={quality}
onInput={this._inputChange('quality', 'number')}
>
Expand Down Expand Up @@ -228,7 +235,7 @@ export class Options extends Component<Props, State> {
<div class={style.optionOneCell}>
<Range
min="0"
max="63"
max="99"
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
value={alphaQuality}
onInput={this._inputChange(
'alphaQuality',
Expand Down
2 changes: 1 addition & 1 deletion src/features/encoders/avif/shared/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const label = 'AVIF';
export const mimeType = 'image/avif';
export const extension = 'avif';
export const defaultOptions: EncodeOptions = {
cqLevel: 33,
cqLevel: 50,
aryanpingle marked this conversation as resolved.
Show resolved Hide resolved
cqAlphaLevel: -1,
denoiseLevel: 0,
tileColsLog2: 0,
Expand Down