From c1159e5f8434ffb4e98c950f45cd682d73933534 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Thu, 31 Aug 2023 08:45:10 -0700 Subject: Use the draw package for resizing the image. This allows me to use the approximate bilinear interpolation, which looks a lot better than my brain-dead nearest-neighbor. --- icat.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'icat.go') diff --git a/icat.go b/icat.go index c26d0d2..ae1b7a0 100644 --- a/icat.go +++ b/icat.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "golang.org/x/image/draw" "golang.org/x/term" "image" _ "image/jpeg" @@ -41,12 +42,12 @@ func printImg(filename string, cols, lines int) error { cols = img.Bounds().Dx() * lines * 5 / 2 / img.Bounds().Dy() } - // nearest-neighbor interpolation + dst := image.NewRGBA(image.Rect(0, 0, cols, lines)) + draw.ApproxBiLinear.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Over, nil) + for y := 0; y < lines; y++ { for x := 0; x < cols; x++ { - sx := x*img.Bounds().Dx()/cols + img.Bounds().Min.X - sy := y*img.Bounds().Dy()/lines + img.Bounds().Min.Y - r, g, b, _ := img.At(sx, sy).RGBA() + r, g, b, _ := dst.At(x, y).RGBA() fmt.Printf("\033[48;2;%d;%d;%dm ", r>>8, g>>8, b>>8) } fmt.Println("\033[49m") -- cgit v1.3.1