[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Bug: numpyarray.pixels_alpha array not properly aligned



Marcus von Appen wrote:
On, Tue Jan 08, 2008, Lenard Lindstrom wrote:

Enclosed is a program that uses pixels_alpha to assign alpha to a surface. It displays two green rectangles, the top one using numpy, the bottom one using Numeric for reference. The center of each rectangle should have alpha 0, as is the case with the bottom rectangle, which appears as a green frame with the white background showing through. The numpy rectangle is scrambled. It would appear the array is not properly aligned with the surface's pitch. The rectangle displays correctly with image_size = (64, 64).

Thanks. It's fixed in rev. 1073. No idea, what I did there, but it was
complete rubbish :-).


The problem is that the major and minor axis of the array are reversed from those of the surface. Try replacing lines 272-276 with:

   return numpy.ndarray(buffer=surface.get_buffer (),
                        dtype=numpy.uint8,
                        shape=surface.get_size (),
                        offset=start,
                        strides=(4, surface.get_pitch ()))

The offset argument sets the relative position of the alpha byte. The strides argument makes the second argument the major axis and the first argument skip by the pixel size of 4 bytes. It works with the test case I submitted and an application I wrote that relies heavily on arrays. Hope this helps.

--
Lenard Lindstrom
<len-l@xxxxxxxxx>