示例#1
0
func WaitEnd() {
	r := bufio.NewReader(os.Stdin)
	for {
		c, _ := r.ReadByte()
		if c == '\n' {
			break
		}
	}
	openvg.RestoreTerm()
	openvg.Finish()
}
示例#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
	}
}
示例#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
}
示例#4
0
func usage(s string) {
	openvg.RestoreTerm()
	fmt.Fprintf(os.Stderr,
		"%s [command]\n\tdemo sec\n\tastro\n\ttest ...\n\trand n\n\trotate n ...\n\timage\n\ttext\n\tfontsize\n\traspi\n\tgradient\n\tadvert\n", s)
}