From 6ea3144379b0cfa6ae4d6a70d3a00745069ad78c Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 19 Oct 2021 22:19:01 +1100 Subject: [PATCH] Add test/data/checkerboard.*.png --- script/make-red-blue-gradient.go | 47 +++++++++++++++++++------- test/data/README.md | 2 ++ test/data/checkerboard.gamma1dot0.png | Bin 0 -> 441 bytes test/data/checkerboard.gamma2dot2.png | Bin 0 -> 441 bytes 4 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 test/data/checkerboard.gamma1dot0.png create mode 100644 test/data/checkerboard.gamma2dot2.png diff --git a/script/make-red-blue-gradient.go b/script/make-red-blue-gradient.go index de3587ad..8b2bc0b3 100644 --- a/script/make-red-blue-gradient.go +++ b/script/make-red-blue-gradient.go @@ -35,8 +35,9 @@ import ( ) var ( - gama = flag.Float64("gama", 0, "Gamma correction value (e.g. 2.2)") - iccp = flag.String("iccp", "", "ICC filename (e.g. foo/bar.icc)") + checkerboard = flag.Bool("checkerboard", false, "Create a checkerboard pattern instead") + 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() { @@ -49,22 +50,42 @@ func main() { func main1() error { flag.Parse() - // Make a red-blue gradient. - m := image.NewRGBA(image.Rect(0, 0, 16, 16)) - for y := 0; y < 16; y++ { - for x := 0; x < 16; x++ { - m.SetRGBA(x, y, color.RGBA{ - R: uint8(x * 0x11), - G: 0x00, - B: uint8(y * 0x11), - A: 0xFF, - }) + // Make a checkerboard or red-blue gradient. + src := image.Image(nil) + if *checkerboard { + // With -gama=1.0 (or -gama=2.2), the two halves of this image should + // have roughly equal (or un-equal) brightness. + m := image.NewGray(image.Rect(0, 0, 256, 256)) + for y := 0; y < 256; y++ { + for x := 0; x < 256; x++ { + if x < 128 { + m.SetGray(x, y, color.Gray{0x80}) + } else if ((x ^ y) & 1) == 1 { + m.SetGray(x, y, color.Gray{0xFF}) + } else { + m.SetGray(x, y, color.Gray{0x00}) + } + } } + src = m + } else { + m := image.NewRGBA(image.Rect(0, 0, 16, 16)) + for y := 0; y < 16; y++ { + for x := 0; x < 16; x++ { + m.SetRGBA(x, y, color.RGBA{ + R: uint8(x * 0x11), + G: 0x00, + B: uint8(y * 0x11), + A: 0xFF, + }) + } + } + src = m } // Encode to PNG. buf := &bytes.Buffer{} - png.Encode(buf, m) + png.Encode(buf, src) original := buf.Bytes() // Split the encoding into a magic+IHDR prefix and an IDAT+IEND suffix. The diff --git a/test/data/README.md b/test/data/README.md index 40b7e820..fd1bf401 100644 --- a/test/data/README.md +++ b/test/data/README.md @@ -49,6 +49,8 @@ library. `cbor-rfc-7049-examples.*.json` files were then generated by `example/cbor-to-json`. +`checkerboard.*.png` was generated by `script/make-red-blue-gradient.go`. + `crude-flag.*` is an original animation by Nigel Tao . See the `lib/nie` documentation. diff --git a/test/data/checkerboard.gamma1dot0.png b/test/data/checkerboard.gamma1dot0.png new file mode 100644 index 0000000000000000000000000000000000000000..77fdb0e6feb8a29789e8f7590eb9f1b4b8291125 GIT binary patch literal 441 zcmeAS@N?(olHy`uVBq!ia0y~yU}OMc4h9AWhDyoryBHW4SkfJR9T^zg78t&m7SF)I zSm5d67*a9k%_T>{1_vINgWRnjEZUEE&hS^~DqD5m_U&8qm-Zk33BR9j3``sfgOPampOJy#|Nl2{*ba5FSUd#9iKnZd%Q~loCIHmoN+|#U literal 0 HcmV?d00001