Guest User

Untitled

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