2001-10-03 14:41:53 +00:00
|
|
|
/* Stuff for correct aspect scaling. */
|
2001-10-18 02:42:20 +00:00
|
|
|
#include "aspect.h"
|
|
|
|
|
2001-10-18 02:43:33 +00:00
|
|
|
//#define ASPECT_DEBUG
|
2001-10-04 11:42:21 +00:00
|
|
|
|
|
|
|
#ifdef ASPECT_DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
2001-10-03 14:41:53 +00:00
|
|
|
|
|
|
|
float monitor_aspect=4.0/3.0;
|
|
|
|
|
2001-10-18 02:42:20 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-03 14:41:53 +00:00
|
|
|
/* aspect is called with the source resolution and the
|
|
|
|
* resolution, that the scaled image should fit into
|
|
|
|
*/
|
|
|
|
|
2001-10-18 02:42:20 +00:00
|
|
|
void aspect(int *srcw, int *srch, int zoom){
|
|
|
|
int tmpw;
|
|
|
|
|
2001-10-04 11:42:21 +00:00
|
|
|
#ifdef ASPECT_DEBUG
|
2001-10-18 02:42:20 +00:00
|
|
|
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);
|
2001-10-04 11:42:21 +00:00
|
|
|
#endif
|
2001-10-18 02:42:20 +00:00
|
|
|
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
|
2001-10-04 11:42:21 +00:00
|
|
|
#ifdef ASPECT_DEBUG
|
2001-10-18 02:42:20 +00:00
|
|
|
printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
|
2001-10-04 11:42:21 +00:00
|
|
|
#endif
|
2001-10-18 02:42:20 +00:00
|
|
|
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
|
2001-10-15 17:22:41 +00:00
|
|
|
}
|
2001-10-03 14:41:53 +00:00
|
|
|
}
|
2001-10-04 11:42:21 +00:00
|
|
|
#ifdef ASPECT_DEBUG
|
2001-10-18 02:42:20 +00:00
|
|
|
printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
|
2001-10-04 11:42:21 +00:00
|
|
|
#endif
|
2001-10-03 14:41:53 +00:00
|
|
|
}
|
|
|
|
|