Commits

Anonymous committed 62e182c

Added numpy surface array module. Removed Numeric dependency and imported Numeric/arrayobject header.

Comments (0)

Files changed (10)

 SMPEG = -lsmpeg
 PNG = -lpng
 JPEG = -ljpeg
-NUMERIC = -I/usr/include/python2.4/Numeric
 SCRAP = -lX11
 #--EndConfig
 
 font src/font.c $(SDL) $(FONT) $(DEBUG)
 mixer src/mixer.c $(SDL) $(MIXER) $(DEBUG)
 mixer_music src/music.c $(SDL) $(MIXER) $(DEBUG)
-surfarray src/surfarray.c $(SDL) $(NUMERIC) $(DEBUG)
-sndarray src/sndarray.c $(SDL) $(NUMERIC) $(MIXER) $(DEBUG)
+surfarray src/surfarray.c $(SDL) $(DEBUG)
+sndarray src/sndarray.c $(SDL) $(MIXER) $(DEBUG)
 movie src/movie.c $(SDL) $(SMPEG) $(DEBUG)
 scrap src/scrap.c $(SDL) $(SCRAP) $(DEBUG)
 
     FrameworkDependency('IMAGE', 'SDL_image.h', 'libSDL_image', 'SDL_image'),
     FrameworkDependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer', 'SDL_mixer'),
     FrameworkDependency('SMPEG', 'smpeg.h', 'libsmpeg', 'smpeg'),
-    DependencyPython('NUMERIC', 'Numeric', 'Numeric/arrayobject.h'),
     Dependency('PNG', 'png.h', 'libpng', ['png']),
     Dependency('JPEG', 'jpeglib.h', 'libjpeg', ['jpeg']),
     Dependency('SCRAP', '','',[])
         Dependency('IMAGE', 'SDL_image.h', 'libSDL_image.so', ['SDL_image']),
         Dependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer.so', ['SDL_mixer']),
         DependencyProg('SMPEG', 'SMPEG_CONFIG', 'smpeg-config', '0.4.3', ['smpeg']),
-        DependencyPython('NUMERIC', 'Numeric', 'Numeric/arrayobject.h')
     ]
 
     if not DEPS[0].found:
         Dependency('IMAGE', 'SDL_image.h', 'libSDL_image.so', ['SDL_image']),
         Dependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer.so', ['SDL_mixer']),
         DependencyProg('SMPEG', 'SMPEG_CONFIG', 'smpeg-config', '0.4.3', ['smpeg']),
-        DependencyPython('NUMERIC', 'Numeric', 'Numeric/arrayobject.h'),
         Dependency('PNG', 'png.h', 'libpng', ['png']),
         Dependency('JPEG', 'jpeglib.h', 'libjpeg', ['jpeg']),
         Dependency('SCRAP', '', 'libX11', ['X11']),
     Dependency('MIXER', ['SDL_mixer-[0-9].*'], ['SDL_mixer']),
     Dependency('SMPEG', ['smpeg-[0-9].*'], ['smpeg']),
     Dependency('SCRAP', ['user32.*', 'gdi32.*'], ['user32', 'gdi32']),
-    DependencyPython('NUMERIC', 'Numeric', 'Numeric/arrayobject.h'),
 ]
 
 def setup_prebuilt():

lib/numpyarray.py

