1 /*
2 * Copyright (C) 2012 British Broadcasting Corporation, All Rights Reserved
3 * Author of de-interlace algorithm: Jim Easterbrook for BBC R&D
4 * Based on the process described by Martin Weston for BBC R&D
5 * Author of FFmpeg filter: Mark Himsley for BBC Broadcast Systems Development
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
32
35 int filter;
///< 0 is simple, 1 is more complex
36 int deint;
///< which frames to deinterlace
37 int linesize[4];
///< bytes of pixel data per line for each plane
39 int field;
///< which field are we on, 0 or 1
45
46 #define OFFSET(x) offsetof(W3FDIFContext, x)
47 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
48 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, unit }
49
55 CONST(
"all",
"deinterlace all frames", 0,
"deint"),
56 CONST(
"interlaced",
"only deinterlace frames marked as interlaced", 1,
"deint"),
58 };
59
61
63 {
75 };
76
78
79 return 0;
80 }
81
83 {
87
90
93
98
99 return 0;
100 }
101
103 {
105
111
112 return 0;
113 }
114
115 /*
116 * Filter coefficients from PH-2071, scaled by 256 * 256.
117 * Each set of coefficients has a set for low-frequencies and high-frequencies.
118 * n_coef_lf[] and n_coef_hf[] are the number of coefs for simple and more-complex.
119 * It is important for later that n_coef_lf[] is even and n_coef_hf[] is odd.
120 * coef_lf[][] and coef_hf[][] are the coefficients for low-frequencies
121 * and high-frequencies for simple and more-complex mode.
122 */
125 { -1704, 34472, 34472, -1704}};
128 { 2032, -7602, 11140, -7602, 2032}};
129
132 const int filter,
const int plane)
133 {
135 uint8_t *in_line, *in_lines_cur[5], *in_lines_adj[5];
137 int32_t *work_line, *work_pixel;
141 const int linesize = s->
linesize[plane];
143 const int cur_line_stride = cur->
linesize[plane];
144 const int adj_line_stride = adj->
linesize[plane];
145 const int dst_line_stride = out->
linesize[plane];
146 int i, j, y_in, y_out;
147
148 /* copy unchanged the lines of the field */
150
151 in_line = cur_data + (y_out * cur_line_stride);
152 out_line = dst_data + (y_out * dst_line_stride);
153
154 while (y_out < height) {
155 memcpy(out_line, in_line, linesize);
156 y_out += 2;
157 in_line += cur_line_stride * 2;
158 out_line += dst_line_stride * 2;
159 }
160
161 /* interpolate other lines of the field */
163
164 out_line = dst_data + (y_out * dst_line_stride);
165
166 while (y_out < height) {
167 /* clear workspace */
169
170 /* get low vertical frequencies from current field */
172 y_in = (y_out + 1) + (j * 2) - n_coef_lf[
filter];
173
174 while (y_in < 0)
175 y_in += 2;
176 while (y_in >= height)
177 y_in -= 2;
178
179 in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
180 }
181
183 switch (n_coef_lf[filter]) {
184 case 2:
185 for (i = 0; i < linesize; i++) {
187 *work_line++ += *in_lines_cur[1]++ * coef_lf[
filter][1];
188 }
189 break;
190 case 4:
191 for (i = 0; i < linesize; i++) {
193 *work_line += *in_lines_cur[1]++ * coef_lf[
filter][1];
194 *work_line += *in_lines_cur[2]++ * coef_lf[
filter][2];
195 *work_line++ += *in_lines_cur[3]++ * coef_lf[
filter][3];
196 }
197 }
198
199 /* get high vertical frequencies from adjacent fields */
201 y_in = (y_out + 1) + (j * 2) - n_coef_hf[
filter];
202
203 while (y_in < 0)
204 y_in += 2;
205 while (y_in >= height)
206 y_in -= 2;
207
208 in_lines_cur[j] = cur_data + (y_in * cur_line_stride);
209 in_lines_adj[j] = adj_data + (y_in * adj_line_stride);
210 }
211
213 switch (n_coef_hf[filter]) {
214 case 3:
215 for (i = 0; i < linesize; i++) {
217 *work_line += *in_lines_adj[0]++ * coef_hf[
filter][0];
218 *work_line += *in_lines_cur[1]++ * coef_hf[
filter][1];
219 *work_line += *in_lines_adj[1]++ * coef_hf[
filter][1];
220 *work_line += *in_lines_cur[2]++ * coef_hf[
filter][2];
221 *work_line++ += *in_lines_adj[2]++ * coef_hf[
filter][2];
222 }
223 break;
224 case 5:
225 for (i = 0; i < linesize; i++) {
227 *work_line += *in_lines_adj[0]++ * coef_hf[
filter][0];
228 *work_line += *in_lines_cur[1]++ * coef_hf[
filter][1];
229 *work_line += *in_lines_adj[1]++ * coef_hf[
filter][1];
230 *work_line += *in_lines_cur[2]++ * coef_hf[
filter][2];
231 *work_line += *in_lines_adj[2]++ * coef_hf[
filter][2];
232 *work_line += *in_lines_cur[3]++ * coef_hf[
filter][3];
233 *work_line += *in_lines_adj[3]++ * coef_hf[
filter][3];
234 *work_line += *in_lines_cur[4]++ * coef_hf[
filter][4];
235 *work_line++ += *in_lines_adj[4]++ * coef_hf[
filter][4];
236 }
237 }
238
239 /* save scaled result to the output frame, scaling down by 256 * 256 */
241 out_pixel = out_line;
242
243 for (j = 0; j < linesize; j++, out_pixel++, work_pixel++)
244 *out_pixel = av_clip(*work_pixel, 0, 255 * 256 * 256) >> 16;
245
246 /* move on to next line */
247 y_out += 2;
248 out_line += dst_line_stride * 2;
249 }
250 }
251
253 {
257 int plane;
258
260 if (!out)
264
265 if (!is_second) {
268 } else {
269 int64_t cur_pts = s->
cur->
pts;
270 int64_t next_pts = s->
next->
pts;
271
273 out->
pts = cur_pts + next_pts;
274 } else {
276 }
277 }
278
280 for (plane = 0; plane < s->
nb_planes; plane++)
282
284
286 }
287
289 {
293
298
303 }
304
307 if (!out)
309
314 }
315
317 return 0;
318
320 if (ret < 0)
322
324 }
325
327 {
330
331 do {
333
336
338
341 if (!next)
346 } else if (ret < 0) {
348 }
350
351 return 0;
352 }
353
355 {
357
362 }
363
365 {
370 },
372 };
373
375 {
380 },
382 };
383
388 .priv_class = &w3fdif_class,
394 };