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 "avfilter.h" | ||
30 | #include "filters.h" | ||
31 | #include "formats.h" | ||
32 | #include "hflip.h" | ||
33 | #include "vf_hflip_init.h" | ||
34 | #include "video.h" | ||
35 | #include "libavutil/pixdesc.h" | ||
36 | #include "libavutil/internal.h" | ||
37 | #include "libavutil/intreadwrite.h" | ||
38 | #include "libavutil/imgutils.h" | ||
39 | |||
40 | 178 | static int query_formats(AVFilterContext *ctx) | |
41 | { | ||
42 | 178 | AVFilterFormats *pix_fmts = NULL; | |
43 | const AVPixFmtDescriptor *desc; | ||
44 | int fmt, ret; | ||
45 | |||
46 |
2/2✓ Branch 1 taken 40584 times.
✓ Branch 2 taken 178 times.
|
40762 | for (fmt = 0; desc = av_pix_fmt_desc_get(fmt); fmt++) { |
47 |
2/2✓ Branch 0 taken 38092 times.
✓ Branch 1 taken 2492 times.
|
40584 | if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL || |
48 |
2/2✓ Branch 0 taken 37202 times.
✓ Branch 1 taken 890 times.
|
38092 | desc->flags & AV_PIX_FMT_FLAG_BITSTREAM || |
49 |
2/2✓ Branch 0 taken 8188 times.
✓ Branch 1 taken 29014 times.
|
37202 | (desc->log2_chroma_w != desc->log2_chroma_h && |
50 |
3/4✓ Branch 0 taken 6764 times.
✓ Branch 1 taken 1424 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 35778 times.
|
43966 | desc->comp[0].plane == desc->comp[1].plane)) && |
51 | 35778 | (ret = ff_add_format(&pix_fmts, fmt)) < 0) | |
52 | ✗ | return ret; | |
53 | } | ||
54 | |||
55 | 178 | return ff_set_common_formats(ctx, pix_fmts); | |
56 | } | ||
57 | |||
58 | 177 | static int config_props(AVFilterLink *inlink) | |
59 | { | ||
60 | 177 | FlipContext *s = inlink->dst->priv; | |
61 | 177 | const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); | |
62 | 177 | const int hsub = pix_desc->log2_chroma_w; | |
63 | 177 | const int vsub = pix_desc->log2_chroma_h; | |
64 | int nb_planes; | ||
65 | |||
66 | 177 | av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); | |
67 | 177 | s->planewidth[0] = s->planewidth[3] = inlink->w; | |
68 | 177 | s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, hsub); | |
69 | 177 | s->planeheight[0] = s->planeheight[3] = inlink->h; | |
70 | 177 | s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, vsub); | |
71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 177 times.
|
177 | s->bayer_plus1 = !!(pix_desc->flags & AV_PIX_FMT_FLAG_BAYER) + 1; |
72 | |||
73 | 177 | nb_planes = av_pix_fmt_count_planes(inlink->format); | |
74 | |||
75 | 177 | return ff_hflip_init(s, s->max_step, nb_planes); | |
76 | } | ||
77 | |||
78 | typedef struct ThreadData { | ||
79 | AVFrame *in, *out; | ||
80 | } ThreadData; | ||
81 | |||
82 | 177 | static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs) | |
83 | { | ||
84 | 177 | FlipContext *s = ctx->priv; | |
85 | 177 | ThreadData *td = arg; | |
86 | 177 | AVFrame *in = td->in; | |
87 | 177 | AVFrame *out = td->out; | |
88 | uint8_t *inrow, *outrow; | ||
89 | int i, plane, step; | ||
90 | |||
91 |
6/6✓ Branch 0 taken 565 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 425 times.
✓ Branch 3 taken 140 times.
✓ Branch 4 taken 424 times.
✓ Branch 5 taken 1 times.
|
601 | for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) { |
92 | 424 | const int width = s->planewidth[plane] / s->bayer_plus1; | |
93 | 424 | const int height = s->planeheight[plane]; | |
94 | 424 | const int start = (height * job ) / nb_jobs; | |
95 | 424 | const int end = (height * (job+1)) / nb_jobs; | |
96 | |||
97 | 424 | step = s->max_step[plane]; | |
98 | |||
99 | 424 | outrow = out->data[plane] + start * out->linesize[plane]; | |
100 | 424 | inrow = in ->data[plane] + start * in->linesize[plane] + (width - 1) * step; | |
101 |
2/2✓ Branch 0 taken 113328 times.
✓ Branch 1 taken 424 times.
|
113752 | for (i = start; i < end; i++) { |
102 | 113328 | s->flip_line[plane](inrow, outrow, width); | |
103 | |||
104 | 113328 | inrow += in ->linesize[plane]; | |
105 | 113328 | outrow += out->linesize[plane]; | |
106 | } | ||
107 | } | ||
108 | |||
109 | 177 | return 0; | |
110 | } | ||
111 | |||
112 | 177 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) | |
113 | { | ||
114 | 177 | AVFilterContext *ctx = inlink->dst; | |
115 | 177 | AVFilterLink *outlink = ctx->outputs[0]; | |
116 | ThreadData td; | ||
117 | AVFrame *out; | ||
118 | |||
119 | 177 | out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | |
120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 177 times.
|
177 | if (!out) { |
121 | ✗ | av_frame_free(&in); | |
122 | ✗ | return AVERROR(ENOMEM); | |
123 | } | ||
124 | 177 | av_frame_copy_props(out, in); | |
125 | |||
126 | /* copy palette if required */ | ||
127 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 176 times.
|
177 | if (av_pix_fmt_desc_get(inlink->format)->flags & AV_PIX_FMT_FLAG_PAL) |
128 | 1 | memcpy(out->data[1], in->data[1], AVPALETTE_SIZE); | |
129 | |||
130 | 177 | td.in = in, td.out = out; | |
131 | 177 | ff_filter_execute(ctx, filter_slice, &td, NULL, | |
132 |
1/2✓ Branch 0 taken 177 times.
✗ Branch 1 not taken.
|
177 | FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); |
133 | |||
134 | 177 | av_frame_free(&in); | |
135 | 177 | return ff_filter_frame(outlink, out); | |
136 | } | ||
137 | |||
138 | static const AVFilterPad avfilter_vf_hflip_inputs[] = { | ||
139 | { | ||
140 | .name = "default", | ||
141 | .type = AVMEDIA_TYPE_VIDEO, | ||
142 | .filter_frame = filter_frame, | ||
143 | .config_props = config_props, | ||
144 | }, | ||
145 | }; | ||
146 | |||
147 | const AVFilter ff_vf_hflip = { | ||
148 | .name = "hflip", | ||
149 | .description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."), | ||
150 | .priv_size = sizeof(FlipContext), | ||
151 | FILTER_INPUTS(avfilter_vf_hflip_inputs), | ||
152 | FILTER_OUTPUTS(ff_video_default_filterpad), | ||
153 | FILTER_QUERY_FUNC(query_formats), | ||
154 | .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, | ||
155 | }; | ||
156 |