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

[pygame] Bug (?): Pygame 1.8 Surface.get_buffer strangeness for 24 bit pixels



Pygame 1.8 for Python 2.5 on Windows:

For a surface with 24 bit pixels, the buffer returned by the get_buffer method is not necessarily the same size as the product of the surface's width, height, and pixel byte size of 3. The attached program demonstrates. This discrepancy breaks the pixels3d function of the new numpyarray module.

--
Lenard Lindstrom
<len-l@xxxxxxxxx>

import pygame as py

py.init()
s = py.Surface((10, 10), 0, 24)
s.fill((255, 0, 0))
surface_size = s.get_width() * s.get_height() * s.get_bytesize()
buffer_size = len(buffer(s.get_buffer()))
if buffer_size == surface_size:
    print "All is right."
else:
    print ("The buffer size (%d) and surface size (%d) differ" %
           (buffer_size, surface_size))
    print len(buffer(s.get_buffer())[:])