1 /*
2 * Copyright (c) 2007 Bobby Bingham
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdint.h>
26
28 "in_w", "iw",
29 "in_h", "ih",
30 "out_w", "ow",
31 "out_h", "oh",
32 "a",
33 "sar",
34 "dar",
35 "hsub",
36 "vsub",
37 "ohsub",
38 "ovsub",
40 };
41
55 };
56
58 const char *w_expr, const char *h_expr,
60 int *ret_w, int *ret_h)
61 {
64 const char *expr;
65 int eval_w, eval_h;
67 double var_values[
VARS_NB], res;
68
75 (
double)
inlink->sample_aspect_ratio.num /
inlink->sample_aspect_ratio.den : 1;
81
82 /* evaluate width and height */
87
93 /* evaluate again the width, as it may depend on the output height */
98 eval_w = (int) res == 0 ?
inlink->w : (
int) res;
99
100 *ret_w = eval_w;
101 *ret_h = eval_h;
102
103 return 0;
104
107 "Error when evaluating the expression '%s'.\n"
108 "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
109 expr, w_expr, h_expr);
111 }
112
114 int *ret_w, int *ret_h,
115 int force_original_aspect_ratio, int force_divisible_by,
116 double w_adj)
117 {
119 int factor_w, factor_h;
120
123
124 /* Check if it is requested that the result has to be divisible by some
125 * factor (w or h = -n with n being the factor). */
126 factor_w = 1;
127 factor_h = 1;
130 }
133 }
134
135 if (
w < 0 &&
h < 0) {
138 }
139
140 /* Make sure that the result is divisible by the factor we determined
141 * earlier. If no factor was set, nothing will happen as the default
142 * factor is 1 */
147
148 /* Note that force_original_aspect_ratio may overwrite the previous set
149 * dimensions so that it is not divisible by the set factors anymore
150 * unless force_divisible_by is defined as well */
152 // Including force_divisible_by here rounds to the nearest multiple of it.
154 * force_divisible_by;
156 * force_divisible_by;
157
161 if (force_divisible_by > 1) {
162 // round down in case provided w or h is not divisible.
163 w =
w / force_divisible_by * force_divisible_by;
164 h =
h / force_divisible_by * force_divisible_by;
165 }
166 } else { // SCALE_FORCE_OAR_INCREASE
169 if (force_divisible_by > 1) {
170 // round up in case provided w or h is not divisible.
171 w = (
w + force_divisible_by - 1) / force_divisible_by * force_divisible_by;
172 h = (
h + force_divisible_by - 1) / force_divisible_by * force_divisible_by;
173 }
174 }
175 }
176
179
182
183 return 0;
184 }