Skip to content

Add image processing support for AVIF#14896

Draft
bep wants to merge 4 commits into
gohugoio:masterfrom
bep:feat/avif-7837
Draft

Add image processing support for AVIF#14896
bep wants to merge 4 commits into
gohugoio:masterfrom
bep:feat/avif-7837

Conversation

@bep
Copy link
Copy Markdown
Member

@bep bep commented May 14, 2026

Test site: https://github.com/bep/hugo-testing-avif-hdr

TODO

  • Check hdr_cosmos01000_cicp9-16-9_yuv444_full_qp20.avif, hdr_cosmos01650_cicp9-16-9_yuv420_limited_qp10.avif (times out) Probably worst case edge cases that perform poorly with WASM.
  • Remove the 4:2:0 / 4:2:2 restriction in avif.c:404. Add some relevant golden tests
  • Make avif.encoder.speed an option, test increasing the default to 10.

Tips

When exporting HDR AVIF images from LightRoom to be processed by Hugo, we suggest you uncheck Maximize Compability:

image

This greatly improves the speed of decoding the images in Hugo.

Options

  • imaging.avif.encoderSpeed: 0-10 (10 default?)

@bep
Copy link
Copy Markdown
Member Author

bep commented May 15, 2026

@jmooring no rush (theres a few pieces missing to get this into a mergeable state, for one I need a bug fix merged in Wazero), but I'm curious as to how this behaves on other OSes (mostly Windows), so if you have a minute in the near future, it would be appreciated if you could build this Hugo branch and test https://github.com/bep/hugo-testing-avif-hdr

  • There's some timings printed to the console.
  • Note that the AVIFs are 10 bit per channel HDR files, so not a "best case scenario".
  • I will do some more research about gaining more performance, but I think this is usable/useful.
  • I need to get out more photographing some more HDR suitable things, because some of those AVIF files looks pretty good.

EDIT in: I have moved the test site to https://github.com/bep/hugo-testing-avif-hdr
EDIT in2: The same set of images are published in both avif (hdr) and jpeg (sdr), see menu top right
EDIT in3 (May 16): I have pushed a new version that uses Dav1d for decoding and also tunes the encoding part, which makes everything about 2.5x faster on my MacBook.

bep added 2 commits May 16, 2026 11:24
2.5x faster roundrip (decodde AVIF, resize and encode AVIF).
@bep bep force-pushed the feat/avif-7837 branch from e81b82c to 055603a Compare May 16, 2026 10:12
@bep bep force-pushed the feat/avif-7837 branch 3 times, most recently from c2d0eca to b906b91 Compare May 17, 2026 09:41
@bep bep force-pushed the feat/avif-7837 branch from b906b91 to 064270b Compare May 17, 2026 13:54
@jmooring
Copy link
Copy Markdown
Member

jmooring commented May 17, 2026

Windows build log (no problems):

console log
Start building sites … 
hugo v0.162.0-DEV-064270b48738da27c04882bed5700e05637aef07 windows/amd64 BuildDate=2026-05-17T10:03:52Z

Decode JPEG 35.449ms
Encode JPEG 23.4316ms
Decode JPEG 42.1339ms
Encode JPEG 19.9061ms
Decode JPEG 54.9676ms
Encode JPEG 19.6545ms
Decode JPEG 34.9011ms
Encode JPEG 25.2304ms
Decode JPEG 58.4454ms
Encode JPEG 24.2434ms
Decode JPEG 38.0319ms
Encode JPEG 15.3559ms
Decode JPEG 43.0622ms
Encode JPEG 23.7848ms
Decode AVIF 902.8534ms
Encode AVIF 416.306ms
Decode AVIF 191.4306ms
Encode AVIF 385.3575ms
Decode AVIF 188.0168ms
Encode AVIF 303.5459ms
Decode AVIF 165.9084ms
Encode AVIF 305.3338ms
Decode AVIF 268.8769ms
Encode AVIF 380.9972ms
Decode AVIF 157.7176ms
Encode AVIF 274.9308ms
Decode AVIF 130.9826ms
Encode AVIF 281.4808ms

                  │ EN 
──────────────────┼────
 Pages            │  3 
 Paginator pages  │  0 
 Non-page files   │ 14 
 Static files     │  0 
 Processed images │ 14 
 Aliases          │  0 
 Cleaned          │  0 

Built in 4875 ms

On my low quality display the SDR images look better.

image image

So I guess I'd want to do something like:

<picture>
  <source srcset="/hdr/20200724_21_03_43_1.avif" media="(dynamic-range: high)">
  <img src="/sdr/20200724_21_03_43_1.jpg">
</picture>

@bep
Copy link
Copy Markdown
Member Author

bep commented May 17, 2026

So I guess I'd want to do something like:

Some notes on this:

  • My test site is focused on HDR, which isn't the entire value proposition of AVIF, but it's certainly impressive that it can produce so small 10 bit HDR images that looks this good, a feature that I suspect will entice many "Hugo photographers" (including myself)
  • When looking through my LightRoom catalog, I found just a handful of photos where the HDR "thing" had any real effect, and the one you pointed out (the one from Barcelona) I think looks better in SDR even on my Retina screen (that photo was taken on my old Pentax K3 II, so old hardware by now).
  • But you're right, HDR files processed by Hugo viewed on SDR screens gets "auto tone mapped", and that method may not always be spot on.
  • LightRoom has an option to export HDR files in "Compatibility mode" which produces both HDR and a fallback SDR version, but supporting that in Hugo's processing filters would make everything massively more complicated.

But, thanks for testing.

Just one note here: The thumbnails are produced by Hugo, the full view is produced by LightRoom (which I suspect I could improve re. your comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants