Anonymous avatar Anonymous committed ca18d73

Fix to SDL_Surface.pixels pitch, and to pixels_ctypes

Comments (0)

Files changed (2)

             if not self._pixels:
                 raise SDL.error.SDL_Exception, 'Surface needs locking'
             bpp = self.format.BitsPerPixel
-            count = self.pitch * self.h
+            byte_pitch = self.pitch / self.format.BytesPerPixel
+            count = byte_pitch * self.h
             if bpp == 1:
                 sz = c_ubyte
-                count = (self.w * self.h + 7) / 8
+                count = (byte_pitch * self.h + 7) / 8
             elif bpp == 8:
                 sz = c_ubyte
             elif bpp == 16:

test/pixels_ctypes.py

     '''
     Draw a 3 colour gradient by setting the pixel values directly.
     '''
-    pixels = [0] * (screen.w * screen.h)
+    pixels = [0] * len(screen.pixels)
     deltaX = 255 / float(screen.w)
     deltaY = 255 / float(screen.h)
     b = 0
             pixels[i] = SDL_MapRGB(format, int(r), int(g), int(b))
             i += 1
         b += deltaY
+        i += screen.pitch / format.BytesPerPixel - screen.w
 
     SDL_LockSurface(screen)
     screen.pixels[:] = pixels
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.