FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_hflip.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 53 56 94.6%
Branches: 24 28 85.7%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2007 Benoit Fouet
3 * Copyright (c) 2010 Stefano Sabatini
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * horizontal flip filter
25 */
26
27 #include <string.h>
28
29 #include "libavutil/opt.h"
30 #include "avfilter.h"
31 #include "formats.h"
32 #include "hflip.h"
33 #include "internal.h"
34 #include "vf_hflip_init.h"
35 #include "video.h"
36 #include "libavutil/pixdesc.h"
37 #include "libavutil/internal.h"
38 #include "libavutil/intreadwrite.h"
39 #include "libavutil/imgutils.h"
40
41 static const AVOption hflip_options[] = {
42 { NULL }
43 };
44
45 AVFILTER_DEFINE_CLASS(hflip);
46
47 172 static int query_formats(AVFilterContext *ctx)
48 {
49 172 AVFilterFormats *pix_fmts = NULL;
50 const AVPixFmtDescriptor *desc;
51 int fmt, ret;
52
53
2/2
✓ Branch 1 taken 38184 times.
✓ Branch 2 taken 172 times.
38356 for (fmt = 0; desc = av_pix_fmt_desc_get(fmt); fmt++) {
54
2/2
✓ Branch 0 taken 35776 times.
✓ Branch 1 taken 2408 times.
38184 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
55
2/2
✓ Branch 0 taken 34916 times.
✓ Branch 1 taken 860 times.
35776 desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ||
56
2/2
✓ Branch 0 taken 7568 times.
✓ Branch 1 taken 27348 times.
34916 (desc->log2_chroma_w != desc->log2_chroma_h &&
57
3/4
✓ Branch 0 taken 6192 times.
✓ Branch 1 taken 1376 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33540 times.
41108 desc->comp[0].plane == desc->comp[1].plane)) &&
58 33540 (ret = ff_add_format(&pix_fmts, fmt)) < 0)
59 return ret;
60 }
61
62 172 return ff_set_common_formats(ctx, pix_fmts);
63 }
64
65 171 static int config_props(AVFilterLink *inlink)
66 {
67 171 FlipContext *s = inlink->dst->priv;
68 171 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
69 171 const int hsub = pix_desc->log2_chroma_w;
70 171 const int vsub = pix_desc->log2_chroma_h;
71 int nb_planes;
72
73 171 av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc);
74 171 s->planewidth[0] = s->planewidth[3] = inlink->w;
75 171 s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
76 171 s->planeheight[0] = s->planeheight[3] = inlink->h;
77 171 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 171 times.
171 s->bayer_plus1 = !!(pix_desc->flags & AV_PIX_FMT_FLAG_BAYER) + 1;
79
80 171 nb_planes = av_pix_fmt_count_planes(inlink->format);
81
82 171 return ff_hflip_init(s, s->max_step, nb_planes);
83 }
84
85 typedef struct ThreadData {
86 AVFrame *in, *out;
87 } ThreadData;
88
89 171 static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
90 {
91 171 FlipContext *s = ctx->priv;
92 171 ThreadData *td = arg;
93 171 AVFrame *in = td->in;
94 171 AVFrame *out = td->out;
95 uint8_t *inrow, *outrow;
96 int i, plane, step;
97
98
6/6
✓ Branch 0 taken 545 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 409 times.
✓ Branch 3 taken 136 times.
✓ Branch 4 taken 408 times.
✓ Branch 5 taken 1 times.
579 for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
99 408 const int width = s->planewidth[plane] / s->bayer_plus1;
100 408 const int height = s->planeheight[plane];
101 408 const int start = (height * job ) / nb_jobs;
102 408 const int end = (height * (job+1)) / nb_jobs;
103
104 408 step = s->max_step[plane];
105
106 408 outrow = out->data[plane] + start * out->linesize[plane];
107 408 inrow = in ->data[plane] + start * in->linesize[plane] + (width - 1) * step;
108
2/2
✓ Branch 0 taken 108720 times.
✓ Branch 1 taken 408 times.
109128 for (i = start; i < end; i++) {
109 108720 s->flip_line[plane](inrow, outrow, width);
110
111 108720 inrow += in ->linesize[plane];
112 108720 outrow += out->linesize[plane];
113 }
114 }
115
116 171 return 0;
117 }
118
119 171 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
120 {
121 171 AVFilterContext *ctx = inlink->dst;
122 171 AVFilterLink *outlink = ctx->outputs[0];
123 ThreadData td;
124 AVFrame *out;
125
126 171 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 171 times.
171 if (!out) {
128 av_frame_free(&in);
129 return AVERROR(ENOMEM);
130 }
131 171 av_frame_copy_props(out, in);
132
133 /* copy palette if required */
134
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 170 times.
171 if (av_pix_fmt_desc_get(inlink->format)->flags & AV_PIX_FMT_FLAG_PAL)
135 1 memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
136
137 171 td.in = in, td.out = out;
138 171 ff_filter_execute(ctx, filter_slice, &td, NULL,
139
1/2
✓ Branch 0 taken 171 times.
✗ Branch 1 not taken.
171 FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
140
141 171 av_frame_free(&in);
142 171 return ff_filter_frame(outlink, out);
143 }
144
145 static const AVFilterPad avfilter_vf_hflip_inputs[] = {
146 {
147 .name = "default",
148 .type = AVMEDIA_TYPE_VIDEO,
149 .filter_frame = filter_frame,
150 .config_props = config_props,
151 },
152 };
153
154 static const AVFilterPad avfilter_vf_hflip_outputs[] = {
155 {
156 .name = "default",
157 .type = AVMEDIA_TYPE_VIDEO,
158 },
159 };
160
161 const AVFilter ff_vf_hflip = {
162 .name = "hflip",
163 .description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."),
164 .priv_size = sizeof(FlipContext),
165 .priv_class = &hflip_class,
166 FILTER_INPUTS(avfilter_vf_hflip_inputs),
167 FILTER_OUTPUTS(avfilter_vf_hflip_outputs),
168 FILTER_QUERY_FUNC(query_formats),
169 .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
170 };
171