Commits

Anonymous committed cb69c3c

Multiple fixes for Phil's games.

Comments (0)

Files changed (10)

  - Performance of simple (non error-checking) SDL/pygame functions improved
  - Software blitting BGR surfaces corrected.
  - Ignore error if default icon not found.
+ - Fixed blend blit to 24-bit surface
+ - Undocumented Rect.w and .h attributes added.
+ - Undocumented allow False for pygame.mixer.init arguments
+ - pygame.error thrown from pygame.music.load instead of SDL_Exception
+ - Allow comparison of Rect with None
+ - pygame.transform.rotozoom of 24-bit and 16-bit surface returns 32-bit
+   surface.
+ - pygame.Surface.set_alpha with 0 value fixed
+ - pygame.display.set_palette fixed
+ - pygame.font.Font.render blended zero-length string has alpha channel
+ - pygame.music.unpause() fixed.
 
 Pygame-ctypes 0.09
 ------------------
 mac default icon
 search libs e.g. SDL_ttf-2.0 before SDL_ttf
 24-bit don't assume RGB, could be BGR.
+default icon and font in py2exe

examples_pygame/blit_blends.py

 
 import time
         
-
 def main():
     pygame.init()
-    screen = pygame.display.set_mode((640, 480))
+    screen = pygame.display.set_mode((640, 480), 0, 16)
 
     im1= pygame.Surface(screen.get_size())
     #im1= im1.convert()

pygame/display.py

     if not palette:
         SDL_SetPalette(surf, SDL_PHYSPAL, surf.format.palette.colors, 0)
 
-    lenth = min(surf.format.palette.ncolors, len(palette))
+    length = min(surf.format.palette.ncolors, len(palette))
     colors = [SDL_Color(r, g, b) for r, g, b in palette[:length]]
     SDL_SetPalette(surf, SDL_PHYSPAL, colors, 0)
 
             # Pygame returns a 1 pixel wide surface if given empty string.
             height = TTF_FontHeight(font)
             surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, height, 32,
-                                        0x00ff0000, 0x0000ff00, 0x000000ff, 0)
+                                        SDL_SwapLE32(0x000000ff), 
+                                        SDL_SwapLE32(0x0000ff00), 
+                                        SDL_SwapLE32(0x00ff0000), 
+                                        SDL_SwapLE32(0xff000000))
             if background:
                 c = SDL_MapRGB(surf.format, background.r, background.g,
                                background.b)
 _channels = {}
 
 def __PYGAMEinit__(frequency=None, size=None, stereo=None, buffer=None):
-    if frequency is None:
+    if not frequency:
         frequency = _request_frequency
-    if size is None:
+    if not size:
         size = _request_size
-    if stereo is None:
+    if not stereo:
         stereo = _request_stereo
-    if buffer is None:
+    if not buffer:
         buffer = _request_buffer
 
     stereo = min(2, stereo)
     pygame.mixer._mixer_init_check()
 
     _free_loaded()
-    _current_music = Mix_LoadMUS(filename)
+    try:
+        _current_music = Mix_LoadMUS(filename)
+    except SDL.SDL_Exception, e:
+        raise pygame.base.error(str(e))
 
 def play(loops=0, start=0.0):
     '''Start the playback of the music stream.
     This will resume the playback of a music stream after it has been paused.
     '''    
     pygame.mixer._mixer_init_check()
-    Mix_UnpauseMusic()
+    Mix_ResumeMusic()
 
 def fadeout(time):
     '''Stop music playback after fading out.
         return '<rect(%d, %d, %d, %d)>' % \
             (self._r.x, self._r.y, self._r.w, self._r.h)
 
-    def __cmp__(self, *other):
-        other = _rect_from_object(other)
+    def __cmp__(self, other):
+        if other is None:
+            return 1
+        other = _rect_from_object((other,))
 
         if self._r.x != other._r.x:
             return cmp(self._r.x, other._r.x)
             return self._r.y + self._r.h / 2
         elif name == 'size':
             return self._r.w, self._r.h
-        elif name == 'width':
+        elif name in  ('width', 'w'):
             return self._r.w
-        elif name == 'height':
+        elif name in ('height', 'h'):
             return self._r.h
         else:
             raise AttributeError, name
             if int(value[0]) < 0 or int(value[1]) < 0:
                 self._ensure_proxy()
             self._r.w, self._r.h = int(value[0]), int(value[1])
-        elif name == 'width':
+        elif name in ('width', 'w'):
             if int(value) < 0:
                 self._ensure_proxy()
             self._r.w = int(value)
-        elif name == 'height':
+        elif name in ('height', 'h'):
             if int(value) < 0:
                 self._ensure_proxy()
             self._r.h = int(value)

pygame/surface.py

         _surface_blit(self, source, destrect, sourcerect, special_flags)
         return pygame.rect.Rect(destrect)
 
-    def convert(self, arg1=None, flags=None):
+    def convert(self, arg1=None, flags=0):
         '''Create a copy of a surface with different format
 
         Creates a new copy of the Surface with the pixel format changed. The
         if surf.flags & SDL_OPENGL:
             raise pygame.base.error, 'Cannot call on OPENGL surfaces'
 
-        if value:
+        if value is not None:
             flags |= SDL_SRCALPHA
             value = max(min(255, value), 0)
         else:
         :return: The current alpha value for the surface, or None if it
             is not set.
         '''
+        self._prep()
         surf = self._surf
+        self._unprep()
 
         if surf.flags & SDL_OPENGL:
             raise pygame.base.error, 'Cannot call on OPENGL surfaces'
         srcpitchdelta = srcpitch - w * 3
     if dst24:
         dstpitch = dst.pitch
-        dsti = dsty * dstpitch + dstx * 3
+        dsti = dstrect.y * dstpitch + dstrect.x * 3
         dstpitchdelta = dstpitch - w * 3
 
     # Both surfaces are already prepped by caller, just need to lock

pygame/transform.py

     sy = sa * surf.h * scale
     width = int(max(abs(cx + sy), abs(cx - sy), abs(-cx + sy), abs(-cx - sy)))
     height = int(max(abs(sx + cy), abs(sx - cy), abs(-sx + cy), abs(-sx - cy)))
-    newsurf = _newsurf_fromsurf(surf, width, height)
     sa /= scale
     ca /= scale
 
+    if surf.format.BytesPerPixel == 1 or surf.format.BytesPerPixel == 4:
+        newsurf = _newsurf_fromsurf(surf, width, height)
+    else:
+        newsurf = SDL_CreateRGBSurface(0, width, height, 32,
+                                       SDL_SwapLE32(0x000000ff),
+                                       SDL_SwapLE32(0x0000ff00),
+                                       SDL_SwapLE32(0x00ff0000),
+                                       SDL_SwapLE32(0xff000000))
+        if surf.flags & SDL_SRCALPHA:
+            SDL_SetAlpha(newsurf, surf.flags, surf.format.alpha)
+
     surface._prep()
     if surf.flags & SDL_SRCCOLORKEY:
         background = surf.format.colorkey
         need_data_sub = True
 
     image = _to_PIL(surf, data)
+
+    if surf.format.BytesPerPixel != 4 and surf.format.BytesPerPixel != 1:
+        image = image.convert('RGBA')
     surface._unprep()
-
     image = image.transform((width, height), Image.AFFINE,
                             (ca, -sa, -width*ca/2 + height*sa/2 + surf.w/2, 
                              sa,  ca, -width*sa/2 - height*ca/2 + surf.h/2),