annotate libmpcodecs/vf_dsize.c @ 30738:25622198a15a

Make -slave also work with the normal console on Windows.
author reimar
date Sat, 27 Feb 2010 23:12:34 +0000
parents a972c1a4a012
children 7af3e6f901fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 25221
diff changeset
18
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
19 #include <stdio.h>
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
20 #include <stdlib.h>
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
21 #include <string.h>
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
22 #include <inttypes.h>
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
23
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16040
diff changeset
24 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16040
diff changeset
25 #include "mp_msg.h"
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
26
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
27 #include "img_format.h"
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
28 #include "mp_image.h"
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
29 #include "vf.h"
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
30
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
31 struct vf_priv_s {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
32 int w, h;
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
33 int method; // aspect method, 0 -> downscale, 1-> upscale. +2 -> original aspect.
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
34 int round;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
35 float aspect;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
36 };
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
37
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
38 static int config(struct vf_instance *vf,
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
39 int width, int height, int d_width, int d_height,
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
40 unsigned int flags, unsigned int outfmt)
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
41 {
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
42 if (vf->priv->aspect < 0.001) { // did the user input aspect or w,h params
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
43 if (vf->priv->w == 0) vf->priv->w = d_width;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
44 if (vf->priv->h == 0) vf->priv->h = d_height;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
45 if (vf->priv->w == -1) vf->priv->w = width;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
46 if (vf->priv->h == -1) vf->priv->h = height;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
47 if (vf->priv->w == -2) vf->priv->w = vf->priv->h * (double)d_width / d_height;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
48 if (vf->priv->w == -3) vf->priv->w = vf->priv->h * (double)width / height;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
49 if (vf->priv->h == -2) vf->priv->h = vf->priv->w * (double)d_height / d_width;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
50 if (vf->priv->h == -3) vf->priv->h = vf->priv->w * (double)height / width;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
51 if (vf->priv->method > -1) {
17227
c2b50fc5d86a I screwed up keep aspect param, made behavior the opposite of man page.
ods15
parents: 17012
diff changeset
52 double aspect = (vf->priv->method & 2) ? ((double)height / width) : ((double)d_height / d_width);
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
53 if ((vf->priv->h > vf->priv->w * aspect) ^ (vf->priv->method & 1)) {
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
54 vf->priv->h = vf->priv->w * aspect;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
55 } else {
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
56 vf->priv->w = vf->priv->h / aspect;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
57 }
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
58 }
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
59 if (vf->priv->round > 1) { // round up
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
60 vf->priv->w += (vf->priv->round - 1 - (vf->priv->w - 1) % vf->priv->round);
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
61 vf->priv->h += (vf->priv->round - 1 - (vf->priv->h - 1) % vf->priv->round);
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
62 }
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
63 d_width = vf->priv->w;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
64 d_height = vf->priv->h;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
65 } else {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
66 if (vf->priv->aspect * height > width) {
18390
f9b0c8fe997e fix float rounding error
ods15
parents: 17227
diff changeset
67 d_width = height * vf->priv->aspect + .5;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
68 d_height = height;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
69 } else {
18390
f9b0c8fe997e fix float rounding error
ods15
parents: 17227
diff changeset
70 d_height = width / vf->priv->aspect + .5;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
71 d_width = width;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
72 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
73 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
74 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
75 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
76
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
77 static void uninit(vf_instance_t *vf) {
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
78 free(vf->priv);
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
79 vf->priv = NULL;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
80 }
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
81
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30633
diff changeset
82 static int vf_open(vf_instance_t *vf, char *args)
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
83 {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
84 vf->config = config;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
85 vf->draw_slice = vf_next_draw_slice;
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
86 vf->uninit = uninit;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
87 //vf->default_caps = 0;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
88 vf->priv = calloc(sizeof(struct vf_priv_s), 1);
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
89 vf->priv->aspect = 0.;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
90 vf->priv->w = -1;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
91 vf->priv->h = -1;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
92 vf->priv->method = -1;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
93 vf->priv->round = 1;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
94 if (args) {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
95 if (strchr(args, '/')) {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
96 int w, h;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
97 sscanf(args, "%d/%d", &w, &h);
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
98 vf->priv->aspect = (float)w/h;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
99 } else if (strchr(args, '.')) {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
100 sscanf(args, "%f", &vf->priv->aspect);
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
101 } else {
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
102 sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->method, &vf->priv->round);
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
103 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
104 }
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
105 if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) ||
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
106 ((vf->priv->w < -1) && (vf->priv->h < -1)) ||
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
107 (vf->priv->method < -1) || (vf->priv->method > 3) ||
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
108 (vf->priv->round < 0)) {
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
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);
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
110 free(vf->priv); vf->priv = NULL;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
111 return -1;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
112 }
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
113 return 1;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
114 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
115
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 18390
diff changeset
116 const vf_info_t vf_info_dsize = {
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
117 "reset displaysize/aspect",
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
118 "dsize",
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
119 "Rich Felker",
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
120 "",
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30633
diff changeset
121 vf_open,
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
122 NULL
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
123 };