LCOV - code coverage report
Current view: top level - libavfilter - vf_swapuv.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 30 31 96.8 %
Date: 2017-12-13 02:34:56 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
       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             :  * swap UV filter
      24             :  */
      25             : 
      26             : #include "libavutil/opt.h"
      27             : #include "libavutil/pixdesc.h"
      28             : #include "libavutil/version.h"
      29             : #include "avfilter.h"
      30             : #include "formats.h"
      31             : #include "internal.h"
      32             : #include "video.h"
      33             : 
      34             : typedef struct SwapUVContext {
      35             :     const AVClass *class;
      36             : } SwapUVContext;
      37             : 
      38             : static const AVOption swapuv_options[] = {
      39             :     { NULL }
      40             : };
      41             : 
      42             : AVFILTER_DEFINE_CLASS(swapuv);
      43             : 
      44         131 : static void do_swap(AVFrame *frame)
      45             : {
      46         131 :     FFSWAP(uint8_t*,     frame->data[1],     frame->data[2]);
      47         131 :     FFSWAP(int,          frame->linesize[1], frame->linesize[2]);
      48         131 :     FFSWAP(AVBufferRef*, frame->buf[1],      frame->buf[2]);
      49             : 
      50             : #if FF_API_ERROR_FRAME
      51             : FF_DISABLE_DEPRECATION_WARNINGS
      52         131 :     FFSWAP(uint64_t,     frame->error[1],    frame->error[2]);
      53             : FF_ENABLE_DEPRECATION_WARNINGS
      54             : #endif
      55         131 : }
      56             : 
      57          65 : static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
      58             : {
      59          65 :     AVFrame *picref = ff_default_get_video_buffer(link, w, h);
      60          65 :     do_swap(picref);
      61          65 :     return picref;
      62             : }
      63             : 
      64          66 : static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
      65             : {
      66          66 :     do_swap(inpicref);
      67          66 :     return ff_filter_frame(link->dst->outputs[0], inpicref);
      68             : }
      69             : 
      70       12261 : static int is_planar_yuv(const AVPixFmtDescriptor *desc)
      71             : {
      72             :     int i;
      73             : 
      74       18559 :     if (desc->flags & ~(AV_PIX_FMT_FLAG_BE | AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_ALPHA) ||
      75       11859 :         desc->nb_components < 3 ||
      76        5561 :         (desc->comp[1].depth != desc->comp[2].depth))
      77        6700 :         return 0;
      78       21239 :     for (i = 0; i < desc->nb_components; i++) {
      79       32763 :         if (desc->comp[i].offset != 0 ||
      80       31624 :             desc->comp[i].shift != 0 ||
      81       15678 :             desc->comp[i].plane != i)
      82        1139 :             return 0;
      83             :     }
      84             : 
      85        4422 :     return 1;
      86             : }
      87             : 
      88          67 : static int query_formats(AVFilterContext *ctx)
      89             : {
      90          67 :     AVFilterFormats *formats = NULL;
      91             :     int fmt, ret;
      92             : 
      93       12328 :     for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
      94       12261 :         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
      95       12261 :         if (is_planar_yuv(desc) && (ret = ff_add_format(&formats, fmt)) < 0)
      96           0 :             return ret;
      97             :     }
      98             : 
      99          67 :     return ff_set_common_formats(ctx, formats);
     100             : }
     101             : 
     102             : static const AVFilterPad swapuv_inputs[] = {
     103             :     {
     104             :         .name             = "default",
     105             :         .type             = AVMEDIA_TYPE_VIDEO,
     106             :         .get_video_buffer = get_video_buffer,
     107             :         .filter_frame     = filter_frame,
     108             :     },
     109             :     { NULL }
     110             : };
     111             : 
     112             : static const AVFilterPad swapuv_outputs[] = {
     113             :     {
     114             :         .name = "default",
     115             :         .type = AVMEDIA_TYPE_VIDEO,
     116             :     },
     117             :     { NULL }
     118             : };
     119             : 
     120             : AVFilter ff_vf_swapuv = {
     121             :     .name          = "swapuv",
     122             :     .description   = NULL_IF_CONFIG_SMALL("Swap U and V components."),
     123             :     .query_formats = query_formats,
     124             :     .priv_size     = sizeof(SwapUVContext),
     125             :     .priv_class    = &swapuv_class,
     126             :     .inputs        = swapuv_inputs,
     127             :     .outputs       = swapuv_outputs,
     128             :     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
     129             : };

Generated by: LCOV version 1.13