aboutsummaryrefslogtreecommitdiffstats
path: root/icat.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2023-08-31 08:46:26 -0700
committerRose Hogenson <rosehogenson@posteo.net>2023-08-31 08:46:26 -0700
commit3d875397ab4f21f06bc490982a62fdd62aa76a91 (patch)
tree77d9484aeb1946e9cafcdbc595b58b448bd43008 /icat.go
parentc1159e5f8434ffb4e98c950f45cd682d73933534 (diff)
downloadimgutil-3d875397ab4f21f06bc490982a62fdd62aa76a91.tar.zst
Use bufio for output.
This is a lot faster for a large image.
Diffstat (limited to 'icat.go')
-rw-r--r--icat.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/icat.go b/icat.go
index ae1b7a0..f2c3f08 100644
--- a/icat.go
+++ b/icat.go
@@ -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
}