Anonymous avatar Anonymous committed 852695e

Adedd OpenMP support for blit and fill operations.
Fixed minor macros expansion bugs in surface.h.
Fixed source and buffer number limitations in openal.Sources and openal.Buffers.
Added compiler (flag) dependency support to build system.
Added simple pygame2.openal player example.
Added simple timing script.

Comments (0)

Files changed (26)

     Build and install the pygame2.openal module. This wraps the
     OpenAL library and gives access to the pygame2.openal module.
 
+WITH_OPENMP=[yes|no|1|True]         Example: make -DWITH_OPENAL=1
+    
+    Add support for the Open Multi-Processing library. This will utilize
+    the OpenMP API to speed up certain routines, such as e.g blit and
+    fill operations. This option is only available for certain compilers
+    and will be disabled by default.
+
 WITH_EXPERIMENTAL=[yes|no|1|True]   Example: make -DWITH_EXPERIMENTAL=True
 
     Build pygame2 modules, which are marked as experimental. Note that those
 # OpenAL (module) support
 build['OPENAL'] = istrue (os.getenv ("WITH_OPENAL", True))
 
+# Open Multiprocessing support
+build['OPENMP'] = istrue (os.getenv ("WITH_OPENMP", False))
+
 # Experimental modules support
 build['EXPERIMENTAL'] = istrue (os.getenv ("WITH_EXPERIMENTAL", False))
+
+

config/__init__.py

 __all__ = [ "config_modules", "config_darwin", "config_msys", "config_unix",
             "config_win", "dll", "helpers", "intelccompiler", "llvmccompiler",
             "mingw32ccompiler", "distutilsext", "mingwcfg", "msys", "msysio",
-            "libconfig" ]
+            "libconfig", "config_compiler" ]

config/config_compiler.py

+class CompilerDependency (object):
+    """
+    Generic compiler flag and dependency class.
+    """
+    def __init__ (self, name, cflags, lflags):
+        self.name = name
+        self.cflags = cflags
+        self.lflags = lflags
+        self.gdefines = [("HAVE_" + self.name.upper(), None)]
+
+    def setup_module (self, module):
+        if not module.canbuild:
+            return
+
+        # update compiler/linker args for the module
+        module.cflags += self.cflags
+        module.lflags += self.lflags
+        module.globaldefines += self.gdefines 
+
+def get_dependencies (cfg, compiler):
+    dep = CompilerDependency
+    deps = []
+    if compiler == 'unix' or compiler == 'cygwin' or \
+       compiler == 'mingw32' or compiler == 'mingw32-console':
+        # TODO: check compiler version!
+        if cfg.build['OPENMP']:
+            deps.append (dep ('openmp', ['-fopenmp'], ['-fopenmp']))
+    elif compiler == 'msvc':
+        if cfg.build['OPENMP']:
+            deps.append (dep ('openmp', ['/openmp'], ['/openmp']))
+    elif compiler == 'icc':
+        if cfg.build['OPENMP']:
+            deps.append (dep ('openmp', ['-openmp'], ['-openmp']))
+
+    for d in deps:
+        print ("Adding compiler flags '%s':" % d.name)
+        print ("")
+        print ("\tCFlags : " + repr(d.cflags))
+        print ("\tLFlags : " + repr(d.lflags))
+        print ("")
+        
+    return deps

config/config_darwin.py

 try: import plistlib
 except: pass
 
-
 def _get_framework_path(library):
     """
         Returns a tuple containing the path to the

config/config_generic.py

 
 class Dependency (object):
     """
-        Generic Dependency class.
+    Generic Dependency class.
+    
+    This class represents a generic library dependency of a PyGame
+    module, i.e. the required compiler and linker flags for building
+    a module which depends on this library.
+    
+    This class is instantiated with the 'linker id' (for example, a
+    library which is linked with '-lpng' has 'png' as its linker id)
+    of the library it represents and the name of a representative
+    header file.
+    
+    It must be then configured with the configure() method; if the
+    configuration is successful, the setup_module() method may be
+    used to update a Module object with the compiler flags which are
+    needed to build it.
+    
+    The process of 'configuring' this Dependency implies setting the
+    following lists with the information relevant to the library:
+    
+        self.incdirs  (all the directories which contain the include files)
+        self.libdirs  (the directory(s) which contain the library itself)
+        self.libs     (the name of the library files which must be linked)
+        self.cflags   (all the flags which must be passed to the C compiler)
+        self.gdefines (all the defines which to be passed to the C compiler)
+        self.lflags   (all the flags which must be passed to the C linker)
 
-        This class represents a generic library dependency of a PyGame
-        module, i.e. the required compiler and linker flags for building
-        a module which depends on this library.
-
-        This class is instantiated with the 'linker id' (for example, a
-        library which is linked with '-lpng' has 'png' as its linker id)
-        of the library it represents and the name of a representative
-        header file.
-
-        It must be then configured with the configure() method; if the
-        configuration is successful, the setup_module() method may be
-        used to update a Module object with the compiler flags which are
-        needed to build it.
-
-        The process of 'configuring' this Dependency implies setting the
-        following lists with the information relevant to the library:
-            
-            self.incdirs  (all the directories which contain the include files)
-            self.libdirs  (the directory(s) which contain the library itself)
-            self.libs     (the name of the library files which must be linked)
-            self.cflags   (all the flags which must be passed to the C compiler)
-            self.gdefines (all the defines which to be passed to the C compiler)
-            self.lflags   (all the flags which must be passed to the C linker)
-
-        Configuration is done by executing 'configuration callbacks'
-        (each one implementing a different configuration method) until
-        the required information has been collected.
-
-        A configuration callback is simply a class method starting by
-        '_configure_' which is automatically executed by the
-        Dependency.configure() method and returns True if the library's
-        information was found.
-
-        By default, this generic class implements the configuration
-        method which is common to all platforms:
-        Dependency._configure_guess() tries to guess the location of the
-        library by looking in system folders for the required files.
-
-        However, all platforms inherit this class to implement their
-        custom configuration callbacks; for instance, Unix systems also
-        try to use the 'pkgconfig' tool to automatically locate
-        installed libraries, and Mac OS X tries to locate installed
-        Framework Bundles containing the libraries.
-
-        See the other configuration callbacks in their respective modules:
-
-            config.config_unix
-            config.config_darwin
-            config.config_msys
-            config.config_win
+    Configuration is done by executing 'configuration callbacks'
+    (each one implementing a different configuration method) until
+    the required information has been collected.
+    
+    A configuration callback is simply a class method starting by
+    '_configure_' which is automatically executed by the
+    Dependency.configure() method and returns True if the library's
+    information was found.
+    
+    By default, this generic class implements the configuration
+    method which is common to all platforms:
+    Dependency._configure_guess() tries to guess the location of the
+    library by looking in system folders for the required files.
+    
+    However, all platforms inherit this class to implement their
+    custom configuration callbacks; for instance, Unix systems also
+    try to use the 'pkgconfig' tool to automatically locate
+    installed libraries, and Mac OS X tries to locate installed
+    Framework Bundles containing the libraries.
+    
+    See the other configuration callbacks in their respective modules:
+    
+        config.config_unix
+        config.config_darwin
+        config.config_msys
+        config.config_win
     """
 
     _incdirs = []
 
     def _canbuild(self, cfg):
         """
