diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-03-17 16:38:36 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-03-17 16:38:36 -0700 |
| commit | 8896fdcf2c049a5b428ca1c49bf28fc2702c0ae1 (patch) | |
| tree | 4c2a5a120b11a69abdff8d96bb19c3c34ad83da4 | |
| parent | 2ef107aee0b4e88b3335b04418ec0e27ad8ebbfc (diff) | |
| download | imgutil-8896fdcf2c049a5b428ca1c49bf28fc2702c0ae1.tar.zst | |
Print in double resolution using â–€
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | icat.go | 19 |
2 files changed, 13 insertions, 8 deletions
@@ -1,4 +1,4 @@ -module icat +module gitlab.com/rhogenson/icat go 1.20 @@ -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 } |
