Commits

Anonymous committed 28f54fd

pygame.Surface.get_at and set_at for 24-bit surfaces

Comments (0)

Files changed (3)

  - pygame.mouse.set_pos accepts a tuple argument
  - pygame.surfarray.array_colorkey mask was inverted; fixed
  - pygame.Surface.set_clip with negative-sized rects.
+ - pygame.Surface.set_at and .get_at for 24-bit surfaces.  Largely untested.
 
 Pygame-ctypes 0.09
 ------------------
 default icon and font in py2exe
 lots of problems in Phil's Zanthor
 segfault in mixer, example in Phil's rustic
+kill audio thread on exit (example in 20k LYIS)

pygame/surface.py

             raise pygame.base.error, 'pixel index out of range'
 
         format = surf.format
-        pitch = surf.pitch / format.BytesPerPixel
-
+        pitch = surf.pitch
         self.lock()
-        color = surf.pixels[y * pitch + x]
+        if format.BytesPerPixel != 3:
+            pitch = surf.pitch / format.BytesPerPixel
+            color = surf.pixels[y * pitch + x]
+        else:
+            color = surf.pixels[y * surf.pitch + x * 3] | \
+                    surf.pixels[y * surf.pitch + x * 3 + 1] << 8 | \
+                    surf.pixels[y * surf.pitch + x * 3 + 2] << 16
+            color = SDL_SwapLE32(color) #XXX untested on big endian
         self.unlock()
 
         return SDL_GetRGBA(color, format)
         if type(color) not in (int, long):
             raise 'invalid color argument'
 
-        pitch = surf.pitch / format.BytesPerPixel
-
         self.lock()
-        self._surf.pixels[y * pitch + x] = color
+        if format.BytesPerPixel != 3:
+            pitch = surf.pitch / format.BytesPerPixel
+            self._surf.pixels[y * pitch + x] = color
+        else:
+            # XXX untested
+            color = SDL_SwapLE32(color)
+            self._surf.pixels[y * pitch + x * 3:y * pitch + x * 3 + 3] = \
+                color & 0xff, (color >> 8) & 0xff, (color >> 16) & 0xff
         self.unlock()
 
     def get_palette(self):