summaryrefslogtreecommitdiffstats
path: root/libvo/aspect.c
blob: 42f3d8a3405947146a3960f39283595a1f3eda8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* Stuff for correct aspect scaling. */
//#define ASPECT_DEBUG

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

float monitor_aspect=4.0/3.0;

/* 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;
#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);
#endif
  srchcp=(int)(((float)fitinw / (float)*srcw * (float)*srch)
            * ((float)fitinh / ((float)fitinw / monitor_aspect)));
  srchcp+=srchcp%2; // round
#ifdef ASPECT_DEBUG
  printf("aspect(2) wh: %dx%d (org: %dx%d)\n",srcwcp,srchcp,*srcw,*srch);
#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
    }
  }
#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);
#endif
}