90 lines
2.7 KiB
Go
90 lines
2.7 KiB
Go
// Command releaseicon creates the small deterministic PNG used only by the
|
|
// Windows release resource generator. Keeping the source rather than a binary
|
|
// asset makes the icon reproducible in the pinned toolchain.
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"image"
|
|
"image/color"
|
|
"image/png"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
const canvasSize = 256
|
|
|
|
func main() {
|
|
output := flag.String("out", "", "absolute PNG output path")
|
|
flag.Parse()
|
|
if *output == "" || !filepath.IsAbs(*output) {
|
|
panic("--out must be an absolute path")
|
|
}
|
|
if err := os.MkdirAll(filepath.Dir(*output), 0o700); err != nil {
|
|
panic(err)
|
|
}
|
|
file, err := os.OpenFile(*output, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
image := image.NewNRGBA(image.Rect(0, 0, canvasSize, canvasSize))
|
|
fill(image, color.NRGBA{R: 15, G: 28, B: 48, A: 255})
|
|
fillRoundedRect(image, 18, 18, 238, 238, 42, color.NRGBA{R: 28, G: 56, B: 92, A: 255})
|
|
// A compact outlined box and terminal prompt remain recognizable at the
|
|
// 16-pixel size Windows Explorer generates from this source image.
|
|
strokeRect(image, 57, 62, 199, 194, 12, color.NRGBA{R: 54, G: 211, B: 189, A: 255})
|
|
fillRect(image, 79, 105, 96, 121, color.NRGBA{R: 240, G: 249, B: 255, A: 255})
|
|
fillRect(image, 95, 121, 112, 137, color.NRGBA{R: 240, G: 249, B: 255, A: 255})
|
|
fillRect(image, 79, 137, 96, 153, color.NRGBA{R: 240, G: 249, B: 255, A: 255})
|
|
fillRect(image, 126, 150, 176, 166, color.NRGBA{R: 240, G: 249, B: 255, A: 255})
|
|
if err := png.Encode(file, image); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func fill(image *image.NRGBA, value color.NRGBA) {
|
|
for y := 0; y < canvasSize; y++ {
|
|
for x := 0; x < canvasSize; x++ {
|
|
image.SetNRGBA(x, y, value)
|
|
}
|
|
}
|
|
}
|
|
|
|
func fillRoundedRect(image *image.NRGBA, left, top, right, bottom, radius int, value color.NRGBA) {
|
|
for y := top; y < bottom; y++ {
|
|
for x := left; x < right; x++ {
|
|
dx, dy := 0, 0
|
|
if x < left+radius {
|
|
dx = left + radius - x
|
|
} else if x >= right-radius {
|
|
dx = x - (right - radius - 1)
|
|
}
|
|
if y < top+radius {
|
|
dy = top + radius - y
|
|
} else if y >= bottom-radius {
|
|
dy = y - (bottom - radius - 1)
|
|
}
|
|
if dx*dx+dy*dy <= radius*radius {
|
|
image.SetNRGBA(x, y, value)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func strokeRect(image *image.NRGBA, left, top, right, bottom, width int, value color.NRGBA) {
|
|
fillRect(image, left, top, right, top+width, value)
|
|
fillRect(image, left, bottom-width, right, bottom, value)
|
|
fillRect(image, left, top, left+width, bottom, value)
|
|
fillRect(image, right-width, top, right, bottom, value)
|
|
}
|
|
|
|
func fillRect(image *image.NRGBA, left, top, right, bottom int, value color.NRGBA) {
|
|
for y := top; y < bottom; y++ {
|
|
for x := left; x < right; x++ {
|
|
image.SetNRGBA(x, y, value)
|
|
}
|
|
}
|
|
}
|