| 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 | 197 | static int query_formats(const AVFilterContext *ctx, | |
| 41 | AVFilterFormatsConfig **cfg_in, | ||
| 42 | AVFilterFormatsConfig **cfg_out) | ||
| 43 | { | ||
| 44 | 197 | AVFilterFormats *pix_fmts = NULL; | |
| 45 | const AVPixFmtDescriptor *desc; | ||
| 46 | int fmt, ret; | ||
| 47 | |||
| 48 |
2/2✓ Branch 1 taken 52599 times.
✓ Branch 2 taken 197 times.
|
52796 | for (fmt = 0; desc = av_pix_fmt_desc_get(fmt); fmt++) { |
| 49 |
2/2✓ Branch 0 taken 49447 times.
✓ Branch 1 taken 3152 times.
|
52599 | if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL || |
| 50 |
2/2✓ Branch 0 taken 48265 times.
✓ Branch 1 taken 1182 times.
|
49447 | desc->flags & AV_PIX_FMT_FLAG_BITSTREAM || |
| 51 |
2/2✓ Branch 0 taken 9456 times.
✓ Branch 1 taken 38809 times.
|
48265 | (desc->log2_chroma_w != desc->log2_chroma_h && |
| 52 |
3/4✓ Branch 0 taken 7486 times.
✓ Branch 1 taken 1970 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 46295 times.
|
55751 | desc->comp[0].plane == desc->comp[1].plane)) && |
| 53 | 46295 | (ret = ff_add_format(&pix_fmts, fmt)) < 0) | |
| 54 | ✗ | return ret; | |
| 55 | } | ||
| 56 | |||
| 57 | 197 | return ff_set_common_formats2(ctx, cfg_in, cfg_out, pix_fmts); | |
| 58 | } | ||
| 59 | |||
| 60 | 196 | static int config_props(AVFilterLink *inlink) | |
| 61 | { | ||
| 62 | 196 | FlipContext *s = inlink->dst->priv; | |
| 63 | 196 | const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); | |
| 64 | 196 | const int hsub = pix_desc->log2_chroma_w; | |
| 65 | 196 | const int vsub = pix_desc->log2_chroma_h; | |
| 66 | int nb_planes; | ||
| 67 | |||
| 68 | 196 | av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); | |
| 69 | 196 | s->planewidth[0] = s->planewidth[3] = inlink->w; | |
| 70 | 196 | s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, hsub); | |
| 71 | 196 | s->planeheight[0] = s->planeheight[3] = inlink->h; | |
| 72 | 196 | s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, vsub); | |
| 73 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 196 times.
|
196 | s->bayer_plus1 = !!(pix_desc->flags & AV_PIX_FMT_FLAG_BAYER) + 1; |
| 74 | |||
| 75 | 196 | nb_planes = av_pix_fmt_count_planes(inlink->format); | |
| 76 | |||
| 77 | 196 | return ff_hflip_init(s, s->max_step, nb_planes); | |
| 78 | } | ||
| 79 | |||
| 80 | typedef struct ThreadData { | ||
| 81 | AVFrame *in, *out; | ||
| 82 | } ThreadData; | ||
| 83 | |||
| 84 | 615 | static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs) | |
| 85 | { | ||
| 86 | 615 | FlipContext *s = ctx->priv; | |
| 87 | 615 | ThreadData *td = arg; | |
| 88 | 615 | AVFrame *in = td->in; | |
| 89 | 615 | AVFrame *out = td->out; | |
| 90 | uint8_t *inrow, *outrow; | ||
| 91 | int i, plane, step; | ||
| 92 | |||
| 93 |
6/6✓ Branch 0 taken 2138 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 1597 times.
✓ Branch 3 taken 541 times.
✓ Branch 4 taken 1595 times.
✓ Branch 5 taken 2 times.
|
2210 | for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) { |
| 94 | 1595 | const int width = s->planewidth[plane] / s->bayer_plus1; | |
| 95 | 1595 | const int height = s->planeheight[plane]; | |
| 96 | 1595 | const int start = (height * job ) / nb_jobs; | |
| 97 | 1595 | const int end = (height * (job+1)) / nb_jobs; | |
| 98 | |||
| 99 | 1595 | step = s->max_step[plane]; | |
| 100 | |||
| 101 | 1595 | outrow = out->data[plane] + start * out->linesize[plane]; | |
| 102 | 1595 | inrow = in ->data[plane] + start * in->linesize[plane] + (width - 1) * step; | |
| 103 |
2/2✓ Branch 0 taken 252392 times.
✓ Branch 1 taken 1595 times.
|
253987 | for (i = start; i < end; i++) { |
| 104 | 252392 | s->flip_line[plane](inrow, outrow, width); | |
| 105 | |||
| 106 | 252392 | inrow += in ->linesize[plane]; | |
| 107 | 252392 | outrow += out->linesize[plane]; | |
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | 615 | return 0; | |
| 112 | } | ||
| 113 | |||
| 114 | 415 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) | |
| 115 | { | ||
| 116 | 415 | AVFilterContext *ctx = inlink->dst; | |
| 117 | 415 | AVFilterLink *outlink = ctx->outputs[0]; | |
| 118 | ThreadData td; | ||
| 119 | AVFrame *out; | ||
| 120 | |||
| 121 | 415 | out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | |
| 122 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 415 times.
|
415 | if (!out) { |
| 123 | ✗ | av_frame_free(&in); | |
| 124 | ✗ | return AVERROR(ENOMEM); | |
| 125 | } | ||
| 126 | 415 | av_frame_copy_props(out, in); | |
| 127 | |||
| 128 | /* copy palette if required */ | ||
| 129 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 413 times.
|
415 | if (av_pix_fmt_desc_get(inlink->format)->flags & AV_PIX_FMT_FLAG_PAL) |
| 130 | 2 | memcpy(out->data[1], in->data[1], AVPALETTE_SIZE); | |
| 131 | |||
| 132 | 415 | td.in = in, td.out = out; | |
| 133 | 415 | ff_filter_execute(ctx, filter_slice, &td, NULL, | |
| 134 |
1/2✓ Branch 0 taken 415 times.
✗ Branch 1 not taken.
|
415 | FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); |
| 135 | |||
| 136 | 415 | av_frame_free(&in); | |
| 137 | 415 | return ff_filter_frame(outlink, out); | |
| 138 | } | ||
| 139 | |||
| 140 | static const AVFilterPad avfilter_vf_hflip_inputs[] = { | ||
| 141 | { | ||
| 142 | .name = "default", | ||
| 143 | .type = AVMEDIA_TYPE_VIDEO, | ||
| 144 | .filter_frame = filter_frame, | ||
| 145 | .config_props = config_props, | ||
| 146 | }, | ||
| 147 | }; | ||
| 148 | |||
| 149 | const FFFilter ff_vf_hflip = { | ||
| 150 | .p.name = "hflip", | ||
| 151 | .p.description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."), | ||
| 152 | .p.flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, | ||
| 153 | .priv_size = sizeof(FlipContext), | ||
| 154 | FILTER_INPUTS(avfilter_vf_hflip_inputs), | ||
| 155 | FILTER_OUTPUTS(ff_video_default_filterpad), | ||
| 156 | FILTER_QUERY_FUNC2(query_formats), | ||
| 157 | }; | ||
| 158 |