A bit of cleanup before putting this in as a filter.

master
Zed A. Shaw 1 month ago
parent a665ffeccb
commit d738eca230
  1. 33
      main.go

@ -6,7 +6,7 @@ import (
"image"
"log"
"image/png"
// "image/color"
"image/color"
"github.com/disintegration/gift"
// "math"
"flag"
@ -36,6 +36,26 @@ func SaveImage(filename string, img image.Image) {
}
}
func UpscaleImage(bounds image.Rectangle, smaller *image.NRGBA, pixel_width int) *image.NRGBA {
upscale := image.NewNRGBA(bounds)
var from_x, from_y int
var from color.Color
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
if x % pixel_width == 0 {
from_x = x / pixel_width
from_y = y / pixel_width
from = smaller.At(from_x, from_y)
}
upscale.Set(x, y, from)
}
}
return upscale
}
type Opts struct {
InFile string
OutFile string
@ -65,16 +85,7 @@ func main() {
smaller := image.NewNRGBA(g.Bounds(bounds))
g.Draw(smaller, src)
upscale := image.NewNRGBA(bounds)
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
from_x := x / opts.PixelWidth
from_y := y / opts.PixelWidth
from := smaller.At(from_x, from_y)
upscale.Set(x, y, from)
}
}
upscale := UpscaleImage(bounds, smaller, opts.PixelWidth)
SaveImage(opts.OutFile, upscale)
}

Loading…
Cancel
Save