Commits

Anonymous committed a15b55e

Another fix to pitch measurement in SDL.video; fix to testbitmap

Comments (0)

Files changed (2)

             if not self._pixels:
                 raise SDL.error.SDL_Exception, 'Surface needs locking'
             bpp = self.format.BitsPerPixel
-            byte_pitch = self.pitch / self.format.BytesPerPixel
+            # Can't rely on BytesPerPixel when calcaulating pitch
+            byte_pitch = self.pitch  * 8 / bpp
             count = byte_pitch * self.h
             if bpp == 1:
                 sz = c_ubyte

test/testbitmap.py

     
     # Reverse bits in each bit
     # (from http://graphics.stanford.edu/~seander/bithacks.html)
+    bytes = [((b * 0x0202020202 & 0x010884422010) % 1023) & 0xff \
+              for b in picture_bits]
+
     buffer = bitmap.pixels
-    buffer[:] = [((b * 0x0202020202 & 0x010884422010) % 1023) & 0xff \
-                 for b in picture_bits]
+    pitch = bitmap.pitch * 8 / bitmap.format.BitsPerPixel
+    for y in range(h):
+        buffer[y*pitch:y*pitch+w] = bytes[y*w:(y+1)*w]
     
     return bitmap