예제 #1
0
파일: openvg.go 프로젝트: xranby/openvg
// Image places the image in s image at (x,y) with dimensions (w,h)
func Image(x, y float64, w, h int, s string) {
	f, ferr := os.Open(s)
	if ferr != nil {
		fakeimage(x, y, w, h, s)
		return
	}
	defer f.Close()
	img, _, err := image.Decode(f)
	if err != nil {
		fakeimage(x, y, w, h, s)
		return
	}
	bounds := img.Bounds()
	minx := bounds.Min.X
	maxx := bounds.Max.X
	miny := bounds.Min.Y
	maxy := bounds.Max.Y
	data := make([]C.VGubyte, w*h*4)
	n := 0
	// println("minx", minx, "maxx", maxx, "miny", miny, "maxy", maxy)
	for y := miny; y < maxy; y++ {
		for x := minx; x < maxx; x++ {
			r, g, b, a := img.At(x, (maxy-1)-y).RGBA() // OpenVG has origin at lower left, y increasing up
			data[n] = C.VGubyte(r)
			n++
			data[n] = C.VGubyte(g)
			n++
			data[n] = C.VGubyte(b)
			n++
			data[n] = C.VGubyte(a)
			n++
		}
	}
	C.makeimage(C.VGfloat(x), C.VGfloat(y), C.int(w), C.int(h), &data[0])
}
예제 #2
0
파일: openvg.go 프로젝트: remogatto/openvg
// Image places the named image at (x,y) with dimensions (w,h)
func Image(x, y float64, w, h int, s string) {
	var img image.Image
	var derr error
	f, err := os.Open(s)
	if err != nil {
		fakeimage(x, y, w, h, s)
		return
	}
	img, _, derr = image.Decode(f)
	defer f.Close()
	if derr != nil {
		fakeimage(x, y, w, h, s)
		return
	}
	bounds := img.Bounds()
	minx := bounds.Min.X
	maxx := bounds.Max.X
	miny := bounds.Min.Y
	maxy := bounds.Max.Y
	data := make([]C.VGubyte, w*h*4)
	n := 0
	var r, g, b, a uint32
	for yp := miny; yp < maxy; yp++ {
		for xp := minx; xp < maxx; xp++ {
			r, g, b, a = img.At(xp, (maxy-1)-yp).RGBA() // OpenVG has origin at lower left, y increasing up
			data[n] = C.VGubyte(r)
			n++
			data[n] = C.VGubyte(g)
			n++
			data[n] = C.VGubyte(b)
			n++
			data[n] = C.VGubyte(a)
			n++
		}
	}
	C.makeimage(C.VGfloat(x), C.VGfloat(y), C.int(w), C.int(h), &data[0])
}
예제 #3
0
// Img places an image object at (x,y)
func Img(x, y VGfloat, im image.Image) {
	bounds := im.Bounds()
	minx := bounds.Min.X
	maxx := bounds.Max.X
	miny := bounds.Min.Y
	maxy := bounds.Max.Y
	data := make([]C.VGubyte, bounds.Dx()*bounds.Dy()*4)
	n := 0
	var r, g, b, a uint32
	for yp := miny; yp < maxy; yp++ {
		for xp := minx; xp < maxx; xp++ {
			r, g, b, a = im.At(xp, (maxy-1)-yp).RGBA() // OpenVG has origin at lower left, y increasing up
			data[n] = C.VGubyte(r >> 8)
			n++
			data[n] = C.VGubyte(g >> 8)
			n++
			data[n] = C.VGubyte(b >> 8)
			n++
			data[n] = C.VGubyte(a >> 8)
			n++
		}
	}
	C.makeimage(C.VGfloat(x), C.VGfloat(y), C.int(bounds.Dx()), C.int(bounds.Dy()), &data[0])
}