Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90d9f81

Browse files
committed
Add image processing support for AVIF
The encode/decode is implemented in a WebAssembly module built from a small C wrapper around libavif. Bundled libraries (statically linked, compiled with the WASI SDK): * libavif v1.4.1 (container + codec glue) * libaom v3.14.1 (AV1 encoder + decoder) * dav1d 1.5.3 (AV1 decoder) * libyuv (Chromium pin) for color conversion * parson for JSON message passing across the wasm boundary HDR handling on the encoder: * SDR images are written as BT.709 / sRGB / BT.601 (8-bit). * 10-bit and up are written as BT.2020 primaries with PQ (SMPTE ST 2084) transfer and BT.2020-NCL matrix coefficients, signalled via CICP. * Adobe-style SDR+gainmap inputs (e.g. Lightroom HDR exports) are baked into a single true-HDR image in BT.2020/PQ at 10-bit, with the CLLI (Content Light Level Information) box carried through so HDR-capable clients can tone-map correctly. Limitations: * Animated input (animated WebP/GIF) is collapsed to its first frame when re-encoded as AVIF; animated AVIF output is not yet supported. Fixes #7837
1 parent 80e6084 commit 90d9f81

41 files changed

Lines changed: 1973 additions & 63 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

common/himage/image.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ type ImageConfigProvider interface {
4343
GetImageConfig() image.Config
4444
}
4545

46+
// ColorPropertiesProvider provides access to CICP color properties (for HDR images).
47+
// Images implementing this interface preserve color space information through processing.
48+
type ColorPropertiesProvider interface {
49+
GetColorPrimaries() int
50+
GetTransferCharacteristics() int
51+
GetMatrixCoefficients() int
52+
}
53+
54+
// HasColorProperties returns true if the image has non-zero color properties that should be preserved.
55+
func HasColorProperties(img image.Image) bool {
56+
if cpp, ok := img.(ColorPropertiesProvider); ok {
57+
// Consider it as having properties if any value is non-zero.
58+
return cpp.GetColorPrimaries() > 0 || cpp.GetTransferCharacteristics() > 0 || cpp.GetMatrixCoefficients() > 0
59+
}
60+
return false
61+
}
62+
4663
// FrameDurationsToGifDelays converts frame durations in milliseconds to
4764
// GIF delays in 100ths of a second.
4865
func FrameDurationsToGifDelays(frameDurations []int) []int {

config/testconfig/testconfig.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ func GetTestDeps(fs afero.Fs, cfg config.Provider, beforeInit ...func(*deps.Deps
6868
warpc.Options{
6969
PoolSize: 1,
7070
},
71+
warpc.Options{
72+
PoolSize: 1,
73+
},
7174
),
7275
}
7376
for _, f := range beforeInit {

docs/.vscode/extensions.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ require (
6868
github.com/spf13/pflag v1.0.10
6969
github.com/tdewolff/minify/v2 v2.24.13
7070
github.com/tdewolff/parse/v2 v2.8.12
71-
github.com/tetratelabs/wazero v1.11.0
71+
github.com/tetratelabs/wazero v1.11.1-0.20260521072212-475a1f8f0dc3
7272
github.com/yuin/goldmark v1.8.2
7373
github.com/yuin/goldmark-emoji v1.0.6
7474
go.uber.org/automaxprocs v1.5.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ github.com/tdewolff/test v1.0.12 h1:7F21DqIajswxuche0geHdrUZRCWE4oko4b7bcmkkrxk=
504504
github.com/tdewolff/test v1.0.12/go.mod h1:XPuWBzvdUzhCuxWO1ojpXsyzsA5bFoS3tO/Q3kFuTG8=
505505
github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
506506
github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU=
507+
github.com/tetratelabs/wazero v1.11.1-0.20260521072212-475a1f8f0dc3 h1:0Jpp+tPkvALC9hcZUYOj/6yWYvUIV/kKoxRDj0a6zk4=
508+
github.com/tetratelabs/wazero v1.11.1-0.20260521072212-475a1f8f0dc3/go.mod h1:LvKtzl2RqO4gyF27BiXU+nKAjcV8f38U+kP/q2vgxh0=
507509
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
508510
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
509511
github.com/woodsbury/decimal128 v1.3.0 h1:8pffMNWIlC0O5vbyHWFZAt5yWvWcrHA+3ovIIjVWss0=

hugolib/site.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,12 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
204204
var (
205205
poolSizeKatex = 2
206206
poolSizeWebP = 1
207+
poolSizeAvif = 1
207208
)
208209
if n := config.GetNumWorkerMultiplier(); n > 1 {
209210
poolSizeKatex = min(n, 8)
210211
poolSizeWebP = max(2, n/2)
212+
poolSizeAvif = max(2, n/2)
211213
}
212214

213215
var logger loggers.Logger
@@ -282,6 +284,14 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
282284
Infof: logger.InfoCommand("webp").Logf,
283285
Warnf: logger.WarnCommand("webp").Logf,
284286
},
287+
// Avif options.
288+
warpc.Options{
289+
CompilationCacheDir: compilationCacheDir,
290+
PoolSize: poolSizeAvif,
291+
Memory: 384, // 384 MiB (4096 MiB Max)
292+
Infof: logger.InfoCommand("avif").Logf,
293+
Warnf: logger.WarnCommand("avif").Logf,
294+
},
285295
),
286296
}
287297

0 commit comments

Comments
 (0)