+##    pygame - Python Game Library
+##    Copyright (C) 2007 Marcus von Appen
+##
+##    This library is free software; you can redistribute it and/or
+##    modify it under the terms of the GNU Library General Public
+##    License as published by the Free Software Foundation; either
+##    version 2 of the License, or (at your option) any later version.
+##
+##    This library is distributed in the hope that it will be useful,
+##    but WITHOUT ANY WARRANTY; without even the implied warranty of
+##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+##    Library General Public License for more details.
+##
+##    You should have received a copy of the GNU Library General Public
+##    License along with this library; if not, write to the Free
+##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+##
+##    Marcus von Appen
+##    mva@sysfault.org
+
+"""pygame module for accessing surface pixel data using numpy
+
+Functions to convert pixel data between pygame Surfaces and Numpy
+arrays. This module will only be available when pygame can use the
+external Numpy package.
+
+Note, that numpyarray is an optional module. It requires that Numpy is
+installed to be used. If not installed, an exception will be raised when
+it is used. eg. ImportError: no module named numpy
+
+Every pixel is stored as a single integer value to represent the red,
+green, and blue colors. The 8bit images use a value that looks into a
+colormap. Pixels with higher depth use a bit packing process to place
+three or four values into a single number.
+
+The Numpy arrays are indexed by the X axis first, followed by the Y
+axis. Arrays that treat the pixels as a single integer are referred to
+as 2D arrays. This module can also separate the red, green, and blue
+color values into separate indices. These types of arrays are referred
+to as 3D arrays, and the last index is 0 for red, 1 for green, and 2 for
+blue.
+
+In contrast to Numeric Numpy does use unsigned 16bit integers, images
+with 16bit data will be treated as unsigned integers.
+"""
+
+import pygame
+import numpy
+import re
+
+def array2d (surface):
+    """pygame.numpyarray.array2d (Surface): return array
+
+    copy pixels into a 2d array
+
+    Copy the pixels from a Surface into a 2D array. The bit depth of the
+    surface will control the size of the integer values, and will work
+    for any type of pixel format.
+
+    This function will temporarily lock the Surface as pixels are copied
+    (see the Surface.lock - lock the Surface memory for pixel access
+    method).
+    """
+    bpp = surface.get_bytesize ()
+    if bpp <= 0 or bpp > 4:
+        raise ValueError, "unsupported bit depth for 2D array"
+
+    if bpp == 3:
+        # The 3 bpp handling is taken from Alex Holkner's pygame-ctypes
+        # package. Thanks a lot.
+        data = surface.get_buffer ().raw
+        
+        # Remove extra pitch from each row
+        width = surface.get_width ()
+        pitchdiff = surface.get_pitch () - width * 3
+        if pitchdiff > 0:
+            pattern = re.compile ('(%s)%s' % ('.' * width * bpp,
+                                              '.' * pitchdiff),
+                                  flags=re.DOTALL)
+            data = ''.join (pattern.findall (data))
+
+        # Pad each triplet of bytes with another zero
+        pattern = re.compile ('...', flags=re.DOTALL)
+        data = '\0'.join (pattern.findall(data))
+        if pygame.get_sdl_byteorder () == pygame.LIL_ENDIAN:
+            data += '\0'
+        else:
+            data = '\0' + data
+        array = numpy.fromstring (data, numpy.uint32)
+        array.shape = (width, surface.get_height ())
+        return array
+    
+    typecode = (numpy.uint8, numpy.uint16, None, numpy.uint32)[bpp - 1]
+    array = numpy.array (numpy.frombuffer (surface.get_buffer (), typecode))
+    array.shape = surface.get_height (), surface.get_pitch () / bpp
+    
+    # Padding correction for certain depth due to padding bytes.
+    array = array[:,:surface.get_width ()]
+    array = numpy.transpose (array)
+    return array
+
+def pixels2d (surface):
+    """pygame.numpyarray.pixels2d (Surface): return array
+
+    reference pixels into a 2d array
+    
+    Create a new 2D array that directly references the pixel values in a
+    Surface. Any changes to the array will affect the pixels in the
+    Surface. This is a fast operation since no data is copied.
+
+    Pixels from a 24-bit Surface cannot be referenced, but all other
+    Surface bit depths can.
+
+    The Surface this references will remain locked for the lifetime of
+    the array (see the Surface.lock - lock the Surface memory for pixel
+    access method).
+    """
+    bpp = surface.get_bytesize ()
+    if bpp == 3 or bpp < 1 or bpp > 4:
+        raise ValueError, "unsupported bit depth for 2D reference array"
+
+    typecode = (numpy.uint8, numpy.uint16, None, numpy.uint32)[bpp - 1]
+    array = numpy.frombuffer (surface.get_buffer (), typecode)
+    array.shape = surface.get_height (), surface.get_pitch () / bpp
+
+    # Padding correction for certain depth due to padding bytes.
+    array = array[:,:surface.get_width ()]
+    array = numpy.transpose (array)
+    return array
+
+def array3d (surface):
+    """pygame.numpyarray.array3d (Surface): return array
+
+    copy pixels into a 3d array
+
+    Copy the pixels from a Surface into a 3D array. The bit depth of the
+    surface will control the size of the integer values, and will work
+    for any type of pixel format.
+
+    This function will temporarily lock the Surface as pixels are copied
+    (see the Surface.lock - lock the Surface memory for pixel access
+    method).
+    """
+    bpp = surface.get_bytesize ()
+    array = array2d (surface)
+
+    # Taken from from Alex Holkner's pygame-ctypes package. Thanks a
+    # lot.
+    if bpp == 1:
+        palette = surface.get_palette ()
+        # Resolve the correct values using the color palette
+        pal_r = numpy.array ([c[0] for c in palette])
+        pal_g = numpy.array ([c[1] for c in palette])
+        pal_b = numpy.array ([c[2] for c in palette])
+        planes = [numpy.choose (array, pal_r),
+                  numpy.choose (array, pal_g),
+                  numpy.choose (array, pal_b)]
+        array = numpy.array (planes)
+        array = numpy.transpose (array, (1, 2, 0))
+        return array
+    else:
+        masks = sf.get_masks ()
+        shifts = sf.get_shifts ()
+        losses = sf.get_losses ()
+        planes = [((array & masks[0]) >> shifts[0]) << losses[0],
+                  ((array & masks[1]) >> shifts[1]) << losses[1],
+                  ((array & masks[2]) >> shifts[2]) << losses[2]]
+        array = numpy.array (planes)
+        return numpy.transpose (array, (1, 2, 0))
+
+def pixels3d (surface):
+    """pygame.numpyarray.pixels3d (Surface): return array
+
+    reference pixels into a 3d array
+
+    Create a new 3D array that directly references the pixel values in a
+    Surface. Any changes to the array will affect the pixels in the
+    Surface. This is a fast operation since no data is copied.
+
+    This will only work on Surfaces that have 24-bit or 32-bit
+    formats. Lower pixel formats cannot be referenced.
+
+    The Surface this references will remain locked for the lifetime of
+    the array (see the Surface.lock - lock the Surface memory for pixel
+    access method).
+    """
+    bpp = surface.get_bytesize ()
+    if bpp < 3 or bpp > 4:
+        raise ValueError, "unsupported bit depth for 3D reference array"
+
+    start = 0
+    step = 0
+    end = 0
+
+    # Check for RGB or BGR surface.
+    shifts = surface.get_shifts ()
+    if shifts[0] == 16 and shifts[1] == 8 and shifts[2] == 0:
+        # RGB 
+        end = None
+        if pygame.get_sdl_byteorder () == pygame.LIL_ENDIAN:
+            start = 2
+            step = -1
+        else:
+            start = 0
+            step = 1
+    else:
+        # BGR
+        end = 3
+        if pygame.get_sdl_byteorder () == pygame.LIL_ENDIAN:
+            start = 0
+            step = 1
+        else:
+            start = 2
+            step = -1
+
+    array = numpy.frombuffer (surface.get_buffer (), numpy.uint8)
+    array.shape  = surface.get_width (), surface.get_height (), 4
+    array = array[:,:,start:end:step]
+    array.strides = (bpp, surface.get_pitch (), step)
+    return array
+
+def array_alpha (surface):
+    """pygame.numpyarray.array_alpha (Surface): return array
+
+    copy pixel alphas into a 2d array
+
+    Copy the pixel alpha values (degree of transparency) from a Surface
+    into a 2D array. This will work for any type of Surface
+    format. Surfaces without a pixel alpha will return an array with all
+    opaque values.
+
+    This function will temporarily lock the Surface as pixels are copied
+    (see the Surface.lock - lock the Surface memory for pixel access
+    method).
+    """
+    if surface.get_bytesize () == 1 or not surface.get_alpha ():
+        # 1 bpp surfaces and surfaces without alpha are always fully
+        # opaque.
+        array = numpy.empty (surface.get_width () * surface.get_height (),
+                             numpy.uint8)
+        array.fill (0xff)
+        array.shape = surface.get_width (), surface.get_height ()
+        return array
+
+    array = array2d (surface)
+    # Those shifts match the results from the old numeric system
+    # exactly.
+    array = array >> surface.get_shifts ()[3] << surface.get_losses ()[3]
+    array = array.astype (numpy.uint8)
+    return array
+
+def pixels_alpha (surface):
+    """pygame.numpyarray.pixels_alpha (Surface): return array
+
+    reference pixel alphas into a 2d array
+
+    Create a new 2D array that directly references the alpha values
+    (degree of transparency) in a Surface. Any changes to the array will
+    affect the pixels in the Surface. This is a fast operation since no
+    data is copied.
+
+    This can only work on 32-bit Surfaces with a per-pixel alpha value.
+
+    The Surface this array references will remain locked for the
+    lifetime of the array.
+    """
+    if surface.get_bytesize () != 4:
+        raise ValueError, "unsupported bit depth for alpha reference array"
+
+    # ARGB surface.
+    start = 0
+    
+    if surface.get_shifts ()[3] == 24:
+        # RGBA surface.
+        start = 3
+
+    shape = surface.get_pitch (), surface.get_height ()
+    array = numpy.frombuffer (surface.get_buffer (), numpy.uint8)
+    array = array[start::4]
+    array.shape = surface.get_width (), surface.get_height ()
+    return array
+
+def array_colorkey (surface):
+    """pygame.numpyarray.array_colorkey (Surface): return array
+
+    copy the colorkey values into a 2d array
+
+    Create a new array with the colorkey transparency value from each
+    pixel. If the pixel matches the colorkey it will be fully
+    tranparent; otherwise it will be fully opaque.
+
+    This will work on any type of Surface format. If the image has no
+    colorkey a solid opaque array will be returned.
+
+    This function will temporarily lock the Surface as pixels are
+    copied.
+    """
+    colorkey = surface.get_colorkey ()
+    if colorkey == None:
+        # No colorkey, return a solid opaque array.
+        array = numpy.empty (surface.get_width () * surface.get_height (),
+                             numpy.uint8)
+        array.fill (0xff)
+        array.shape = surface.get_width (), surface.get_height ()
+        return array
+
+    # Taken from from Alex Holkner's pygame-ctypes package. Thanks a
+    # lot.
+    array = array2d (sf)
+    # Check each pixel value for the colorkey and mark it as opaque or
+    # transparent as needed.
+    array = numpy.choose (numpy.equal (array, colorkey), (0xff, 0))
+    array = array.astype (numpy.uint8)
+    return array
+
+def make_surface (array):
+    """pygame.numpyarray.make_surface (array): return Surface
+
+    copy an array to a new surface
+
+    Create a new Surface that best resembles the data and format on the
+    array. The array can be 2D or 3D with any sized integer values.
+    """ 
+    # Taken from from Alex Holkner's pygame-ctypes package. Thanks a
+    # lot.
+    bpp = 0
+    r = g = b = 0
+    shape = array.shape
+    if len (shape) == 2:
+        # 2D array
+        bpp = 8
+        
+    elif len (shape) == 3 and shape[2] == 3:
+        bpp = 32
+        r = 0xff << 16
+        g = 0xff << 8
+        b = 0xff
+    else:
+        raise ValueError, "must be a valid 2d or 3d array"
+
+    surface = pygame.Surface ((shape[0], shape[1]), 0, bpp, (r, g, b,0))
+    blit_array (surface, array)
+    return surface
+
+def blit_array (surface, array):
+    """pygame.numpyarray.blit_array (Surface, array): return None
+
+    blit directly from a array values
+
+    Directly copy values from an array into a Surface. This is faster
+    than converting the array into a Surface and blitting. The array
+    must be the same dimensions as the Surface and will completely
+    replace all pixel values.
+
+    This function will temporarily lock the Surface as the new values
+    are copied.
+    """
+    # Taken from from Alex Holkner's pygame-ctypes package. Thanks a
+    # lot.
+    bpp = surface.get_bytesize ()
+    shape = array.shape
+    width = surface.get_width ()
+
+    if len(shape) == 3 and shape[2] == 3:
+        array = numpy.transpose (array, (1, 0, 2))
+        shifts = surface.get_shifts ()
+        losses = surface.get_losses ()
+        array = (array[:,:,::3] >> losses[0] << shifts[0]) | \
+                (array[:,:,1::3] >> losses[1] << shifts[1]) | \
+                (array[:,:,2::3] >> losses[2] << shifts[2])
+    elif len (shape) == 2:
+        array = numpy.transpose (array)
+    else:
+        raise ValueError, "must be a valid 2d or 3d array"
+
+    if width != shape[0] or surface.get_height () != shape[1]:
+        raise ValueError, "array must match the surface dimensions"
+
+    itemsize = array.itemsize
+    data = array.tostring ()
+    
+    if itemsize > bpp:
+        # Trim bytes from each element, keep least significant byte(s)
+        pattern = '%s(%s)' % ('.' * (itemsize - bpp), '.' * bpp)
+        if pygame.get_sdl_byteorder () == pygame.LIL_ENDIAN:
+            pattern = '(%s)%s' % ('.' * bpp, '.' * (itemsize - bpp))
+        data = ''.join (re.compile (pattern, flags=re.DOTALL).findall (data))
+    elif itemsize < bpp:
+        # Add pad bytes to each element, at most significant end
+        pad = '\0' * (bpp - itemsize)
+        pixels = re.compile ('.' * itemsize, flags=re.DOTALL).findall (data)
+        data = pad.join (pixels)
+        if pygame.get_sdl_byteorder () == pygame.LIL_ENDIAN:
+            data = data + pad
+        else:
+            data = pad + data
+
+    # Add zeros pad for pitch correction
+    pitchdiff = surface.get_pitch () - width * bpp
+    if pitchdiff > 0:
+        pad = '\0' * pitchdiff
+        rows = re.compile ('.' * width * bpp, flags=re.DOTALL).findall (data)
+        data = pad.join (rows) + pad
+
+    surface.get_buffer ().write (data, 0)
+    
+def map_array (surface, array):
+    """pygame.numpyarray.map_array (Surface, array3d): return array2d
+
+    map a 3d array into a 2d array
+
+    Convert a 3D array into a 2D array. This will use the given Surface
+    format to control the conversion. Palette surface formats are not
+    supported.
+
+    Note: arrays do not need to be 3D, as long as the minor axis has
+    three elements giving the component colours, any array shape can be
+    used (for example, a single colour can be mapped, or an array of
+    colours).
+    """
+    # Taken from from Alex Holkner's pygame-ctypes package. Thanks a
+    # lot.
+    bpp = surface.get_bytesize ()
+    if bpp <= 0 or bpp > 4:
+        raise ValueError, "unsupported bit depth for surface array"
+
+    shape = array.shape
+    if shape[-1] != 3:
+        raise ValueError, "array must be a 3d array of 3-value color data"
+
+    shifts = surface.get_shifts ()
+    losses = surface.get_losses ()
+    array = (array[:,:,::3] >> losses[0] << shifts[0]) | \
+            (array[:,:,1::3] >> losses[1] << shifts[1]) | \
+            (array[:,:,2::3] >> losses[2] << shifts[2])
+    return array
 
 #headers to install
 headers = glob.glob(os.path.join('src', '*.h'))
