From 8896fdcf2c049a5b428ca1c49bf28fc2702c0ae1 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Mon, 17 Mar 2025 16:38:36 -0700 Subject: Print in double resolution using ▀ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- icat.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'icat.go') diff --git a/icat.go b/icat.go index 1a8dd8a..15f10d1 100644 --- a/icat.go +++ b/icat.go @@ -3,12 +3,13 @@ package main import ( "bufio" "fmt" - "golang.org/x/image/draw" - "golang.org/x/term" "image" _ "image/jpeg" _ "image/png" "os" + + "golang.org/x/image/draw" + "golang.org/x/term" ) var stdout = bufio.NewWriter(os.Stdout) @@ -45,16 +46,20 @@ func printImg(filename string, cols, lines int) error { cols = img.Bounds().Dx() * lines * 5 / 2 / img.Bounds().Dy() } - dst := image.NewRGBA(image.Rect(0, 0, cols, lines)) - draw.ApproxBiLinear.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Over, nil) + dst := image.NewRGBA(image.Rect(0, 0, cols, 2*lines)) + draw.CatmullRom.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Over, nil) - for y := 0; y < lines; y++ { + for y := 0; y < 2*lines; y += 2 { for x := 0; x < cols; x++ { - r, g, b, _ := dst.At(x, y).RGBA() - fmt.Fprintf(stdout, "\033[48;2;%d;%d;%dm ", r>>8, g>>8, b>>8) + hiR, hiG, hiB, _ := dst.At(x, y).RGBA() + loR, loG, loB, _ := dst.At(x, y+1).RGBA() + fmt.Fprintf(stdout, "\033[38;2;%d;%d;%dm\033[48;2;%d;%d;%dm▀", + hiR>>8, hiG>>8, hiB>>8, + loR>>8, loG>>8, loB>>8) } fmt.Fprintln(stdout, "\033[49m") } + fmt.Fprint(stdout, "\033[39m") return nil } -- cgit v1.3.1