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/pixdesc.h" | ||
27 | #include "avfilter.h" | ||
28 | #include "filters.h" | ||
29 | #include "formats.h" | ||
30 | #include "video.h" | ||
31 | |||
32 | 139 | static void do_swap(AVFrame *frame) | |
33 | { | ||
34 | 139 | FFSWAP(uint8_t*, frame->data[1], frame->data[2]); | |
35 | 139 | FFSWAP(int, frame->linesize[1], frame->linesize[2]); | |
36 | 139 | FFSWAP(AVBufferRef*, frame->buf[1], frame->buf[2]); | |
37 | 139 | } | |
38 | |||
39 | 69 | static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h) | |
40 | { | ||
41 | 69 | AVFrame *picref = ff_default_get_video_buffer(link, w, h); | |
42 | 69 | do_swap(picref); | |
43 | 69 | return picref; | |
44 | } | ||
45 | |||
46 | 70 | static int filter_frame(AVFilterLink *link, AVFrame *inpicref) | |
47 | { | ||
48 | 70 | do_swap(inpicref); | |
49 | 70 | return ff_filter_frame(link->dst->outputs[0], inpicref); | |
50 | } | ||
51 | |||
52 | 16188 | static int is_planar_yuv(const AVPixFmtDescriptor *desc) | |
53 | { | ||
54 | int i; | ||
55 | |||
56 |
2/2✓ Branch 0 taken 8804 times.
✓ Branch 1 taken 7384 times.
|
16188 | if (desc->flags & ~(AV_PIX_FMT_FLAG_BE | AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_ALPHA) || |
57 |
2/2✓ Branch 0 taken 7810 times.
✓ Branch 1 taken 994 times.
|
8804 | desc->nb_components < 3 || |
58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7810 times.
|
7810 | (desc->comp[1].depth != desc->comp[2].depth)) |
59 | 8378 | return 0; | |
60 |
2/2✓ Branch 0 taken 21371 times.
✓ Branch 1 taken 4970 times.
|
26341 | for (i = 0; i < desc->nb_components; i++) { |
61 |
2/2✓ Branch 0 taken 19667 times.
✓ Branch 1 taken 1704 times.
|
21371 | if (desc->comp[i].offset != 0 || |
62 |
2/2✓ Branch 0 taken 18531 times.
✓ Branch 1 taken 1136 times.
|
19667 | desc->comp[i].shift != 0 || |
63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18531 times.
|
18531 | desc->comp[i].plane != i) |
64 | 2840 | return 0; | |
65 | } | ||
66 | |||
67 | 4970 | return 1; | |
68 | } | ||
69 | |||
70 | 71 | static int query_formats(AVFilterContext *ctx) | |
71 | { | ||
72 | 71 | AVFilterFormats *formats = NULL; | |
73 | int fmt, ret; | ||
74 | |||
75 |
2/2✓ Branch 1 taken 16188 times.
✓ Branch 2 taken 71 times.
|
16259 | for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) { |
76 | 16188 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); | |
77 |
3/4✓ Branch 1 taken 4970 times.
✓ Branch 2 taken 11218 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4970 times.
|
16188 | if (is_planar_yuv(desc) && (ret = ff_add_format(&formats, fmt)) < 0) |
78 | ✗ | return ret; | |
79 | } | ||
80 | |||
81 | 71 | return ff_set_common_formats(ctx, formats); | |
82 | } | ||
83 | |||
84 | static const AVFilterPad swapuv_inputs[] = { | ||
85 | { | ||
86 | .name = "default", | ||
87 | .type = AVMEDIA_TYPE_VIDEO, | ||
88 | .get_buffer.video = get_video_buffer, | ||
89 | .filter_frame = filter_frame, | ||
90 | }, | ||
91 | }; | ||
92 | |||
93 | const AVFilter ff_vf_swapuv = { | ||
94 | .name = "swapuv", | ||
95 | .description = NULL_IF_CONFIG_SMALL("Swap U and V components."), | ||
96 | FILTER_INPUTS(swapuv_inputs), | ||
97 | FILTER_OUTPUTS(ff_video_default_filterpad), | ||
98 | FILTER_QUERY_FUNC(query_formats), | ||
99 | .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, | ||
100 | }; | ||
101 |