Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) 2013 Paul B Mahol | ||
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 | #include "config_components.h" | ||
22 | |||
23 | #include "libavutil/avstring.h" | ||
24 | #include "libavutil/imgutils.h" | ||
25 | #include "libavutil/opt.h" | ||
26 | #include "libavutil/pixdesc.h" | ||
27 | |||
28 | #include "avfilter.h" | ||
29 | #include "drawutils.h" | ||
30 | #include "filters.h" | ||
31 | #include "formats.h" | ||
32 | #include "internal.h" | ||
33 | #include "video.h" | ||
34 | |||
35 | #define PLANE_R 0x01 | ||
36 | #define PLANE_G 0x02 | ||
37 | #define PLANE_B 0x04 | ||
38 | #define PLANE_A 0x08 | ||
39 | #define PLANE_Y 0x10 | ||
40 | #define PLANE_U 0x20 | ||
41 | #define PLANE_V 0x40 | ||
42 | |||
43 | typedef struct ExtractPlanesContext { | ||
44 | const AVClass *class; | ||
45 | int requested_planes; | ||
46 | int map[4]; | ||
47 | int linesize[4]; | ||
48 | int is_packed; | ||
49 | int depth; | ||
50 | int step; | ||
51 | } ExtractPlanesContext; | ||
52 | |||
53 | #define OFFSET(x) offsetof(ExtractPlanesContext, x) | ||
54 | #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM | ||
55 | static const AVOption extractplanes_options[] = { | ||
56 | { "planes", "set planes", OFFSET(requested_planes), AV_OPT_TYPE_FLAGS, {.i64=1}, 1, 0xff, FLAGS, "flags"}, | ||
57 | { "y", "set luma plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_Y}, 0, 0, FLAGS, "flags"}, | ||
58 | { "u", "set u plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_U}, 0, 0, FLAGS, "flags"}, | ||
59 | { "v", "set v plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_V}, 0, 0, FLAGS, "flags"}, | ||
60 | { "r", "set red plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_R}, 0, 0, FLAGS, "flags"}, | ||
61 | { "g", "set green plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_G}, 0, 0, FLAGS, "flags"}, | ||
62 | { "b", "set blue plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_B}, 0, 0, FLAGS, "flags"}, | ||
63 | { "a", "set alpha plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_A}, 0, 0, FLAGS, "flags"}, | ||
64 | { NULL } | ||
65 | }; | ||
66 | |||
67 | AVFILTER_DEFINE_CLASS(extractplanes); | ||
68 | |||
69 | #define EIGHTBIT_FORMATS \ | ||
70 | AV_PIX_FMT_YUV410P, \ | ||
71 | AV_PIX_FMT_YUV411P, \ | ||
72 | AV_PIX_FMT_YUV440P, \ | ||
73 | AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, \ | ||
74 | AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA422P, \ | ||
75 | AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, \ | ||
76 | AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P, \ | ||
77 | AV_PIX_FMT_YUVJ411P, \ | ||
78 | AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA444P, \ | ||
79 | AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A, \ | ||
80 | AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, \ | ||
81 | AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, \ | ||
82 | AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, \ | ||
83 | AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0, \ | ||
84 | AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR, \ | ||
85 | AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP | ||
86 | |||
87 | #define HIGHDEPTH_FORMATS(suf) \ | ||
88 | AV_PIX_FMT_YA16##suf, \ | ||
89 | AV_PIX_FMT_GRAY9##suf, \ | ||
90 | AV_PIX_FMT_GRAY10##suf, \ | ||
91 | AV_PIX_FMT_GRAY12##suf, \ | ||
92 | AV_PIX_FMT_GRAY14##suf, \ | ||
93 | AV_PIX_FMT_GRAY16##suf, \ | ||
94 | AV_PIX_FMT_YUV420P16##suf, AV_PIX_FMT_YUVA420P16##suf, \ | ||
95 | AV_PIX_FMT_YUV422P16##suf, AV_PIX_FMT_YUVA422P16##suf, \ | ||
96 | AV_PIX_FMT_YUV444P16##suf, AV_PIX_FMT_YUVA444P16##suf, \ | ||
97 | AV_PIX_FMT_RGB48##suf, AV_PIX_FMT_BGR48##suf, \ | ||
98 | AV_PIX_FMT_RGBA64##suf, AV_PIX_FMT_BGRA64##suf, \ | ||
99 | AV_PIX_FMT_GBRP16##suf, AV_PIX_FMT_GBRAP16##suf, \ | ||
100 | AV_PIX_FMT_YUV420P10##suf, \ | ||
101 | AV_PIX_FMT_YUV422P10##suf, \ | ||
102 | AV_PIX_FMT_YUV444P10##suf, \ | ||
103 | AV_PIX_FMT_YUV440P10##suf, \ | ||
104 | AV_PIX_FMT_YUVA420P10##suf, \ | ||
105 | AV_PIX_FMT_YUVA422P10##suf, \ | ||
106 | AV_PIX_FMT_YUVA444P10##suf, \ | ||
107 | AV_PIX_FMT_YUV420P12##suf, \ | ||
108 | AV_PIX_FMT_YUV422P12##suf, \ | ||
109 | AV_PIX_FMT_YUV444P12##suf, \ | ||
110 | AV_PIX_FMT_YUV440P12##suf, \ | ||
111 | AV_PIX_FMT_YUVA422P12##suf, \ | ||
112 | AV_PIX_FMT_YUVA444P12##suf, \ | ||
113 | AV_PIX_FMT_GBRP10##suf, AV_PIX_FMT_GBRAP10##suf, \ | ||
114 | AV_PIX_FMT_GBRP12##suf, AV_PIX_FMT_GBRAP12##suf, \ | ||
115 | AV_PIX_FMT_YUV420P9##suf, \ | ||
116 | AV_PIX_FMT_YUV422P9##suf, \ | ||
117 | AV_PIX_FMT_YUV444P9##suf, \ | ||
118 | AV_PIX_FMT_YUVA420P9##suf, \ | ||
119 | AV_PIX_FMT_YUVA422P9##suf, \ | ||
120 | AV_PIX_FMT_YUVA444P9##suf, \ | ||
121 | AV_PIX_FMT_GBRP9##suf, \ | ||
122 | AV_PIX_FMT_GBRP14##suf, \ | ||
123 | AV_PIX_FMT_YUV420P14##suf, \ | ||
124 | AV_PIX_FMT_YUV422P14##suf, \ | ||
125 | AV_PIX_FMT_YUV444P14##suf | ||
126 | |||
127 | #define FLOAT_FORMATS(suf) \ | ||
128 | AV_PIX_FMT_GRAYF32##suf, \ | ||
129 | AV_PIX_FMT_RGBF32##suf, AV_PIX_FMT_RGBAF32##suf, \ | ||
130 | AV_PIX_FMT_GBRPF32##suf, AV_PIX_FMT_GBRAPF32##suf \ | ||
131 | |||
132 | 4 | static int query_formats(AVFilterContext *ctx) | |
133 | { | ||
134 | static const enum AVPixelFormat in_pixfmts_le[] = { | ||
135 | EIGHTBIT_FORMATS, | ||
136 | HIGHDEPTH_FORMATS(LE), | ||
137 | FLOAT_FORMATS(LE), | ||
138 | AV_PIX_FMT_NONE, | ||
139 | }; | ||
140 | static const enum AVPixelFormat in_pixfmts_be[] = { | ||
141 | EIGHTBIT_FORMATS, | ||
142 | HIGHDEPTH_FORMATS(BE), | ||
143 | FLOAT_FORMATS(BE), | ||
144 | AV_PIX_FMT_NONE, | ||
145 | }; | ||
146 | static const enum AVPixelFormat out8_pixfmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE }; | ||
147 | static const enum AVPixelFormat out9le_pixfmts[] = { AV_PIX_FMT_GRAY9LE, AV_PIX_FMT_NONE }; | ||
148 | static const enum AVPixelFormat out9be_pixfmts[] = { AV_PIX_FMT_GRAY9BE, AV_PIX_FMT_NONE }; | ||
149 | static const enum AVPixelFormat out10le_pixfmts[] = { AV_PIX_FMT_GRAY10LE, AV_PIX_FMT_NONE }; | ||
150 | static const enum AVPixelFormat out10be_pixfmts[] = { AV_PIX_FMT_GRAY10BE, AV_PIX_FMT_NONE }; | ||
151 | static const enum AVPixelFormat out12le_pixfmts[] = { AV_PIX_FMT_GRAY12LE, AV_PIX_FMT_NONE }; | ||
152 | static const enum AVPixelFormat out12be_pixfmts[] = { AV_PIX_FMT_GRAY12BE, AV_PIX_FMT_NONE }; | ||
153 | static const enum AVPixelFormat out14le_pixfmts[] = { AV_PIX_FMT_GRAY14LE, AV_PIX_FMT_NONE }; | ||
154 | static const enum AVPixelFormat out14be_pixfmts[] = { AV_PIX_FMT_GRAY14BE, AV_PIX_FMT_NONE }; | ||
155 | static const enum AVPixelFormat out16le_pixfmts[] = { AV_PIX_FMT_GRAY16LE, AV_PIX_FMT_NONE }; | ||
156 | static const enum AVPixelFormat out16be_pixfmts[] = { AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_NONE }; | ||
157 | static const enum AVPixelFormat out32le_pixfmts[] = { AV_PIX_FMT_GRAYF32LE, AV_PIX_FMT_NONE }; | ||
158 | static const enum AVPixelFormat out32be_pixfmts[] = { AV_PIX_FMT_GRAYF32BE, AV_PIX_FMT_NONE }; | ||
159 | const enum AVPixelFormat *out_pixfmts, *in_pixfmts; | ||
160 | const AVPixFmtDescriptor *desc; | ||
161 | AVFilterFormats *avff; | ||
162 | 4 | int i, ret, depth = 0, be = 0; | |
163 | |||
164 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (!ctx->inputs[0]->incfg.formats || |
165 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | !ctx->inputs[0]->incfg.formats->nb_formats) { |
166 | ✗ | return AVERROR(EAGAIN); | |
167 | } | ||
168 | |||
169 | 4 | avff = ctx->inputs[0]->incfg.formats; | |
170 | 4 | desc = av_pix_fmt_desc_get(avff->formats[0]); | |
171 | 4 | depth = desc->comp[0].depth; | |
172 | 4 | be = desc->flags & AV_PIX_FMT_FLAG_BE; | |
173 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (be) { |
174 | ✗ | in_pixfmts = in_pixfmts_be; | |
175 | } else { | ||
176 | 4 | in_pixfmts = in_pixfmts_le; | |
177 | } | ||
178 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (!ctx->inputs[0]->outcfg.formats) |
179 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if ((ret = ff_formats_ref(ff_make_format_list(in_pixfmts), &ctx->inputs[0]->outcfg.formats)) < 0) |
180 | ✗ | return ret; | |
181 | |||
182 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 2 times.
|
27 | for (i = 1; i < avff->nb_formats; i++) { |
183 | 25 | desc = av_pix_fmt_desc_get(avff->formats[i]); | |
184 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 2 times.
|
25 | if (depth != desc->comp[0].depth || |
185 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | be != (desc->flags & AV_PIX_FMT_FLAG_BE)) { |
186 | 2 | return AVERROR(EAGAIN); | |
187 | } | ||
188 | } | ||
189 | |||
190 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (depth == 8) |
191 | 2 | out_pixfmts = out8_pixfmts; | |
192 | ✗ | else if (!be && depth == 9) | |
193 | ✗ | out_pixfmts = out9le_pixfmts; | |
194 | ✗ | else if (be && depth == 9) | |
195 | ✗ | out_pixfmts = out9be_pixfmts; | |
196 | ✗ | else if (!be && depth == 10) | |
197 | ✗ | out_pixfmts = out10le_pixfmts; | |
198 | ✗ | else if (be && depth == 10) | |
199 | ✗ | out_pixfmts = out10be_pixfmts; | |
200 | ✗ | else if (!be && depth == 12) | |
201 | ✗ | out_pixfmts = out12le_pixfmts; | |
202 | ✗ | else if (be && depth == 12) | |
203 | ✗ | out_pixfmts = out12be_pixfmts; | |
204 | ✗ | else if (!be && depth == 14) | |
205 | ✗ | out_pixfmts = out14le_pixfmts; | |
206 | ✗ | else if (be && depth == 14) | |
207 | ✗ | out_pixfmts = out14be_pixfmts; | |
208 | ✗ | else if (be && depth == 16) | |
209 | ✗ | out_pixfmts = out16be_pixfmts; | |
210 | ✗ | else if (!be && depth == 16) | |
211 | ✗ | out_pixfmts = out16le_pixfmts; | |
212 | ✗ | else if (be && depth == 32) | |
213 | ✗ | out_pixfmts = out32be_pixfmts; | |
214 | else | ||
215 | ✗ | out_pixfmts = out32le_pixfmts; | |
216 | |||
217 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | for (i = 0; i < ctx->nb_outputs; i++) |
218 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if ((ret = ff_formats_ref(ff_make_format_list(out_pixfmts), &ctx->outputs[i]->incfg.formats)) < 0) |
219 | ✗ | return ret; | |
220 | 2 | return 0; | |
221 | } | ||
222 | |||
223 | 2 | static int config_input(AVFilterLink *inlink) | |
224 | { | ||
225 | 2 | AVFilterContext *ctx = inlink->dst; | |
226 | 2 | ExtractPlanesContext *s = ctx->priv; | |
227 | 2 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); | |
228 | int plane_avail, ret, i; | ||
229 | uint8_t rgba_map[4]; | ||
230 | |||
231 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
3 | plane_avail = ((desc->flags & AV_PIX_FMT_FLAG_RGB) ? PLANE_R|PLANE_G|PLANE_B : |
232 | 1 | PLANE_Y | | |
233 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ((desc->nb_components > 2) ? PLANE_U|PLANE_V : 0)) | |
234 | 2 | ((desc->flags & AV_PIX_FMT_FLAG_ALPHA) ? PLANE_A : 0); | |
235 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (s->requested_planes & ~plane_avail) { |
236 | ✗ | av_log(ctx, AV_LOG_ERROR, "Requested planes not available.\n"); | |
237 | ✗ | return AVERROR(EINVAL); | |
238 | } | ||
239 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0) |
240 | ✗ | return ret; | |
241 | |||
242 | 2 | s->depth = desc->comp[0].depth >> 3; | |
243 | 2 | s->step = av_get_padded_bits_per_pixel(desc) >> 3; | |
244 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
3 | s->is_packed = !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) && |
245 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | (desc->nb_components > 1); |
246 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (desc->flags & AV_PIX_FMT_FLAG_RGB) { |
247 | 1 | ff_fill_rgba_map(rgba_map, inlink->format); | |
248 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (i = 0; i < 4; i++) |
249 | 4 | s->map[i] = rgba_map[s->map[i]]; | |
250 | } | ||
251 | |||
252 | 2 | return 0; | |
253 | } | ||
254 | |||
255 | 2 | static int config_output(AVFilterLink *outlink) | |
256 | { | ||
257 | 2 | AVFilterContext *ctx = outlink->src; | |
258 | 2 | AVFilterLink *inlink = ctx->inputs[0]; | |
259 | 2 | ExtractPlanesContext *s = ctx->priv; | |
260 | 2 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); | |
261 | 2 | const int output = outlink->srcpad - ctx->output_pads; | |
262 | |||
263 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (s->map[output] == 1 || s->map[output] == 2) { |
264 | ✗ | outlink->h = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); | |
265 | ✗ | outlink->w = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); | |
266 | } | ||
267 | |||
268 | 2 | return 0; | |
269 | } | ||
270 | |||
271 | 50 | static void extract_from_packed(uint8_t *dst, int dst_linesize, | |
272 | const uint8_t *src, int src_linesize, | ||
273 | int width, int height, | ||
274 | int depth, int step, int comp) | ||
275 | { | ||
276 | int x, y; | ||
277 | |||
278 |
2/2✓ Branch 0 taken 14400 times.
✓ Branch 1 taken 50 times.
|
14450 | for (y = 0; y < height; y++) { |
279 |
1/4✓ Branch 0 taken 14400 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
14400 | switch (depth) { |
280 | 14400 | case 1: | |
281 |
2/2✓ Branch 0 taken 5068800 times.
✓ Branch 1 taken 14400 times.
|
5083200 | for (x = 0; x < width; x++) |
282 | 5068800 | dst[x] = src[x * step + comp]; | |
283 | 14400 | break; | |
284 | ✗ | case 2: | |
285 | ✗ | for (x = 0; x < width; x++) { | |
286 | ✗ | dst[x * 2 ] = src[x * step + comp * 2 ]; | |
287 | ✗ | dst[x * 2 + 1] = src[x * step + comp * 2 + 1]; | |
288 | } | ||
289 | ✗ | break; | |
290 | ✗ | case 4: | |
291 | ✗ | for (x = 0; x < width; x++) { | |
292 | ✗ | dst[x * 4 ] = src[x * step + comp * 4 ]; | |
293 | ✗ | dst[x * 4 + 1] = src[x * step + comp * 4 + 1]; | |
294 | ✗ | dst[x * 4 + 2] = src[x * step + comp * 4 + 2]; | |
295 | ✗ | dst[x * 4 + 3] = src[x * step + comp * 4 + 3]; | |
296 | } | ||
297 | ✗ | break; | |
298 | } | ||
299 | 14400 | dst += dst_linesize; | |
300 | 14400 | src += src_linesize; | |
301 | } | ||
302 | 50 | } | |
303 | |||
304 | 100 | static int extract_plane(AVFilterLink *outlink, AVFrame *frame) | |
305 | { | ||
306 | 100 | AVFilterContext *ctx = outlink->src; | |
307 | 100 | ExtractPlanesContext *s = ctx->priv; | |
308 | 100 | const int idx = s->map[FF_OUTLINK_IDX(outlink)]; | |
309 | AVFrame *out; | ||
310 | |||
311 | 100 | out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | |
312 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
|
100 | if (!out) |
313 | ✗ | return AVERROR(ENOMEM); | |
314 | 100 | av_frame_copy_props(out, frame); | |
315 | |||
316 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 50 times.
|
100 | if (s->is_packed) { |
317 | 50 | extract_from_packed(out->data[0], out->linesize[0], | |
318 | 50 | frame->data[0], frame->linesize[0], | |
319 | outlink->w, outlink->h, | ||
320 | s->depth, | ||
321 | s->step, idx); | ||
322 | } else { | ||
323 | 50 | av_image_copy_plane(out->data[0], out->linesize[0], | |
324 | 50 | frame->data[idx], frame->linesize[idx], | |
325 | s->linesize[idx], outlink->h); | ||
326 | } | ||
327 | |||
328 | 100 | return ff_filter_frame(outlink, out); | |
329 | } | ||
330 | |||
331 | 202 | static int activate(AVFilterContext *ctx) | |
332 | { | ||
333 | 202 | AVFilterLink *inlink = ctx->inputs[0]; | |
334 | int status, ret; | ||
335 | AVFrame *in; | ||
336 | int64_t pts; | ||
337 | |||
338 |
2/2✓ Branch 0 taken 202 times.
✓ Branch 1 taken 202 times.
|
404 | for (int i = 0; i < ctx->nb_outputs; i++) { |
339 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 202 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
202 | FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[i], ctx); |
340 | } | ||
341 | |||
342 | 202 | ret = ff_inlink_consume_frame(inlink, &in); | |
343 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 202 times.
|
202 | if (ret < 0) |
344 | ✗ | return ret; | |
345 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 102 times.
|
202 | if (ret > 0) { |
346 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
|
200 | for (int i = 0; i < ctx->nb_outputs; i++) { |
347 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 100 times.
|
100 | if (ff_outlink_get_status(ctx->outputs[i])) |
348 | ✗ | continue; | |
349 | |||
350 | 100 | ret = extract_plane(ctx->outputs[i], in); | |
351 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
|
100 | if (ret < 0) |
352 | ✗ | break; | |
353 | } | ||
354 | |||
355 | 100 | av_frame_free(&in); | |
356 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
|
100 | if (ret < 0) |
357 | ✗ | return ret; | |
358 | } | ||
359 | |||
360 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 200 times.
|
202 | if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { |
361 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | for (int i = 0; i < ctx->nb_outputs; i++) { |
362 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (ff_outlink_get_status(ctx->outputs[i])) |
363 | ✗ | continue; | |
364 | 2 | ff_outlink_set_status(ctx->outputs[i], status, pts); | |
365 | } | ||
366 | 2 | return 0; | |
367 | } | ||
368 | |||
369 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 100 times.
|
300 | for (int i = 0; i < ctx->nb_outputs; i++) { |
370 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 200 times.
|
200 | if (ff_outlink_get_status(ctx->outputs[i])) |
371 | ✗ | continue; | |
372 | |||
373 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
|
200 | if (ff_outlink_frame_wanted(ctx->outputs[i])) { |
374 | 100 | ff_inlink_request_frame(inlink); | |
375 | 100 | return 0; | |
376 | } | ||
377 | } | ||
378 | |||
379 | 100 | return FFERROR_NOT_READY; | |
380 | } | ||
381 | |||
382 | ✗ | static av_cold int init(AVFilterContext *ctx) | |
383 | { | ||
384 | ✗ | ExtractPlanesContext *s = ctx->priv; | |
385 | ✗ | int planes = (s->requested_planes & 0xf) | (s->requested_planes >> 4); | |
386 | int i, ret; | ||
387 | |||
388 | ✗ | for (i = 0; i < 4; i++) { | |
389 | char *name; | ||
390 | ✗ | AVFilterPad pad = { 0 }; | |
391 | |||
392 | ✗ | if (!(planes & (1 << i))) | |
393 | ✗ | continue; | |
394 | |||
395 | ✗ | name = av_asprintf("out%d", ctx->nb_outputs); | |
396 | ✗ | if (!name) | |
397 | ✗ | return AVERROR(ENOMEM); | |
398 | ✗ | s->map[ctx->nb_outputs] = i; | |
399 | ✗ | pad.name = name; | |
400 | ✗ | pad.type = AVMEDIA_TYPE_VIDEO; | |
401 | ✗ | pad.config_props = config_output; | |
402 | |||
403 | ✗ | if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0) | |
404 | ✗ | return ret; | |
405 | } | ||
406 | |||
407 | ✗ | return 0; | |
408 | } | ||
409 | |||
410 | static const AVFilterPad extractplanes_inputs[] = { | ||
411 | { | ||
412 | .name = "default", | ||
413 | .type = AVMEDIA_TYPE_VIDEO, | ||
414 | .config_props = config_input, | ||
415 | }, | ||
416 | }; | ||
417 | |||
418 | const AVFilter ff_vf_extractplanes = { | ||
419 | .name = "extractplanes", | ||
420 | .description = NULL_IF_CONFIG_SMALL("Extract planes as grayscale frames."), | ||
421 | .priv_size = sizeof(ExtractPlanesContext), | ||
422 | .priv_class = &extractplanes_class, | ||
423 | .init = init, | ||
424 | .activate = activate, | ||
425 | FILTER_INPUTS(extractplanes_inputs), | ||
426 | .outputs = NULL, | ||
427 | FILTER_QUERY_FUNC(query_formats), | ||
428 | .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS, | ||
429 | }; | ||
430 | |||
431 | #if CONFIG_ALPHAEXTRACT_FILTER | ||
432 | |||
433 | 4 | static av_cold int init_alphaextract(AVFilterContext *ctx) | |
434 | { | ||
435 | 4 | ExtractPlanesContext *s = ctx->priv; | |
436 | |||
437 | 4 | s->requested_planes = PLANE_A; | |
438 | 4 | s->map[0] = 3; | |
439 | |||
440 | 4 | return 0; | |
441 | } | ||
442 | |||
443 | static const AVFilterPad alphaextract_outputs[] = { | ||
444 | { | ||
445 | .name = "default", | ||
446 | .type = AVMEDIA_TYPE_VIDEO, | ||
447 | .config_props = config_output, | ||
448 | }, | ||
449 | }; | ||
450 | |||
451 | const AVFilter ff_vf_alphaextract = { | ||
452 | .name = "alphaextract", | ||
453 | .description = NULL_IF_CONFIG_SMALL("Extract an alpha channel as a " | ||
454 | "grayscale image component."), | ||
455 | .priv_size = sizeof(ExtractPlanesContext), | ||
456 | .init = init_alphaextract, | ||
457 | .activate = activate, | ||
458 | FILTER_INPUTS(extractplanes_inputs), | ||
459 | FILTER_OUTPUTS(alphaextract_outputs), | ||
460 | FILTER_QUERY_FUNC(query_formats), | ||
461 | }; | ||
462 | #endif /* CONFIG_ALPHAEXTRACT_FILTER */ | ||
463 |