Commits

Anonymous committed c462779

Merged with trunk revision 2262

Comments (0)

Files changed (9)

 # BUG    = fixed a bug that was (or could have been) crashing
 #
 #
+
+[SVN 2259] May 26, 2009
+    [BUG] surflock.c PySurface_LockBy was leaking weakrefs.
+    Thanks Tom Rothamel for the patch!
+
 [SVN 2118] May 12, 2009
     [BUG] Fixed bug in font.c where pygame.font.Font returned the wrong
     exception type and message when a font file was not found.
                  "Buffer length does not equal format and resolution size");
         surf = SDL_CreateRGBSurfaceFrom (data, w, h, 24, w * 3,
                                          0xFF, 0xFF<<8, 0xFF<<16, 0);
+/*
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+                                         0xFF, 0xFF<<8, 0xFF<<16, 0xFF<<24
+#else
+                                         0xFF<<24, 0xFF<<16, 0xFF<<8, 0xFF
+#endif
+               );
+
+*/
+
+
     }
     else if (!strcmp (format, "RGBA") || !strcmp (format, "RGBX"))
     {
     return (PyObject*)maskobj;
 }
 
-void bitmask_threshold (bitmask_t *m, SDL_Surface *surf, SDL_Surface *surf2,
-                        Uint32 color,  Uint32 threshold)
+
+/*
+
+palette_colors - this only affects surfaces with a palette 
+    if true we look at the colors from the palette, 
+    otherwise we threshold the pixel values.  This is useful if 
+    the surface is actually greyscale colors, and not palette colors.
+
+*/
+
+void bitmask_threshold (bitmask_t *m, 
+                        SDL_Surface *surf, 
+                        SDL_Surface *surf2,
+                        Uint32 color,  
+                        Uint32 threshold,
+                        int palette_colors)
 {
     int x, y, rshift, gshift, bshift, rshift2, gshift2, bshift2;
     int rloss, gloss, bloss, rloss2, gloss2, bloss2;
                         pixels2 += 4;
                         break;
                 }
-                if ((abs((((the_color2 & rmask2) >> rshift2) << rloss2) - (((the_color & rmask) >> rshift) << rloss)) < tr) &
+                /* TODO: will need to handle surfaces with palette colors.
+                */
+                if((bpp2 == 1) && (bpp1 == 1) && (!palette_colors)) {
+                    /* Don't look at the color of the surface, just use the
+                       value. This is useful for 8bit images that aren't
+                       actually using the palette.
+                    */
+                    if (  (abs( (the_color2) - (the_color)) < tr )  ) {
+                        
+                        /* this pixel is within the threshold of othersurface. */
+                        bitmask_setbit(m, x, y);
+                    }
+                    
+                } else if ((abs((((the_color2 & rmask2) >> rshift2) << rloss2) - (((the_color & rmask) >> rshift) << rloss)) < tr) &
                     (abs((((the_color2 & gmask2) >> gshift2) << gloss2) - (((the_color & gmask) >> gshift) << gloss)) < tg) &
                     (abs((((the_color2 & bmask2) >> bshift2) << bloss2) - (((the_color & bmask) >> bshift) << bloss)) < tb)) {
                     /* this pixel is within the threshold of othersurface. */
                     bitmask_setbit(m, x, y);
                 }
+
+            /* TODO: will need to handle surfaces with palette colors.
+               TODO: will need to handle the case where palette_colors == 0
+            */
+
             } else if ((abs((((the_color & rmask) >> rshift) << rloss) - r) < tr) &
                        (abs((((the_color & gmask) >> gshift) << gloss) - g) < tg) &
                        (abs((((the_color & bmask) >> bshift) << bloss) - b) < tb)) {
     Uint8 rgba_threshold[4] = {0, 0, 0, 255};
     Uint32 color;
     Uint32 color_threshold;
+    int palette_colors = 1;
 
-    if (!PyArg_ParseTuple (args, "O!O|OO!", &PySurface_Type, &surfobj,
+
+    if (!PyArg_ParseTuple (args, "O!O|OO!i", &PySurface_Type, &surfobj,
                            &rgba_obj_color,  &rgba_obj_threshold,
-                           &PySurface_Type, &surfobj2))
+                           &PySurface_Type, &surfobj2, &palette_colors))
         return NULL;
 
     surf = PySurface_AsSurface (surfobj);
     }
 
     Py_BEGIN_ALLOW_THREADS;
-    bitmask_threshold (m, surf, surf2, color,  color_threshold);
+    bitmask_threshold (m, surf, surf2, color, color_threshold, palette_colors);
     Py_END_ALLOW_THREADS;
 
     PySurface_Unlock(surfobj);
 
 from_threshold
 Creates a mask by thresholding Surfaces
-pygame.mask.from_surface(Surface, color, threshold = (0,0,0,255), othersurface = None) -> Mask
+pygame.mask.from_surface(Surface, color, threshold = (0,0,0,255), othersurface = None, palette_colors = 1) -> Mask
 
 This is a more featureful method of getting a Mask from a Surface.  If supplied
 with only one Surface, all pixels within the threshold of the supplied color are
         return 0;
     }
     PyList_Append (surf->locklist, ref);
+    Py_DECREF (ref);
 
     if (surf->subsurface)
         PySurface_Prep (surfobj);
                                         (Uint8) (*(the_idx) * div_inv + .5f),
                                         (Uint8) (*(the_idx + 1) * div_inv + .5f),
                                         (Uint8) (*(the_idx + 2) * div_inv + .5f));
-                
+
+                /* TODO: should it take into consideration the output
+                    shifts/masks/losses?  Or does SDL_MapRGB do that correctly?
+
+                    *(the_idx) += ((the_color & rmask) >> rshift) << rloss;
+                    *(the_idx + 1) += ((the_color & gmask) >> gshift) << gloss;
+                    *(the_idx + 2) += ((the_color & bmask) >> bshift) << bloss;
+                */
+
                 SURF_SET_AT(the_color, destsurf, x, y, destpixels, destformat, byte_buf);
                 
                 the_idx += 3;

test/font_test.py

     def test_get_default_font(self):
         self.failUnlessEqual(pygame.font.get_default_font(), 'freesansbold.ttf')
 
-    def test_get_fonts(self):
+    def Xtest_get_fonts(self):
         fnts = pygame.font.get_fonts()
         self.failUnless(fnts)
         for name in fnts:
     def test_init(self):
         pygame.font.init()
 
-    def test_match_font(self):
+    def Xtest_match_font(self):
         fonts = pygame.font.get_fonts()
 
         # Ensure all listed fonts are in fact available, and the returned file

test/midi_tags.py

+__tags__ = ['interactive']

test/transform_test.py

         self.assertEqual( sr.get_flags(), s1.get_flags() )
         self.assertEqual( sr.get_losses(), s1.get_losses() )
 
-        #print ( sr.get_masks(), s1.get_masks() )
-        #print ( sr.get_flags(), s1.get_flags() )
-        #print ( sr.get_losses(), s1.get_losses() )
+        if 0:
+            print ( sr, s1 )
+            print ( sr.get_masks(), s1.get_masks() )
+            print ( sr.get_flags(), s1.get_flags() )
+            print ( sr.get_losses(), s1.get_losses() )
+            print ( sr.get_shifts(), s1.get_shifts() )
 
         self.assertEqual(sr.get_at((0,0)), (10,53,50,255))