-            Returns if this library has been manually disabled
-            by the user on the 'cfg.py' module, and hence cannot be built.
+        Returns if this library has been manually disabled
+        by the user on the 'cfg.py' module, and hence cannot be built.
         """
         cfg_entry = self.library_id.upper()
 
 
     def _find_libdir(self, name):
         """
-            Searches the library folders for the specified library
-            file.
+        Searches the library folders for the specified library
+        file.
         """
         for d in self._searchdirs:
             for g in self._libdirs:
 
     def _find_incdir(self, name):
         """
-            Recursively search all include dirs for the specified
-            header file.
+        Recursively search all include dirs for the specified
+        header file.
         """
         for d in self._searchdirs:
             for g in self._incdirs:
 
     def _configure_guess(self):
         """
-            Configuration callback which automatically looks for
-            the required headers and libraries in some default
-            system folders.
+        Configuration callback which automatically looks for
+        the required headers and libraries in some default
+        system folders.
         """
         dirs = []
         for h in self.header_files:
 
     def configure(self, cfg):
         """
-            Finds the compiler/linker information needed
-            to configure this library.
+        Finds the compiler/linker information needed
+        to configure this library.
         """
         print ("Configuring library '%s':" % self.library_id)
         if self.nocheck:
 
     def setup_module(self, module, optional = False):
         """
-            Updates a modules.Module object with all the compiler
-            and linker flags required to build it with this library.
-
-            module - modules.Module object
-            optional - whether the module requires the library to build
+        Updates a modules.Module object with all the compiler
+        and linker flags required to build it with this library.
+        
+        module - modules.Module object
+        optional - whether the module requires the library to build
         """
 
         # if the building for this module is disabled already, it means

config/config_modules.py

 import os, sys
 from config import helpers
 from config import config_unix, config_win, config_darwin, config_msys
+from config import config_compiler
 from config.config_generic import Dependency
 
 OS_MODULES = {
     'darwin': config_darwin
 }
 
-def get_dependencies(buildsystem, cfg):
+def get_librarydependencies(buildsystem, cfg):
     """
-        Returns a dict with all the configured libraries which 
-        will be used when linking PyGame modules.
-
-        Configuring a library implies finding its location
-        and storing the compiler/linker arguments which
-        will be passed to all the modules which rely on such
-        library.
+    Returns a dict with all the configured libraries which will be used
+    when linking PyGame modules.
+    
+    Configuring a library implies finding its location and storing the
+    compiler/linker arguments which will be passed to all the modules
+    which rely on such library.
     """
     dep = OS_MODULES[buildsystem].Dependency
     pygame_sdl_path = os.path.join ("src", "sdl")
             pkgconfig_name='openal')
         }
 
-    OS_MODULES[buildsystem].update_sys_deps (DEPENDENCIES)
-
+    OS_MODULES[buildsystem].update_sys_libdeps (DEPENDENCIES)
     for (dep_name, dep) in DEPENDENCIES.items():
         dep.configure(cfg)
 
     return DEPENDENCIES
 
+def get_compilerdependencies (buildsystem, cfg):
+    """
+    Returns the configurable compiler flags and dependencies.
+    """
+    return OS_MODULES[buildsystem].get_compilerdependencies (cfg)
+
 def sdl_get_version(buildsystem):
     """
-        Returns the version of the installed SDL library
+    Returns the version of the installed SDL library
     """
     return OS_MODULES[buildsystem].sdl_get_version()
 
 def get_install_libs(buildsystem, cfg):
     """
-        Return a list with the libraries which must be bundled
-        and installed with Pygame, based on the active OS
+    Return a list with the libraries which must be bundled and installed
+    with Pygame, based on the active OS
     """
     return OS_MODULES[buildsystem].get_install_libs(cfg)
 
-def prepare_modules(buildsystem, modules, cfg):
+def prepare_modules(buildsystem, modules, cfg, compiler):
     """
-        Updates all the modules that must be built by adding
-        compiler/link information for the libraries on which
-        they depend.
+    Updates all the modules that must be built by adding compiler/link
+    information for the libraries on which they depend.
 
