Commits

Anonymous committed 9e5e5a7

Added exception throwing if the linked surface is not the right aspect ratio,
ie, if the aspect ratio is different from the movie's aspect ratio.
This is done because otherwise, surfaces suffer nasty corruption which doesn't
look very good.

Comments (0)

Files changed (3)

 SCRAP = -lX11
 PORTMIDI = -lportmidi
 PORTTIME = -lporttime
-FREETYPE = -lfreetype 
+FREETYPE = -lfreetype
+AVFORMAT  = -lavformat 
+SWSCALE   = -lswscale 
 #--EndConfig
 
 DEBUG = 
 _numericsurfarray src/_numericsurfarray.c $(SDL) $(DEBUG)
 _numericsndarray src/_numericsndarray.c $(SDL) $(MIXER) $(DEBUG)
 movie src/movie.c $(SDL) $(SMPEG) $(DEBUG)
+_movie src/_gsound.c src/_gmovie.c src/_gcommand.c src/gmovie.c $(SDL)  $(AVFORMAT) $(SWSCALE) $(MIXER) $(DEBUG)
 scrap src/scrap.c $(SDL) $(SCRAP) $(DEBUG)
 _camera src/_camera.c src/camera_v4l2.c src/camera_v4l.c $(SDL) $(DEBUG)
 pypm src/pypm.c $(SDL) $(PORTMIDI) $(PORTTIME) $(DEBUG)

examples/__movie_test.py

 #m.play(9)
 #time.sleep(9*130)
 
+surf = pygame.surface.Surface((100, 100))
+#this should cause an error:
+try:
+    m.surface = surf
+except Exception, e:
+    print e
+    del e
 
 print "Playing infinitely"
 
 import sys
 #sys.exit()
 print "Surface time..."
+
+
 screen = pygame.display.set_mode((800, 340))
 ##m.surface=screen
 ##time.sleep(1)
 ##time.sleep(5)
 ##del m
 
+
 m=movie.Movie(filename, screen)
 counter = 0
 actions = {1: lambda x: x.paused, 6: lambda x:x.pause(), 11: lambda x:x.pause(), 2000:lambda x: x.stop(), 3000: lambda x: x.play(-1)}
         Py_DECREF(self);
         return;
     }
+	if(self->canon_surf)
+	{
+		/*Here we check if the surface's dimensions match the aspect ratio of the video. If not, 
+		 * we throw an error. 
+		 */
+		int width = self->canon_surf->w;
+		int height = self->canon_surf->h;
+		double aspect_ratio = (double)self->video_st->codec->width/(double)self->video_st->codec->height;
+		double surf_ratio = (double)width/(double)height;
+		if (surf_ratio!=aspect_ratio)
+		{
+			PyErr_SetString(PyExc_ValueError, "surface does not have the same aspect ratio as the video. This would cause surface corruption.");
+			Py_DECREF(self);
+			return;
+		}
+	}
     //PySys_WriteStdout("Movie->filename: %s\n", self->filename);
     Py_DECREF(self);
     return;
     surfaceCommand *surf;
     if(PySurface_Check(surface))
     {
-        /*movie->canon_surf=PySurface_AsSurface(surface);
+		SDL_Surface *surfa = PySurface_AsSurface(surface);
+        int width = surfa->w;
+		int height = surfa->h;
+		double aspect_ratio = (double)movie->video_st->codec->width/(double)movie->video_st->codec->height;
+		double surf_ratio = (double)width/(double)height;
+		if (surf_ratio!=aspect_ratio)
+		{
+			RAISE(PyExc_ValueError, "surface does not have the same aspect ratio as the video. This would cause surface corruption.");
+			return -1;
+		}
+		/*movie->canon_surf=PySurface_AsSurface(surface);
         movie->overlay=0;*/
         surf = (surfaceCommand *)PyMem_Malloc(sizeof(surfaceCommand));
         surf->type = movie->surfaceCommandType;
-        surf->surface = PySurface_AsSurface(surface);
+        surf->surface = surfa;
         addCommand(movie->commands, (Command *)surf);
         return 0;
     }