diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2026-06-11 21:35:19 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2026-06-11 21:35:19 -0700 |
| commit | 38b5c1a8ab5a6e9c1eadc4ebb56b4af9dc0cb7c6 (patch) | |
| tree | 2289db9bdf35006ff3b7558e3ecbc7515aff26e1 | |
| parent | Don't resize up every image (diff) | |
| download | imgutil-38b5c1a8ab5a6e9c1eadc4ebb56b4af9dc0cb7c6.tar.zst | |
Don't resize unless necessary
| -rw-r--r-- | icat.go | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -234,23 +234,26 @@ func medianCut(img image.Image) color.Palette { func printImg(img image.Image, maxX, maxY, pixelX, pixelY int) error { x := min(img.Bounds().Dx(), maxX) y := min(img.Bounds().Dy(), maxY) - // Try not to stretch the image. - if y == 0 || x != 0 && img.Bounds().Dy()*x <= img.Bounds().Dx()*y*pixelY/pixelX { - y = divRound(img.Bounds().Dy()*x*pixelX, img.Bounds().Dx()*pixelY) - } else { - x = divRound(img.Bounds().Dx()*y*pixelY, pixelX*img.Bounds().Dy()) - } + if x != img.Bounds().Dx() || y != img.Bounds().Dy() { + // Try not to stretch the image. + if y == 0 || x != 0 && img.Bounds().Dy()*x <= img.Bounds().Dx()*y*pixelY/pixelX { + y = divRound(img.Bounds().Dy()*x*pixelX, img.Bounds().Dx()*pixelY) + } else { + x = divRound(img.Bounds().Dx()*y*pixelY, pixelX*img.Bounds().Dy()) + } - dst := image.NewRGBA(image.Rect(0, 0, x, y)) - draw.BiLinear.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Src, nil) + dst := image.NewRGBA(image.Rect(0, 0, x, y)) + draw.BiLinear.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Src, nil) + img = dst + } switch *m { case modeBlock: - sixel.PrintXTerm16(os.Stdout, dst) + sixel.PrintXTerm16(os.Stdout, img) case modeBlock24: - sixel.PrintBlock(os.Stdout, dst) + sixel.PrintBlock(os.Stdout, img) case modeSixel: - sixel.Print(os.Stdout, dst, medianCut(dst)) + sixel.Print(os.Stdout, img, medianCut(img)) } fmt.Println() return nil |
