Esempio n. 1
0
def glGetTexImage( target, level,format,type, outputType=str ):
	"""Get a texture-level as an image
	
	target -- enum constant for the texture engine to be read 
	level -- the mip-map level to read 
	format -- image format to read out the data 
	type -- data-type into which to read the data
	
	outputType -- default (str) provides string output of the 
		results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True 
		and type == GL_UNSIGNED_BYTE.  Any other value will cause 
		output in the default array output format.
	
	returns the pixel data array in the format defined by the 
	format, type and outputType
	"""
	from OpenGL.GL import glget
	dims = [glget.glGetTexLevelParameteriv( target, level, simple.GL_TEXTURE_WIDTH )]
	if target != simple.GL_TEXTURE_1D:
		dims.append( glget.glGetTexLevelParameteriv( target, level, simple.GL_TEXTURE_HEIGHT ) )
		if target != simple.GL_TEXTURE_2D:
			dims.append( glget.glGetTexLevelParameteriv( target, level, simple.GL_TEXTURE_DEPTH ) )
	array = images.SetupPixelRead( format, tuple(dims), type )
	arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[ images.TYPE_TO_ARRAYTYPE.get(type,type) ]
	simple.glGetTexImage( 
		target, level, format, type, ctypes.c_void_p( arrayType.dataPointer(array)) 
	)
	if outputType is str:
		return images.returnFormat( array, type )
	else:
		return array
Esempio n. 2
0
def glGetTexImage(target, level, format, type, array=None, outputType=bytes):
    """Get a texture-level as an image

    target -- enum constant for the texture engine to be read
    level -- the mip-map level to read
    format -- image format to read out the data
    type -- data-type into which to read the data
    array -- optional array/offset into which to store the value

    outputType -- default (bytes) provides string output of the
        results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True
        and type == GL_UNSIGNED_BYTE.  Any other value will cause
        output in the default array output format.

    returns the pixel data array in the format defined by the
    format, type and outputType
    """
    arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[images.TYPE_TO_ARRAYTYPE.get(
        type, type)]
    if array is None:
        dims = _get_texture_level_dims(target, level)
        array = imageData = images.SetupPixelRead(format, tuple(dims), type)
        owned = True
    else:
        if isinstance(array, integer_types):
            imageData = ctypes.c_void_p(array)
        else:
            array = arrayType.asArray(array)
            imageData = arrayType.voidDataPointer(array)
        owned = False
    GL_1_1.glGetTexImage(target, level, format, type, imageData)
    if outputType is bytes:
        return images.returnFormat(array, type)
    else:
        return array
Esempio n. 3
0
    def glReadPixels(x,
                     y,
                     width,
                     height,
                     format,
                     type=type,
                     array=None,
                     outputType=bytes):
        """Read specified pixels from the current display buffer

        This typed version returns data in your specified default
        array data-type format, or in the passed array, which will
        be converted to the array-type required by the format.
        """
        x, y, width, height = asInt(x), asInt(y), asInt(width), asInt(height)
        arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[
            images.TYPE_TO_ARRAYTYPE.get(type, type)]

        if array is None:
            array = imageData = images.SetupPixelRead(format, (width, height),
                                                      type)
            owned = True
        else:
            if isinstance(array, integer_types):
                imageData = ctypes.c_void_p(array)
            else:
                array = arrayType.asArray(array)
                imageData = arrayType.voidDataPointer(array)
            owned = False
        GL_1_1.glReadPixels(x, y, width, height, format, type, imageData)
        if owned and outputType is bytes:
            return images.returnFormat(array, type)
        else:
            return array
Esempio n. 4
0
def glReadPixels( x,y,width,height,format,type, outputType=str ):
	"""Read specified pixels from the current display buffer
	
	x,y,width,height -- location and dimensions of the image to read 
		from the buffer
	format -- pixel format for the resulting data
	type -- data-format for the resulting data
	outputType -- default (str) provides string output of the 
		results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True 
		and type == GL_UNSIGNED_BYTE.  Any other value will cause 
		output in the default array output format.
	
	returns the pixel data array in the format defined by the 
	format, type and outputType
	"""
	x,y,width,height = asInt(x),asInt(y),asInt(width),asInt(height)
	array = images.SetupPixelRead( format, (width,height), type )
	arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[ images.TYPE_TO_ARRAYTYPE.get(type,type) ]
	imageData = arrayType.dataPointer(array)
	simple.glReadPixels( 
		x,y,width,height,
		format,type, 
		ctypes.c_void_p( imageData ) 
	)
	if outputType is str:
		return images.returnFormat( array, type )
	else:
		return array
