Highly efficient client for Pixelflut
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9KB

  1. package main
  2. import (
  3. "flag"
  4. "image"
  5. "log"
  6. "net"
  7. "os"
  8. "runtime/pprof"
  9. "time"
  10. "github.com/SpeckiJ/Hochwasser/pixelflut"
  11. )
  12. var err error
  13. var cpuprofile = flag.String("cpuprofile", "", "Destination file for CPU Profile")
  14. var image_path = flag.String("image", "", "Absolute Path to image")
  15. var image_offsetx = flag.Int("xoffset", 0, "Offset of posted image from left border")
  16. var image_offsety = flag.Int("yoffset", 0, "Offset of posted image from top border")
  17. var connections = flag.Int("connections", 4, "Number of simultaneous connections. Each connection posts a subimage")
  18. var address = flag.String("host", "127.0.0.1:1337", "Server address")
  19. var runtime = flag.String("runtime", "60s", "exit after timeout")
  20. var shuffle = flag.Bool("shuffle", false, "pixel send ordering")
  21. var fetchImgPath = flag.String("fetch-image", "", "path to save the fetched pixel state to")
  22. func main() {
  23. flag.Parse()
  24. if *image_path == "" {
  25. log.Fatal("No image provided")
  26. }
  27. // check connectivity by opening one test connection
  28. conn, err := net.Dial("tcp", *address)
  29. if err != nil {
  30. log.Fatal(err)
  31. }
  32. conn.Close()
  33. // Start cpu profiling if wanted
  34. if *cpuprofile != "" {
  35. f, err := os.Create(*cpuprofile)
  36. if err != nil {
  37. log.Fatal(err)
  38. }
  39. defer f.Close()
  40. pprof.StartCPUProfile(f)
  41. defer pprof.StopCPUProfile()
  42. }
  43. offset := image.Pt(*image_offsetx, *image_offsety)
  44. img := readImage(*image_path)
  45. var fetchedImg *image.NRGBA
  46. if *fetchImgPath != "" {
  47. fetchedImg = pixelflut.FetchImage(img.Bounds().Add(offset), *address, 1)
  48. *connections -= 1
  49. }
  50. // 🌊🌊🌊🌊🌊🌊🌊🌊🌊🌊🌊🌊🌊🌊🌊
  51. pixelflut.Flut(img, offset, *shuffle, *address, *connections)
  52. // Terminate after timeout to save resources
  53. timer, err := time.ParseDuration(*runtime)
  54. if err != nil {
  55. log.Fatal("Invalid runtime specified: " + err.Error())
  56. }
  57. time.Sleep(timer)
  58. if *fetchImgPath != "" {
  59. writeImage(*fetchImgPath, fetchedImg)
  60. }
  61. }