diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2023-08-31 08:46:26 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2023-08-31 08:46:26 -0700 |
| commit | 3d875397ab4f21f06bc490982a62fdd62aa76a91 (patch) | |
| tree | 77d9484aeb1946e9cafcdbc595b58b448bd43008 | |
| parent | c1159e5f8434ffb4e98c950f45cd682d73933534 (diff) | |
| download | imgutil-3d875397ab4f21f06bc490982a62fdd62aa76a91.tar.zst | |
Use bufio for output.
This is a lot faster for a large image.
| -rw-r--r-- | icat.go | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -1,6 +1,7 @@ package main import ( + "bufio" "fmt" "golang.org/x/image/draw" "golang.org/x/term" @@ -45,12 +46,14 @@ func printImg(filename string, cols, lines int) error { dst := image.NewRGBA(image.Rect(0, 0, cols, lines)) draw.ApproxBiLinear.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Over, nil) + buf := bufio.NewWriter(os.Stdout) + defer buf.Flush() for y := 0; y < lines; y++ { for x := 0; x < cols; x++ { r, g, b, _ := dst.At(x, y).RGBA() - fmt.Printf("\033[48;2;%d;%d;%dm ", r>>8, g>>8, b>>8) + fmt.Fprintf(buf, "\033[48;2;%d;%d;%dm ", r>>8, g>>8, b>>8) } - fmt.Println("\033[49m") + fmt.Fprintln(buf, "\033[49m") } return nil } |
