[Mplayer-users] Re: All non 4:3 movies in -vo sdl starts ungly resized

Ivan Kalvatchev iive at yahoo.com
Thu Sep 13 16:25:45 CEST 2001


Sorry for double post, and that this is triple post.
I decide to put the patch in plain text here ( it was
attachment) becouse i am not sure that it could be
readed by others. I am even not sure that the S yahoo
do attach it!

--- vo_sdl.c.orig	Mon Aug 27 14:49:10 2001
+++ vo_sdl.c.new	Thu Sep 13 11:21:08 2001
@@ -100,7 +100,7 @@
 //#define BUGGY_SDL //defined by configure
 
 /* MONITOR_ASPECT MUST BE FLOAT */
-#define MONITOR_ASPECT 4.0/3.0
+#define MONITOR_ASPECT (4.0/3.0)
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -475,9 +475,30 @@
 
 	return 0;
 }
+/** 
+   Enlarge image to match new aspect ratio 
+	witch is old_aspect*aspect_correction 
+
+      params: imw == image width
+    	      imh == image height
+	      aspc == aspect_correction
+	      
+**/
+void change_aspect(int * imw, int *imh, float aspc)
+{	
+	if(verbose > 1) printf("SDL new aspect: src:
%ix%i\n", *imw, *imh);
+	
+	if(aspc>1.0)	    
+	    (*imw)*=aspc;
+	else	    
+	    (*imh)/=aspc;
+	
+	if(verbose) printf("SDL new aspect: dst: %ix%i\n",
*imw, *imh);
+	
+}
 
 /**
- * Do aspect ratio calculations
+ * Makes src image fit into dst
  *
  *   params : srcw == sourcewidth
  *            srch == sourceheight
@@ -487,20 +508,22 @@
  *  returns : SDL_Rect structure with new x and y, w
and h
  **/
 
-static SDL_Rect aspect(int srcw, int srch, int dstw,
int dsth) {
+static SDL_Rect save_aspect(int srcw, int srch, int
dstw, int dsth) {
 	SDL_Rect newres;
 	if(verbose > 1) printf("SDL Aspect: src: %ix%i dst:
%ix%i\n", srcw, srch, dstw, dsth);
-	newres.h = ((float)dstw / (float)srcw * (float)srch)
* ((float)dsth/((float)dstw/(MONITOR_ASPECT)));
-	if(newres.h > dsth) {
-		newres.w = ((float)dsth / (float)newres.h) * dstw;
-		newres.h = dsth;
-		newres.x = (dstw - newres.w) / 2;
-		newres.y = 0;
-	}
-	else {
-		newres.w = dstw;
-		newres.x = 0;
-		newres.y = (dsth - newres.h) / 2;
+	if(srcw*dsth<srch*dstw) //true if dest is wider
+	{
+	    newres.w = dsth*srcw/srch;
+	    newres.h = dsth;
+	    newres.x= (dstw - newres.w) / 2;
+	    newres.y= 0;
+	}
+	else//false if dest is narrow
+	{ 
+	    newres.w = dstw;
+	    newres.h = dstw*srch/srcw;
+	    newres.x = 0;
+	    newres.y = (dsth - newres.h) / 2;
 	}
 	
 	if(verbose) printf("SDL Aspect-Destinationres: %ix%i
(x: %i, y: %i)\n", newres.w, newres.h, newres.x,
newres.y);
@@ -515,39 +538,6 @@
  *  returns : doesn't return
  **/
 
-#if 0
-static void set_fullmode (int mode)
-{
-	struct sdl_priv_s *priv = &sdl_priv;
-	SDL_Surface *newsurface = NULL;
-	int haspect, waspect = 0;
-	
-	/* if we haven't set a fullmode yet, default to the
lowest res fullmode first */
-	if (mode < 0) 
-		mode = priv->fullmode =
findArrayEnd(priv->fullmodes) - 1;
-
-	/* Calculate proper aspect ratio for fullscreen
-	 * Height smaller than expected: add horizontal
black bars (haspect)*/
-	haspect = (priv->width * (float) ((float)
priv->fullmodes[mode]->h / (float)
priv->fullmodes[mode]->w) - priv->height) * (float)
((float) priv->fullmodes[mode]->w / (float)
priv->width);
-	/* Height bigger than expected: add vertical black
bars (waspect)*/
-	if (haspect < 0) {
-		haspect = 0; /* set haspect to zero because image
will be scaled horizontal instead of vertical */
-		waspect = priv->fullmodes[mode]->w - ((float)
((float) priv->fullmodes[mode]->h / (float)
priv->height) * (float) priv->width);
-	}	
-//	printf ("W-Aspect: %i  H-Aspect: %i\n", waspect,
haspect);
-	
-	/* change to given fullscreen mode and hide the
mouse cursor */
-	newsurface =
SDL_SetVideoMode(priv->fullmodes[mode]->w - waspect,
priv->fullmodes[mode]->h - haspect, priv->bpp,
priv->sdlfullflags);
-	
-	/* if we were successfull hide the mouse cursor and
save the mode */
-	if (newsurface) {
-		if (priv->surface)
-	    	    SDL_FreeSurface(priv->surface);
-		priv->surface = newsurface;
-		SDL_ShowCursor(0);
-	}
-}
-#endif
 
 static void set_fullmode (int mode) {
 	struct sdl_priv_s *priv = &sdl_priv;
@@ -560,13 +550,13 @@
 	
 	/* calculate new video size/aspect */
 	if(priv->fulltype&FS) {
-		newsize = aspect(priv->width, priv->height,
priv->XWidth ? priv->XWidth : priv->dstwidth,
priv->XHeight ? priv->XHeight : priv->dstheight);
+		newsize = save_aspect(priv->dstwidth,
priv->dstheight, priv->XWidth ? priv->XWidth :
priv->dstwidth, priv->XHeight ? priv->XHeight :
priv->dstheight);
 	} else
 	if(priv->fulltype&VM) {	
-		newsize = aspect(priv->dstwidth, priv->dstheight,
priv->dstwidth, priv->dstwidth*((float)priv->XHeight /
(float)priv->XWidth));
+		newsize = save_aspect(priv->dstwidth,
priv->dstheight, priv->dstwidth, priv->dstheight);
 	}	
 	else {
-		newsize = aspect(priv->dstwidth, priv->dstheight,
priv->fullmodes[mode]->w, priv->fullmodes[mode]->h);
+		newsize = save_aspect(priv->dstwidth,
priv->dstheight, priv->fullmodes[mode]->w,
priv->fullmodes[mode]->h);
 	}
 
 	/* try to change to given fullscreenmode */
@@ -673,6 +663,9 @@
 		if(verbose) printf("SDL: X11 Resolution %ix%i\n",
priv->XWidth, priv->XHeight);
 		saver_off(XDisplay);
 		XCloseDisplay(XDisplay);
+		change_aspect(&d_width,&d_height,
+		  ( (float)priv->XWidth/(float)priv->XHeight ) /
MONITOR_ASPECT
+				);//this should be in dec_video!!
 	}
 #endif
 	if (sdl_open(NULL, NULL) != 0)
@@ -686,20 +679,14 @@
 	
 	priv->width  = width;
 	priv->height = height;
-	priv->dstwidth  = d_width ? d_width : width;
+	
+
+	priv->dstwidth  = d_width  ? d_width  : width;
 	priv->dstheight = d_height ? d_height : height;
 
-	/*priv->width  = res.w;
-	priv->height = res.h;*/
         priv->format = format;
-#ifdef HAVE_X11
-	res = aspect(priv->dstwidth, priv->dstheight,
priv->dstwidth, priv->dstwidth*((float)priv->XHeight /
(float)priv->XWidth));
-	priv->windowsize.w = res.w;
-  	priv->windowsize.h = res.h;
-#else		
 	priv->windowsize.w = priv->dstwidth;
   	priv->windowsize.h = priv->dstheight;
-#endif
         
 	/* bit 0 (0x01) means fullscreen (-fs)
 	 * bit 1 (0x02) means mode switching (-vm)
@@ -737,11 +724,7 @@
         else {
 		if((strcmp(priv->driver, "x11") == 0) ||
((strcmp(priv->driver, "aalib") == 0) && priv->X)) {
 			if(verbose) printf("SDL: setting windowed
mode\n");
-#ifdef HAVE_X11		
-          	priv->surface = SDL_SetVideoMode (res.w,
res.h, priv->bpp, priv->sdlflags);
-#else			
           	priv->surface = SDL_SetVideoMode
(priv->dstwidth, priv->dstheight, priv->bpp,
priv->sdlflags);
-#endif
 		}
 		else {
 			if(verbose) printf("SDL: setting zoomed fullscreen
with modeswitching\n");
@@ -1074,7 +1057,7 @@
 					if (priv->surface->flags & SDL_FULLSCREEN) {
 						priv->surface =
SDL_SetVideoMode(priv->windowsize.w,
priv->windowsize.h, priv->bpp, priv->sdlflags);
 						SDL_ShowCursor(1);
-						if(verbose > 1) printf("SDL: Windowed mode\n");
+						if(verbose > 1) printf("SDL: Windowed mode
(%dx%d)\n",priv->windowsize.w,priv->windowsize.h);
 					} 
 					else if (priv->fullmodes){
 						set_fullmode(priv->fullmode);


__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

_______________________________________________
Mplayer-users mailing list
Mplayer-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mplayer-users



More information about the MPlayer-users mailing list