FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_swapuv.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 29 30 96.7%
Branches: 17 20 85.0%

Line Branch Exec Source
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 "avfilter.h"
29 #include "formats.h"
30 #include "internal.h"
31 #include "video.h"
32
33 typedef struct SwapUVContext {
34 const AVClass *class;
35 } SwapUVContext;
36
37 static const AVOption swapuv_options[] = {
38 { NULL }
39 };
40
41 AVFILTER_DEFINE_CLASS(swapuv);
42
43 139 static void do_swap(AVFrame *frame)
44 {
45 139 FFSWAP(uint8_t*, frame->data[1], frame->data[2]);
46 139 FFSWAP(int, frame->linesize[1], frame->linesize[2]);
47 139 FFSWAP(AVBufferRef*, frame->buf[1], frame->buf[2]);
48 139 }
49
50 69 static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
51 {
52 69 AVFrame *picref = ff_default_get_video_buffer(link, w, h);
53 69 do_swap(picref);
54 69 return picref;
55 }
56
57 70 static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
58 {
59 70 do_swap(inpicref);
60 70 return ff_filter_frame(link->dst->outputs[0], inpicref);
61 }
62
63 15762 static int is_planar_yuv(const AVPixFmtDescriptor *desc)
64 {
65 int i;
66
67
2/2
✓ Branch 0 taken 8662 times.
✓ Branch 1 taken 7100 times.
15762 if (desc->flags & ~(AV_PIX_FMT_FLAG_BE | AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_ALPHA) ||
68
2/2
✓ Branch 0 taken 7668 times.
✓ Branch 1 taken 994 times.
8662 desc->nb_components < 3 ||
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7668 times.
7668 (desc->comp[1].depth != desc->comp[2].depth))
70 8094 return 0;
71
2/2
✓ Branch 0 taken 21229 times.
✓ Branch 1 taken 4970 times.
26199 for (i = 0; i < desc->nb_components; i++) {
72
2/2
✓ Branch 0 taken 19525 times.
✓ Branch 1 taken 1704 times.
21229 if (desc->comp[i].offset != 0 ||
73
2/2
✓ Branch 0 taken 18531 times.
✓ Branch 1 taken 994 times.
19525 desc->comp[i].shift != 0 ||
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18531 times.
18531 desc->comp[i].plane != i)
75 2698 return 0;
76 }
77
78 4970 return 1;
79 }
80
81 71 static int query_formats(AVFilterContext *ctx)
82 {
83 71 AVFilterFormats *formats = NULL;
84 int fmt, ret;
85
86
2/2
✓ Branch 1 taken 15762 times.
✓ Branch 2 taken 71 times.
15833 for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
87 15762 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
88
3/4
✓ Branch 1 taken 4970 times.
✓ Branch 2 taken 10792 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4970 times.
15762 if (is_planar_yuv(desc) && (ret = ff_add_format(&formats, fmt)) < 0)
89 return ret;
90 }
91
92 71 return ff_set_common_formats(ctx, formats);
93 }
94
95 static const AVFilterPad swapuv_inputs[] = {
96 {
97 .name = "default",
98 .type = AVMEDIA_TYPE_VIDEO,
99 .get_buffer.video = get_video_buffer,
100 .filter_frame = filter_frame,
101 },
102 };
103
104 static const AVFilterPad swapuv_outputs[] = {
105 {
106 .name = "default",
107 .type = AVMEDIA_TYPE_VIDEO,
108 },
109 };
110
111 const AVFilter ff_vf_swapuv = {
112 .name = "swapuv",
113 .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
114 .priv_size = sizeof(SwapUVContext),
115 .priv_class = &swapuv_class,
116 FILTER_INPUTS(swapuv_inputs),
117 FILTER_OUTPUTS(swapuv_outputs),
118 FILTER_QUERY_FUNC(query_formats),
119 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
120 };
121