cmd/gopngquant: allow setting -Speed parameter

This commit is contained in:
mappu 2016-11-24 20:57:49 +13:00
parent 67b09086b4
commit 2d513a1a66

View File

@ -52,7 +52,7 @@ func Rgb8PaletteToGoImage(w, h int, rgb8data []byte, pal color.Palette) image.Im
return ret
}
func Crush(sourcefile, destfile string) error {
func Crush(sourcefile, destfile string, speed int) error {
fh, err := os.OpenFile(sourcefile, os.O_RDONLY, 0444)
if err != nil {
@ -74,6 +74,11 @@ func Crush(sourcefile, destfile string) error {
}
defer attr.Release()
err = attr.SetSpeed(speed)
if err != nil {
return fmt.Errorf("SetSpeed: %s", err.Error())
}
rgba32data := GoImageToRgba32(img)
iqm, err := imagequant.NewImage(attr, string(rgba32data), width, height, 0)
@ -116,6 +121,7 @@ func main() {
ShouldDisplayVersion := flag.Bool("Version", false, "")
Infile := flag.String("In", "", "Input filename")
Outfile := flag.String("Out", "", "Output filename")
Speed := flag.Int("Speed", 3, "Speed (1 slowest, 10 fastest)")
flag.Parse()
@ -124,7 +130,7 @@ func main() {
os.Exit(1)
}
err := Crush(*Infile, *Outfile)
err := Crush(*Infile, *Outfile, *Speed)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)