Mercurial > mplayer.hg
comparison libvo/geometry.c @ 8745:93f78fb709e6
Added support for X style -geometry options (adapted from Henk's patch)
-- Mark
author | mark |
---|---|
date | Fri, 03 Jan 2003 20:46:44 +0000 |
parents | 772d6d27fd66 |
children | e497d7e42d8a |
comparison
equal
deleted
inserted
replaced
8744:f3c6f022d6b0 | 8745:93f78fb709e6 |
---|---|
2 | 2 |
3 #include "geometry.h" | 3 #include "geometry.h" |
4 #include "../mp_msg.h" | 4 #include "../mp_msg.h" |
5 #include "../mplayer.h" /* exit_player() */ | 5 #include "../mplayer.h" /* exit_player() */ |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdlib.h> /* strtol */ | |
8 | 7 |
9 /* A string of the form xpos[%]:ypos[%] */ | 8 /* A string of the form [WxH][+X+Y] or xpos[%]:ypos[%] */ |
10 char *vo_geometry = NULL; | 9 char *vo_geometry = NULL; |
11 | 10 |
12 int geometry_error() | 11 int geometry_error() |
13 { | 12 { |
14 mp_msg(MSGT_VO, MSGL_ERR, "-geometry option format incorrect (%s)\n", vo_geometry); | 13 mp_msg(MSGT_VO, MSGL_ERR, "-geometry must be in [WxH][+X+Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry); |
15 exit_player(NULL); /* ????? what else could we do ? */ | 14 exit_player(NULL); /* ????? what else could we do ? */ |
16 return 0; | 15 return 0; |
17 } | 16 } |
18 | 17 |
19 int get_num(char *s, int *num, char *end) | 18 // A little kludge as to not to have to update all drivers |
19 // Only the vo_xv driver supports now the full [WxH][+X+Y] option | |
20 int geometryFull(int *pwidth, int *pheight, int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh) | |
20 { | 21 { |
21 char *e; | 22 int width, height, xoff, yoff, xper, yper; |
22 long int t; | |
23 | 23 |
24 t = strtol(s, &e, 10); | 24 width = height = xoff = yoff = xper = yper = -1; |
25 | 25 |
26 if(e != end) | 26 /* no need to save a few extra cpu cycles here ;) */ |
27 return 0; | 27 /* PUKE i will rewrite this code sometime maybe - euck but it works */ |
28 if(vo_geometry != NULL) { | |
29 if(sscanf(vo_geometry, "%ix%i+%i+%i", &width, &height, &xoff, &yoff) != 4 && | |
30 sscanf(vo_geometry, "%ix%i", &width, &height) != 2 && | |
31 sscanf(vo_geometry, "+%i+%i", &xoff, &yoff) != 2 && | |
32 sscanf(vo_geometry, "%i:%i", &xoff, &yoff) != 2 && | |
33 sscanf(vo_geometry, "%i:%i%%", &xper, &yper) != 2 && | |
34 sscanf(vo_geometry, "%i%%:%i", &xper, &yper) != 2 && | |
35 sscanf(vo_geometry, "%i%%:%i%%", &xper, &yper) != 2 && | |
36 sscanf(vo_geometry, "%i%%", &xper) != 1) | |
37 return geometry_error(); | |
38 } | |
28 | 39 |
29 *num = t; | 40 if(xper >= 0 && xper <= 100) xoff = (scrw - vidw) * ((float)xper / 100.0); |
41 if(yper >= 0 && yper <= 100) yoff = (scrh - vidh) * ((float)yper / 100.0); | |
42 | |
43 /* FIXME: better checking of bounds... */ | |
44 if(width < 0 || width > scrw) width = vidw; | |
45 if(height < 0 || height > scrh) height = vidh; | |
46 if(xoff < 0 || xoff + vidw > scrw) xoff = 0; | |
47 if(yoff < 0 || yoff + vidh > scrh) yoff = 0; | |
48 | |
49 if(xpos) *xpos = xoff; | |
50 if(ypos) *ypos = yoff; | |
51 if(pwidth) *pwidth = width; | |
52 if(pheight) *pheight = height; | |
30 return 1; | 53 return 1; |
31 } | 54 } |
32 | 55 |
33 int geometry(int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh, int fs) | 56 // compatibility function |
57 // only libvo working with full geometry options. | |
58 int geometry(int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh) | |
34 { | 59 { |
35 int xper = 0, yper = 0; | 60 return geometryFull(NULL, NULL, xpos, ypos, scrw, scrh, vidw, vidh); |
36 int glen; | |
37 char *colpos; | |
38 | |
39 *xpos = 0; *ypos = 0; | |
40 | |
41 if(vo_geometry == NULL) | |
42 return 1; | |
43 | |
44 glen = strlen(vo_geometry); | |
45 colpos = strchr(vo_geometry, ':'); | |
46 if(colpos == NULL) | |
47 colpos = (char *)(vo_geometry + glen); | |
48 | |
49 /* Parse the x bit */ | |
50 if(colpos[-1] == '%') { | |
51 if(!get_num(vo_geometry, &xper, colpos - 1)) | |
52 return geometry_error(); | |
53 } else { | |
54 if(!get_num(vo_geometry, xpos, colpos)) | |
55 return geometry_error(); | |
56 } | |
57 | |
58 if(*colpos != '\0') { | |
59 if(vo_geometry[glen - 1] == '%') { | |
60 if(!get_num(colpos + 1, &yper, vo_geometry + glen - 1)) | |
61 return geometry_error(); | |
62 } else { | |
63 if(!get_num(colpos + 1, ypos, vo_geometry + glen)) | |
64 return geometry_error(); | |
65 } | |
66 } | |
67 | |
68 if(xper) | |
69 *xpos = (scrw - vidw) * ((float)xper / 100.0); | |
70 if(yper) | |
71 *ypos = (scrh - vidh) * ((float)yper / 100.0); | |
72 | |
73 if(*xpos + vidw > scrw) { | |
74 mp_msg(MSGT_VO, MSGL_ERR, "X position is too large\n"); | |
75 return geometry_error(); | |
76 } | |
77 if(*ypos + vidh > scrh) { | |
78 mp_msg(MSGT_VO, MSGL_ERR, "Y position is too large\n"); | |
79 return geometry_error(); | |
80 } | |
81 | |
82 return 1; | |
83 } | 61 } |