Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // OrderedDither applies a Bayer matrix to dither.
- func OrderedDither(img image.Image, palette []color.Color) image.Image {
- rImage := image.NewRGBA(img.Bounds())
- matrix := [][]float64{
- {0, 4, 1, 5},
- {8, 12, 9, 13},
- {2, 6, 3, 7},
- {10, 6, 11, 15}}
- for j := 0; j < img.Bounds().Max.Y; j++ {
- for i := 0; i < img.Bounds().Max.X; i++ {
- m := matrix[i%4][j%4] / 16
- oldPixel, _ := colorful.MakeColor(img.At(i, j))
- oldPixel.R = oldPixel.R*m + oldPixel.R
- oldPixel.G = oldPixel.G*m + oldPixel.G
- oldPixel.B = oldPixel.B*m + oldPixel.B
- newPixel := GetClosestColor(palette, oldPixel)
- r, g, b, _ := newPixel.RGBA()
- rImage.Set(i, j, color.RGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: 255})
- }
- }
- return rImage
Add Comment
Please, Sign In to add comment