plugin.go 631 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "image"
  4. "image/color"
  5. )
  6. // Convert to binary image
  7. func Transform(src image.Image) image.Image {
  8. bounds := src.Bounds()
  9. w, h := bounds.Max.X, bounds.Max.Y
  10. ret := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})
  11. for x := 0; x < w; x++ {
  12. for y := 0; y < h; y++ {
  13. r, g, b, _ := src.At(x, y).RGBA()
  14. r, g, b = r/256, g/256, b/256
  15. if r < 100 {
  16. r = 0
  17. } else {
  18. r = 255
  19. }
  20. if g < 100 {
  21. g = 0
  22. } else {
  23. g = 255
  24. }
  25. if b < 100 {
  26. b = 0
  27. } else {
  28. b = 255
  29. }
  30. ret.Set(x, y, color.RGBA{uint8(r), uint8(g), uint8(b), 0})
  31. }
  32. }
  33. return ret
  34. }