1 /*
2 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3 * Copyright (c) 2012 Jeremy Tran
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 /**
23 * @file
24 * Apply a smartblur filter to the input video
25 * Ported from MPlayer libmpcodecs/vf_smartblur.c by Michael Niedermayer.
26 */
27
31
35
36 #define RADIUS_MIN 0.1
37 #define RADIUS_MAX 5.0
38
39 #define STRENGTH_MIN -1.0
40 #define STRENGTH_MAX 1.0
41
42 #define THRESHOLD_MIN -30
43 #define THRESHOLD_MAX 30
44
45 typedef struct {
46 float radius;
47 float strength;
49 float quality;
52
61
62 #define OFFSET(x) offsetof(SmartblurContext, x)
63 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
64
72
79
80 { NULL }
81 };
82
84
86 {
88
89 /* make chroma default to luma values, if not explicitly set */
96
99
101 "luma_radius:%f luma_strength:%f luma_threshold:%d "
102 "chroma_radius:%f chroma_strength:%f chroma_threshold:%d\n",
105
106 return 0;
107 }
108
110 {
112
115 }
116
118 {
125 };
126
128
129 return 0;
130 }
131
133 {
136
138
139 if (!vec)
141
144 sws_filter.
lumH = sws_filter.
lumV = vec;
145 sws_filter.
chrH = sws_filter.
chrV = NULL;
149 flags, &sws_filter, NULL, NULL);
150
152
155
156 return 0;
157 }
158
160 {
163
166
172
173 return 0;
174 }
175
178 const int w, const int h, const int threshold,
180 {
182 int orig, filtered;
184 /* Declare arrays of 4 to get aligned data */
185 const uint8_t*
const src_array[4] = {src};
187 int src_linesize_array[4] = {src_linesize};
188 int dst_linesize_array[4] = {dst_linesize};
189
190 sws_scale(filter_context, src_array, src_linesize_array,
191 0, h, dst_array, dst_linesize_array);
192
193 if (threshold > 0) {
194 for (y = 0; y < h; ++
y) {
195 for (x = 0; x < w; ++x) {
196 orig = src[x + y * src_linesize];
197 filtered = dst[x + y * dst_linesize];
198 diff = orig - filtered;
199
200 if (diff > 0) {
201 if (diff > 2 * threshold)
202 dst[x + y * dst_linesize] = orig;
203 else if (diff > threshold)
204 /* add 'diff' and substract 'threshold' from 'filtered' */
205 dst[x + y * dst_linesize] = orig - threshold;
206 } else {
207 if (-diff > 2 * threshold)
208 dst[x + y * dst_linesize] = orig;
209 else if (-diff > threshold)
210 /* add 'diff' and 'threshold' to 'filtered' */
211 dst[x + y * dst_linesize] = orig + threshold;
212 }
213 }
214 }
215 } else if (threshold < 0) {
216 for (y = 0; y < h; ++
y) {
217 for (x = 0; x < w; ++x) {
218 orig = src[x + y * src_linesize];
219 filtered = dst[x + y * dst_linesize];
220 diff = orig - filtered;
221
222 if (diff > 0) {
223 if (diff <= -threshold)
224 dst[x + y * dst_linesize] = orig;
225 else if (diff <= -2 * threshold)
226 /* substract 'diff' and 'threshold' from 'orig' */
227 dst[x + y * dst_linesize] = filtered - threshold;
228 } else {
229 if (diff >= threshold)
230 dst[x + y * dst_linesize] = orig;
231 else if (diff >= 2 * threshold)
232 /* add 'threshold' and substract 'diff' from 'orig' */
233 dst[x + y * dst_linesize] = filtered + threshold;
234 }
235 }
236 }
237 }
238 }
239
241 {
247
249 if (!outpic) {
252 }
254
259
260 if (inpic->
data[2]) {
269 }
270
273 }
274
276 {
281 },
282 { NULL }
283 };
284
286 {
289 },
290 { NULL }
291 };
292
296
298
302 .
inputs = smartblur_inputs,
304 .priv_class = &smartblur_class,
306 };