Esempio n. 5
0
    def glReadPixels( x,y,width,height,format,type=type, array=None, outputType=bytes ):
        """Read specified pixels from the current display buffer

        This typed version returns data in your specified default
        array data-type format, or in the passed array, which will
        be converted to the array-type required by the format.
        """
        x,y,width,height = asInt(x),asInt(y),asInt(width),asInt(height)
        arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[ images.TYPE_TO_ARRAYTYPE.get(type,type) ]
        
        if array is None:
            array = imageData = images.SetupPixelRead( format, (width,height), type )
            owned = True
        else:
            if isinstance( array, integer_types):
                imageData = ctypes.c_void_p( array )
            else:
                array = arrayType.asArray( array )
                imageData = arrayType.voidDataPointer( array )
            owned = False
        GL_1_1.glReadPixels(
            x,y,
            width, height,
            format,type,
            imageData
        )
        if owned and outputType is bytes:
            return images.returnFormat( array, type )
        else:
            return array
Esempio n. 6
0
    def glGetTexImage(target,
                      level,
                      format,
                      type,
                      array=None,
                      outputType=bytes):
        """bug fixed overwirte version"""
        arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[
            images.TYPE_TO_ARRAYTYPE.get(type, type)]
        if array is None:
            dims = OpenGLContext._get_texture_level_dims(target, level)
            imageData = images.SetupPixelRead(format, tuple(dims), type)
            array = imageData
        else:
            if isinstance(array, integer_types):
                imageData = ctypes.c_void_p(array)
            else:
                array = arrayType.asArray(array)
                imageData = arrayType.voidDataPointer(array)

        GL_1_1.glGetTexImage(target, level, format, type, imageData)

        if outputType is bytes:
            return images.returnFormat(array, type)
        else:
            return array
Esempio n. 7
0
def glGetTexImage(target, level, format, type, array=None, outputType=bytes):
    """Get a texture-level as an image

    target -- enum constant for the texture engine to be read
    level -- the mip-map level to read
    format -- image format to read out the data
    type -- data-type into which to read the data
    array -- optional array/offset into which to store the value

    outputType -- default (bytes) provides string output of the
        results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True
        and type == GL_UNSIGNED_BYTE.  Any other value will cause
        output in the default array output format.

    returns the pixel data array in the format defined by the
    format, type and outputType
    """
    arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[images.TYPE_TO_ARRAYTYPE.get(type, type)]
    if array is None:
        dims = _get_texture_level_dims(target, level)
        array = imageData = images.SetupPixelRead(format, tuple(dims), type)
        owned = True
    else:
        if isinstance(array, integer_types):
            imageData = ctypes.c_void_p(array)
        else:
            array = arrayType.asArray(array)
            imageData = arrayType.voidDataPointer(array)
        owned = False
    GL_1_1.glGetTexImage(target, level, format, type, imageData)
    if outputType is bytes:
        return images.returnFormat(array, type)
    else:
        return array
Esempio n. 8
0
def glReadPixels(x, y, width, height, format, type, array=None, outputType=bytes):
    """Read specified pixels from the current display buffer

    x,y,width,height -- location and dimensions of the image to read
        from the buffer
    format -- pixel format for the resulting data
    type -- data-format for the resulting data
    array -- optional array/offset into which to store the value
    outputType -- default (bytes) provides string output of the
        results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True
        and type == GL_UNSIGNED_BYTE.  Any other value will cause
        output in the default array output format.

    returns the pixel data array in the format defined by the
    format, type and outputType
    """
    x, y, width, height = asInt(x), asInt(y), asInt(width), asInt(height)

    arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[images.TYPE_TO_ARRAYTYPE.get(type, type)]
    if array is None:
        array = imageData = images.SetupPixelRead(format, (width, height), type)
        owned = True
    else:
        if isinstance(array, integer_types):
            imageData = ctypes.c_void_p(array)
        else:
            array = arrayType.asArray(array)
            imageData = arrayType.voidDataPointer(array)
        owned = False

    GL_1_1.glReadPixels(x, y, width, height, format, type, imageData)
    if owned and outputType is bytes:
        return images.returnFormat(array, type)
    else:
        return array
Esempio n. 9
0
def glReadPixels(x,
                 y,
                 width,
                 height,
                 format,
                 type,
                 array=None,
                 outputType=bytes):
    """Read specified pixels from the current display buffer

    x,y,width,height -- location and dimensions of the image to read
        from the buffer
    format -- pixel format for the resulting data
    type -- data-format for the resulting data
    array -- optional array/offset into which to store the value
    outputType -- default (bytes) provides string output of the
        results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True
        and type == GL_UNSIGNED_BYTE.  Any other value will cause
        output in the default array output format.

    returns the pixel data array in the format defined by the
    format, type and outputType
    """
    x, y, width, height = asInt(x), asInt(y), asInt(width), asInt(height)

    arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[images.TYPE_TO_ARRAYTYPE.get(
        type, type)]
    if array is None:
        array = imageData = images.SetupPixelRead(format, (width, height),
                                                  type)
        owned = True
    else:
        if isinstance(array, integer_types):
            imageData = ctypes.c_void_p(array)
        else:
            array = arrayType.asArray(array)
            imageData = arrayType.voidDataPointer(array)
        owned = False

    GL_1_1.glReadPixels(x, y, width, height, format, type, imageData)
    if owned and outputType is bytes:
        return images.returnFormat(array, type)
    else:
        return array