Exemplo n.º 1
0
func ReadAlpha(image *image.Alpha) {

	alignment := C.GLint(0)
	C.glGetIntegerv(C.GL_PACK_ALIGNMENT, &alignment)

	align := C.GLint(1)

	for align < alignment && image.Stride%(int(align)*2) == 0 {
		align *= 2
	}

	// need smaller alignment
	if align < alignment {
		C.glPixelStorei(C.GL_PACK_ALIGNMENT, align)
	}

	C.glReadPixels(C.GLint(image.Rect.Min.X), C.GLint(image.Rect.Min.Y),
		C.GLsizei(image.Rect.Dx()), C.GLsizei(image.Rect.Dy()),
		C.GL_ALPHA, C.GL_UNSIGNED_BYTE, unsafe.Pointer(&image.Pix[0]))

	// restore alignment
	if align < alignment {
		C.glPixelStorei(C.GL_PACK_ALIGNMENT, alignment)
	}
}
Exemplo n.º 2
0
func ReadPixels(dst []byte, x, y, width, height int, format, ty Enum) {
	defer func() {
		errstr := errDrain()
		log.Printf("gl.ReadPixels(len(%d), %v, %v, %v, %v, %v, %v) %v", len(dst), x, y, width, height, format, ty, errstr)
	}()
	C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), format.c(), ty.c(), unsafe.Pointer(&dst[0]))
}
Exemplo n.º 3
0
func ReadPixels(
	x int32, y int32, width Sizei, height Sizei,
	format Enum, type_ Enum, pixels Void) {
	C.glReadPixels(
		C.GLint(x),
		C.GLint(y),
		C.GLsizei(width),
		C.GLsizei(height),
		C.GLenum(format),
		C.GLenum(type_),
		unsafe.Pointer(pixels))
}
Exemplo n.º 4
0
Arquivo: gl.go Projeto: extrame/gl
// Add the interface to export image
func ReadPixels(x int, y int, w int, h int) image.Image {
	data := make([]uint16, 4*w*h)
	p := unsafe.Pointer(&data[0])
	C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(w), C.GLsizei(h), C.GLenum(RGBA), C.GLenum(UNSIGNED_SHORT), p)
	rec := image.Rect(x, y, x+w, y+h)
	rgba := image.NewRGBA64(rec)
	for i := 0; i < w*h; i++ {
		c := color.RGBA64{data[4*i], data[4*i+1], data[4*i+2], data[4*i+3]}
		rgba.Set(i%w, h-i/w-1, c)
	}
	return rgba
}
Exemplo n.º 5
0
func ReadRGBA(image *image.NRGBA) {

	alignment := C.GLint(0)
	C.glGetIntegerv(C.GL_PACK_ALIGNMENT, &alignment)

	align := image.Stride % int(alignment) // align: 4 or 0

	// need smaller alignment
	if align > 0 {
		C.glPixelStorei(C.GL_PACK_ALIGNMENT, C.GLint(align))
	}

	C.glReadPixels(C.GLint(image.Rect.Min.X), C.GLint(image.Rect.Min.Y),
		C.GLsizei(image.Rect.Dx()), C.GLsizei(image.Rect.Dy()),
		C.GL_RGBA, C.GL_UNSIGNED_BYTE, unsafe.Pointer(&image.Pix[0]))

	// restore alignment
	if align > 0 {
		C.glPixelStorei(C.GL_PACK_ALIGNMENT, alignment)
	}
}
Exemplo n.º 6
0
func ReadPixels(dst []byte, x, y, width, height int, format, ty Enum) {
	C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), format.c(), ty.c(), unsafe.Pointer(&dst[0]))
}
Exemplo n.º 7
0
Arquivo: gl.go Projeto: james4k/gl
//void glReadPixels (int x, int y, int width, int height, GLenum format, GLenum type, GLvoid *pixels)
func ReadPixels(x int, y int, width int, height int, format, typ GLenum, pixels interface{}) {
	C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height),
		C.GLenum(format), C.GLenum(typ), ptr(pixels))
}
Exemplo n.º 8
0
func ReadPixels(x, y, width, height int, format, type_ uint, pixels Void) {
	C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height),
		C.GLenum(format), C.GLenum(type_), unsafe.Pointer(pixels))
}
Exemplo n.º 9
0
// ReadPixels returns pixel data from a buffer.
//
// In GLES 3, the source buffer is controlled with ReadBuffer.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glReadPixels.xhtml
func ReadPixels(dst []byte, x, y, width, height int, format, ty Enum) {
	// TODO(crawshaw): support PIXEL_PACK_BUFFER in GLES3, uses offset.
	C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), format.c(), ty.c(), unsafe.Pointer(&dst[0]))
}