Commits

Anonymous committed 45d74d6

Fixed surfarray.make_surface() and surfarray.blit_array() bugs as reported by Lenard Lindstrom.

Comments (0)

Files changed (2)

lib/_numpysurfarray.py

     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 ()
+    if bpp <= 0 or bpp > 4:
+        raise ValueError, "unsupported bit depth for surface"
+    
     shape = array.shape
     width = surface.get_width ()
 
+    typecode = (numpy.uint8, numpy.uint16, None, numpy.uint32)[bpp - 1]
+    array = array.astype (typecode)
+
+    # Taken from from Alex Holkner's pygame-ctypes package. Thanks a
+    # lot.
     if len(shape) == 3 and shape[2] == 3:
         array = numpy.transpose (array, (1, 0, 2))
         shifts = surface.get_shifts ()
     array. The array can be 2D or 3D with any sized integer values.
     """ 
     if __arraytype == "numeric":
-        return numericsf.make_surface (surface)
+        return numericsf.make_surface (array)
     elif __arraytype == "numpy":
-        return numpysf.make_surface (surface)
+        return numpysf.make_surface (array)
     raise NotImplementedError, "surface arrays are not supported"
 
 def blit_array (surface, array):