plugin.go 479 B

1234567891011121314151617181920212223
  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 = 255-r/256, 255-g/256, 255-b/256
  15. ret.Set(x, y, color.RGBA{uint8(r), uint8(g), uint8(b), 0})
  16. }
  17. }
  18. return ret
  19. }