Debian Codegraph @

internal/warpc/avif_color_test.go

raw
1 package warpc_test
2
3 import (
4 "os/exec"
5 "path/filepath"
6 "strings"
7 "testing"
8
9 qt "github.com/frankban/quicktest"
10 "github.com/gohugoio/hugo/hugolib"
11 )
12
13 func TestAvifColorPropertyPreservation(t *testing.T) {
14 if testing.Short() {
15 t.Skip("Skipping in short mode")
16 }
17
18 // dock-75-hdr.avif is Lightroom-style SDR+gain-map HDR; the decoder bakes the
19 // gain map into a single BT.2020/PQ HDR AVIF.
20 files := `
21 -- hugo.toml --
22 -- assets/dock.avif --
23 sourcefilename: ../../resources/testdata/bep/dock-75-hdr.avif
24 -- layouts/home.html --
25 {{ $dock := resources.Get "dock.avif" }}
26 Dock: {{ $dock.Width }}x{{ $dock.Height }}
27 {{ $dockReencoded := $dock.Process "avif q75" }}
28 DockReencoded: {{ $dockReencoded.RelPermalink }}
29 `
30
31 b, err := hugolib.TestE(t, files, hugolib.TestOptWithOSFs())
32 b.Assert(err, qt.IsNil)
33 b.AssertFileContent("public/index.html", "Dock: 1024x683")
34
35 // Check color properties of re-encoded files using exiftool
36 checkColorProps := func(t *testing.T, name, filepath string, expectedPrimaries, expectedTransfer string) {
37 cmd := exec.Command("exiftool", "-ColorPrimaries", "-TransferCharacteristics", filepath)
38 output, err := cmd.Output()
39 if err != nil {
40 t.Skipf("exiftool not available: %v", err)
41 }
42 outputStr := string(output)
43 t.Logf("Color properties for %s:\n%s", name, outputStr)
44
45 if !strings.Contains(outputStr, expectedPrimaries) {
46 t.Errorf("%s: Expected color primaries %q, got:\n%s", name, expectedPrimaries, outputStr)
47 }
48 if !strings.Contains(outputStr, expectedTransfer) {
49 t.Errorf("%s: Expected transfer characteristics %q, got:\n%s", name, expectedTransfer, outputStr)
50 }
51 }
52
53 // Find the generated files - use Cfg.WorkingDir
54 publicDir := filepath.Join(b.Cfg.WorkingDir, "public")
55 t.Logf("Looking in: %s", publicDir)
56
57 // dock-75-hdr.avif has a gain map, so the output should be BT.2020/PQ.
58 dockMatches, _ := filepath.Glob(filepath.Join(publicDir, "dock_hu*.avif"))
59 if len(dockMatches) > 0 {
60 checkColorProps(t, "dock", dockMatches[0], "BT.2020", "PQ")
61 } else {
62 t.Error("No dock AVIF file found in output")
63 }
64 }