changeset 2249:48f0ac1e9d13

Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
author atmos4
date Thu, 18 Oct 2001 02:42:20 +0000
parents 13bbd8326efd
children d7923c09dd46
files libvo/aspect.c libvo/aspect.h libvo/vo_gl.c libvo/vo_gl2.c libvo/vo_sdl.c libvo/vo_xmga.c libvo/vo_xv.c
diffstat 7 files changed, 113 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/aspect.c	Wed Oct 17 21:17:56 2001 +0000
+++ b/libvo/aspect.c	Thu Oct 18 02:42:20 2001 +0000
@@ -1,5 +1,7 @@
 /* Stuff for correct aspect scaling. */
-//#define ASPECT_DEBUG
+#include "aspect.h"
+
+#define ASPECT_DEBUG
 
 #ifdef ASPECT_DEBUG
 #include <stdio.h>
@@ -7,39 +9,69 @@
 
 float monitor_aspect=4.0/3.0;
 
+static struct {
+  int orgw; // real width
+  int orgh; // real height
+  int prew; // prescaled width
+  int preh; // prescaled height
+  int scrw; // horizontal resolution
+  int scrh; // vertical resolution
+} aspdat;
+
+void aspect_save_orig(int orgw, int orgh){
+  aspdat.orgw = orgw;
+  aspdat.orgh = orgh;
+}
+
+void aspect_save_prescale(int prew, int preh){
+  aspdat.prew = prew;
+  aspdat.preh = preh;
+}
+
+void aspect_save_screenres(int scrw, int scrh){
+  aspdat.scrw = scrw;
+  aspdat.scrh = scrh;
+}
+
 /* aspect is called with the source resolution and the
  * resolution, that the scaled image should fit into
  */
 