-        buildsystem - The active build system
-        modules - List of module.Module objects
-        cfg - The currently loaded 'cfg' module
+    buildsystem - The active build system
+    modules - List of module.Module objects
+    cfg - The currently loaded 'cfg' module
     """
 
     os_config = OS_MODULES[buildsystem]
 
-    # configure our library dependencies
-    dependencies = get_dependencies(buildsystem, cfg)
+    # configure our library and compiler dependencies
+    dependencies = get_librarydependencies (buildsystem, cfg)
+    compilerdeps = config_compiler.get_dependencies (cfg, compiler)
 
     for mod in modules:
         mod.canbuild = (not mod.experimental) or \
             (mod.experimental and cfg.build['EXPERIMENTAL'])
 
         # Pull in OS-specific dependencies.
-        os_config.add_sys_deps (mod)
+        os_config.add_sys_libdeps (mod)
 
         # add build/link information for the library dependencies 
         # on which mod relies.
             if dep_name in dependencies:
                 dep = dependencies[dep_name]
                 dep.setup_module(mod, True)
+
+        # add compiler dependencies
+        for dep in compilerdeps:
+            dep.setup_module (mod)

config/config_msys.py

 def sdl_get_version ():
     return config_unix.sdl_get_version()
 
-def add_sys_deps (module):
-    config_win.add_sys_deps(module)
+def add_sys_libdeps (module):
+    config_win.add_sys_libdeps(module)
 
-def update_sys_deps (deps):
-    config_win.update_sys_deps(deps)
+def update_sys_libdeps (deps):
+    config_win.update_sys_libdeps(deps)
 
 def _hunt_libs (name, dirs):
     # Used by get_install_libs(). It resolves the dependency libraries
 
     return [ k.replace ("/", os.sep) for k in libraries.keys() ]
 
-
 class Dependency (config_unix.Dependency):
     _searchdirs = [ "/usr", "/usr/local", "/mingw" ]
     _incdirs = [ "include", "X11/include" ]

config/config_unix.py

 import os, glob, sys
 from config import config_generic, libconfig, pkgconfig, helpers
 
-def update_sys_deps (deps):
+def update_sys_libdeps (deps):
     deps["x11"] = Dependency (['Xutil.h'], 'X11', pkgconfig_name='x11')
 
-def add_sys_deps (module):
+def add_sys_libdeps (module):
     if module.name == "sdlext.scrap":
         module.depends.append ("x11")
 

config/config_win.py

     # TODO: Is there some way to detect the correct version?
     return "Unknown"
 
-def update_sys_deps (deps):
+def update_sys_libdeps (deps):
     deps["user32"] = Dependency ([], 'user32')
     deps["user32"].nocheck = True
     deps["gdi32"] = Dependency ([], 'gdi32')
     deps["gdi32"].nocheck = True
     deps["openal"].libs = [ "OpenAL32" ]
 
-def add_sys_deps (module):
+def add_sys_libdeps (module):
     if module.name.startswith("sdl"):
         module.libs += ["SDLmain"]
     if module.name == "sdlext.scrap":
 Build and install the :mod:`pygame2.openal` module. This wraps the OpenAL
 library and gives access to the :mod:`pygame2.openal` module. ::
 
+  WITH_OPENMP=[yes|no|1|True]         Example: make -DWITH_OPENAL=1
+    
+Add support for the Open Multi-Processing library. This will utilize the
+OpenMP API to speed up certain routines, such as e.g blit and fill
+operations.
+
+.. note::
+
+  This option is only available for certain compilers (GCC, Intel, MS
+  VC++) and disabled by default.
+
+::
+
   WITH_EXPERIMENTAL=[yes|no|1|True]       Example: make -DWITH_EXPERIMENTAL=True
 
 Build pygame2 modules, which are marked as experimental. Note that those

examples/openal/__init__.py

+"""Examples for pygame2.openal."""

examples/openal/player.py

+import sys, wave
+import pygame2
+import pygame2.examples
+
+try:
+    import pygame2.openal as openal
+    import pygame2.openal.constants as const
+except ImportError:
+    print ("No pygame2.openal support")
+    sys.exit ()
+
+# Format mappings, used to determine the sample byte size and channels
+# used.
+formatmap = {
+    (1, 8) : const.AL_FORMAT_MONO8,
+    (2, 8) : const.AL_FORMAT_STEREO8,
+    (1, 16): const.AL_FORMAT_MONO16,
+    (2, 16) : const.AL_FORMAT_STEREO16,
+    }
+
+class SimplePlayer (object):
+    """A simple OpenAL-based audio player."""
+    def __init__ (self, format, data, samplerate):
+        if format not in formatmap:
+            raise ValueError ("format must be a valid AL_FORMAT_* constant")
+        self.channels, self.samplesize = format
+        self.alformat = formatmap[format]
+
+        # Create the device and default context.
+        self.device = openal.Device ()
+        self.context = openal.Context (self.device)
+        self.context.make_current ()
+
+        # Create a playback source.
+        self.sources = self.context.create_sources (1)
+
+        self.sources.set_prop (self.sources.sources[0], const.AL_PITCH, 1., 'f')
+        self.sources.set_prop (self.sources.sources[0], const.AL_GAIN, 1., 'f')
+        self.sources.set_prop(self.sources.sources[0], const.AL_POSITION,
+                              (0., 0., 0.), 'fa')
+        self.sources.set_prop(self.sources.sources[0], const.AL_VELOCITY,
+                              (0., 0., 0.), 'fa')
+
+        buffers = self.context.create_buffers (1)
+        buffers.buffer_data (buffers.buffers[0],self.alformat, data, samplerate)
+        self.sources.queue_buffers (self.sources.sources[0], buffers)
+
+    def play (self):
+        if not self.isplaying ():
+            self.sources.play (self.sources.sources[0])
+
+    def isplaying (self):
+        state = self.sources.get_prop (self.sources.sources[0],
+                                       const.AL_SOURCE_STATE, 'i')
+        return state == const.AL_PLAYING
+
+    def pause (self):
+        if not self.isplaying ():
+            return
+        self.sources.pause (self.sources.sources[0])
+
+def run ():
+    if len (sys.argv) < 2:
+        print ("Usage: player.py wavefile")
+        print ("    Using an example wav file...")
+        wavefp = wave.open (pygame2.examples.RESOURCES.get ("house_lo.wav"),
+                            "rb")
+    else:
+        wavefp = wave.open (sys.argv[1], "rb")
+        
+    channels = wavefp.getnchannels ()
+    bitrate = wavefp.getsampwidth () * 8
+    samplerate = wavefp.getframerate ()
+
+    player = SimplePlayer ((channels, bitrate),
+                           wavefp.readframes (wavefp.getnframes ()),
+                           samplerate)
+    player.play ()
+
+    # Wait until the playback is done
+    while player.isplaying ():
+        pass 
+    
+if __name__ == "__main__":
+    run ()
Add a comment to this file

examples/resources/house_lo.wav

Binary file added.

examples/sdl/surface_fill.py

     import pygame2.sdl.wm as wm
 except ImportError:
     print ("No pygame2.sdl support")
-    sys.exit ()
+    sys.exit (1)
 
 white = pygame2.Color (255, 255, 255)
 black = pygame2.Color (0, 0, 0)
             docfile = "sdlextnumericsurfarray.xml",
             depends = ['SDL']))
 
-def get_extensions (buildsystem):
+def get_extensions (buildsystem, compiler):
     extensions = []
 
     compatpath = "src"
     docpath = os.path.join ("src", "doc")
     baseincpath = os.path.join ("src", "base")
 
-    config.config_modules.prepare_modules (buildsystem, modules, cfg)
+    config.config_modules.prepare_modules (buildsystem, modules, cfg, compiler)
     
     alldefines = []
     for mod in modules:
             pkgdata.append (os.path.join (subd, f))
     return pkgdata
 
+def get_compiler (args):
+    coffset = 0
+    compiler = ''
+    if '-c' in args:
+        coffset = args.index ('-c')
+        if coffset < len (args) - 1:
+            compiler = args[coffset+1]
+    else:
+        for arg in args:
+            if '--compiler=' in arg:
+                compiler = arg.split ('=')[1]
+    return compiler
+
 def run_checks ():
     # Python version check.
     if helpers.getversion () < PYTHON_MINIMUM: # major, minor check
 
     buildsystem = None
     builddefines = []
+    defcompiler = ''
     if sys.platform == "win32":
         if msys.is_msys ():
             buildsystem = "msys"
             builddefines.append (("IS_MSYS", None))
+            defcompiler = "mingw32"
         else:
             buildsystem = "win"
             builddefines.append (("IS_WIN32", None))
             builddefines.append (("WIN32", None))
+            defcompiler = "msvc"
     elif sys.platform == "darwin":
         buildsystem = "darwin"
         builddefines.append (("IS_DARWIN", None))
+        defcompiler = "unix"
     else:
         buildsystem = "unix"
+        defcompiler = "unix"
         builddefines.append (("IS_UNIX", None))
 
     if cfg.build['SDL']:
         sdlversion = config_modules.sdl_get_version (buildsystem)
+    compiler = get_compiler (sys.argv) or defcompiler
 
     print ("\nThe following information will be used to build Pygame:")
-    print ("\t System: %s" % buildsystem)
-    print ("\t Python: %d.%d.%d" % helpers.getversion ())
+    print ("\t System:   %s" % buildsystem)
+    print ("\t Python:   %d.%d.%d" % helpers.getversion ())
+    print ("\t Compiler: %s" % compiler)
     if cfg.build['SDL']:
-        print ("\t SDL:    %s" % sdlversion)
-    return buildsystem, builddefines
+        print ("\t SDL:      %s" % sdlversion)
+    return buildsystem, builddefines, compiler
 
 if __name__ == "__main__":
 
     buildsystem = None
     buildcflags = None
     try:
-        buildsystem, builddefines = run_checks ()
+        buildsystem, builddefines, compiler = run_checks ()
     except:
         print (helpers.geterror ())
         print (helpers.gettraceback ())
         VERSION = VERSION.replace("-alpha", "a")
         VERSION = VERSION.replace("-rc", "r")
 
-    if buildsystem in ("msys", "unix", "darwin") and DEBUG:
+    if DEBUG and buildsystem in ("msys", "unix", "darwin") and \
+       compiler in ("unix", "cygwin", "mingw32", "mingw32-console"):
         os.environ["CFLAGS"] += " -W -Wall -Wimplicit-int " + \
                         "-Wimplicit-function-declaration " + \
                         "-Wimplicit -Wreturn-type -Wunused " + \
 
     dllfiles = [ os.path.join ("pygame2", "dll"),
                  config_modules.get_install_libs (buildsystem, cfg) ]
-    ext_modules = modules.get_extensions (buildsystem)
+    ext_modules = modules.get_extensions (buildsystem, compiler)
     modules.update_packages (ext_modules, packages, package_dir, package_data)
 
     headerfiles = []

src/openal/buffers.c

             &type))
         return NULL;
 
-    if (bufnum < 0 || bufnum > ((PyBuffers*)self)->count)
-    {
-        PyErr_SetString (PyExc_ValueError, "buffer index out of range");
-        return NULL;
-    }
-
     if (type)
     {
         ptype = GetPropTypeFromStr (type);
     if (!PyArg_ParseTuple (args, "lls:get_prop", &bufnum, &param, &type))
     {
         PyErr_Clear ();
-        if (!PyArg_ParseTuple (args, "ll|si:get_prop", &bufnum, &param, &type,
+        if (!PyArg_ParseTuple (args, "lls|i:get_prop", &bufnum, &param, &type,
             &size))
             return NULL;
         if (size <= 0)
         }
     }
 
-    if (bufnum < 0 || bufnum > ((PyBuffers*)self)->count)
-    {
-        PyErr_SetString (PyExc_ValueError, "buffer index out of range");
-        return NULL;
-    }
-
     ptype = GetPropTypeFromStr (type);
     CLEAR_ALERROR_STATE ();
     switch (ptype)
 static PyObject*
 _buffers_bufferdata (PyObject *self, PyObject *args)
 {
-    long bufnum;
-    ALenum format;
+    long bufnum, format;
     const char *buf;
     Py_ssize_t len;
     ALsizei freq;
     if (!PyArg_ParseTuple (args, "lls#l", &bufnum, &format, &buf, &len, &freq))
         return NULL;
     
-    /* TODO */
-    if (bufnum < 0 || bufnum > ((PyBuffers*)self)->count)
-    {
-        PyErr_SetString (PyExc_ValueError, "buffer index out of range");
-        return NULL;
-    }
     CLEAR_ALERROR_STATE ();
-    alBufferData ((ALuint) bufnum, format, (const void*) buf, (ALsizei)len,
-        freq);
+    alBufferData ((ALuint) bufnum, (ALenum)format, (const void*) buf,
+        (ALsizei)len, freq);
     if (SetALErrorException (alGetError (), 0))
         return NULL;
     Py_RETURN_NONE;

src/openal/sources.c

             &type))
         return NULL;
 
-    if (bufnum < 0 || bufnum > ((PySources*)self)->count)
-    {
-        PyErr_SetString (PyExc_ValueError, "source index out of range");
-        return NULL;
-    }
-
     if (type)
     {
         ptype = GetPropTypeFromStr (type);
     if (!PyArg_ParseTuple (args, "lls:get_prop", &bufnum, &param, &type))
     {
         PyErr_Clear ();
-        if (!PyArg_ParseTuple (args, "ll|si:get_prop", &bufnum, &param, &type,
+        if (!PyArg_ParseTuple (args, "lls|i:get_prop", &bufnum, &param, &type,
             &size))
             return NULL;
         if (size <= 0)
         }
     }
 
-    if (bufnum < 0 || bufnum > ((PySources*)self)->count)
-    {
-        PyErr_SetString (PyExc_ValueError, "source index out of range");
-        return NULL;
-    }
-
     ptype = GetPropTypeFromStr (type);
     CLEAR_ALERROR_STATE ();
     switch (ptype)
     
     if (!PyArg_ParseTuple (args, "lO:queue_buffers", &bufnum, &buffers))
         return NULL;
-    
-    if (bufnum < 0 || bufnum > ((PySources*)self)->count)
-    {
-        PyErr_SetString (PyExc_ValueError, "source index out of range");
-        return NULL;
-    }
+
     if (!PyBuffers_Check (buffers))
     {
         PyErr_SetString (PyExc_TypeError, "argument must be a Buffers object");
     if (!PyArg_ParseTuple (args, "lO:unqueue_buffers", &bufnum, &buffers))
         return NULL;
     
-    if (bufnum < 0 || bufnum > ((PySources*)self)->count)
-    {
-        PyErr_SetString (PyExc_ValueError, "source index out of range");
-        return NULL;
-    }
     if (!PyBuffers_Check (buffers))
     {
         PyErr_SetString (PyExc_TypeError, "argument must be a Buffers object");

src/sdl/surface.h

     }                                                                   \
     else                                                                \
     {                                                                   \
-        rgb = SDL_MapRGB (format,                                       \
+        (rgb) = SDL_MapRGB (format,                                     \
             ((Uint8)(((rgb) & 0xff0000) >> 16)),                        \
             ((Uint8)(((rgb) & 0x00ff00) >>  8)),                        \
             ((Uint8)((rgb) & 0x0000ff)));                               \
     }                                                                   \
     else                                                                \
     {                                                                   \
-        argb = SDL_MapRGBA (format,                                     \
+        (argb) = SDL_MapRGBA (format,                                   \
             ((Uint8)(((argb) & 0x00ff0000) >> 16)),                     \
             ((Uint8)(((argb) & 0x0000ff00) >>  8)),                     \
             ((Uint8) ((argb) & 0x000000ff)),                            \
     switch ((bpp))                                                      \
     {                                                                   \
     case 1:                                                             \
-        pxl = *((Uint8*) ((Uint8*)(surface)->pixels) + (_y) *           \
+        (pxl) = *((Uint8*) ((Uint8*)(surface)->pixels) + (_y) *         \
             (surface)->pitch + (_x));                                   \
         break;                                                          \
     case 2:                                                             \
-        pxl = *((Uint16*)(((Uint8*)(surface)->pixels) + (_y) *          \
+        (pxl) = *((Uint16*)(((Uint8*)(surface)->pixels) + (_y) *        \
                 (surface)->pitch) + (_x));                              \
         break;                                                          \
     case 4:                                                             \
-        pxl = *((Uint32*)(((Uint8*)(surface)->pixels) + (_y) *          \
+        (pxl) = *((Uint32*)(((Uint8*)(surface)->pixels) + (_y) *        \
                 (surface)->pitch) + (_x));                              \
         break;                                                          \
     default:                                                            \
     {                                                                   \
         Uint8* buf = ((Uint8 *) (((Uint8*)(surface)->pixels) + (_y) *   \
                 (surface)->pitch) + (_x) * 3);                          \
-        pxl = GET_PIXEL24(buf);                                         \
+        (pxl) = GET_PIXEL24(buf);                                       \
         break;                                                          \
     }                                                                   \
     }

src/sdl/surface_blit.c

         info.d_width = dstrect->w;
         info.d_height = dstrect->h;
         info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel;
+        info.s_pitch = src->pitch;
+        info.d_pitch = dst->pitch;
         info.src = src->format;
         info.dst = dst->format;
 

src/sdl/surface_blit.h

     int             s_width;
     int             s_height;
     int             s_skip;
+    int             s_pitch;
     Uint8          *d_pixels;
     int             d_width;
     int             d_height;
     int             d_skip;
+    int             d_pitch;
     void           *aux_data;
     SDL_PixelFormat *src;
     Uint8          *table;

src/sdl/surface_blit_rgb.c

 */
 
 #include "surface_blit.h"
+#ifdef HAVE_OPENMP
+#include <omp.h>
+#endif
 
+#ifdef HAVE_OPENMP
+#define CREATE_BLITTER(_name,_blitop)                                   \
+    void blit_##_name(SDL_BlitInfo *info)                               \
+    {                                                                   \
+        int             width = info->d_width;                          \
+        int             height = info->d_height;                        \
+        Uint8          *src = info->s_pixels;                           \
+        Uint8          *dst = info->d_pixels;                           \
+        SDL_PixelFormat *srcfmt = info->src;                            \
+        SDL_PixelFormat *dstfmt = info->dst;                            \
+        int             srcbpp = srcfmt->BytesPerPixel;                 \
+        int             dstbpp = dstfmt->BytesPerPixel;                 \
+        Uint8           dR, dG, dB, dA, sR, sG, sB, sA;                 \
+        Uint32          pixel;                                          \
+        Uint32          tmp;                                            \
+        Sint32          tmp2;                                           \
+        Uint8          *sppx, *dppx;                                    \
+        int             x, y;                                           \
+                                                                        \
+        if (srcbpp == 4 && dstbpp == 4)                                 \
+        {                                                               \
+            _Pragma("omp parallel")                                     \
+            {                                                           \
+                _Pragma("omp for private(sppx,dppx,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                for (y = 0; y < height; y++)                            \
+                {                                                       \
+                    for (x = 0; x < width; x++)                         \
+                    {                                                   \
+                        sppx = src + y * info->s_pitch + x * srcbpp;    \
+                        dppx = dst + y * info->d_pitch + x * dstbpp;    \
+                        GET_RGB_VALS ((*(Uint32*)sppx), srcfmt, sR, sG, sB, sA); \
+                        GET_RGB_VALS ((*(Uint32*)dppx), dstfmt, dR, dG, dB, dA); \
+                        _blitop;                                        \
+                        CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+            return;                                                     \
+        }                                                               \
+                                                                        \
+        if (srcbpp == 1)                                                \
+        {                                                               \
+            if (dstbpp == 1)                                            \
+            {                                                           \
+                _Pragma("omp parallel")                                 \
+                {                                                       \
+                    _Pragma("omp for private(sppx,dppx,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                    for (y = 0; y < height; y++)                        \
+                    {                                                   \
+                        for (x = 0; x < width; x++)                     \
+                        {                                               \
+                            sppx = src + y * info->s_pitch + x * srcbpp; \
+                            dppx = dst + y * info->d_pitch + x * dstbpp; \
+                            GET_PALETTE_VALS(sppx, srcfmt, sR, sG, sB, sA); \
+                            GET_PALETTE_VALS(dppx, dstfmt, dR, dG, dB, dA); \
+                            _blitop;                                    \
+                            CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                        }                                               \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+            else /* dstbpp > 1 */                                       \
+            {                                                           \
+                _Pragma("omp parallel")                                 \
+                {                                                       \
+                    _Pragma("omp for private(sppx,dppx,pixel,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                    for (y = 0; y < height; y++)                        \
+                    {                                                   \
+                        for (x = 0; x < width; x++)                     \
+                        {                                               \
+                            sppx = src + y * info->s_pitch + x * srcbpp; \
+                            dppx = dst + y * info->d_pitch + x * dstbpp; \
+                            GET_PALETTE_VALS(sppx, srcfmt, sR, sG, sB, sA); \
+                            GET_PIXEL (pixel, dstbpp, dppx);             \
+                            GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA); \
+                            _blitop;                                    \
+                            CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                        }                                               \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+        }                                                               \
+        else /* srcbpp > 1 */                                           \
+        {                                                               \
+            if (dstbpp == 1)                                            \
+            {                                                           \
+                _Pragma("omp parallel")                                 \
+                {                                                       \
+                    _Pragma("omp for private(sppx,dppx,pixel,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                    for (y = 0; y < height; y++)                        \
+                    {                                                   \
+                        for (x = 0; x < width; x++)                     \
+                        {                                               \
+                            sppx = src + y * info->s_pitch + x * srcbpp; \
+                            dppx = dst + y * info->d_pitch + x * dstbpp; \
+                            GET_PIXEL(pixel, srcbpp, sppx);             \
+                            GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA); \
+                            GET_PALETTE_VALS(dppx, dstfmt, dR, dG, dB, dA); \
+                            _blitop;                                    \
+                            CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                        }                                               \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+            else /* dstbpp > 1 */                                       \
+            {                                                           \
+                _Pragma("omp parallel")                                 \
+                {                                                       \
+                    _Pragma("omp for private(sppx,dppx,pixel,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                    for (y = 0; y < height; y++)                        \
+                    {                                                   \
+                        for (x = 0; x < width; x++)                     \
+                        {                                               \
+                            sppx = src + y * info->s_pitch + x * srcbpp; \
+                            dppx = dst + y * info->d_pitch + x * dstbpp; \
+                            GET_PIXEL(pixel, srcbpp, sppx);             \
+                            GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA); \
+                            GET_PIXEL (pixel, dstbpp, dppx);            \
+                            GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA); \
+                            _blitop;                                    \
+                            CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                        }                                               \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+        }                                                               \
+    }
+#else /* HAVE_OPENMP */
 #define CREATE_BLITTER(_name,_blitop)                                   \
     void blit_##_name(SDL_BlitInfo *info)                               \
     {                                                                   \
             }                                                           \
         }                                                               \
     }
-
+#endif /* HAVE_OPENMP */
 CREATE_BLITTER(blend_rgb_add, D_BLEND_RGB_ADD(tmp,sR,sG,sB,dR,dG,dB))
 CREATE_BLITTER(blend_rgb_sub, D_BLEND_RGB_SUB(tmp2,sR,sG,sB,dR,dG,dB))
 CREATE_BLITTER(blend_rgb_mul, D_BLEND_RGB_MULT(sR,sG,sB,dR,dG,dB))

src/sdl/surface_blit_rgba.c

 */
 
 #include "surface_blit.h"
+#ifdef HAVE_OPENMP
+#include <omp.h>
+#endif
 
+#ifdef HAVE_OPENMP
+#define CREATE_BLITTER(_name,_blitop)                                   \
+    void blit_##_name(SDL_BlitInfo *info)                               \
+    {                                                                   \
+        int             width = info->d_width;                          \
+        int             height = info->d_height;                        \
+        Uint8          *src = info->s_pixels;                           \
+        Uint8          *dst = info->d_pixels;                           \
+        SDL_PixelFormat *srcfmt = info->src;                            \
+        SDL_PixelFormat *dstfmt = info->dst;                            \
+        int             srcbpp = srcfmt->BytesPerPixel;                 \
+        int             dstbpp = dstfmt->BytesPerPixel;                 \
+        Uint8           dR, dG, dB, dA, sR, sG, sB, sA;                 \
+        Uint32          pixel;                                          \
+        Uint32          tmp;                                            \
+        Sint32          tmp2;                                           \
+        Uint8          *sppx, *dppx;                                    \
+        int             x, y;                                           \
+                                                                        \
+        if (srcbpp == 4 && dstbpp == 4)                                 \
+        {                                                               \
+            _Pragma("omp parallel")                                     \
+            {                                                           \
+                _Pragma("omp for private(sppx,dppx,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                for (y = 0; y < height; y++)                            \
+                {                                                       \
+                    for (x = 0; x < width; x++)                         \
+                    {                                                   \
+                        sppx = src + y * info->s_pitch + x * srcbpp;    \
+                        dppx = dst + y * info->d_pitch + x * dstbpp;    \
+                        GET_RGB_VALS ((*(Uint32*)sppx), srcfmt, sR, sG, sB, sA); \
+                        GET_RGB_VALS ((*(Uint32*)dppx), dstfmt, dR, dG, dB, dA); \
+                        _blitop;                                        \
+                        CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+            return;                                                     \
+        }                                                               \
+                                                                        \
+        if (srcbpp == 1)                                                \
+        {                                                               \
+            if (dstbpp == 1)                                            \
+            {                                                           \
+                _Pragma("omp parallel")                                 \
+                {                                                       \
+                    _Pragma("omp for private(sppx,dppx,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                    for (y = 0; y < height; y++)                        \
+                    {                                                   \
+                        for (x = 0; x < width; x++)                     \
+                        {                                               \
+                            sppx = src + y * info->s_pitch + x * srcbpp; \
+                            dppx = dst + y * info->d_pitch + x * dstbpp; \
+                            GET_PALETTE_VALS(sppx, srcfmt, sR, sG, sB, sA); \
+                            GET_PALETTE_VALS(dppx, dstfmt, dR, dG, dB, dA); \
+                            _blitop;                                    \
+                            CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                        }                                               \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+            else /* dstbpp > 1 */                                       \
+            {                                                           \
+                _Pragma("omp parallel")                                 \
+                {                                                       \
+                    _Pragma("omp for private(sppx,dppx,pixel,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                    for (y = 0; y < height; y++)                        \
+                    {                                                   \
+                        for (x = 0; x < width; x++)                     \
+                        {                                               \
+                            sppx = src + y * info->s_pitch + x * srcbpp; \
+                            dppx = dst + y * info->d_pitch + x * dstbpp; \
+                            GET_PALETTE_VALS(sppx, srcfmt, sR, sG, sB, sA); \
+                            GET_PIXEL (pixel, dstbpp, dppx);             \
+                            GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA); \
+                            _blitop;                                    \
+                            CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                        }                                               \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+        }                                                               \
+        else /* srcbpp > 1 */                                           \
+        {                                                               \
+            if (dstbpp == 1)                                            \
+            {                                                           \
+                _Pragma("omp parallel")                                 \
+                {                                                       \
+                    _Pragma("omp for private(sppx,dppx,pixel,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                    for (y = 0; y < height; y++)                        \
+                    {                                                   \
+                        for (x = 0; x < width; x++)                     \
+                        {                                               \
+                            sppx = src + y * info->s_pitch + x * srcbpp; \
+                            dppx = dst + y * info->d_pitch + x * dstbpp; \
+                            GET_PIXEL(pixel, srcbpp, sppx);             \
+                            GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA); \
+                            GET_PALETTE_VALS(dppx, dstfmt, dR, dG, dB, dA); \
+                            _blitop;                                    \
+                            CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                        }                                               \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+            else /* dstbpp > 1 */                                       \
+            {                                                           \
+                _Pragma("omp parallel")                                 \
+                {                                                       \
+                    _Pragma("omp for private(sppx,dppx,pixel,x,sR,sG,sB,sA,dR,dG,dB,dA,tmp,tmp2)") \
+                    for (y = 0; y < height; y++)                        \
+                    {                                                   \
+                        for (x = 0; x < width; x++)                     \
+                        {                                               \
+                            sppx = src + y * info->s_pitch + x * srcbpp; \
+                            dppx = dst + y * info->d_pitch + x * dstbpp; \
+                            GET_PIXEL(pixel, srcbpp, sppx);             \
+                            GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA); \
+                            GET_PIXEL (pixel, dstbpp, dppx);            \
+                            GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA); \
+                            _blitop;                                    \
+                            CREATE_PIXEL(dppx, dR, dG, dB, dA, dstbpp, dstfmt); \
+                        }                                               \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+        }                                                               \
+    }
+#else /* HAVE_OPENMP */
 #define CREATE_BLITTER(_name,_blitop)                                   \
     void blit_##_name(SDL_BlitInfo *info)                               \
     {                                                                   \
         Uint32          tmp;                                            \
         Sint32          tmp2;                                           \
                                                                         \
-        if (srcbpp == 4 && dstbpp == 4)                                     \
-        {                                                                   \
-            while (height--)                                                \
-            {                                                               \
-                LOOP_UNROLLED4(                                             \
+        if (srcbpp == 4 && dstbpp == 4)                                 \
+        {                                                               \
+            while (height--)                                            \
+            {                                                           \
+                LOOP_UNROLLED4(                                         \
                 {                                                           \
                     GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA); \
                     GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA); \
                     src += srcbpp;                                          \
                     dst += dstbpp;                                          \
                 }, n, width);                                               \
-                src += srcskip;                                             \
-                dst += dstskip;                                             \
-            }                                                               \
-            return;                                                         \
-        }                                                                   \
+                src += srcskip;                                         \
+                dst += dstskip;                                         \
+            }                                                           \
+            return;                                                     \
+        }                                                               \
                                                                         \
         if (srcbpp == 1)                                                \
         {                                                               \
             }                                                           \
         }                                                               \
     }
+#endif /* HAVE_OPENMP */
 
 CREATE_BLITTER(blend_rgba_add, D_BLEND_RGBA_ADD(tmp,sR,sG,sB,sA,dR,dG,dB,dA))
 CREATE_BLITTER(blend_rgba_sub, D_BLEND_RGBA_SUB(tmp2,sR,sG,sB,sA,dR,dG,dB,dA))

src/sdl/surface_fill.c

 */
 
 #include "surface.h"
+#ifdef HAVE_OPENMP
+#include <omp.h>
+#endif
 
+#ifdef HAVE_OPENMP
+#define CREATE_FILLER(_name,_fillop)                                    \
+    static int surface_fill_##_name(SDL_Surface *surface,               \
+        SDL_Rect *rect, Uint32 color)                                   \
+    {                                                                   \
+        Uint8 *pixels, *ppx;                                            \
+        int width = rect->w;                                            \
+        int height = rect->h;                                           \
+        int skip;                                                       \
+        int bpp;                                                        \
+        int n;                                                          \
+        SDL_PixelFormat *fmt;                                           \
+        Uint8 sR, sG, sB, sA, cR, cG, cB, cA;                           \
+        Uint32 pixel;                                                   \
+        Uint32 tmp;                                                     \
+        int result = -1;                                                \
+                                                                        \
+        bpp = surface->format->BytesPerPixel;                           \
+        fmt = surface->format;                                          \
+        pixels = (Uint8 *) surface->pixels + surface->offset +          \
+            (Uint16) rect->y * surface->pitch + (Uint16) rect->x * bpp; \
+        skip = surface->pitch - width * bpp;                            \
+                                                                        \
+        switch (bpp)                                                    \
+        {                                                               \
+        case 1:                                                         \
+        {                                                               \
+            int x, y;                                                   \
+            SDL_GetRGBA (color, fmt, &cR, &cG, &cB, &cA);               \
+            _Pragma("omp parallel")                                     \
+            {                                                           \
+                _Pragma("omp for private(ppx,x,sR,sG,sB,sA,tmp)")       \
+                for (y = 0; y < height; y++)                            \
+                {                                                       \
+                    for (x = 0; x < width; x++)                         \
+                    {                                                   \
+                        ppx = pixels + y * surface->pitch + x * bpp;    \
+                        GET_PALETTE_VALS(ppx,fmt,sR,sG,sB,sA);          \
+                        _fillop;                                        \
+                        *ppx = SDL_MapRGBA(fmt,sR,sG,sB,sA);            \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+            result = 0;                                                 \
+            break;                                                      \
+        }                                                               \
+        default:                                                        \
+        {                                                               \
+            int x, y;                                                   \
+            GET_RGB_VALS (color, fmt, cR, cG, cB, cA);                  \
+            _Pragma("omp parallel")                                     \
+            {                                                           \
+                _Pragma("omp for private(ppx,pixel,x,sR,sG,sB,sA,tmp)") \
+                for (y = 0; y < height; y++)                            \
+                {                                                       \
+                    for (x = 0; x < width; x++)                         \
+                    {                                                   \
+                        ppx = pixels + y * surface->pitch + x * bpp;    \
+                        GET_PIXEL(pixel,bpp,ppx);                       \
+                        GET_RGB_VALS(pixel,fmt,sR,sG,sB,sA);            \
+                        _fillop;                                        \
+                        CREATE_PIXEL(ppx,sR,sG,sB,sA,bpp,fmt);          \
+                    }                                                   \
+                }                                                       \
+            }                                                           \
+            result = 0;                                                 \
+            break;                                                      \
+        }                                                               \
+        }                                                               \
+        return result;                                                  \
+    }
+#else /* HAVE_OPENMP */
 #define CREATE_FILLER(_name,_fillop)                                    \
     static int surface_fill_##_name(SDL_Surface *surface,               \
         SDL_Rect *rect, Uint32 color)                                   \
         }                                                               \
         return result;                                                  \
     }
+#endif /* HAVE_OPENMP */
 
 CREATE_FILLER(blend_rgba_add, D_BLEND_RGBA_ADD(tmp,cR,cG,cB,cA,sR,sG,sB,sA))
 CREATE_FILLER(blend_rgba_sub, D_BLEND_RGBA_SUB(tmp,cR,cG,cB,cA,sR,sG,sB,sA))
+import timeit
+
+fillfuncmap = {
+    'BLEND_RGBA_ADD' : """
+    fill (c2, blendargs=const.BLEND_RGBA_ADD)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_AND' : """
+    fill (c2, blendargs=const.BLEND_RGBA_AND)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_AVG' : """
+    fill (c2, blendargs=const.BLEND_RGBA_AVG)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_DIFF' : """
+    fill (c2, blendargs=const.BLEND_RGBA_DIFF)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_MAX' : """
+    fill (c2, blendargs=const.BLEND_RGBA_MAX)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_MIN' : """
+    fill (c2, blendargs=const.BLEND_RGBA_MIN)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_MULT' : """
+    fill (c2, blendargs=const.BLEND_RGBA_MULT)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_OR' : """
+    fill (c2, blendargs=const.BLEND_RGBA_OR)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_SCREEN' : """
+    fill (c2, blendargs=const.BLEND_RGBA_SCREEN)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_SUB' : """
+    fill (c2, blendargs=const.BLEND_RGBA_SUB)
+    c1, c2 = c2, c1
+    """,
+    'BLEND_RGBA_XOR' : """
+    fill (c2, blendargs=const.BLEND_RGBA_XOR)
+    c1, c2 = c2, c1
+    """,
+    }   
+
+fillsetupstr = """
+from pygame2 import Color
+import pygame2.sdl.video as video
+import pygame2.sdl.constants as const
+
+c1 = Color (250, 126, 2)
+c2 = Color (2, 126, 250)
+
+video.init ()
+sf = video.Surface (500, 500, 32, const.SRCALPHA)
+sf.fill (c2)
+fill = sf.fill
+"""
+
+blendfuncmap = {
+    'BLEND_RGBA_ADD' : """
+    blit (sf, blendargs=const.BLEND_RGBA_ADD)
+    fill (color)
+    """,
+    'BLEND_RGBA_AND' : """
+    blit (sf, blendargs=const.BLEND_RGBA_AND)
+    fill (color)
+    """,
+    'BLEND_RGBA_AVG' : """
+    blit (sf, blendargs=const.BLEND_RGBA_AVG)
+    fill (color)
+    """,
+    'BLEND_RGBA_DIFF' : """
+    blit (sf, blendargs=const.BLEND_RGBA_DIFF)
+    fill (color)
+    """,
+    'BLEND_RGBA_MAX' : """
+    blit (sf, blendargs=const.BLEND_RGBA_MAX)
+    fill (color)
+    """,
+    'BLEND_RGBA_MIN' : """
+    blit (sf, blendargs=const.BLEND_RGBA_MIN)
+    fill (color)
+    """,
+    'BLEND_RGBA_MULT' : """
+    blit (sf, blendargs=const.BLEND_RGBA_MULT)
+    fill (color)
+    """,
+    'BLEND_RGBA_OR' : """
+    blit (sf, blendargs=const.BLEND_RGBA_OR)
+    fill (color)
+    """,
+    'BLEND_RGBA_SCREEN' : """
+    blit (sf, blendargs=const.BLEND_RGBA_SCREEN)
+    fill (color)
+    """,
+    'BLEND_RGBA_SUB' : """
+    blit (sf, blendargs=const.BLEND_RGBA_SUB)
+    fill (color)
+    """,
+    'BLEND_RGBA_XOR' : """
+    blit (sf, blendargs=const.BLEND_RGBA_XOR)
+    fill (color)
+    """,
+    }   
+
+blendsetupstr = """
+from pygame2 import Color
+import pygame2.sdl.video as video
+import pygame2.sdl.constants as const
+
+color = Color (170, 126, 23)
+
+video.init ()
+surface = video.Surface (500, 500, 32, const.SRCALPHA)
+sf = video.Surface (400, 400, 32, const.SRCALPHA)
+surface.fill (color)
+fill = surface.fill
+blit = surface.blit
+"""
+
+print ("SDL Surface fill functions")
+print ("##########################")
+for n, f in fillfuncmap.items():
+    print ("%s:\t %f" % (n , timeit.timeit (f, fillsetupstr, number=1000)))
+print ("##########################")
+print ("SDL Surface blit functions")
+print ("##########################")
+for n, f in blendfuncmap.items():
+    print ("%s:\t %f" % (n , timeit.timeit (f, blendsetupstr, number=1000)))
+print ("##########################")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.