LCOV - code coverage report
Current view: top level - libavfilter - vf_vflip.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 26 96.2 %
Date: 2017-12-17 16:07:53 Functions: 3 3 100.0 %

          Line data    Source code
       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             : /**
      22             :  * @file
      23             :  * video vertical flip filter
      24             :  */
      25             : 
      26             : #include "libavutil/internal.h"
      27             : #include "libavutil/opt.h"
      28             : #include "libavutil/pixdesc.h"
      29             : #include "avfilter.h"
      30             : #include "internal.h"
      31             : #include "video.h"
      32             : 
      33             : typedef struct FlipContext {
      34             :     const AVClass *class;
      35             :     int vsub;   ///< vertical chroma subsampling
      36             : } FlipContext;
      37             : 
      38             : static const AVOption vflip_options[] = {
      39             :     { NULL }
      40             : };
      41             : 
      42             : AVFILTER_DEFINE_CLASS(vflip);
      43             : 
      44         150 : static int config_input(AVFilterLink *link)
      45             : {
      46         150 :     FlipContext *flip = link->dst->priv;
      47         150 :     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
      48             : 
      49         150 :     flip->vsub = desc->log2_chroma_h;
      50             : 
      51         150 :     return 0;
      52             : }
      53             : 
      54         150 : static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
      55             : {
      56         150 :     FlipContext *flip = link->dst->priv;
      57             :     AVFrame *frame;
      58             :     int i;
      59             : 
      60         150 :     frame = ff_get_video_buffer(link->dst->outputs[0], w, h);
      61         150 :     if (!frame)
      62           0 :         return NULL;
      63             : 
      64         750 :     for (i = 0; i < 4; i ++) {
      65         600 :         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
      66         600 :         int height = AV_CEIL_RSHIFT(h, vsub);
      67             : 
      68         600 :         if (frame->data[i]) {
      69         374 :             frame->data[i] += (height - 1) * frame->linesize[i];
      70         374 :             frame->linesize[i] = -frame->linesize[i];
      71             :         }
      72             :     }
      73             : 
      74         150 :     return frame;
      75             : }
      76             : 
      77         186 : static int filter_frame(AVFilterLink *link, AVFrame *frame)
      78             : {
      79         186 :     FlipContext *flip = link->dst->priv;
      80             :     int i;
      81             : 
      82         930 :     for (i = 0; i < 4; i ++) {
      83         744 :         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
      84         744 :         int height = AV_CEIL_RSHIFT(link->h, vsub);
      85             : 
      86         744 :         if (frame->data[i]) {
      87         482 :             frame->data[i] += (height - 1) * frame->linesize[i];
      88         482 :             frame->linesize[i] = -frame->linesize[i];
      89             :         }
      90             :     }
      91             : 
      92         186 :     return ff_filter_frame(link->dst->outputs[0], frame);
      93             : }
      94             : static const AVFilterPad avfilter_vf_vflip_inputs[] = {
      95             :     {
      96             :         .name             = "default",
      97             :         .type             = AVMEDIA_TYPE_VIDEO,
      98             :         .get_video_buffer = get_video_buffer,
      99             :         .filter_frame     = filter_frame,
     100             :         .config_props     = config_input,
     101             :     },
     102             :     { NULL }
     103             : };
     104             : 
     105             : static const AVFilterPad avfilter_vf_vflip_outputs[] = {
     106             :     {
     107             :         .name = "default",
     108             :         .type = AVMEDIA_TYPE_VIDEO,
     109             :     },
     110             :     { NULL }
     111             : };
     112             : 
     113             : AVFilter ff_vf_vflip = {
     114             :     .name        = "vflip",
     115             :     .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
     116             :     .priv_size   = sizeof(FlipContext),
     117             :     .priv_class  = &vflip_class,
     118             :     .inputs      = avfilter_vf_vflip_inputs,
     119             :     .outputs     = avfilter_vf_vflip_outputs,
     120             :     .flags       = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
     121             : };

Generated by: LCOV version 1.13