-
+headers.remove (os.path.join ('src', 'numeric_arrayobject.h'))
 
 #sanity check for any arguments
 if len(sys.argv) == 1:

src/numeric_arrayobject.h

+/*
+ * Imported Numeric-24.2 numeric/arrayobject.h header file to make the
+ * Numeric dependency obsolete.
+ */
+
+/* 
+ * Legal Notice
+ *
+ * *** Legal Notice for all LLNL-contributed files *** 
+ *
+ * Copyright (c) 1996. The Regents of the University of California. All
+ * rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose without fee is hereby granted, provided that this entire
+ * notice is included in all copies of any software which is or includes
+ * a copy or modification of this software and in all copies of the
+ * supporting documentation for such software.
+ *
+ * This work was produced at the University of California, Lawrence
+ * Livermore National Laboratory under contract no. W-7405-ENG-48
+ * between the U.S. Department of Energy and The Regents of the
+ * University of California for the operation of UC LLNL.
+ *
+ * DISCLAIMER 
+ *
+ * This software was prepared as an account of work sponsored by an
+ * agency of the United States Government. Neither the United States
+ * Government nor the University of California nor any of their
+ * employees, makes any warranty, express or implied, or assumes any
+ * liability or responsibility for the accuracy, completeness, or
+ * usefulness of any information, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe
+ * privately-owned rights. Reference herein to any specific commercial
+ * products, process, or service by trade name, trademark, manufacturer,
+ * or otherwise, does not necessarily constitute or imply its
+ * endorsement, recommendation, or favoring by the United States
+ * Government or the University of California. The views and opinions of
+ * authors expressed herein do not necessarily state or reflect those of
+ * the United States Government or the University of California, and
+ * shall not be used for advertising or product endorsement purposes.
+ */
+
+#ifndef Py_ARRAYOBJECT_H
+#define Py_ARRAYOBJECT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
+#define MAX_ELSIZE 16
+
+#define PyArray_UNSIGNED_TYPES
+
+enum PyArray_TYPES {    PyArray_CHAR, PyArray_UBYTE, PyArray_SBYTE,
+		        PyArray_SHORT, PyArray_USHORT,
+		        PyArray_INT, PyArray_UINT,
+			PyArray_LONG,
+			PyArray_FLOAT, PyArray_DOUBLE,
+			PyArray_CFLOAT, PyArray_CDOUBLE,
+			PyArray_OBJECT,
+			PyArray_NTYPES, PyArray_NOTYPE};
+
+typedef void (PyArray_VectorUnaryFunc) (char *, int, char *, int, int);
+
+typedef PyObject * (PyArray_GetItemFunc) (char *);
+typedef int (PyArray_SetItemFunc) (PyObject *, char *);
+
+typedef struct {
+  PyArray_VectorUnaryFunc *cast[PyArray_NTYPES]; /* Functions to cast to */
+					           /* all other types */
+  PyArray_GetItemFunc *getitem;
+  PyArray_SetItemFunc *setitem;
+
+  int type_num, elsize;
+  char *one, *zero;
+  char type;
+
+} PyArray_Descr;
+
+/* Array flags */
+#define CONTIGUOUS 1
+#define OWN_DIMENSIONS 2
+#define OWN_STRIDES 4
+#define OWN_DATA 8
+#define SAVESPACE 16
+
+/* type bit */
+#define SAVESPACEBIT 128
+
+typedef struct {
+  PyObject_HEAD
+  char *data;
+  int nd;
+  int *dimensions, *strides;
+  PyObject *base;
+  PyArray_Descr *descr;
+  int flags;
+  PyObject *weakreflist;
+} PyArrayObject;
+
+/* Array Interface flags */
+#define FORTRAN       0x002
+#define ALIGNED       0x100
+#define NOTSWAPPED    0x200
+#define WRITEABLE     0x400
+
+typedef struct {
+  int version;
+  int nd;
+  char typekind;
+  int itemsize;
+  int flags;
+  Py_intptr_t *shape;
+  Py_intptr_t *strides;
+  void *data;
+} PyArrayInterface;
+
+
+/*
+ * C API
+ */
+
+/* Type definitions */
+
+#define PyArray_Type_NUM 0
+
+/* Function definitions */
+
+/* The following are not intended for use in user code, only needed by umath. */
+/* If you write your own match library, you might want this function. */
+#define PyArray_SetNumericOps_RET int
+#define PyArray_SetNumericOps_PROTO (PyObject *)
+#define PyArray_SetNumericOps_NUM 1
+
+#define PyArray_INCREF_RET int
+#define PyArray_INCREF_PROTO (PyArrayObject *ap)
+#define PyArray_INCREF_NUM 2
+
+#define PyArray_XDECREF_RET int
+#define PyArray_XDECREF_PROTO (PyArrayObject *ap)
+#define PyArray_XDECREF_NUM 3
+
+/* Export the array error object.  Is this a good idea?  */
+#define PyArrayError_RET PyObject *
+#define PyArrayError_PROTO (void)
+#define PyArrayError_NUM 4
+
+/* Set the array print function to be a python function */
+#define PyArray_SetStringFunction_RET void
+#define PyArray_SetStringFunction_PROTO (PyObject *op, int repr)
+#define PyArray_SetStringFunction_NUM 5
+
+/* Get the PyArray_Descr structure for a typecode */
+#define PyArray_DescrFromType_RET PyArray_Descr *
+#define PyArray_DescrFromType_PROTO (int)
+#define PyArray_DescrFromType_NUM 6
+
+/* Cast an array to a different type */
+#define PyArray_Cast_RET PyObject *
+#define PyArray_Cast_PROTO (PyArrayObject *, int)
+#define PyArray_Cast_NUM 7
+
+/* Check the type coercion rules */
+#define PyArray_CanCastSafely_RET int
+#define PyArray_CanCastSafely_PROTO (int fromtype, int totype)
+#define PyArray_CanCastSafely_NUM 8
+
+/* Return the typecode to use for an object if it was an array */
+#define PyArray_ObjectType_RET int
+#define PyArray_ObjectType_PROTO (PyObject *, int)
+#define PyArray_ObjectType_NUM 9
+
+#define _PyArray_multiply_list_RET int
+#define _PyArray_multiply_list_PROTO (int *lp, int n)
+#define _PyArray_multiply_list_NUM 10
+
+
+/* The following defines the C API for the array object for most users */
+
+#define PyArray_SIZE(mp) (_PyArray_multiply_list((mp)->dimensions, (mp)->nd))
+#define PyArray_NBYTES(mp) ((mp)->descr->elsize * PyArray_SIZE(mp))
+/* Obviously this needs some work. */
+#define PyArray_ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)
+#define PyArray_ISSPACESAVER(m) (((PyArrayObject *)m)->flags & SAVESPACE)
+#define PyScalarArray_Check(m) (PyArray_Check((m)) && (((PyArrayObject *)(m))->nd == 0))
+
+/* Return the size in number of items of an array */
+#define PyArray_Size_RET int
+#define PyArray_Size_PROTO (PyObject *)
+#define PyArray_Size_NUM 11
+
+
+/* Array creation functions */
+/* new_array = PyArray_FromDims(n_dimensions, dimensions[n_dimensions], item_type); */
+#define PyArray_FromDims_RET PyObject *
+#define PyArray_FromDims_PROTO (int, int *, int)
+#define PyArray_FromDims_NUM 12
+
+/* array_from_existing_data = PyArray_FromDimsAndData(n_dims, dims[n_dims], item_type, old_data); */
+/* WARNING: using PyArray_FromDimsAndData is not reccommended!  It should only be used to refer to */
+/* global arrays that will never be freed (like FORTRAN common blocks). */
+#define PyArray_FromDimsAndData_RET PyObject *
+#define PyArray_FromDimsAndData_PROTO (int, int *, int, char *)
+#define PyArray_FromDimsAndData_NUM 13
+
+/* Initialize from a python object. */
+
+/* PyArray_ContiguousFromObject(object, typecode, min_dimensions, max_dimensions) */
+/* if max_dimensions = 0, then any number of dimensions are allowed. */
+/* If you want an exact number of dimensions, you should use max_dimensions */
+/* = min_dimensions. */
+
+#define PyArray_ContiguousFromObject_RET PyObject *
+#define PyArray_ContiguousFromObject_PROTO (PyObject *, int, int, int)
+#define PyArray_ContiguousFromObject_NUM 14
+
+/* Same as contiguous, except guarantees a copy of the original data */
+#define PyArray_CopyFromObject_RET PyObject *
+#define PyArray_CopyFromObject_PROTO (PyObject *, int, int, int)
+#define PyArray_CopyFromObject_NUM 15
+
+/* Shouldn't be used unless you know what you're doing and are not scared by discontiguous arrays */
+#define PyArray_FromObject_RET PyObject *
+#define PyArray_FromObject_PROTO (PyObject *, int, int, int)
+#define PyArray_FromObject_NUM 16
+
+/* Return either an array, or if passed a 0d array return the appropriate python scalar */
+#define PyArray_Return_RET PyObject *
+#define PyArray_Return_PROTO (PyArrayObject *)
+#define PyArray_Return_NUM 17
+
+#define PyArray_Reshape_RET PyObject *
+#define PyArray_Reshape_PROTO (PyArrayObject *ap, PyObject *shape)
+#define PyArray_Reshape_NUM 18
+
+#define PyArray_Copy_RET PyObject *
+#define PyArray_Copy_PROTO (PyArrayObject *ap)
+#define PyArray_Copy_NUM 19
+
+#define PyArray_Take_RET PyObject *
+#define PyArray_Take_PROTO (PyObject *ap, PyObject *items, int axis)
+#define PyArray_Take_NUM 20
+
+/*Getting arrays in various useful forms. */
+#define PyArray_As1D_RET int
+#define PyArray_As1D_PROTO (PyObject **op, char **ptr, int *d1, int typecode)
+#define PyArray_As1D_NUM 21
+
+#define PyArray_As2D_RET int
+#define PyArray_As2D_PROTO (PyObject **op, char ***ptr, int *d1, int *d2, int typecode)
+#define PyArray_As2D_NUM 22
+
+#define PyArray_Free_RET int
+#define PyArray_Free_PROTO (PyObject *op, char *ptr)
+#define PyArray_Free_NUM 23
+
+/* array_from_existing_data = PyArray_FromDimsAndDataAndDescr(n_dims, dims[n_dims], descr, old_data); */
+/* WARNING: using PyArray_FromDimsAndDataAndDescr is not reccommended!  It should only be used to refer to */
+/* global arrays that will never be freed (like FORTRAN common blocks). */
+#define PyArray_FromDimsAndDataAndDescr_RET PyObject *
+#define PyArray_FromDimsAndDataAndDescr_PROTO (int, int *, PyArray_Descr *, char *)
+#define PyArray_FromDimsAndDataAndDescr_NUM 24
+
+#define PyArray_Converter_RET int
+#define PyArray_Converter_PROTO (PyObject *, PyObject **)
+#define PyArray_Converter_NUM 25
+
+#define PyArray_Put_RET PyObject *
+#define PyArray_Put_PROTO (PyObject *ap, PyObject *items, PyObject* values)
+#define PyArray_Put_NUM 26
+
+#define PyArray_PutMask_RET PyObject *
+#define PyArray_PutMask_PROTO (PyObject *ap, PyObject *mask, PyObject* values)
+#define PyArray_PutMask_NUM 27
+
+#define PyArray_CopyArray_RET int
+#define PyArray_CopyArray_PROTO (PyArrayObject *dest, PyArrayObject *src)
+#define PyArray_CopyArray_NUM 28
+
+#define PyArray_ValidType_RET int
+#define PyArray_ValidType_PROTO (int type)
+#define PyArray_ValidType_NUM 29
+
+/* Convert a Python object to a C int, if possible. Checks for
+   potential overflow, which is important on machines where
+   sizeof(int) != sizeof(long) (note that a Python int is a C long).
+   Handles Python ints, Python longs, and any ArrayObject that
+   works in int(). */
+#define PyArray_IntegerAsInt_RET int
+#define PyArray_IntegerAsInt_PROTO (PyObject *o)
+#define PyArray_IntegerAsInt_NUM 30
+
+/* Total number of C API pointers */
+#define PyArray_API_pointers 31
+
+
+#ifdef _ARRAY_MODULE
+
+extern PyTypeObject PyArray_Type;
+#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type)
+
+extern PyArray_SetNumericOps_RET PyArray_SetNumericOps \
+       PyArray_SetNumericOps_PROTO;
+extern PyArray_INCREF_RET PyArray_INCREF PyArray_INCREF_PROTO;
+extern PyArray_XDECREF_RET PyArray_XDECREF PyArray_XDECREF_PROTO;
+extern PyArrayError_RET PyArrayError PyArrayError_PROTO;
+extern PyArray_SetStringFunction_RET PyArray_SetStringFunction \
+       PyArray_SetStringFunction_PROTO;
+extern PyArray_DescrFromType_RET PyArray_DescrFromType \
+       PyArray_DescrFromType_PROTO;
+extern PyArray_Cast_RET PyArray_Cast PyArray_Cast_PROTO;
+extern PyArray_CanCastSafely_RET PyArray_CanCastSafely \
+       PyArray_CanCastSafely_PROTO;
+extern PyArray_ObjectType_RET PyArray_ObjectType PyArray_ObjectType_PROTO;
+extern _PyArray_multiply_list_RET _PyArray_multiply_list \
+       _PyArray_multiply_list_PROTO;
+extern PyArray_Size_RET PyArray_Size PyArray_Size_PROTO;
+extern PyArray_FromDims_RET PyArray_FromDims PyArray_FromDims_PROTO;
+extern PyArray_FromDimsAndData_RET PyArray_FromDimsAndData \
+       PyArray_FromDimsAndData_PROTO;
+extern PyArray_FromDimsAndDataAndDescr_RET PyArray_FromDimsAndDataAndDescr \
+       PyArray_FromDimsAndDataAndDescr_PROTO;
+extern PyArray_ContiguousFromObject_RET PyArray_ContiguousFromObject \
+       PyArray_ContiguousFromObject_PROTO;
+extern PyArray_CopyFromObject_RET PyArray_CopyFromObject \
+       PyArray_CopyFromObject_PROTO;
+extern PyArray_FromObject_RET PyArray_FromObject PyArray_FromObject_PROTO;
+extern PyArray_Return_RET PyArray_Return PyArray_Return_PROTO;
+extern PyArray_Reshape_RET PyArray_Reshape PyArray_Reshape_PROTO;
+extern PyArray_Copy_RET PyArray_Copy PyArray_Copy_PROTO;
+extern PyArray_Take_RET PyArray_Take PyArray_Take_PROTO;
+extern PyArray_As1D_RET PyArray_As1D PyArray_As1D_PROTO;
+extern PyArray_As2D_RET PyArray_As2D PyArray_As2D_PROTO;
+extern PyArray_Free_RET PyArray_Free PyArray_Free_PROTO;
+extern PyArray_Converter_RET PyArray_Converter PyArray_Converter_PROTO;
+extern PyArray_Put_RET PyArray_Put PyArray_Put_PROTO;
+extern PyArray_PutMask_RET PyArray_PutMask PyArray_PutMask_PROTO;
+extern PyArray_CopyArray_RET PyArray_CopyArray PyArray_CopyArray_PROTO;
+extern PyArray_ValidType_RET PyArray_ValidType PyArray_ValidType_PROTO;
+extern PyArray_IntegerAsInt_RET PyArray_IntegerAsInt PyArray_IntegerAsInt_PROTO;
+
+#else
+
+#if defined(PY_ARRAY_UNIQUE_SYMBOL)
+#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL
+#endif
+
+/* C API address pointer */
+#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
+extern void **PyArray_API;
+#else
+#if defined(PY_ARRAY_UNIQUE_SYMBOL)
+void **PyArray_API;
+#else
+static void **PyArray_API;
+#endif
+#endif
+
+#define PyArray_Check(op) \
+   ((op)->ob_type == (PyTypeObject *)PyArray_API[PyArray_Type_NUM])
+#define PyArray_Type *(PyTypeObject *)PyArray_API[PyArray_Type_NUM]
+
+#define PyArray_SetNumericOps \
+  (*(PyArray_SetNumericOps_RET (*)PyArray_SetNumericOps_PROTO) \
+   PyArray_API[PyArray_SetNumericOps_NUM])
+#define PyArray_INCREF \
+  (*(PyArray_INCREF_RET (*)PyArray_INCREF_PROTO) \
+   PyArray_API[PyArray_INCREF_NUM])
+#define PyArray_XDECREF \
+  (*(PyArray_XDECREF_RET (*)PyArray_XDECREF_PROTO) \
+   PyArray_API[PyArray_XDECREF_NUM])
+#define PyArrayError \
+  (*(PyArrayError_RET (*)PyArrayError_PROTO) \
+   PyArray_API[PyArrayError_NUM])
+#define PyArray_SetStringFunction \
+  (*(PyArray_SetStringFunction_RET (*)PyArray_SetStringFunction_PROTO) \
+   PyArray_API[PyArray_SetStringFunction_NUM])
+#define PyArray_DescrFromType \
+  (*(PyArray_DescrFromType_RET (*)PyArray_DescrFromType_PROTO) \
+   PyArray_API[PyArray_DescrFromType_NUM])
+#define PyArray_Cast \
+  (*(PyArray_Cast_RET (*)PyArray_Cast_PROTO) \
+   PyArray_API[PyArray_Cast_NUM])
+#define PyArray_CanCastSafely \
+  (*(PyArray_CanCastSafely_RET (*)PyArray_CanCastSafely_PROTO) \
+   PyArray_API[PyArray_CanCastSafely_NUM])
+#define PyArray_ObjectType \
+  (*(PyArray_ObjectType_RET (*)PyArray_ObjectType_PROTO) \
+   PyArray_API[PyArray_ObjectType_NUM])
+#define _PyArray_multiply_list \
+  (*(_PyArray_multiply_list_RET (*)_PyArray_multiply_list_PROTO) \
+   PyArray_API[_PyArray_multiply_list_NUM])
+#define PyArray_Size \
+  (*(PyArray_Size_RET (*)PyArray_Size_PROTO) \
+   PyArray_API[PyArray_Size_NUM])
+#define PyArray_FromDims \
+  (*(PyArray_FromDims_RET (*)PyArray_FromDims_PROTO) \
+   PyArray_API[PyArray_FromDims_NUM])
+#define PyArray_FromDimsAndData \
+  (*(PyArray_FromDimsAndData_RET (*)PyArray_FromDimsAndData_PROTO) \
+   PyArray_API[PyArray_FromDimsAndData_NUM])
+#define PyArray_FromDimsAndDataAndDescr \
+  (*(PyArray_FromDimsAndDataAndDescr_RET (*)PyArray_FromDimsAndDataAndDescr_PROTO) \
+   PyArray_API[PyArray_FromDimsAndDataAndDescr_NUM])
+#define PyArray_ContiguousFromObject \
+  (*(PyArray_ContiguousFromObject_RET (*)PyArray_ContiguousFromObject_PROTO) \
+   PyArray_API[PyArray_ContiguousFromObject_NUM])
+#define PyArray_CopyFromObject \
+  (*(PyArray_CopyFromObject_RET (*)PyArray_CopyFromObject_PROTO) \
+   PyArray_API[PyArray_CopyFromObject_NUM])
+#define PyArray_FromObject \
+  (*(PyArray_FromObject_RET (*)PyArray_FromObject_PROTO) \
+   PyArray_API[PyArray_FromObject_NUM])
+#define PyArray_Return \
+  (*(PyArray_Return_RET (*)PyArray_Return_PROTO) \
+   PyArray_API[PyArray_Return_NUM])
+#define PyArray_Reshape \
+  (*(PyArray_Reshape_RET (*)PyArray_Reshape_PROTO) \
+   PyArray_API[PyArray_Reshape_NUM])
+#define PyArray_Copy \
+  (*(PyArray_Copy_RET (*)PyArray_Copy_PROTO) \
+   PyArray_API[PyArray_Copy_NUM])
+#define PyArray_Take \
+  (*(PyArray_Take_RET (*)PyArray_Take_PROTO) \
+   PyArray_API[PyArray_Take_NUM])
+#define PyArray_As1D \
+  (*(PyArray_As1D_RET (*)PyArray_As1D_PROTO) \
+   PyArray_API[PyArray_As1D_NUM])
+#define PyArray_As2D \
+  (*(PyArray_As2D_RET (*)PyArray_As2D_PROTO) \
+   PyArray_API[PyArray_As2D_NUM])
+#define PyArray_Free \
+  (*(PyArray_Free_RET (*)PyArray_Free_PROTO) \
+   PyArray_API[PyArray_Free_NUM])
+#define PyArray_Converter \
+  (*(PyArray_Converter_RET (*)PyArray_Converter_PROTO) \
+   PyArray_API[PyArray_Converter_NUM])
+#define PyArray_Put \
+  (*(PyArray_Put_RET (*)PyArray_Put_PROTO) \
+   PyArray_API[PyArray_Put_NUM])
+#define PyArray_PutMask \
+  (*(PyArray_PutMask_RET (*)PyArray_PutMask_PROTO) \
+   PyArray_API[PyArray_PutMask_NUM])
+#define PyArray_CopyArray \
+  (*(PyArray_CopyArray_RET (*)PyArray_CopyArray_PROTO) \
+   PyArray_API[PyArray_CopyArray_NUM])
+#define PyArray_ValidType \
+  (*(PyArray_ValidType_RET (*)PyArray_ValidType_PROTO) \
+   PyArray_API[PyArray_ValidType_NUM])
+#define PyArray_IntegerAsInt \
+  (*(PyArray_IntegerAsInt_RET (*)PyArray_IntegerAsInt_PROTO) \
+   PyArray_API[PyArray_IntegerAsInt_NUM])
+
+#define import_array() \
+{ \
+  PyObject *numpy = PyImport_ImportModule("_numpy"); \
+  if (numpy != NULL) { \
+    PyObject *module_dict = PyModule_GetDict(numpy); \
+    PyObject *c_api_object = PyDict_GetItemString(module_dict, "_ARRAY_API"); \
+    if (PyCObject_Check(c_api_object)) { \
+      PyArray_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
+    } \
+  } \
+}
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_ARRAYOBJECT_H */
 
 #include "pygame.h"
 #include "pygamedocs.h"
-#include"mixer.h"
-#include<Numeric/arrayobject.h>
-#include<SDL_byteorder.h>
+#include "mixer.h"
+#include "numeric_arrayobject.h"
+#include <SDL_byteorder.h>
 
 static PyObject*
 sndarray_samples (PyObject* self, PyObject* arg)
   pete@shinners.org
 */
 
-#include"pygame.h"
+#include "pygame.h"
 #include "pygamedocs.h"
-#include<Numeric/arrayobject.h>
-#include<SDL_byteorder.h>
+#include "numeric_arrayobject.h"
+#include <SDL_byteorder.h>
 
 static PyObject*
 pixels3d (PyObject* self, PyObject* arg)