aboutsummaryrefslogtreecommitdiffstats
path: root/icat.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2023-08-31 08:45:10 -0700
committerRose Hogenson <rosehogenson@posteo.net>2023-08-31 08:45:10 -0700
commitc1159e5f8434ffb4e98c950f45cd682d73933534 (patch)
tree9c6b92f80316caa59e2652a4447d89a24e5d2c68 /icat.go
parentLoad terminal size once at the beginning. (diff)
downloadimgutil-c1159e5f8434ffb4e98c950f45cd682d73933534.tar.zst
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.
Diffstat (limited to 'icat.go')
-rw-r--r--icat.go9
1 files changed, 5 insertions, 4 deletions
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")