Commits

zeroth  committed a11f661

Merged with trunk rev 2482

  • Participants
  • Parent commits 9c90743
  • Branches tylerthemovie

Comments (0)

Files changed (9)

 # BREAK = change breaks existing code
 # BUG    = fixed a bug that was (or could have been) crashing
 
+
+[SVN 2481] July 7, 2009
+    [BUG] typo in examples/sound_array_demos.py Thanks Evan Kroske!
+
+[SVN 2472] July 6, 2009
+    [BUG]Fixed some failing tests for Color and LONG_MAX on 64bit python.
+    From Campbell Barton.FloatFromObj speedup. 
+      register_quit cleanup.
+      PyErr_Format used in CheckSDLVersions.
+
 [SVN 2454] July 2, 2009
-    Patch to work around cpu detection bugs in SDL 64bit from Lenard.  
+    [BUG] Patch to work around cpu detection bugs in SDL 64bit from Lenard.  
       Thanks to Lorenz for bug hunting.
 
 [SVN 2380-2381] Jun 19, 2009

File examples/sound_array_demos.py

         if 'numpy' in sndarray.get_arraytypes():
             sndarray.use_arraytype('numpy')
         elif 'numeric' in sndarray.get_arraytype():
-            sndfarray.use_arraytype('numeric')
+            sndarray.use_arraytype('numeric')
         else:
             raise ImportError('No array package is installed')
     else:

File movie_test.py

 # time.
 
 counter = 0
-actions = {1: lambda x: x.paused, 6: lambda x:x.pause(), 11: lambda x:x.pause(), 15: lambda x: x.resize(x.width/2, x.height/2), 2000:lambda x: x.stop(), 3000: lambda x: x.play(-1)}
+actions = {1: lambda x: x.paused, 6: lambda x:x.pause(), 11: lambda x:x.pause(), 15: lambda x: x.resize(x.width*2, x.height*2), 2000:lambda x: x.stop(), 3000: lambda x: x.play(-1)}
 prev_time = time.time()
 m.surface = screen
 print "About to do surface gymnastics..."

File src/_gmovie.c

     get_width(movie, width);
 }
 
+void WritePicture2Surface(AVPicture *picture, SDL_Surface *surface)
+{
+	/* AVPicture initialized with PIX_FMT_RGBA only fills pict->data[0]
+	 *  This however is only in {R,G,B, A} format. So we just copy the data over. 
+	 */
+	uint32_t *RGBA = surface->pixels;
+	int64_t size = surface->w*surface->h*surface->format->BytesPerPixel;
+	//memcpy(surface->pixels, picture->data[0], size-1);
+	int64_t ix=0;
+	
+	while(ix<size)
+	{
+		uint8_t red   = picture->data[0][ix]; 
+		uint8_t green = picture->data[0][ix+1];
+		uint8_t blue  = picture->data[0][ix+2];
+		//skip the alpha... we don't care
+        //endianess issue here... red has to be shifted by 16, green by 8, and blue gets no shift.
+        /* shift components to the correct place in pixel */
+        *RGBA = ( red   << (long) surface->format->Rshift) | /* red */
+                ( blue  << (long) surface->format->Bshift ) | /* green */
+                ( green << (long) surface->format->Gshift ) | /* blue */
+                ( 0   << (long) surface->format->Ashift);
+        /* goto next pixel */
+        RGBA++;
+        ix+=4;
+	}
+}
+
 int inline clamp0_255(int x)
 {
     x &= (~x) >> 31;
 	        {
 	            th=screen->h;
 	        }
-	        /*GRABGIL
+	        GRABGIL
 	        PySys_WriteStdout("screen->BitsPerPixel: %i\nscreen->RMask: %i\nscreen->Gmask: %i\nscreen->Bmask: %i\nscreen->Amask: %i\n",
 	         screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
-	        RELEASEGIL*/
+	        RELEASEGIL
 	        vp->dest_surface = SDL_CreateRGBSurface(screen->flags,
 	                                                tw,
 	                                                th,
     else if(vp->dest_surface)
     {
         /* get a pointer on the bitmap */
+        dst_pix_fmt = PIX_FMT_RGBA;
         avpicture_alloc(&pict, dst_pix_fmt, w, h);
         SDL_LockSurface(vp->dest_surface);
     }
     }
     else if(vp->dest_surface)
     {
-        ConvertYUV420PtoRGBA(&pict,vp->dest_surface, src_frame->interlaced_frame );
+        //ConvertYUV420PtoRGBA(&pict,vp->dest_surface, src_frame->interlaced_frame );
+        WritePicture2Surface(&pict, vp->dest_surface);
         SDL_UnlockSurface(vp->dest_surface);
         avpicture_free(&pict);
     }
 
     if (compiled.major != linked->major || compiled.minor != linked->minor)
     {
-        char err[1024];
-        sprintf (err, "SDL compiled with version %d.%d.%d, linked to %d.%d.%d",
+		PyErr_Format(PyExc_RuntimeError, "SDL compiled with version %d.%d.%d, linked to %d.%d.%d",
                  compiled.major, compiled.minor, compiled.patch,
                  linked->major, linked->minor, linked->patch);
-        PyErr_SetString (PyExc_RuntimeError, err);
         return 0;
     }
     return 1;
 }
 
 static PyObject*
-register_quit (PyObject* self, PyObject* arg)
+register_quit (PyObject* self, PyObject* value)
 {
-    PyObject* quitfunc;
-
-    if (!PyArg_ParseTuple (arg, "O", &quitfunc))
-        return NULL;
-
     if (!quitfunctions)
     {
         quitfunctions = PyList_New (0);
         if (!quitfunctions)
             return NULL;
     }
-    PyList_Append (quitfunctions, quitfunc);
+    PyList_Append (quitfunctions, value);
 
     Py_RETURN_NONE;
 }
     return 1;
 }
 
