[MPlayer-users] libvo\aspect.c buggy?

Frank Leavis f.t.leavis at student.utwente.nl
Mon May 6 21:51:01 CEST 2002


When using the -fs and/or rescaling the image, the movie would often be rescaled to resolutions bigger than what my framebuffer is set at (like for example playing back a 640x480 .avi on a 16:9 aspect ratio framebuffer of 800x600, 
the video would be rescaled to 800x800 instead of 600x600). 

I tried to fix aspect.c , but I didn't fully understand the already written aspect ratio rescaling routines... so I just wrote my own routines which on my pc work ok. I probably broke part of the code, since this is my first C code ever, and 
because I didn't fully understand some of the stuff that already was in the aspect.c file). Please look into the changed code, and if mine is complete crap, consider this something as to be looked further into by someone else who 
_can_ code C properly :).

Here's my changed aspect.c :
------------------------------------------------------------------
/* Stuff for correct aspect scaling. */
#include "aspect.h"

//#define ASPECT_DEBUG

#ifdef ASPECT_DEBUG
#include <stdio.h>
#endif

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 zoom){
  float tmp_movie_aspect;
  float tmp_aspect_diff;
  int tmpw;

#ifdef ASPECT_DEBUG
  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
  
  tmp_movie_aspect = (float)*srcw / (float)*srch;
  tmp_aspect_diff = monitor_aspect / ((float)*srcw / (float)*srch );

  if(zoom){
    if(tmp_aspect_diff <= 1){
      *srcw = aspdat.scrw;
      *srch = (int)((float)aspdat.scrh * tmp_aspect_diff);
      *srch+= *srch%2; //round
    }else{
      *srcw = (int)((float)aspdat.scrw / tmp_aspect_diff);
      *srch = aspdat.scrh;
      *srcw+= *srcw%2; //round
    }
  }else{
    if(*srcw > aspdat.scrw){
      *srcw = aspdat.scrw;
      *srch = (int)((float)aspdat.scrw * (tmp_aspect_diff / tmp_movie_aspect));
      *srch+= *srcw%2; //round
    }
    if(*srch > aspdat.scrh){
      *srch = aspdat.scrh;
      *srcw = (int)((float)aspdat.scrw / tmp_aspect_diff);
      *srcw+= *srcw%2; //round
    }
  }

#ifdef ASPECT_DEBUG
  printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
#endif
}
------------------------------------------------------------------





More information about the MPlayer-users mailing list