Exemplo n.º 1
0
func Encode(x, y, w, h uint, e []byte) {
	//
	const M = C.ulong(1<<32 - 1)
	ximg := C.XGetImage(display, C.Drawable(window), C.int(x), C.int(y), C.uint(w), C.uint(h), M, C.XYPixmap)
	n := uint(0)
	//  var pixel C.ulong
	for y := 0; y < int(h); y++ {
		for x := 0; x < int(w); x++ {
			pixel := C.xGetPixel(ximg, C.int(x), C.int(y)) // = C.XGetPixel (ximg, C.int(x), C.int(y))
			copy(e[n:n+4], cd(uint(pixel)))
			n += 4
		}
	}
	C.xDestroyImage(ximg) // C.XDestroyImage (ximg)
}
Exemplo n.º 2
0
func Decode(x, y, w, h uint, b []byte) {
	//
	const M = C.ulong(1<<32 - 1)
	//////////////////////////////////////////////////////////////////////////////////////////////  steals a lot of time
	ximg := C.XGetImage(display, C.Drawable(window), C.int(x), C.int(y), C.uint(w), C.uint(h), M, C.XYPixmap)
	//////////////////////////////////////////////////////////////////////////////////////////////  steals a lot of time
	n := uint(0)
	//  var pixel C.ulong
	for j := uint(0); j < h; j++ {
		for i := uint(0); i < w; i++ {
			pixel := (C.ulong)(obj.Decode(n, b[n:n+4]).(uint))
			C.xPutPixel(ximg, C.int(i), C.int(j), pixel) // C.XPutPixel (ximg, C.int(i), C.int(j), pixel)
			n += 4
		}
	}
	C.XPutImage(display, C.Drawable(window), graphicsContext, ximg, 0, 0, C.int(x), C.int(y), C.uint(w), C.uint(h))
	C.XCopyArea(display, C.Drawable(window), C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h), C.int(x), C.int(y))
	C.XFlush(display)
	C.xDestroyImage(ximg) // C.XDestroyImage (ximg)
}