Exemple #1
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
Exemple #2
0
	def glReadPixels( x,y,width,height,format,type=type ):
		"""Read specified pixels from the current display buffer
		
		This typed version returns data in your specified default 
		array data-type format
		"""
		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 )
		)
		return array
 def glReadPixels(x, y, width, height, format, type=type, array=None):
     """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 = images.SetupPixelRead(format, (width, height), type)
     else:
         array = arrayType.asArray(array)
     imageData = arrayType.voidDataPointer(array)
     simple.glReadPixels(int(x), int(y), int(width), int(height), format,
                         type, imageData)
     return array
Exemple #4
0
 def glReadPixels( x,y,width,height,format,type=type, array=None ):
     """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 = images.SetupPixelRead( format, (width,height), type )
     else:
         array = arrayType.asArray( array )
     imageData = arrayType.voidDataPointer( array )
     simple.glReadPixels( 
         int(x),int(y),
         int(width), int(height),
         format,type, 
         imageData
     )
     return array
Exemple #5
0
def process_image():
    """ copy image and process using CUDA """
    global pycuda_source_pbo,source_pbo,current_size, dest_pbo
    image_width, image_height = current_size
    assert source_pbo is not None

    # tell cuda we are going to get into these buffers
    pycuda_source_pbo.unregister()

    # activate destination buffer
    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, long(source_pbo))

    # read data into pbo. note: use BGRA format for optimal performance
    import OpenGL.raw.GL as rawgl

    rawgl.glReadPixels(
             0,                  #start x
             0,                  #start y
             image_width,        #end   x
             image_height,       #end   y
             GL_BGRA,            #format
             GL_UNSIGNED_BYTE,   #output type
             ctypes.c_void_p(0))

    pycuda_source_pbo = cuda_gl.BufferObject(long(source_pbo))
    
    # run the Cuda kernel
    process(image_width, image_height)
    # blit convolved texture onto the screen
    # download texture from PBO
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, long(dest_pbo))
    glBindTexture(GL_TEXTURE_2D, output_texture)

    rawgl.glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
                    image_width, image_height,
                    GL_BGRA, GL_UNSIGNED_BYTE, ctypes.c_void_p(0))