[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
BUG Re: [pygame] Exception in _numpysurfarray.py
- To: pygame-users@xxxxxxxx
- Subject: BUG Re: [pygame] Exception in _numpysurfarray.py
- From: "René Dudfield" <renesd@xxxxxxxxx>
- Date: Thu, 10 Apr 2008 09:42:26 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Wed, 09 Apr 2008 19:42:31 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=Q/0Tro/sWisy1JJKz/ClOEZHXpaA60LSEfb0G87eq6Q=; b=TNXFSFeszuOgqw6DCmt1eT7Il82D+fEiLKdyYJmVsBfo2KrP7NrMF9ofu8PMf+VRD/X49k90LyONy2dGckchKa1u7UdUEXWJhKXoqOQX1F4O3mUtYfY5qrthpyEq2sf85e8GmCuHb0Gx6wEjeRRsv6M74o08dKS9YshPYQxzR7k=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=EVyv4gA6yMcUrT7lpqojP1LFAsKRROclIgUU0iAmJMGvdoFv2XL0zRGBxmbGWYyBaFy+/sYZNg1zj/eWh7HMSl54XR4ZhyEDFsEwh10zc5jp8MeKLeJO2QS4D/kNtA9YwVqRfuw8w6KBhbquJDVp1Frn1QMgHowvunXMQ+3TT+I=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Thanks Lorenz. Your patch does look correct.
What do you think Marcus?
cheers,
On Thu, Apr 10, 2008 at 6:35 AM, Lorenz Quack <don@xxxxxxxxxxxxxxxxx> wrote:
> Hi all,
>
> a friend of mine had a problem using pygame.surarray.pixels3d
> creation would raise the following Exception:
>
> File "C:\Python25\lib\site-packages\pygame\surfarray.py", line 165, in
> pixels3d
> return numpysf.pixels3d (surface)
> File "C:\Python25\lib\site-packages\pygame\_numpysurfarray.py", line 213,
> in pixels3d
> array.shape = surface.get_width (), surface.get_height (), bpp
> AttributeError: incompatible shape for a non-contiguous array
>
> here is the code section in question from the _numpysurfarray.py:
>
> array = numpy.frombuffer (surface.get_buffer (), numpy.uint8)
> array.shape = surface.get_height (), surface.get_pitch ()
> # I believe this line make the array in some cases non-contiguous
> array = array[:,:surface.get_width () * bpp]
> # the next line raises the exception
> array.shape = surface.get_width (), surface.get_height (), bpp
> array = array[:,:,start:end:step]
> return array
>
> My analysis was that the line before makes the array non-contiguous and
> thus the direct assignment of the shape attribute fails. reshape copies the
> data to a new array if necessary. I might be wrong since I never had this
> problem myself (it might be due to the fact that I'm on Linux while my
> friend is using MS Windows).
>
> I attached a patch that uses reshape instead of the direct assignment.
> I left all the other places where array.shape is assigned untouched because
> they are mostly directly after the arrays creation and should therefor
> always be contiguous.
>
> Please can someone (with more numpy experience than myself) look at this?
>
> yours
> //Lorenz
>
> --- _numpysurfarray.py 2008-04-06 13:47:47.000000000 +0200
> +++ _numpysurfarray_patched.py 2008-04-09 20:37:00.000000000 +0200
> @@ -210,7 +210,7 @@
> array = numpy.frombuffer (surface.get_buffer (), numpy.uint8)
> array.shape = surface.get_height (), surface.get_pitch ()
> array = array[:,:surface.get_width () * bpp]
> - array.shape = surface.get_width (), surface.get_height (), bpp
> + array = numpy.reshape(array, (surface.get_width (), surface.get_height
> (), bpp))
> array = array[:,:,start:end:step]
> return array
>
>
>