Mercurial > mplayer.hg
comparison libmpcodecs/vf_dsize.c @ 32702:7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
author | cehoyos |
---|---|
date | Fri, 14 Jan 2011 22:10:21 +0000 |
parents | a972c1a4a012 |
children |
comparison
equal
deleted
inserted
replaced
32701:02bc7c860503 | 32702:7af3e6f901fd |
---|---|
27 #include "img_format.h" | 27 #include "img_format.h" |
28 #include "mp_image.h" | 28 #include "mp_image.h" |
29 #include "vf.h" | 29 #include "vf.h" |
30 | 30 |
31 struct vf_priv_s { | 31 struct vf_priv_s { |
32 int w, h; | 32 int w, h; |
33 int method; // aspect method, 0 -> downscale, 1-> upscale. +2 -> original aspect. | 33 int method; // aspect method, 0 -> downscale, 1-> upscale. +2 -> original aspect. |
34 int round; | 34 int round; |
35 float aspect; | 35 float aspect; |
36 }; | 36 }; |
37 | 37 |
38 static int config(struct vf_instance *vf, | 38 static int config(struct vf_instance *vf, |
39 int width, int height, int d_width, int d_height, | 39 int width, int height, int d_width, int d_height, |
40 unsigned int flags, unsigned int outfmt) | 40 unsigned int flags, unsigned int outfmt) |
41 { | 41 { |
42 if (vf->priv->aspect < 0.001) { // did the user input aspect or w,h params | 42 if (vf->priv->aspect < 0.001) { // did the user input aspect or w,h params |
43 if (vf->priv->w == 0) vf->priv->w = d_width; | 43 if (vf->priv->w == 0) vf->priv->w = d_width; |
44 if (vf->priv->h == 0) vf->priv->h = d_height; | 44 if (vf->priv->h == 0) vf->priv->h = d_height; |
45 if (vf->priv->w == -1) vf->priv->w = width; | 45 if (vf->priv->w == -1) vf->priv->w = width; |
46 if (vf->priv->h == -1) vf->priv->h = height; | 46 if (vf->priv->h == -1) vf->priv->h = height; |
47 if (vf->priv->w == -2) vf->priv->w = vf->priv->h * (double)d_width / d_height; | 47 if (vf->priv->w == -2) vf->priv->w = vf->priv->h * (double)d_width / d_height; |
48 if (vf->priv->w == -3) vf->priv->w = vf->priv->h * (double)width / height; | 48 if (vf->priv->w == -3) vf->priv->w = vf->priv->h * (double)width / height; |
49 if (vf->priv->h == -2) vf->priv->h = vf->priv->w * (double)d_height / d_width; | 49 if (vf->priv->h == -2) vf->priv->h = vf->priv->w * (double)d_height / d_width; |
50 if (vf->priv->h == -3) vf->priv->h = vf->priv->w * (double)height / width; | 50 if (vf->priv->h == -3) vf->priv->h = vf->priv->w * (double)height / width; |
51 if (vf->priv->method > -1) { | 51 if (vf->priv->method > -1) { |
52 double aspect = (vf->priv->method & 2) ? ((double)height / width) : ((double)d_height / d_width); | 52 double aspect = (vf->priv->method & 2) ? ((double)height / width) : ((double)d_height / d_width); |
53 if ((vf->priv->h > vf->priv->w * aspect) ^ (vf->priv->method & 1)) { | 53 if ((vf->priv->h > vf->priv->w * aspect) ^ (vf->priv->method & 1)) { |
54 vf->priv->h = vf->priv->w * aspect; | 54 vf->priv->h = vf->priv->w * aspect; |
55 } else { | 55 } else { |
56 vf->priv->w = vf->priv->h / aspect; | 56 vf->priv->w = vf->priv->h / aspect; |
57 } | 57 } |
58 } | 58 } |
59 if (vf->priv->round > 1) { // round up | 59 if (vf->priv->round > 1) { // round up |
60 vf->priv->w += (vf->priv->round - 1 - (vf->priv->w - 1) % vf->priv->round); | 60 vf->priv->w += (vf->priv->round - 1 - (vf->priv->w - 1) % vf->priv->round); |
61 vf->priv->h += (vf->priv->round - 1 - (vf->priv->h - 1) % vf->priv->round); | 61 vf->priv->h += (vf->priv->round - 1 - (vf->priv->h - 1) % vf->priv->round); |
62 } | 62 } |
63 d_width = vf->priv->w; | 63 d_width = vf->priv->w; |
64 d_height = vf->priv->h; | 64 d_height = vf->priv->h; |
65 } else { | 65 } else { |
66 if (vf->priv->aspect * height > width) { | 66 if (vf->priv->aspect * height > width) { |
67 d_width = height * vf->priv->aspect + .5; | 67 d_width = height * vf->priv->aspect + .5; |
68 d_height = height; | 68 d_height = height; |
69 } else { | 69 } else { |
70 d_height = width / vf->priv->aspect + .5; | 70 d_height = width / vf->priv->aspect + .5; |
71 d_width = width; | 71 d_width = width; |
72 } | 72 } |
73 } | 73 } |
74 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); | 74 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); |
75 } | 75 } |
76 | 76 |
77 static void uninit(vf_instance_t *vf) { | 77 static void uninit(vf_instance_t *vf) { |
78 free(vf->priv); | 78 free(vf->priv); |
79 vf->priv = NULL; | 79 vf->priv = NULL; |
80 } | 80 } |
81 | 81 |
82 static int vf_open(vf_instance_t *vf, char *args) | 82 static int vf_open(vf_instance_t *vf, char *args) |
83 { | 83 { |
84 vf->config = config; | 84 vf->config = config; |
85 vf->draw_slice = vf_next_draw_slice; | 85 vf->draw_slice = vf_next_draw_slice; |
86 vf->uninit = uninit; | 86 vf->uninit = uninit; |
87 //vf->default_caps = 0; | 87 //vf->default_caps = 0; |
88 vf->priv = calloc(sizeof(struct vf_priv_s), 1); | 88 vf->priv = calloc(sizeof(struct vf_priv_s), 1); |
89 vf->priv->aspect = 0.; | 89 vf->priv->aspect = 0.; |
90 vf->priv->w = -1; | 90 vf->priv->w = -1; |
91 vf->priv->h = -1; | 91 vf->priv->h = -1; |
92 vf->priv->method = -1; | 92 vf->priv->method = -1; |
93 vf->priv->round = 1; | 93 vf->priv->round = 1; |
94 if (args) { | 94 if (args) { |
95 if (strchr(args, '/')) { | 95 if (strchr(args, '/')) { |
96 int w, h; | 96 int w, h; |
97 sscanf(args, "%d/%d", &w, &h); | 97 sscanf(args, "%d/%d", &w, &h); |
98 vf->priv->aspect = (float)w/h; | 98 vf->priv->aspect = (float)w/h; |
99 } else if (strchr(args, '.')) { | 99 } else if (strchr(args, '.')) { |
100 sscanf(args, "%f", &vf->priv->aspect); | 100 sscanf(args, "%f", &vf->priv->aspect); |
101 } else { | 101 } else { |
102 sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->method, &vf->priv->round); | 102 sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->method, &vf->priv->round); |
103 } | 103 } |
104 } | 104 } |
105 if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) || | 105 if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) || |
106 ((vf->priv->w < -1) && (vf->priv->h < -1)) || | 106 ((vf->priv->w < -1) && (vf->priv->h < -1)) || |
107 (vf->priv->method < -1) || (vf->priv->method > 3) || | 107 (vf->priv->method < -1) || (vf->priv->method > 3) || |
108 (vf->priv->round < 0)) { | 108 (vf->priv->round < 0)) { |
109 mp_msg(MSGT_VFILTER, MSGL_ERR, "[dsize] Illegal value(s): aspect: %f w: %d h: %d aspect_method: %d round: %d\n", vf->priv->aspect, vf->priv->w, vf->priv->h, vf->priv->method, vf->priv->round); | 109 mp_msg(MSGT_VFILTER, MSGL_ERR, "[dsize] Illegal value(s): aspect: %f w: %d h: %d aspect_method: %d round: %d\n", vf->priv->aspect, vf->priv->w, vf->priv->h, vf->priv->method, vf->priv->round); |
110 free(vf->priv); vf->priv = NULL; | 110 free(vf->priv); vf->priv = NULL; |
111 return -1; | 111 return -1; |
112 } | 112 } |
113 return 1; | 113 return 1; |
114 } | 114 } |
115 | 115 |
116 const vf_info_t vf_info_dsize = { | 116 const vf_info_t vf_info_dsize = { |
117 "reset displaysize/aspect", | 117 "reset displaysize/aspect", |
118 "dsize", | 118 "dsize", |