cdef extern from "stdlib.h": ctypedef int size_t void *calloc(size_t nmemb, size_t size) void *malloc(size_t size) void free(void *ptr) # cdef extern from "stdlib.h" cdef extern from "libvisual.h": ########################################################################## ## Types ## ########################################################################## ctypedef unsigned char uint8_t #------------------------------------------------------------------------ # lv_param ctypedef struct VisParamContainer #------------------------------------------------------------------------ # lv_pallete ctypedef struct VisPalette #------------------------------------------------------------------------ # lv_video ctypedef enum VisVideoFlags: VISUAL_VIDEO_FLAG_NONE = 0 VISUAL_VIDEO_FLAG_ALLOCATED_BUFFER = 1 VISUAL_VIDEO_FLAG_EXTERNAL_BUFFER = 2 ctypedef enum VisVideoDepth: VISUAL_VIDEO_DEPTH_NONE = 0 VISUAL_VIDEO_DEPTH_8BIT = 1 VISUAL_VIDEO_DEPTH_16BIT = 2 VISUAL_VIDEO_DEPTH_24BIT = 4 VISUAL_VIDEO_DEPTH_32BIT = 8 VISUAL_VIDEO_DEPTH_GL = 16 VISUAL_VIDEO_DEPTH_ENDLIST = 32 VISUAL_VIDEO_DEPTH_ERROR = -1 VISUAL_VIDEO_DEPTH_ALL = VISUAL_VIDEO_DEPTH_8BIT | \ VISUAL_VIDEO_DEPTH_16BIT | \ VISUAL_VIDEO_DEPTH_24BIT | \ VISUAL_VIDEO_DEPTH_32BIT | \ VISUAL_VIDEO_DEPTH_GL ctypedef struct VisVideo ########################################################################## ## Functions ## ########################################################################## #------------------------------------------------------------------------ # lv_libvisual char *visual_get_version() VisParamContainer *visual_get_params() int visual_init_path_add( char *pathadd ) int visual_init( int *argc, char ***argv ) int visual_is_initialized() int visual_quit() #------------------------------------------------------------------------ # lv_video VisVideo *visual_video_new() VisVideo *visual_video_new_with_buffer( int width, int height, VisVideoDepth depth ) int visual_video_free( VisVideo *video ) int visual_video_free_with_buffer( VisVideo *video ) int visual_video_free_buffer( VisVideo *video ) int visual_video_allocate_buffer( VisVideo *video ) int visual_video_have_allocated_buffer( VisVideo *video ) int visual_video_clone( VisVideo *dest, VisVideo *src ) int visual_video_compare( VisVideo *src1, VisVideo *src2 ) int visual_video_set_palette( VisVideo *video, VisPalette *pal ) int visual_video_set_buffer( VisVideo *video, void *buffer ) int visual_video_set_dimension( VisVideo *video, int width, int height ) int visual_video_set_pitch( VisVideo *video, int pitch ) int visual_video_set_depth( VisVideo *video, VisVideoDepth depth ) int visual_video_depth_is_supported( int depthflag, VisVideoDepth depth ) VisVideoDepth visual_video_depth_get_next( int depthflag, VisVideoDepth depth ) VisVideoDepth visual_video_depth_get_prev( int depthflag, VisVideoDepth depth ) VisVideoDepth visual_video_depth_get_lowest( int depthflag ) VisVideoDepth visual_video_depth_get_highest( int depthflag ) VisVideoDepth visual_video_depth_get_highest_nogl( int depthflag ) int visual_video_depth_is_sane( VisVideoDepth depth ) int visual_video_depth_value_from_enum( VisVideoDepth depth ) VisVideoDepth visual_video_depth_enum_from_value( int depthvalue ) int visual_video_bpp_from_depth( VisVideoDepth depth ) int visual_video_blit_overlay( VisVideo *dest, VisVideo *src, int x, int y, int alpha ) int visual_video_alpha_color( VisVideo *video, uint8_t r, uint8_t g, uint8_t b, uint8_t density ) int visual_video_alpha_fill( VisVideo *video, uint8_t density ) int visual_video_color_bgr_to_rgb( VisVideo *dest, VisVideo *src ) int visual_video_depth_transform( VisVideo *viddest, VisVideo *vidsrc ) int visual_video_depth_transform_to_buffer( uint8_t *dest, VisVideo *video, VisPalette *pal, VisVideoDepth destdepth, int pitch ) # cdef extern from "libvisual.h" ############################################################################## ## Wrapper Functions ## ############################################################################## def get_version(): """Gives the libvisual version.""" return visual_get_version() # get_version() def get_params(): """Returns a pointer to the libvisual global VisParamContainer. Returns: A pointer to the libvisual global VisParamContainer. """ print "get_params(): Not Implemented Yet!" # get_params() def init_path_add( pathadd ): """Adds extra plugin registry paths. Parameters: * pathadd: A string containing a path where plugins are located. Returns: 0 on succes -1 on error. """ return visual_init_path_add( pathadd ) # init_path_add() def init( argv ): """Initialize libvisual. Sets up a plugin registry, register the program name and such. Parameters: * argv: list of strings representing the argument Returns: 0 on succes -1 on error. """ if not isinstance( argv, list ): raise TypeError( "argument must be a list of strings!" ) # hold original values cdef int aco cdef char **avo # hold to be passed values cdef int ac cdef char **av aco = len( argv ) if aco == 0: raise TypeError( "argument list must contain at least one argument!" ) # build an argument list avo = calloc( aco, sizeof(char *) ) for i from 0 <= i < aco: if not isinstance( argv[ i ], str ): free( avo ) raise TypeError( "argument must be a list of strings!" ) txt = argv[ i ] avo[ i ] = txt av = avo ac = aco ret = visual_init( &ac, &av ) # rebuild argv from the modified av del argv[ : ] for i from 0 <= i < ac: argv.append( av[ i ] ) free( avo ) return ret # init() def is_initialized(): """Tells whether Libvisual is (correctly) initialized. Returns: True if it is initialized, False otherwise. """ if visual_is_initialized(): return True else: return False # is_initialized() def quit(): """Quits libvisual, destroys all the plugin registries. Returns: 0 on succes -1 on error. """ return visual_quit() # quit() ############################################################################## ## Wrapper Classes ## ############################################################################## cdef getvideo( instance ): return instance.video #----------------------------------------------------------------------------- # Video #----------------------------------------------------------------------------- cdef class Video: cdef VisVideo *video def __new__( self, width=None, height=None, depth=VISUAL_VIDEO_DEPTH_32BIT ): """Creates a new Video instance. If optional parameters are given it also allocates a buffer. Parameters: * width: the buffer width * height: the buffer height * depth: the buffer depth (defaults to 32Bit) Returns: Video instance """ cdef int w cdef int h cdef VisVideoDepth d if width and height: if depth is None: depth = VISUAL_VIDEO_DEPTH_NONE w = width h = height d = depth self.video = visual_video_new_with_buffer( w, h, d ) else: self.video = visual_video_new() # __new__() def __dealloc__( self ): if self.have_allocated_buffer(): visual_video_free_with_buffer( self.video ) else: visual_video_free( self.video ) # __dealloc__() def allocate_buffer( self, width=None, height=None, depth=VISUAL_VIDEO_DEPTH_32BIT ): """Allocates a screenbuffer for the Video. Allocates based on it's information about the screen dimension and depth. Parameters: * width: the buffer width * height: the buffer height * depth: the bufffer depth Returns: 0 on succes -1 on error. Notes: these parameters are not present in C api. """ if width and height: self.set_depth( depth ) self.set_dimension( width, height ) return visual_video_allocate_buffer( self.video ) # allocate_buffer() def have_allocated_buffer( self ): """Checks if has a private allocated buffer. Returns: True if it has, False otherwise. """ if visual_video_have_allocated_buffer( self.video ): return True else: return False # have_allocated_buffer() def clone( self, source ): """Clones the information from a Video to another. This will clone the depth, dimension and screen pitch into another Video. It doesn't clone the palette or screenbuffer. Parameters: * source: source Video in which the information needs to be obtained. Returns: @return 0 on succes -1 on error. """ if not isinstance( source, Video ): raise TypeError( "source must be a Video instance!" ) return visual_video_clone( self.video, source.video ) # clone() # Video