GoogleChromeLabs / squoosh

Make images smaller using best-in-class codecs, right in the browser.
https://squoosh.app
Apache License 2.0
22.07k stars 1.56k forks source link

AVIF encoding uses chroma subsampling #1368

Open kornelski opened 1 year ago

kornelski commented 1 year ago

AVIF encoding option has "Subsample chroma: Half".

This is an exceptionally bad choice:

  1. Chroma upsampling algorithm is not specified for AVIF, which makes a blocky nearest-neighbor a valid implementation. Appearance of AVIFs with subsampled chroma will be inconsistent across implementations. This is even worse than the worst of WebP, because WebP at least has a guaranteed upsampling algorithm and filters that reduce the distortion.

  2. AV1 supports chroma-from-luma compression technique, which is a proper effective way to compress chroma. Naive destruction of 75% of the color data misses out on the unique ability to compress it well.

I think it'd be best to completely remove the subsampling option, and pretend it never existed.

jakearchibald commented 1 year ago

It's the default in avif-enc, right?

I agree that lack of specified upscaling is bad, they should fix that.

From my own testing, for photos, subsampling still seems worth it in terms of compression. But yeah, I worry that the option is buried, because you don't want it for other types of imagery.

kornelski commented 1 year ago

I've asked for upsampling to be specified, and it has been closed as wontfix.

I would not interpret defaults of avif-enc as an informed recommendation. Codecs and their tooling are full of "we've always done it this way", and subsampling has been a normal thing since 1953.

AV1 inherited a few weird features and a ton of obsolete color modes that nobody should be using anymore, which are carried over because people don't want to touch Chesterton's fence.

AFAIK AV1 is the first codec to have chroma-from-luma technique which allows it to compress full-res sharp chroma cheaply. It also scales to low bitrates very well, so even if you want to mangle color, you can do by increasing compression of chroma channels without having to outright decimate their resolution.

Subsampling is useful in JPEG which isn’t as resolution-independent and lower-res higher-quality channel may look better than a higher-res lower-quality channel. But there’s no such problem with AV1, so subsampling just destroys chroma’s edges without having a chance to use any of AV1’s techniques that could have saved those edges.