On, Fri Apr 11, 2008, Lenard Lindstrom wrote:
> Lorenz Quack wrote:
[...]
>>
>> The patch may have been a bit premature:
>> The person who initially reported this problem to me tells me that with
>> this fix applying changes to the pixels3d array does not change the
>> original surface. I guess that numpy.reshape() making a copy does cause
>> problems in some cases. I'm out of ideas how to go about this...
>>
> That's peculiar.
>
> >>> import numpy
> >>> help(numpy.ndarray.reshape)
>
> Help on method_descriptor:
>
> reshape(...)
> a.reshape(d1, d2, ..., dn, order='c')
>
> Return a new array from this one. The new array must have the same
> number
> of elements as self. Also always returns a view or raises a ValueError
> if
> that is impossible.
>
>
> Unless I am mistaken a view is an array that references another array.
pydoc numpy.reshape:
Help on function reshape in numpy:
numpy.reshape = reshape(a, newshape, order='C')
Returns an array containing the data of a, but with a new shape.
[...]
*Returns*:
reshaped_array : array
This will be a new view object if possible; otherwise, it will
return a copy.
Attached you'll find the second try to get rid of this issue. Can you
please test it? It (once more) works well for me :-).
Regards
Marcus
Index: lib/_numpysurfarray.py
===================================================================
--- lib/_numpysurfarray.py (Revision 1201)
+++ lib/_numpysurfarray.py (Arbeitskopie)
@@ -207,12 +207,10 @@
start = 2
step = -1
- array = numpy.frombuffer (surface.get_buffer (), numpy.uint8)
- array.shape = surface.get_height (), surface.get_pitch ()
- array = array[:,:surface.get_width () * bpp]
- array = numpy.reshape (array, (surface.get_width (), surface.get_height (),
- bpp))
- array = array[:,:,start:end:step]
+ array = numpy.ndarray \
+ (shape=(surface.get_width (), surface.get_height (), bpp),
+ dtype=numpy.uint8, buffer=surface.get_buffer (),
+ offset=start, strides=(bpp, surface.get_pitch (),step))
return array
def array_alpha (surface):
Attachment:
pgpa7oPJ8gYGr.pgp
Description: PGP signature