FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_swapuv.c
Go to the documentation of this file.
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/pixdesc.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
33  int w, int h)
34 {
35  AVFilterBufferRef *picref =
36  ff_default_get_video_buffer(link, perms, w, h);
37 
38  FFSWAP(uint8_t*, picref->data[1], picref->data[2]);
39  FFSWAP(int, picref->linesize[1], picref->linesize[2]);
40 
41  return picref;
42 }
43 
44 static int filter_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
45 {
46  FFSWAP(uint8_t*, inpicref->data[1], inpicref->data[2]);
47  FFSWAP(int, inpicref->linesize[1], inpicref->linesize[2]);
48 
49  return ff_filter_frame(link->dst->outputs[0], inpicref);
50 }
51 
52 static int is_planar_yuv(const AVPixFmtDescriptor *desc)
53 {
54  int i;
55 
56  if (desc->flags & ~(PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_ALPHA) ||
57  desc->nb_components < 3 ||
58  (desc->comp[1].depth_minus1 != desc->comp[2].depth_minus1))
59  return 0;
60  for (i = 0; i < desc->nb_components; i++) {
61  if (desc->comp[i].offset_plus1 != 1 ||
62  desc->comp[i].shift != 0 ||
63  desc->comp[i].plane != i)
64  return 0;
65  }
66 
67  return 1;
68 }
69 
71 {
73  int fmt;
74 
75  for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
76  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
77  if (is_planar_yuv(desc))
78  ff_add_format(&formats, fmt);
79  }
80 
81  ff_set_common_formats(ctx, formats);
82  return 0;
83 }
84 
85 static const AVFilterPad swapuv_inputs[] = {
86  {
87  .name = "default",
88  .type = AVMEDIA_TYPE_VIDEO,
89  .get_video_buffer = get_video_buffer,
90  .filter_frame = filter_frame,
91  },
92  { NULL }
93 };
94 
95 static const AVFilterPad swapuv_outputs[] = {
96  {
97  .name = "default",
98  .type = AVMEDIA_TYPE_VIDEO,
99  },
100  { NULL }
101 };
102 
104  .name = "swapuv",
105  .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
106  .priv_size = 0,
107  .query_formats = query_formats,
108  .inputs = swapuv_inputs,
109  .outputs = swapuv_outputs,
110 };