Ejemplo n.º 1
0
// main initializes the system and shows the picture.
// Exit and clean up when you hit [RETURN].
func main() {
	rseed()
	openvg.SaveTerm()
	nargs := len(os.Args)
	w, h := openvg.Init()
	openvg.RawTerm()
	progname := os.Args[0]
	n := 5
	if nargs > 2 {
		n, _ = strconv.Atoi(os.Args[2])
	}
	if nargs > 1 {
		switch os.Args[1] {
		case "help":
			usage(progname)
			os.Exit(1)
		case "advert":
			advert(w, h)
		case "image":
			imagetable(w, h)
		case "text":
			tb(w, h)
		case "textplay":
			textplay(w, h)
		case "astro":
			planets(w, h, "You are here")
		case "fontsize":
			fontrange(w, h)
		case "raspi":
			raspi(w, h, "The Raspberry Pi")
		case "loop":
			loop(w, h)
		case "demo":
			demo(w, h, n)
		case "rand":
			rshapes(w, h, n)
		case "test":
			testpattern(w, h, "hello, world")
		case "rotate":
			rotext(w, h, n, "Raspi")
		case "gradient":
			gradient(w, h)
		default:
			refcard(w, h)
		}
	} else {
		refcard(w, h)
	}
	WaitEnd()
}
Ejemplo n.º 2
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stdout,
			`usage: %s [ opts ] image-path

Set specified image as an overlay screen via OpenVG lib.
Default is to put this image to the center.

`, os.Args[0])
		flag.PrintDefaults()
	}

	var resize bool
	var bg_color string
	flag.BoolVar(&resize, "resize", false, `Resize image to fit the screen (using "convert" binary.`)
	flag.StringVar(&bg_color, "bg-color", "",
		`Background color to use with centered image, in RRGGBB (hex, e.g. "aabbcc") format.`)

	flag.Parse()
	if flag.NArg() != 1 {
		log.Print("ERROR: Exactly one image-path argument must be specified.")
		flag.Usage()
	}
	var r, g, b uint8
	var err error
	if len(bg_color) == 0 {
		r, g, b = 0, 0, 0
	} else if len(bg_color) == 6 {
		n, err := strconv.ParseUint(bg_color[:2], 16, 8)
		if err == nil {
			r = uint8(n)
			n, err = strconv.ParseUint(bg_color[2:4], 16, 8)
		}
		if err == nil {
			g = uint8(n)
			n, err = strconv.ParseUint(bg_color[4:6], 16, 8)
		}
		if err == nil {
			b = uint8(n)
		}
	}
	if err != nil {
		log.Fatalf("ERROR: Failed to parse bg-color value (%v): %v", bg_color, err)
	}
	image_path := flag.Args()[0]

	exit_code := 0
	defer func() {
		os.Exit(exit_code)
	}()

	openvg.SaveTerm()
	w, h := openvg.Init()
	openvg.RawTerm()
	defer openvg.Finish()
	defer openvg.RestoreTerm()

	image_conf, err := get_image_conf(image_path)
	if err == nil && resize && (image_conf.Width != w || image_conf.Height != h) {
		image_path, err = resize_image(w, h, image_path)
	}
	if err != nil {
		log.Printf("ERROR: Failed to process image (%v): %v", image_path, err)
		exit_code = 1
	} else {
		sig_chan := make(chan os.Signal, 1)
		signal.Notify(sig_chan, os.Interrupt, os.Kill,
			syscall.SIGHUP, syscall.SIGTERM, syscall.SIGALRM)

		openvg.Start(w, h)
		openvg.Background(r, g, b)
		if resize {
			openvg.Image(0, 0, w, h, image_path)
		} else {
			x, y := openvg.VGfloat(w)/2-openvg.VGfloat(image_conf.Width)/2,
				openvg.VGfloat(h)/2-openvg.VGfloat(image_conf.Height)/2
			openvg.Image(x, y, image_conf.Width, image_conf.Height, image_path)
		}
		openvg.End()

		_ = <-sig_chan
	}
}
Ejemplo n.º 3
0
func main() {
	var resize = flag.Bool("resize", false, "Resize image to fit the screen.")
	var bgcolor = flag.String("bg", "black", "Background color (named color or rgb(r,g,b)).")
	var fgcolor = flag.String("fg", "white", "text color (named color or rgb(r,g,b)).")
	var title = flag.String("t", "", "text annotation")
	var fontsize = flag.Float64("fp", 2.0, "fontsize %")
	var px = flag.Float64("px", 50, "x position %")
	var py = flag.Float64("py", 50, "y position %")
	var texty = flag.Float64("ty", 0, "text y %")
	var exit_code int
	defer func() {
		os.Exit(exit_code)
	}()
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, `usage: %s [ flags ] image-path

Set specified image as an overlay screen via OpenVG lib.
Default is to put this image to the center.

`, os.Args[0])
		flag.PrintDefaults()
		exit_code = 1
		return
	}

	flag.Parse()
	if flag.NArg() != 1 {
		fmt.Fprintf(os.Stderr, "Exactly one image-path argument must be specified.\n")
		flag.Usage()
		exit_code = 2
		return
	}

	openvg.SaveTerm()
	w, h := openvg.Init()
	openvg.RawTerm()
	defer openvg.Finish()
	defer openvg.RestoreTerm()

	img, err := getimage(flag.Args()[0], w, h, *resize)
	if err != nil {
		exit_code = 3
		return
	}
	ib := img.Bounds()
	imw, imh := ib.Max.X-ib.Min.X, ib.Max.Y-ib.Min.Y
	sig_chan := make(chan os.Signal, 1)
	signal.Notify(sig_chan, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGALRM)

	openvg.Start(w, h)
	openvg.BackgroundColor(*bgcolor)
	var x, y openvg.VGfloat
	if *px < 0 || *px > 100 {
		x = openvg.VGfloat(w)/2 - openvg.VGfloat(imw)/2
	} else {
		x = openvg.VGfloat(w)*openvg.VGfloat(*px/100) - openvg.VGfloat(imw)/2
	}

	if *py < 0 || *py > 100 {
		y = openvg.VGfloat(h)/2 - openvg.VGfloat(imh)/2
	} else {
		y = openvg.VGfloat(h)*openvg.VGfloat(*py/100) - openvg.VGfloat(imh)/2
	}
	openvg.Img(x, y, img)
	if len(*title) > 0 {
		var typ openvg.VGfloat
		fs := openvg.VGfloat(*fontsize/100.0) * openvg.VGfloat(w)
		if *texty == 0 {
			typ = y - fs*1.5
		} else {
			typ = openvg.VGfloat(h) * openvg.VGfloat(*texty/100)
		}
		openvg.FillColor(*fgcolor)
		openvg.TextMid(x+openvg.VGfloat(imw)/2, typ, *title, "sans", int(fs))
	}
	openvg.End()

	_ = <-sig_chan
}