예제 #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
func DisplaySubImageShifted(
	itlx, itly int, w, h int,
	image *opencv.IplImage,
	otlx, otly int) {

	channels := image.Channels()
	in := toByteSlice(image.ImageData(),
		image.Width()*image.Height()*channels)

	for iy, oy := itly, otly; iy < itly+h; iy, oy = iy+1, oy+1 {
		for ix, ox := itlx, otlx; ix < itlx+w; ix, ox = ix+1, ox+1 {
			// image origin is top-left
			imagep := (ix + (iHeight-1-iy)*iWidth) * channels
			// openVG origin is bottom-left
			outp := (ox + oy*iWidth) * VG_CHANS

			out[outp+0] = C.VGubyte(in[imagep+2]) // red
			out[outp+1] = C.VGubyte(in[imagep+1]) // green
			out[outp+2] = C.VGubyte(in[imagep+0]) // blue
			out[outp+3] = 255                     // alpha
		}
	}
}
예제 #3
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])
}
예제 #4
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])
}