main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "net"
  6. )
  7. func main() {
  8. const brotherPort int = 54921
  9. brotherIP := flag.String("a", "192.168.0.157", "IP address of the Brother scanner")
  10. color := flag.String("c", "CGRAY", "Color mode of the scan (CGRAY, TEXT)")
  11. debug := flag.Bool("d", false, "Enable debug mode - save .rawbytes and .raw file")
  12. rawinput := flag.String("i", "", "raw input file to parse instead of socket")
  13. name := flag.String("n", "scan.tiff", "Name of the output file")
  14. resolution := flag.Int("r", 300, "Resolution of the scan")
  15. flag.Parse()
  16. if net.ParseIP(*brotherIP) == nil {
  17. HandleError(fmt.Errorf("invalid IP address: %s", *brotherIP))
  18. }
  19. rawImages, width, height := Scan(*brotherIP, brotherPort, *resolution, *color, *rawinput, *debug)
  20. for i, rawImage := range rawImages {
  21. if i == len(rawImages)-1 {
  22. SaveImage(rawImage, width, height, fmt.Sprintf("%s-%d.tiff", *name, i), *color, *debug, *resolution)
  23. } else {
  24. go SaveImage(rawImage, width, height, fmt.Sprintf("%s-%d.tiff", *name, i), *color, *debug, *resolution)
  25. }
  26. }
  27. }