A simple tool I use to "jankify" my textures. It performs a series of transforms that gives everything a consistent pixelated 80s look.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jankifier/filters/upscale.go

40 lines
845 B

package filters
import (
"image"
"image/draw"
"image/color"
"github.com/disintegration/gift"
)
type UpscaleFilter struct {
Size image.Rectangle
PixelWidth int
}
func Upscale(size image.Rectangle, width int) gift.Filter {
return UpscaleFilter{size, width}
}
func (filter UpscaleFilter) Bounds(src image.Rectangle) (dst_bounds image.Rectangle) {
return filter.Size
}
func (filter UpscaleFilter) Draw(dst draw.Image, src image.Image, _ *gift.Options) {
var from_x, from_y int
var from color.Color
bounds := filter.Size
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
if x % filter.PixelWidth == 0 {
from_x = x / filter.PixelWidth
from_y = y / filter.PixelWidth
from = src.At(from_x, from_y)
}
dst.Set(x, y, from)
}
}
}