diff --git a/script/make-red-blue-gradient.go b/script/make-red-blue-gradient.go index 5f912a0b..de3587ad 100644 --- a/script/make-red-blue-gradient.go +++ b/script/make-red-blue-gradient.go @@ -24,6 +24,7 @@ package main import ( "bytes" + "compress/zlib" "flag" "hash/crc32" "image" @@ -34,7 +35,8 @@ import ( ) var ( - gama = flag.Float64("gama", 2.2, "Gamma correction value (e.g. 2.2)") + gama = flag.Float64("gama", 0, "Gamma correction value (e.g. 2.2)") + iccp = flag.String("iccp", "", "ICC filename (e.g. foo/bar.icc)") ) func main() { @@ -71,7 +73,8 @@ func main1() error { out := []byte(nil) out = append(out, prefix...) - // Insert the optional gAMA chunk between the prefix and suffix. + // Insert the optional chunks between the prefix and suffix. + if *gama > 0 { g := uint32(math.Round(100000 / *gama)) out = appendPNGChunk(out, "gAMA", @@ -82,6 +85,20 @@ func main1() error { ) } + if *iccp != "" { + raw, err := os.ReadFile(*iccp) + if err != nil { + return err + } + data := &bytes.Buffer{} + data.WriteString("icc\x00") // An arbitrary NUL terminated name. + data.WriteByte(0x00) // 0x00 means zlib compression. + w := zlib.NewWriter(data) + w.Write(raw) + w.Close() + out = appendPNGChunk(out, "iCCP", data.Bytes()...) + } + // Append the suffix and write to stdout. out = append(out, suffix...) _, err := os.Stdout.Write(out) diff --git a/test/data/DCI-P3-D65.icc b/test/data/DCI-P3-D65.icc new file mode 100644 index 00000000..6e69c142 Binary files /dev/null and b/test/data/DCI-P3-D65.icc differ diff --git a/test/data/DCI-P3-D65.icc.zlib b/test/data/DCI-P3-D65.icc.zlib new file mode 100644 index 00000000..31a44f45 Binary files /dev/null and b/test/data/DCI-P3-D65.icc.zlib differ diff --git a/test/data/README.md b/test/data/README.md index 8a254d15..40b7e820 100644 --- a/test/data/README.md +++ b/test/data/README.md @@ -29,6 +29,11 @@ The non-ascii directory holds trivial UTF-8 (but not ASCII) text files. --- +`DCI-P3-D65.icc` comes from +[color.org](https://www.color.org/chardata/rgb/DCIP3.xalter). +`DCI-P3-D65.icc.zlib` is a zlib-compresion of that, created by Go's standard +library. + `archive.*` archives a subset of other files in this directory. `animated-red-blue.gif` is an original animation by Nigel Tao diff --git a/test/data/red-blue-gradient.dcip3d65.png b/test/data/red-blue-gradient.dcip3d65.png new file mode 100644 index 00000000..8ca2e206 Binary files /dev/null and b/test/data/red-blue-gradient.dcip3d65.png differ diff --git a/test/data/red-blue-gradient.vanilla.png b/test/data/red-blue-gradient.vanilla.png new file mode 100644 index 00000000..1cefb354 Binary files /dev/null and b/test/data/red-blue-gradient.vanilla.png differ