-static int FloatFromObj (PyObject* obj, float* val)
+static int
+FloatFromObj (PyObject* obj, float* val)
 {
-    PyObject* floatobj;
+    float f= (float)PyFloat_AsDouble (obj);
 
-    if (PyNumber_Check (obj))
-    {
-        if (!(floatobj = PyNumber_Float (obj)))
-            return 0;
-        *val = (float) PyFloat_AsDouble (floatobj);
-        Py_DECREF (floatobj);
-        return 1;
-    }
-    return 0;
+    if (f==-1 && PyErr_Occurred()) {
+		PyErr_Clear ();
+        return 0;
+	}
+    
+    *val = f;
+    return 1;
 }
 
 static int
 {
     { "init", (PyCFunction) init, METH_NOARGS, DOC_PYGAMEINIT },
     { "quit", (PyCFunction) quit, METH_NOARGS, DOC_PYGAMEQUIT },
-    { "register_quit", register_quit, METH_VARARGS, DOC_PYGAMEREGISTERQUIT },
+    { "register_quit", register_quit, METH_O, DOC_PYGAMEREGISTERQUIT },
     { "get_error", (PyCFunction) get_error, METH_NOARGS, DOC_PYGAMEGETERROR },
     { "set_error", (PyCFunction) set_error, METH_VARARGS, DOC_PYGAMESETERROR },
     { "get_sdl_version", (PyCFunction) get_sdl_version, METH_NOARGS,
 static PyObject*
 _color_int (PyColor *color)
 {
-    unsigned long tmp = (color->r << 24) + (color->g << 16) + (color->b << 8) +
-        color->a;
+    Uint32 tmp = (color->r << 24) + (color->g << 16) + 
+                 (color->b << 8) + color->a;
 #if !PY3
-    if (tmp < INT_MAX)
+    if (tmp < LONG_MAX)
         return PyInt_FromLong ((long) tmp);
 #endif
     return PyLong_FromUnsignedLong (tmp);
 static PyObject*
 _color_long (PyColor *color)
 {
-    unsigned long tmp = (color->r << 24) + (color->g << 16) + (color->b << 8) +
+    Uint32 tmp = (color->r << 24) + (color->g << 16) + (color->b << 8) +
         color->a;
     return PyLong_FromUnsignedLong (tmp);
 }
 static PyObject*
 _color_float (PyColor *color)
 {
-    unsigned long tmp = (color->r << 24) + (color->g << 16) + (color->b << 8) +
+    Uint32 tmp = (color->r << 24) + (color->g << 16) + (color->b << 8) +
         color->a;
     return PyFloat_FromDouble ((double) tmp);
 }
 _color_oct (PyColor *color)
 {
     char buf[100];
-    unsigned long tmp = (color->r << 24) + (color->g << 16) + (color->b << 8) +
+    Uint32 tmp = (color->r << 24) + (color->g << 16) + (color->b << 8) +
         color->a;
-    if (tmp < INT_MAX)
-        PyOS_snprintf (buf, sizeof (buf), "0%lo", tmp);
+
+    if (tmp < LONG_MAX)
+        PyOS_snprintf (buf, sizeof (buf), "0%lo", (unsigned long) tmp);
     else
-        PyOS_snprintf (buf, sizeof (buf), "0%loL", tmp);
+        PyOS_snprintf (buf, sizeof (buf), "0%loL", (unsigned long) tmp);
     return PyString_FromString (buf);
 }
 
 _color_hex (PyColor *color)
 {
     char buf[100];
-    unsigned long tmp = (color->r << 24) + (color->g << 16) + (color->b << 8) +
+    Uint32 tmp = (color->r << 24) + (color->g << 16) + (color->b << 8) +
         color->a;
-    if (tmp < INT_MAX)
-        PyOS_snprintf (buf, sizeof (buf), "0x%lx", tmp);
+    if (tmp < LONG_MAX)
+        PyOS_snprintf (buf, sizeof (buf), "0x%lx", (unsigned long) tmp);
     else
     {
 #if PY_VERSION_HEX >= 0x02050000
-        PyOS_snprintf (buf, sizeof (buf), "0x%lxL", tmp);
+        PyOS_snprintf (buf, sizeof (buf), "0x%lxL", (unsigned long) tmp);
 #else
         /* <= 2.4 uses capitalised hex chars. */
-        PyOS_snprintf (buf, sizeof (buf), "0x%lXL", tmp);
+        PyOS_snprintf (buf, sizeof (buf), "0x%lXL", (unsigned long) tmp);
 #endif
     }
     return Text_FromUTF8 (buf);

File src/pygame.h

      PyGAME_C_API[PYGAMEAPI_DISPLAY_FIRSTSLOT + 0])
 
 #define PyVidInfo_Type                                                  \
-    (*(PyTypeObject*)PyGAME_C_API[PYGAMEAPI_SURFACE_FIRSTSLOT + 0])
+    (*(PyTypeObject*)PyGAME_C_API[PYGAMEAPI_DISPLAY_FIRSTSLOT + 0])
 #define PyVidInfo_New                                   \
     (*(PyObject*(*)(SDL_VideoInfo*))                    \
      PyGAME_C_API[PYGAMEAPI_DISPLAY_FIRSTSLOT + 1])

File test/color_test.py

         self.assertEquals(pygame.color.Color('red'), pygame.color.Color(' r e d '))
 
     def test_slice(self):
+        """|tags: python3_ignore|"""
         # slicing a color gives you back a tuple.
         # do all sorts of slice combinations.
         c = pygame.Color(1,2,3,4)
         self.assertRaises (ValueError, c.set_length, 5)
         self.assertRaises (ValueError, c.set_length, -1)
         self.assertRaises (ValueError, c.set_length, 0)
-        self.assertRaises (ValueError, c.set_length, pow(2,33L))
+        self.assertRaises (ValueError, c.set_length, pow(2,long_(33)))
         
         
     def test_case_insensitivity_of_string_args(self):

File test/test_utils/run_tests.py

         option_exclude += ('subprocess_ignore',)
     elif 'ignore' not in option_exclude:
         option_exclude += ('ignore',)
+    if sys.version_info < (3, 0, 0):
+        option_exclude += ('python2_ignore',)
+    else:
+        option_exclude += ('python3_ignore',)
 
     main_dir, test_subdir, fake_test_subdir = prepare_test_env()
     test_runner_py = os.path.join(test_subdir, "test_utils", "test_runner.py")