-void aspect(int *srcw, int *srch, int fitinw, int fitinh){
-  int srcwcp, srchcp, tmp;
-  srcwcp=*srcw; srchcp=*srch;
-  srcwcp=fitinw;
+void aspect(int *srcw, int *srch, int zoom){
+  int tmpw;
+
 #ifdef ASPECT_DEBUG
-  printf("aspect(0) fitin: %dx%d \n",fitinw,fitinh);
-  printf("aspect(1) wh: %dx%d (org: %dx%d)\n",srcwcp,srchcp,*srcw,*srch);
+  printf("aspect(0) fitin: %dx%d zoom: %d \n",aspdat.scrw,aspdat.scrh,zoom);
+  printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
 #endif
-  srchcp=(int)(((float)fitinw / (float)*srcw * (float)*srch)
-            * ((float)fitinh / ((float)fitinw / monitor_aspect)));
-  srchcp+=srchcp%2; // round
+  if(zoom){
+    *srcw = aspdat.scrw;
+    *srch = (int)(((float)aspdat.scrw / (float)aspdat.prew * (float)aspdat.preh)
+               * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
+  }else{
+    *srcw = aspdat.prew;
+    *srch = (int)((float)aspdat.preh
+               * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
+  }
+  *srch+= *srch%2; // round
 #ifdef ASPECT_DEBUG
-  printf("aspect(2) wh: %dx%d (org: %dx%d)\n",srcwcp,srchcp,*srcw,*srch);
+  printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
 #endif
-  if(srchcp>fitinh || srchcp<*srch){
-    tmp=(int)(((float)fitinh / (float)*srch * (float)*srcw)
-           * ((float)fitinw / ((float)fitinh / (1/monitor_aspect))));
-    if(srcwcp>fitinw){
-      srchcp=fitinh;
-      srcwcp=tmp;
-      srcwcp+=srcwcp%2; // round
+  if(*srch>aspdat.scrh || *srch<aspdat.orgh){
+    if(zoom)
+      tmpw = (int)(((float)aspdat.scrh / (float)aspdat.preh * (float)aspdat.prew)
+                * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
+    else
+      tmpw = (int)((float)aspdat.prew
+                * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
+    if(tmpw<=aspdat.scrw && tmpw>=aspdat.orgw){
+      *srch = zoom?aspdat.scrh:aspdat.preh;
+      *srcw = tmpw;
+      *srcw+= *srcw%2; // round
     }
   }
 #ifdef ASPECT_DEBUG
-  printf("aspect(3) wh: %dx%d (org: %dx%d)\n",srcwcp,srchcp,*srcw,*srch);
-#endif
-  *srcw=srcwcp; *srch=srchcp;
-#ifdef ASPECT_DEBUG
-  printf("aspect(4) wh: %dx%d (org: %dx%d)\n",srcwcp,srchcp,*srcw,*srch);
+  printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
 #endif
 }
 
--- a/libvo/aspect.h	Wed Oct 17 21:17:56 2001 +0000
+++ b/libvo/aspect.h	Thu Oct 18 02:42:20 2001 +0000
@@ -2,7 +2,16 @@
 #define __ASPECT_H
 /* Stuff for correct aspect scaling. */
 
-void aspect(int *srcw, int *srch, int fitinw, int fitinh);
+void aspect_save_orig(int orgw, int orgh);
+
+void aspect_save_prescale(int prew, int preh);
+
+void aspect_save_screenres(int scrw, int scrh);
+
+#define A_ZOOM 1
+#define A_NOZOOM 0
+
+void aspect(int *srcw, int *srch, int zoom);
 
 #endif
 
--- a/libvo/vo_gl.c	Wed Oct 17 21:17:56 2001 +0000
+++ b/libvo/vo_gl.c	Thu Oct 18 02:42:20 2001 +0000
@@ -99,7 +99,6 @@
 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
 {
 //	int screen;
-        int dwidth,dheight;
 	unsigned int fg, bg;
 	char *hello = (title == NULL) ? "OpenGL rulez" : title;
 //	char *name = ":0.0";
@@ -118,13 +117,16 @@
 	if (X_already_started) return -1;
 	if(!vo_init()) return -1;
 
+	aspect_save_orig(width,height);
+	aspect_save_prescale(d_width,d_height);
+	aspect_save_screenres(vo_screenwidth,vo_screenheight);
+
 	X_already_started++;
 
-        dwidth=d_width; dheight=d_height;
+	aspect(&d_width,&d_height,A_NOZOOM);
 #ifdef X11_FULLSCREEN
         if( flags&0x01 ){ // (-fs)
-          aspect(&d_width,&d_height,vo_screenwidth,vo_screenheight);
-          dwidth=d_width; dheight=d_height;
+          aspect(&d_width,&d_height,A_ZOOM);
         }
 #endif
 	hint.x = 0;
--- a/libvo/vo_gl2.c	Wed Oct 17 21:17:56 2001 +0000
+++ b/libvo/vo_gl2.c	Thu Oct 18 02:42:20 2001 +0000
@@ -395,7 +395,6 @@
 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
 {
 //	int screen;
-        int dwidth,dheight;
 	unsigned int fg, bg;
 	char *hello = (title == NULL) ? "OpenGL rulez" : title;
 //	char *name = ":0.0";
@@ -414,13 +413,16 @@
 	if (X_already_started) return -1;
 	if(!vo_init()) return -1;
 
+	aspect_save_orig(width,height);
+	aspect_save_prescale(d_width,d_height);
+	aspect_save_screenres(vo_screenwidth,vo_screenheight);
+
 	X_already_started++;
 
-        dwidth=d_width; dheight=d_height;
+	aspect(&d_width,&d_height,A_NOZOOM);
 #ifdef X11_FULLSCREEN
         if( flags&0x01 ){ // (-fs)
-          aspect(&d_width,&d_height,vo_screenwidth,vo_screenheight);
-          dwidth=d_width; dheight=d_height;
+          aspect(&d_width,&d_height,A_ZOOM);
         }
 #endif
 	hint.x = 0;
--- a/libvo/vo_sdl.c	Wed Oct 17 21:17:56 2001 +0000
+++ b/libvo/vo_sdl.c	Thu Oct 18 02:42:20 2001 +0000
@@ -555,35 +555,26 @@
 static void set_fullmode (int mode) {
 	struct sdl_priv_s *priv = &sdl_priv;
 	SDL_Surface *newsurface = NULL;
-	int newwidth = priv->dstwidth,
-	    newheight= priv->dstheight;
 	
 	/* 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;
 	
+	aspect_save_screenres(priv->fullmodes[mode]->w, priv->fullmodes[mode]->h);
+
 	/* calculate new video size/aspect */
 	if(!priv->mode) {
 	if(priv->fulltype&FS) {
 #ifdef HAVE_X11		
-		aspect(&newwidth, &newheight, priv->XWidth ? priv->XWidth : priv->dstwidth, priv->XHeight ? priv->XHeight : priv->dstheight);
-#else		
-		aspect(&newwidth, &newheight, priv->dstwidth, priv->dstheight);
+		aspect_save_screenres(priv->XWidth, priv->XHeight);
 #endif		
-	} else
-	if(priv->fulltype&VM) {	
-#ifdef HAVE_X11		
-		aspect(&newwidth, &newheight, priv->dstwidth, (int)((float)priv->dstwidth*((float)priv->XHeight / (float)priv->XWidth)));
-#else		
-		aspect(&newwidth, &newheight, priv->dstwidth, priv->dstheight);
-#endif		
-	} else {
-		aspect(&newwidth, &newheight, priv->fullmodes[mode]->w, priv->fullmodes[mode]->h);
 	}
+	aspect(&priv->dstwidth, &priv->dstheight, A_ZOOM);
+
 	}
 
 	/* try to change to given fullscreenmode */
-	newsurface = SDL_SetVideoMode(newwidth, newheight, priv->bpp, priv->sdlfullflags);
+	newsurface = SDL_SetVideoMode(priv->dstwidth, priv->dstheight, priv->bpp, priv->sdlfullflags);
 	
 	/* if creation of new surface was successfull, save it and hide mouse cursor */
 	if(newsurface) {
@@ -615,7 +606,8 @@
 	static Display *XDisplay;
 	static int XScreen;
 #endif
-	int newwidth, newheight;
+	aspect_save_orig(width,height);
+	aspect_save_prescale(d_width,d_height);
 
 	sdl_format = format;
         switch(format){
@@ -701,17 +693,16 @@
 	priv->height = height;
 	priv->dstwidth  = d_width ? d_width : width;
 	priv->dstheight = d_height ? d_height : height;
-	newwidth  = priv->dstwidth;
-	newheight = priv->dstheight;
 
 	/*priv->width  = res.w;
 	priv->height = res.h;*/
         priv->format = format;
 #ifdef HAVE_X11
-	aspect(&newwidth, &newheight, priv->dstwidth, (int)((float)priv->dstwidth*((float)priv->XHeight / (float)priv->XWidth)));
+	aspect_save_screenres(priv->XWidth,priv->XHeight);
+	aspect(&priv->dstwidth,&priv->dstheight,A_NOZOOM);
 #endif
-	priv->windowsize.w = newwidth;
-  	priv->windowsize.h = newheight;
+	priv->windowsize.w = priv->dstwidth;
+  	priv->windowsize.h = priv->dstheight;
         
 	/* bit 0 (0x01) means fullscreen (-fs)
 	 * bit 1 (0x02) means mode switching (-vm)
@@ -726,15 +717,14 @@
 	}
 	if(flags&FS) {
 	  	if(verbose) printf("SDL: setting zoomed fullscreen without modeswitching\n");
-		printf("SDL: Info - please use -vm (unscaled) or -zoom (scaled) for best fullscreen experience\n");
+		printf("SDL: Info - please use -vm or -zoom to switch to best resolution.\n");
 		priv->fulltype = FS;
 		set_fullmode(priv->fullmode);
           	/*if((priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlfullflags)))
 			SDL_ShowCursor(0);*/
 	} else	
 	if(flags&VM) {
-	 	if(verbose) printf("SDL: setting nonzoomed fullscreen with modeswitching\n");
-		printf("SDL: Info - please use -zoom switch to scale video\n");
+	 	if(verbose) printf("SDL: setting zoomed fullscreen with modeswitching\n");
 		priv->fulltype = VM;
 		set_fullmode(priv->fullmode);
           	/*if((priv->surface = SDL_SetVideoMode (d_width ? d_width : width, d_height ? d_height : height, priv->bpp, priv->sdlfullflags)))
@@ -742,18 +732,16 @@
 	} else
 	if(flags&ZOOM) {
 	 	if(verbose) printf("SDL: setting zoomed fullscreen with modeswitching\n");
-		printf("SDL: Info - please use -vm switch instead if you don't want scaled video\n");
 		priv->fulltype = ZOOM;
 		set_fullmode(priv->fullmode);
 	} 
         else {
 		if((strcmp(priv->driver, "x11") == 0) || ((strcmp(priv->driver, "aalib") == 0) && priv->X)) {
 			if(verbose) printf("SDL: setting windowed mode\n");
-          	priv->surface = SDL_SetVideoMode (newwidth, newheight, priv->bpp, priv->sdlflags);
+          	priv->surface = SDL_SetVideoMode (priv->dstwidth, priv->dstheight, priv->bpp, priv->sdlflags);
 		}
 		else {
 			if(verbose) printf("SDL: setting zoomed fullscreen with modeswitching\n");
-			printf("SDL: Info - please use -vm switch instead if you don't want scaled video\n");
 			priv->fulltype = ZOOM;
 			set_fullmode(priv->fullmode);
 		}	
@@ -1092,20 +1080,17 @@
 				}
 
 				else if ( keypressed == SDLK_n ) {
-					int newwidth = priv->dstwidth, newheight = priv->dstheight;
 #ifdef HAVE_X11					
-					aspect(&newwidth, &newheight, priv->dstwidth, (int)((float)priv->dstwidth*((float)priv->XHeight / (float)priv->XWidth)));
-#else
-					aspect(&newwidth, &newheight, priv->dstwidth, priv->dstheight);
+					aspect(&priv->dstwidth, &priv->dstheight,A_NOZOOM);
 #endif					
-					if (priv->surface->w != newwidth || priv->surface->h != newheight) {
-						priv->surface = SDL_SetVideoMode(newwidth, newheight, priv->bpp, priv->sdlflags);
+					if (priv->surface->w != priv->dstwidth || priv->surface->h != priv->dstheight) {
+						priv->surface = SDL_SetVideoMode(priv->dstwidth, priv->dstheight, priv->bpp, priv->sdlflags);
 					    	priv->windowsize.w = priv->surface->w;
 						priv->windowsize.h = priv->surface->h;
 						if(verbose > 1) printf("SDL: Normal size\n");
 					} else
-					if (priv->surface->w != newwidth * 2 || priv->surface->h != newheight * 2) {
-						priv->surface = SDL_SetVideoMode(newwidth * 2, newheight * 2, priv->bpp, priv->sdlflags);
+					if (priv->surface->w != priv->dstwidth * 2 || priv->surface->h != priv->dstheight * 2) {
+						priv->surface = SDL_SetVideoMode(priv->dstwidth * 2, priv->dstheight * 2, priv->bpp, priv->sdlflags);
 					    	priv->windowsize.w = priv->surface->w;
 						priv->windowsize.h = priv->surface->h;
 						if(verbose > 1) printf("SDL: Double size\n");
--- a/libvo/vo_xmga.c	Wed Oct 17 21:17:56 2001 +0000
+++ b/libvo/vo_xmga.c	Thu Oct 18 02:42:20 2001 +0000
@@ -230,11 +230,14 @@
 
  if (!vo_init()) return -1;
 
+ aspect_save_orig(width,height);
+ aspect_save_prescale(d_width,d_height);
+ aspect_save_screenres(vo_screenwidth,vo_screenheight);
+
  mvWidth=width; mvHeight=height;
 
  wndX=0; wndY=0;
  wndWidth=d_width; wndHeight=d_height;
- dwidth=d_width; dheight=d_height;
  #ifdef HAVE_NEW_GUI
 //  mdwidth=d_width; mdheight=d_height;
   mdwidth=width; mdheight=height;
@@ -250,6 +253,7 @@
    default: printf( "Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1;
   }
 
+  aspect(&d_width,&d_height,A_NOZOOM);
 #ifdef HAVE_NEW_GUI
  if ( vo_window == None )
   {
@@ -259,10 +263,10 @@
      wndWidth=vo_screenwidth;
      wndHeight=vo_screenheight;
 #ifdef X11_FULLSCREEN
-     aspect(&d_width,&d_height,vo_screenwidth,vo_screenheight);
-     dwidth=d_width; dheight=d_height;
+     aspect(&d_width,&d_height,A_ZOOM);
 #endif
     }
+   dwidth=d_width; dheight=d_height;
 
    XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
    mDepth=attribs.depth;
--- a/libvo/vo_xv.c	Wed Oct 17 21:17:56 2001 +0000
+++ b/libvo/vo_xv.c	Thu Oct 18 02:42:20 2001 +0000
@@ -132,6 +132,9 @@
  XSetWindowAttributes xswa;
  unsigned long xswamask;
 
+ aspect_save_orig(width,height);
+ aspect_save_prescale(d_width,d_height);
+
  image_height = height;
  image_width = width;
  image_format=format;
@@ -142,11 +145,12 @@
 #endif
 
  mFullscreen=flags&1;
- dwidth=d_width; dheight=d_height;
  num_buffers=vo_doublebuffering?NUM_BUFFERS:1;
  
  if (!vo_init()) return -1;
 
+ aspect_save_screenres(vo_screenwidth,vo_screenheight);
+
 #ifdef HAVE_NEW_GUI
  if ( vo_window == None )
   {
@@ -155,6 +159,8 @@
    hint.y = 0;
    hint.width = d_width;
    hint.height = d_height;
+   aspect(&d_width,&d_height,A_NOZOOM);
+
    if ( mFullscreen )
     {
      hint.width=vo_screenwidth;
@@ -167,13 +173,11 @@
       * irritated for now (and send lots o' mails ;) ::atmos
       */
 
-     {
-       aspect(&d_width,&d_height,vo_screenwidth,vo_screenheight);
-       dwidth=d_width; dheight=d_height;
-     }
+     aspect(&d_width,&d_height,A_ZOOM);
 #endif
 
     }
+   dwidth=d_width; dheight=d_height; //XXX: what are the copy vars used for?
    hint.flags = PPosition | PSize;
    XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
    depth=attribs.depth;