|
|
|
@ -6,7 +6,7 @@ import ( |
|
|
|
"image" |
|
|
|
"image" |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"image/png" |
|
|
|
"image/png" |
|
|
|
// "image/color"
|
|
|
|
"image/color" |
|
|
|
"github.com/disintegration/gift" |
|
|
|
"github.com/disintegration/gift" |
|
|
|
// "math"
|
|
|
|
// "math"
|
|
|
|
"flag" |
|
|
|
"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 { |
|
|
|
type Opts struct { |
|
|
|
InFile string |
|
|
|
InFile string |
|
|
|
OutFile string |
|
|
|
OutFile string |
|
|
|
@ -65,16 +85,7 @@ func main() { |
|
|
|
smaller := image.NewNRGBA(g.Bounds(bounds)) |
|
|
|
smaller := image.NewNRGBA(g.Bounds(bounds)) |
|
|
|
g.Draw(smaller, src) |
|
|
|
g.Draw(smaller, src) |
|
|
|
|
|
|
|
|
|
|
|
upscale := image.NewNRGBA(bounds) |
|
|
|
upscale := UpscaleImage(bounds, smaller, opts.PixelWidth) |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SaveImage(opts.OutFile, upscale) |
|
|
|
SaveImage(opts.OutFile, upscale) |
|
|
|
} |
|
|
|
} |
|
|
|
|