Lenard Lindstrom avatar Lenard Lindstrom committed e870634

fix transform.threshold bug involving a long threshold

Comments (0)

Files changed (3)

 
 static PyObject* surf_threshold(PyObject* self, PyObject* arg)
 {
-    PyObject *surfobj, *surfobj2, *surfobj3;
-    SDL_Surface* surf, *destsurf, *surf2;
-    int bpp, change_return, inverse;
-    int num_threshold_pixels;
+    PyObject *surfobj, *surfobj2 = NULL, *surfobj3 = NULL;
+    SDL_Surface* surf = NULL, *destsurf = NULL, *surf2 = NULL;
+    int bpp, change_return = 1, inverse = 0;
+    int num_threshold_pixels = 0;
 
-
-    PyObject *rgba_obj_color, *rgba_obj_threshold, *rgba_obj_diff_color;
+    PyObject *rgba_obj_color;
+    PyObject *rgba_obj_threshold = NULL;
+    PyObject *rgba_obj_diff_color = NULL;
     Uint8 rgba_color[4];
-    Uint8 rgba_threshold[4];
-    Uint8 rgba_diff_color[4];
+    Uint8 rgba_threshold[4] = {0, 0, 0, 255};
+    Uint8 rgba_diff_color[4] = {0, 0, 0, 255};
 
     Uint32 color;
     Uint32 color_threshold;
     Uint32 color_diff_color;
 
-    surf2 = destsurf = surf = NULL;
-
-    surfobj2 = NULL;
-    surfobj3 = NULL;
-
-
-
-    /* Set some defaults */
-    rgba_obj_threshold = NULL;
-    rgba_obj_diff_color = NULL;
-
-    num_threshold_pixels = 0;
-    change_return = 1;
-    inverse = 0;
-
-    rgba_threshold[0] = 0; rgba_threshold[1] = 0; rgba_threshold[2] = 0; rgba_threshold[3] = 255;
-    rgba_diff_color[0] = 0; rgba_diff_color[1] = 0; rgba_diff_color[2] = 0; rgba_diff_color[3] = 255;
-
     /*get all the arguments*/
     if (!PyArg_ParseTuple (arg, "O!O!O|OOiO!i", &PySurface_Type, &surfobj,
                            &PySurface_Type, &surfobj2,
             color_threshold = (Uint32) PyLong_AsUnsignedLong
                 (rgba_obj_threshold);
         else if (RGBAFromColorObj (rgba_obj_threshold, rgba_threshold))
-            color_threshold = SDL_MapRGBA (surf->format, rgba_threshold[0], rgba_threshold[1], rgba_threshold[2], rgba_threshold[3]);
+            color_threshold = SDL_MapRGBA (surf->format,
+                                           rgba_threshold[0], 
+                                           rgba_threshold[1],
+                                           rgba_threshold[2], 
+                                           rgba_threshold[3]);
         else
             return RAISE (PyExc_TypeError, "invalid threshold argument");
 
     } else {
-        color_threshold = SDL_MapRGBA (surf->format, rgba_threshold[0], rgba_threshold[1], rgba_threshold[2], rgba_threshold[3]);
+        color_threshold = SDL_MapRGBA (surf->format,
+                                       rgba_threshold[0],
+                                       rgba_threshold[1],
+                                       rgba_threshold[2],
+                                       rgba_threshold[3]);
     }
 
     if(rgba_obj_diff_color) {
 
         if (PyInt_Check (rgba_obj_diff_color))
             color_diff_color = (Uint32) PyInt_AsLong (rgba_obj_diff_color);
-        else if (PyLong_Check (rgba_obj_threshold))
+        else if (PyLong_Check (rgba_obj_diff_color))
             color_diff_color = (Uint32) PyLong_AsUnsignedLong
                 (rgba_obj_diff_color);
         else if (RGBAFromColorObj (rgba_obj_diff_color, rgba_diff_color))
-            color_diff_color = SDL_MapRGBA (surf->format, rgba_diff_color[0], rgba_diff_color[1], rgba_diff_color[2], rgba_diff_color[3]);
+            color_diff_color = SDL_MapRGBA (surf->format,
+                                            rgba_diff_color[0],
+                                            rgba_diff_color[1],
+                                            rgba_diff_color[2],
+                                            rgba_diff_color[3]);
         else
             return RAISE (PyExc_TypeError, "invalid diff_color argument");
     } else {
-        color_diff_color = SDL_MapRGBA (surf->format, rgba_diff_color[0], rgba_diff_color[1], rgba_diff_color[2], rgba_diff_color[3]);
+        color_diff_color = SDL_MapRGBA (surf->format,
+                                        rgba_diff_color[0],
+                                        rgba_diff_color[1],
+                                        rgba_diff_color[2],
+                                        rgba_diff_color[3]);
     }
 
     bpp = surf->format->BytesPerPixel;
     Py_BEGIN_ALLOW_THREADS;
 
 
-    num_threshold_pixels = get_threshold (destsurf, surf, surf2, color,  color_threshold,  color_diff_color, change_return, inverse);
+    num_threshold_pixels = get_threshold (destsurf,
+                                          surf,
+                                          surf2,
+                                          color,
+                                          color_threshold,
+                                          color_diff_color,
+                                          change_return,
+                                          inverse);
 
 
     Py_END_ALLOW_THREADS;

test/base_test.py

         import platform
         if platform.system().startswith('Darwin'):
             return
-        
-        self.assertRaises(pygame.error, pygame.scrap.get)
+
+        try:
+            self.assertRaises(pygame.error, pygame.scrap.get)
+        except NotImplementedError:
+            # Scrap is optional.
+            pass
         
         # pygame.cdrom
         # pygame.joystick

test/cursors_test.py

         cursor = pygame.cursors.load_xbm(cursorfile, maskfile)
         
         # Test that load_xbm will take file objects as arguments
-        cursorfile, maskfile = map(file, (cursorfile, maskfile))
+        cursorfile, maskfile = [open(pth) for pth in (cursorfile, maskfile)]
         cursor = pygame.cursors.load_xbm(cursorfile, maskfile)
 
         # Is it in a format that mouse.set_cursor won't blow up on?
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.