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/posterize.go

44 lines
789 B

package filters
import (
"image"
"image/draw"
"image/color"
"github.com/disintegration/gift"
)
type PosterizeFilter struct {
Depth uint8
}
func Posterize(depth uint8) gift.Filter {
return PosterizeFilter{depth}
}
func (filter PosterizeFilter) Bounds(src image.Rectangle) (dst_bounds image.Rectangle) {
return src
}
func bin(c uint8) uint8 {
if c <= 64 {
return 0
} else {
return 255
}
}
func (filter PosterizeFilter) Draw(dst draw.Image, src image.Image, _ *gift.Options) {
bounds := src.Bounds()
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
from := src.At(x, y)
c := from.(color.NRGBA)
c.R = bin(c.R)
c.G = bin(c.G)
c.B = bin(c.B)
dst.Set(x, y, c)
}
}
}