plugin.go 587 B

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