LCOV - code coverage report
Current view: top level - libavfilter - vf_bwdif.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 247 0.0 %
Date: 2017-12-10 21:22:29 Functions: 0 16 0.0 %

          Line data    Source code
       1             : /*
       2             :  * BobWeaver Deinterlacing Filter
       3             :  * Copyright (C) 2016 Thomas Mundt <loudmax@yahoo.de>
       4             :  *
       5             :  * Based on YADIF (Yet Another Deinterlacing Filter)
       6             :  * Copyright (C) 2006-2011 Michael Niedermayer <michaelni@gmx.at>
       7             :  *               2010      James Darnley <james.darnley@gmail.com>
       8             :  *
       9             :  * With use of Weston 3 Field Deinterlacing Filter algorithm
      10             :  * Copyright (C) 2012 British Broadcasting Corporation, All Rights Reserved
      11             :  * Author of de-interlace algorithm: Jim Easterbrook for BBC R&D
      12             :  * Based on the process described by Martin Weston for BBC R&D
      13             :  *
      14             :  * This file is part of FFmpeg.
      15             :  *
      16             :  * FFmpeg is free software; you can redistribute it and/or
      17             :  * modify it under the terms of the GNU Lesser General Public
      18             :  * License as published by the Free Software Foundation; either
      19             :  * version 2.1 of the License, or (at your option) any later version.
      20             :  *
      21             :  * FFmpeg is distributed in the hope that it will be useful,
      22             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24             :  * Lesser General Public License for more details.
      25             :  *
      26             :  * You should have received a copy of the GNU Lesser General Public
      27             :  * License along with FFmpeg; if not, write to the Free Software
      28             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      29             :  */
      30             : 
      31             : #include "libavutil/avassert.h"
      32             : #include "libavutil/common.h"
      33             : #include "libavutil/opt.h"
      34             : #include "libavutil/pixdesc.h"
      35             : #include "libavutil/imgutils.h"
      36             : #include "avfilter.h"
      37             : #include "formats.h"
      38             : #include "internal.h"
      39             : #include "video.h"
      40             : #include "bwdif.h"
      41             : 
      42             : /*
      43             :  * Filter coefficients coef_lf and coef_hf taken from BBC PH-2071 (Weston 3 Field Deinterlacer).
      44             :  * Used when there is spatial and temporal interpolation.
      45             :  * Filter coefficients coef_sp are used when there is spatial interpolation only.
      46             :  * Adjusted for matching visual sharpness impression of spatial and temporal interpolation.
      47             :  */
      48             : static const uint16_t coef_lf[2] = { 4309, 213 };
      49             : static const uint16_t coef_hf[3] = { 5570, 3801, 1016 };
      50             : static const uint16_t coef_sp[2] = { 5077, 981 };
      51             : 
      52             : typedef struct ThreadData {
      53             :     AVFrame *frame;
      54             :     int plane;
      55             :     int w, h;
      56             :     int parity;
      57             :     int tff;
      58             : } ThreadData;
      59             : 
      60             : #define FILTER_INTRA() \
      61             :     for (x = 0; x < w; x++) { \
      62             :         interpol = (coef_sp[0] * (cur[mrefs] + cur[prefs]) - coef_sp[1] * (cur[mrefs3] + cur[prefs3])) >> 13; \
      63             :         dst[0] = av_clip(interpol, 0, clip_max); \
      64             :  \
      65             :         dst++; \
      66             :         cur++; \
      67             :     }
      68             : 
      69             : #define FILTER1() \
      70             :     for (x = 0; x < w; x++) { \
      71             :         int c = cur[mrefs]; \
      72             :         int d = (prev2[0] + next2[0]) >> 1; \
      73             :         int e = cur[prefs]; \
      74             :         int temporal_diff0 = FFABS(prev2[0] - next2[0]); \
      75             :         int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e)) >> 1; \
      76             :         int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e)) >> 1; \
      77             :         int diff = FFMAX3(temporal_diff0 >> 1, temporal_diff1, temporal_diff2); \
      78             :  \
      79             :         if (!diff) { \
      80             :             dst[0] = d; \
      81             :         } else {
      82             : 
      83             : #define SPAT_CHECK() \
      84             :             int b = ((prev2[mrefs2] + next2[mrefs2]) >> 1) - c; \
      85             :             int f = ((prev2[prefs2] + next2[prefs2]) >> 1) - e; \
      86             :             int dc = d - c; \
      87             :             int de = d - e; \
      88             :             int max = FFMAX3(de, dc, FFMIN(b, f)); \
      89             :             int min = FFMIN3(de, dc, FFMAX(b, f)); \
      90             :             diff = FFMAX3(diff, min, -max);
      91             : 
      92             : #define FILTER_LINE() \
      93             :             SPAT_CHECK() \
      94             :             if (FFABS(c - e) > temporal_diff0) { \
      95             :                 interpol = (((coef_hf[0] * (prev2[0] + next2[0]) \
      96             :                     - coef_hf[1] * (prev2[mrefs2] + next2[mrefs2] + prev2[prefs2] + next2[prefs2]) \
      97             :                     + coef_hf[2] * (prev2[mrefs4] + next2[mrefs4] + prev2[prefs4] + next2[prefs4])) >> 2) \
      98             :                     + coef_lf[0] * (c + e) - coef_lf[1] * (cur[mrefs3] + cur[prefs3])) >> 13; \
      99             :             } else { \
     100             :                 interpol = (coef_sp[0] * (c + e) - coef_sp[1] * (cur[mrefs3] + cur[prefs3])) >> 13; \
     101             :             }
     102             : 
     103             : #define FILTER_EDGE() \
     104             :             if (spat) { \
     105             :                 SPAT_CHECK() \
     106             :             } \
     107             :             interpol = (c + e) >> 1;
     108             : 
     109             : #define FILTER2() \
     110             :             if (interpol > d + diff) \
     111             :                 interpol = d + diff; \
     112             :             else if (interpol < d - diff) \
     113             :                 interpol = d - diff; \
     114             :  \
     115             :             dst[0] = av_clip(interpol, 0, clip_max); \
     116             :         } \
     117             :  \
     118             :         dst++; \
     119             :         cur++; \
     120             :         prev++; \
     121             :         next++; \
     122             :         prev2++; \
     123             :         next2++; \
     124             :     }
     125             : 
     126           0 : static void filter_intra(void *dst1, void *cur1, int w, int prefs, int mrefs,
     127             :                          int prefs3, int mrefs3, int parity, int clip_max)
     128             : {
     129           0 :     uint8_t *dst = dst1;
     130           0 :     uint8_t *cur = cur1;
     131             :     int interpol, x;
     132             : 
     133           0 :     FILTER_INTRA()
     134           0 : }
     135             : 
     136           0 : static void filter_line_c(void *dst1, void *prev1, void *cur1, void *next1,
     137             :                           int w, int prefs, int mrefs, int prefs2, int mrefs2,
     138             :                           int prefs3, int mrefs3, int prefs4, int mrefs4,
     139             :                           int parity, int clip_max)
     140             : {
     141           0 :     uint8_t *dst   = dst1;
     142           0 :     uint8_t *prev  = prev1;
     143           0 :     uint8_t *cur   = cur1;
     144           0 :     uint8_t *next  = next1;
     145           0 :     uint8_t *prev2 = parity ? prev : cur ;
     146           0 :     uint8_t *next2 = parity ? cur  : next;
     147             :     int interpol, x;
     148             : 
     149           0 :     FILTER1()
     150           0 :     FILTER_LINE()
     151           0 :     FILTER2()
     152           0 : }
     153             : 
     154           0 : static void filter_edge(void *dst1, void *prev1, void *cur1, void *next1,
     155             :                         int w, int prefs, int mrefs, int prefs2, int mrefs2,
     156             :                         int parity, int clip_max, int spat)
     157             : {
     158           0 :     uint8_t *dst   = dst1;
     159           0 :     uint8_t *prev  = prev1;
     160           0 :     uint8_t *cur   = cur1;
     161           0 :     uint8_t *next  = next1;
     162           0 :     uint8_t *prev2 = parity ? prev : cur ;
     163           0 :     uint8_t *next2 = parity ? cur  : next;
     164             :     int interpol, x;
     165             : 
     166           0 :     FILTER1()
     167           0 :     FILTER_EDGE()
     168           0 :     FILTER2()
     169           0 : }
     170             : 
     171           0 : static void filter_intra_16bit(void *dst1, void *cur1, int w, int prefs, int mrefs,
     172             :                                int prefs3, int mrefs3, int parity, int clip_max)
     173             : {
     174           0 :     uint16_t *dst = dst1;
     175           0 :     uint16_t *cur = cur1;
     176             :     int interpol, x;
     177             : 
     178           0 :     FILTER_INTRA()
     179           0 : }
     180             : 
     181           0 : static void filter_line_c_16bit(void *dst1, void *prev1, void *cur1, void *next1,
     182             :                                 int w, int prefs, int mrefs, int prefs2, int mrefs2,
     183             :                                 int prefs3, int mrefs3, int prefs4, int mrefs4,
     184             :                                 int parity, int clip_max)
     185             : {
     186           0 :     uint16_t *dst   = dst1;
     187           0 :     uint16_t *prev  = prev1;
     188           0 :     uint16_t *cur   = cur1;
     189           0 :     uint16_t *next  = next1;
     190           0 :     uint16_t *prev2 = parity ? prev : cur ;
     191           0 :     uint16_t *next2 = parity ? cur  : next;
     192             :     int interpol, x;
     193             : 
     194           0 :     FILTER1()
     195           0 :     FILTER_LINE()
     196           0 :     FILTER2()
     197           0 : }
     198             : 
     199           0 : static void filter_edge_16bit(void *dst1, void *prev1, void *cur1, void *next1,
     200             :                               int w, int prefs, int mrefs, int prefs2, int mrefs2,
     201             :                               int parity, int clip_max, int spat)
     202             : {
     203           0 :     uint16_t *dst   = dst1;
     204           0 :     uint16_t *prev  = prev1;
     205           0 :     uint16_t *cur   = cur1;
     206           0 :     uint16_t *next  = next1;
     207           0 :     uint16_t *prev2 = parity ? prev : cur ;
     208           0 :     uint16_t *next2 = parity ? cur  : next;
     209             :     int interpol, x;
     210             : 
     211           0 :     FILTER1()
     212           0 :     FILTER_EDGE()
     213           0 :     FILTER2()
     214           0 : }
     215             : 
     216           0 : static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
     217             : {
     218           0 :     BWDIFContext *s = ctx->priv;
     219           0 :     ThreadData *td  = arg;
     220           0 :     int linesize = s->cur->linesize[td->plane];
     221           0 :     int clip_max = (1 << (s->csp->comp[td->plane].depth)) - 1;
     222           0 :     int df = (s->csp->comp[td->plane].depth + 7) / 8;
     223           0 :     int refs = linesize / df;
     224           0 :     int slice_start = (td->h *  jobnr   ) / nb_jobs;
     225           0 :     int slice_end   = (td->h * (jobnr+1)) / nb_jobs;
     226             :     int y;
     227             : 
     228           0 :     for (y = slice_start; y < slice_end; y++) {
     229           0 :         if ((y ^ td->parity) & 1) {
     230           0 :             uint8_t *prev = &s->prev->data[td->plane][y * linesize];
     231           0 :             uint8_t *cur  = &s->cur ->data[td->plane][y * linesize];
     232           0 :             uint8_t *next = &s->next->data[td->plane][y * linesize];
     233           0 :             uint8_t *dst  = &td->frame->data[td->plane][y * td->frame->linesize[td->plane]];
     234           0 :             if (!s->inter_field) {
     235           0 :                 s->filter_intra(dst, cur, td->w, (y + df) < td->h ? refs : -refs,
     236           0 :                                 y > (df - 1) ? -refs : refs,
     237           0 :                                 (y + 3*df) < td->h ? 3 * refs : -refs,
     238           0 :                                 y > (3*df - 1) ? -3 * refs : refs,
     239           0 :                                 td->parity ^ td->tff, clip_max);
     240           0 :             } else if ((y < 4) || ((y + 5) > td->h)) {
     241           0 :                 s->filter_edge(dst, prev, cur, next, td->w,
     242           0 :                                (y + df) < td->h ? refs : -refs,
     243           0 :                                y > (df - 1) ? -refs : refs,
     244           0 :                                refs << 1, -(refs << 1),
     245           0 :                                td->parity ^ td->tff, clip_max,
     246           0 :                                (y < 2) || ((y + 3) > td->h) ? 0 : 1);
     247             :             } else {
     248           0 :                 s->filter_line(dst, prev, cur, next, td->w,
     249           0 :                                refs, -refs, refs << 1, -(refs << 1),
     250           0 :                                3 * refs, -3 * refs, refs << 2, -(refs << 2),
     251           0 :                                td->parity ^ td->tff, clip_max);
     252             :             }
     253             :         } else {
     254           0 :             memcpy(&td->frame->data[td->plane][y * td->frame->linesize[td->plane]],
     255           0 :                    &s->cur->data[td->plane][y * linesize], td->w * df);
     256             :         }
     257             :     }
     258           0 :     return 0;
     259             : }
     260             : 
     261           0 : static void filter(AVFilterContext *ctx, AVFrame *dstpic,
     262             :                    int parity, int tff)
     263             : {
     264           0 :     BWDIFContext *bwdif = ctx->priv;
     265           0 :     ThreadData td = { .frame = dstpic, .parity = parity, .tff = tff };
     266             :     int i;
     267             : 
     268           0 :     for (i = 0; i < bwdif->csp->nb_components; i++) {
     269           0 :         int w = dstpic->width;
     270           0 :         int h = dstpic->height;
     271             : 
     272           0 :         if (i == 1 || i == 2) {
     273           0 :             w = AV_CEIL_RSHIFT(w, bwdif->csp->log2_chroma_w);
     274           0 :             h = AV_CEIL_RSHIFT(h, bwdif->csp->log2_chroma_h);
     275             :         }
     276             : 
     277           0 :         td.w     = w;
     278           0 :         td.h     = h;
     279           0 :         td.plane = i;
     280             : 
     281           0 :         ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ff_filter_get_nb_threads(ctx)));
     282             :     }
     283           0 :     if (!bwdif->inter_field) {
     284           0 :         bwdif->inter_field = 1;
     285             :     }
     286             : 
     287           0 :     emms_c();
     288           0 : }
     289             : 
     290           0 : static int return_frame(AVFilterContext *ctx, int is_second)
     291             : {
     292           0 :     BWDIFContext *bwdif = ctx->priv;
     293           0 :     AVFilterLink *link  = ctx->outputs[0];
     294             :     int tff, ret;
     295             : 
     296           0 :     if (bwdif->parity == -1) {
     297           0 :         tff = bwdif->cur->interlaced_frame ?
     298           0 :               bwdif->cur->top_field_first : 1;
     299             :     } else {
     300           0 :         tff = bwdif->parity ^ 1;
     301             :     }
     302             : 
     303           0 :     if (is_second) {
     304           0 :         bwdif->out = ff_get_video_buffer(link, link->w, link->h);
     305           0 :         if (!bwdif->out)
     306           0 :             return AVERROR(ENOMEM);
     307             : 
     308           0 :         av_frame_copy_props(bwdif->out, bwdif->cur);
     309           0 :         bwdif->out->interlaced_frame = 0;
     310           0 :         if (bwdif->inter_field < 0)
     311           0 :             bwdif->inter_field = 0;
     312             :     }
     313             : 
     314           0 :     filter(ctx, bwdif->out, tff ^ !is_second, tff);
     315             : 
     316           0 :     if (is_second) {
     317           0 :         int64_t cur_pts  = bwdif->cur->pts;
     318           0 :         int64_t next_pts = bwdif->next->pts;
     319             : 
     320           0 :         if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) {
     321           0 :             bwdif->out->pts = cur_pts + next_pts;
     322             :         } else {
     323           0 :             bwdif->out->pts = AV_NOPTS_VALUE;
     324             :         }
     325             :     }
     326           0 :     ret = ff_filter_frame(ctx->outputs[0], bwdif->out);
     327             : 
     328           0 :     bwdif->frame_pending = (bwdif->mode&1) && !is_second;
     329           0 :     return ret;
     330             : }
     331             : 
     332           0 : static int checkstride(BWDIFContext *bwdif, const AVFrame *a, const AVFrame *b)
     333             : {
     334             :     int i;
     335           0 :     for (i = 0; i < bwdif->csp->nb_components; i++)
     336           0 :         if (a->linesize[i] != b->linesize[i])
     337           0 :             return 1;
     338           0 :     return 0;
     339             : }
     340             : 
     341           0 : static void fixstride(AVFilterLink *link, AVFrame *f)
     342             : {
     343           0 :     AVFrame *dst = ff_default_get_video_buffer(link, f->width, f->height);
     344           0 :     if(!dst)
     345           0 :         return;
     346           0 :     av_frame_copy_props(dst, f);
     347           0 :     av_image_copy(dst->data, dst->linesize,
     348           0 :                   (const uint8_t **)f->data, f->linesize,
     349           0 :                   dst->format, dst->width, dst->height);
     350           0 :     av_frame_unref(f);
     351           0 :     av_frame_move_ref(f, dst);
     352           0 :     av_frame_free(&dst);
     353             : }
     354             : 
     355           0 : static int filter_frame(AVFilterLink *link, AVFrame *frame)
     356             : {
     357           0 :     AVFilterContext *ctx = link->dst;
     358           0 :     BWDIFContext *bwdif = ctx->priv;
     359             : 
     360           0 :     av_assert0(frame);
     361             : 
     362           0 :     if (bwdif->frame_pending)
     363           0 :         return_frame(ctx, 1);
     364             : 
     365           0 :     if (bwdif->prev)
     366           0 :         av_frame_free(&bwdif->prev);
     367           0 :     bwdif->prev = bwdif->cur;
     368           0 :     bwdif->cur  = bwdif->next;
     369           0 :     bwdif->next = frame;
     370             : 
     371           0 :     if (!bwdif->cur) {
     372           0 :         bwdif->cur = av_frame_clone(bwdif->next);
     373           0 :         if (!bwdif->cur)
     374           0 :             return AVERROR(ENOMEM);
     375           0 :         bwdif->inter_field = 0;
     376             :     }
     377             : 
     378           0 :     if (checkstride(bwdif, bwdif->next, bwdif->cur)) {
     379           0 :         av_log(ctx, AV_LOG_VERBOSE, "Reallocating frame due to differing stride\n");
     380           0 :         fixstride(link, bwdif->next);
     381             :     }
     382           0 :     if (checkstride(bwdif, bwdif->next, bwdif->cur))
     383           0 :         fixstride(link, bwdif->cur);
     384           0 :     if (bwdif->prev && checkstride(bwdif, bwdif->next, bwdif->prev))
     385           0 :         fixstride(link, bwdif->prev);
     386           0 :     if (checkstride(bwdif, bwdif->next, bwdif->cur) || (bwdif->prev && checkstride(bwdif, bwdif->next, bwdif->prev))) {
     387           0 :         av_log(ctx, AV_LOG_ERROR, "Failed to reallocate frame\n");
     388           0 :         return -1;
     389             :     }
     390             : 
     391           0 :     if (!bwdif->prev)
     392           0 :         return 0;
     393             : 
     394           0 :     if ((bwdif->deint && !bwdif->cur->interlaced_frame) ||
     395           0 :         ctx->is_disabled ||
     396           0 :         (bwdif->deint && !bwdif->prev->interlaced_frame && bwdif->prev->repeat_pict) ||
     397           0 :         (bwdif->deint && !bwdif->next->interlaced_frame && bwdif->next->repeat_pict)
     398             :     ) {
     399           0 :         bwdif->out  = av_frame_clone(bwdif->cur);
     400           0 :         if (!bwdif->out)
     401           0 :             return AVERROR(ENOMEM);
     402             : 
     403           0 :         av_frame_free(&bwdif->prev);
     404           0 :         if (bwdif->out->pts != AV_NOPTS_VALUE)
     405           0 :             bwdif->out->pts *= 2;
     406           0 :         return ff_filter_frame(ctx->outputs[0], bwdif->out);
     407             :     }
     408             : 
     409           0 :     bwdif->out = ff_get_video_buffer(ctx->outputs[0], link->w, link->h);
     410           0 :     if (!bwdif->out)
     411           0 :         return AVERROR(ENOMEM);
     412             : 
     413           0 :     av_frame_copy_props(bwdif->out, bwdif->cur);
     414           0 :     bwdif->out->interlaced_frame = 0;
     415             : 
     416           0 :     if (bwdif->out->pts != AV_NOPTS_VALUE)
     417           0 :         bwdif->out->pts *= 2;
     418             : 
     419           0 :     return return_frame(ctx, 0);
     420             : }
     421             : 
     422           0 : static int request_frame(AVFilterLink *link)
     423             : {
     424           0 :     AVFilterContext *ctx = link->src;
     425           0 :     BWDIFContext *bwdif = ctx->priv;
     426             :     int ret;
     427             : 
     428           0 :     if (bwdif->frame_pending) {
     429           0 :         return_frame(ctx, 1);
     430           0 :         return 0;
     431             :     }
     432             : 
     433           0 :     if (bwdif->eof)
     434           0 :         return AVERROR_EOF;
     435             : 
     436           0 :     ret  = ff_request_frame(link->src->inputs[0]);
     437             : 
     438           0 :     if (ret == AVERROR_EOF && bwdif->cur) {
     439           0 :         AVFrame *next = av_frame_clone(bwdif->next);
     440             : 
     441           0 :         if (!next)
     442           0 :             return AVERROR(ENOMEM);
     443             : 
     444           0 :         bwdif->inter_field = -1;
     445           0 :         next->pts = bwdif->next->pts * 2 - bwdif->cur->pts;
     446             : 
     447           0 :         filter_frame(link->src->inputs[0], next);
     448           0 :         bwdif->eof = 1;
     449           0 :     } else if (ret < 0) {
     450           0 :         return ret;
     451             :     }
     452             : 
     453           0 :     return 0;
     454             : }
     455             : 
     456           0 : static av_cold void uninit(AVFilterContext *ctx)
     457             : {
     458           0 :     BWDIFContext *bwdif = ctx->priv;
     459             : 
     460           0 :     av_frame_free(&bwdif->prev);
     461           0 :     av_frame_free(&bwdif->cur );
     462           0 :     av_frame_free(&bwdif->next);
     463           0 : }
     464             : 
     465           0 : static int query_formats(AVFilterContext *ctx)
     466             : {
     467             :     static const enum AVPixelFormat pix_fmts[] = {
     468             :         AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV420P,
     469             :         AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
     470             :         AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
     471             :         AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P,
     472             :         AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
     473             :         AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
     474             :         AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12,
     475             :         AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
     476             :         AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
     477             :         AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P,
     478             :         AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9,
     479             :         AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
     480             :         AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
     481             :         AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
     482             :         AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
     483             :         AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP16,
     484             :         AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16,
     485             :         AV_PIX_FMT_NONE
     486             :     };
     487             : 
     488           0 :     AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
     489           0 :     if (!fmts_list)
     490           0 :         return AVERROR(ENOMEM);
     491             : 
     492           0 :     return ff_set_common_formats(ctx, fmts_list);
     493             : }
     494             : 
     495           0 : static int config_props(AVFilterLink *link)
     496             : {
     497           0 :     AVFilterContext *ctx = link->src;
     498           0 :     BWDIFContext *s = link->src->priv;
     499             : 
     500           0 :     link->time_base.num = link->src->inputs[0]->time_base.num;
     501           0 :     link->time_base.den = link->src->inputs[0]->time_base.den * 2;
     502           0 :     link->w             = link->src->inputs[0]->w;
     503           0 :     link->h             = link->src->inputs[0]->h;
     504             : 
     505           0 :     if(s->mode&1)
     506           0 :         link->frame_rate = av_mul_q(link->src->inputs[0]->frame_rate, (AVRational){2,1});
     507             : 
     508           0 :     if (link->w < 3 || link->h < 3) {
     509           0 :         av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
     510           0 :         return AVERROR(EINVAL);
     511             :     }
     512             : 
     513           0 :     s->csp = av_pix_fmt_desc_get(link->format);
     514           0 :     if (s->csp->comp[0].depth > 8) {
     515           0 :         s->filter_intra = filter_intra_16bit;
     516           0 :         s->filter_line  = filter_line_c_16bit;
     517           0 :         s->filter_edge  = filter_edge_16bit;
     518             :     } else {
     519           0 :         s->filter_intra = filter_intra;
     520           0 :         s->filter_line  = filter_line_c;
     521           0 :         s->filter_edge  = filter_edge;
     522             :     }
     523             : 
     524             :     if (ARCH_X86)
     525           0 :         ff_bwdif_init_x86(s);
     526             : 
     527           0 :     return 0;
     528             : }
     529             : 
     530             : 
     531             : #define OFFSET(x) offsetof(BWDIFContext, x)
     532             : #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
     533             : 
     534             : #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }
     535             : 
     536             : static const AVOption bwdif_options[] = {
     537             :     { "mode",   "specify the interlacing mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=BWDIF_MODE_SEND_FIELD}, 0, 1, FLAGS, "mode"},
     538             :     CONST("send_frame", "send one frame for each frame", BWDIF_MODE_SEND_FRAME, "mode"),
     539             :     CONST("send_field", "send one frame for each field", BWDIF_MODE_SEND_FIELD, "mode"),
     540             : 
     541             :     { "parity", "specify the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=BWDIF_PARITY_AUTO}, -1, 1, FLAGS, "parity" },
     542             :     CONST("tff",  "assume top field first",    BWDIF_PARITY_TFF,  "parity"),
     543             :     CONST("bff",  "assume bottom field first", BWDIF_PARITY_BFF,  "parity"),
     544             :     CONST("auto", "auto detect parity",        BWDIF_PARITY_AUTO, "parity"),
     545             : 
     546             :     { "deint", "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=BWDIF_DEINT_ALL}, 0, 1, FLAGS, "deint" },
     547             :     CONST("all",        "deinterlace all frames",                       BWDIF_DEINT_ALL,        "deint"),
     548             :     CONST("interlaced", "only deinterlace frames marked as interlaced", BWDIF_DEINT_INTERLACED, "deint"),
     549             : 
     550             :     { NULL }
     551             : };
     552             : 
     553             : AVFILTER_DEFINE_CLASS(bwdif);
     554             : 
     555             : static const AVFilterPad avfilter_vf_bwdif_inputs[] = {
     556             :     {
     557             :         .name          = "default",
     558             :         .type          = AVMEDIA_TYPE_VIDEO,
     559             :         .filter_frame  = filter_frame,
     560             :     },
     561             :     { NULL }
     562             : };
     563             : 
     564             : static const AVFilterPad avfilter_vf_bwdif_outputs[] = {
     565             :     {
     566             :         .name          = "default",
     567             :         .type          = AVMEDIA_TYPE_VIDEO,
     568             :         .request_frame = request_frame,
     569             :         .config_props  = config_props,
     570             :     },
     571             :     { NULL }
     572             : };
     573             : 
     574             : AVFilter ff_vf_bwdif = {
     575             :     .name          = "bwdif",
     576             :     .description   = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
     577             :     .priv_size     = sizeof(BWDIFContext),
     578             :     .priv_class    = &bwdif_class,
     579             :     .uninit        = uninit,
     580             :     .query_formats = query_formats,
     581             :     .inputs        = avfilter_vf_bwdif_inputs,
     582             :     .outputs       = avfilter_vf_bwdif_outputs,
     583             :     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
     584             : };

Generated by: LCOV version 1.13