示例#1
0
文件: cute.go 项目: ww24/go-cute
func run() (e error) {
	engine := qml.NewEngine()
	component, err := engine.LoadFile("file.qml")
	if err != nil {
		return err
	}

	file, err := os.Open("material/line.png")
	if err != nil {
		return err
	}
	defer file.Close()

	pix := pixel.NewPixel(file)

	images := []*pixel.Pixel{pix,
		pix.Map(pseudo.ConvLinear),
		pix.Map(pseudo.ConvSigmoid),
		pix.Map(pseudo.ConvSin)}

	engine.AddImageProvider("imgprv", func(imgId string, width, height int) (img image.Image) {
		index, _ := strconv.Atoi(imgId)
		img = images[index].Image
		return
	})

	win := component.CreateWindow(nil)
	win.Show()
	win.Wait()
	return
}
示例#2
0
func main() {

	flag.Parse()

	mode, filepathIn, filepathOut := flag.Arg(0), flag.Arg(1), flag.Arg(2)

	if mode == "" || filepathIn == "" || filepathOut == "" {
		fmt.Fprintln(os.Stderr, "usage: go-pseudo-color mode in_path out_path")
		fmt.Fprintln(os.Stderr, "mode = (linear, sigmoid, sin)")
		_main()
		return
	}

	file, err := os.Open(filepathIn)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	inPix := pixel.NewPixel(file)
	var outPix *pixel.Pixel

	switch mode {
	case "linear":
		outPix = inPix.Map(pseudo.ConvLinear)
	case "sigmoid":
		outPix = inPix.Map(pseudo.ConvSigmoid)
	case "sin":
		outPix = inPix.Map(pseudo.ConvSin)
	default:
		fmt.Fprintln(os.Stderr, "mode = (linear, sigmoid, sin)")
		return
	}

	file, err = os.Create(filepathOut)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	outPix.Save(file)
}