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
27
33
41
51
52 #define OFFSET(x) offsetof(ExtractPlanesContext, x)
53 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
64 };
65
67
68 #define EIGHTBIT_FORMATS \
69 AV_PIX_FMT_YUV410P, \
70 AV_PIX_FMT_YUV411P, \
71 AV_PIX_FMT_YUV440P, \
72 AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, \
73 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA422P, \
74 AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, \
75 AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P, \
76 AV_PIX_FMT_YUVJ411P, \
77 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA444P, \
78 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A, \
79 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, \
80 AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, \
81 AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, \
82 AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0, \
83 AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR, \
84 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP
85
86 #define HIGHDEPTH_FORMATS(suf) \
87 AV_PIX_FMT_YA16##suf, \
88 AV_PIX_FMT_GRAY9##suf, \
89 AV_PIX_FMT_GRAY10##suf, \
90 AV_PIX_FMT_GRAY12##suf, \
91 AV_PIX_FMT_GRAY14##suf, \
92 AV_PIX_FMT_GRAY16##suf, \
93 AV_PIX_FMT_YUV420P16##suf, AV_PIX_FMT_YUVA420P16##suf, \
94 AV_PIX_FMT_YUV422P16##suf, AV_PIX_FMT_YUVA422P16##suf, \
95 AV_PIX_FMT_YUV444P16##suf, AV_PIX_FMT_YUVA444P16##suf, \
96 AV_PIX_FMT_RGB48##suf, AV_PIX_FMT_BGR48##suf, \
97 AV_PIX_FMT_RGBA64##suf, AV_PIX_FMT_BGRA64##suf, \
98 AV_PIX_FMT_GBRP16##suf, AV_PIX_FMT_GBRAP16##suf, \
99 AV_PIX_FMT_YUV420P10##suf, \
100 AV_PIX_FMT_YUV422P10##suf, \
101 AV_PIX_FMT_YUV444P10##suf, \
102 AV_PIX_FMT_YUV440P10##suf, \
103 AV_PIX_FMT_YUVA420P10##suf, \
104 AV_PIX_FMT_YUVA422P10##suf, \
105 AV_PIX_FMT_YUVA444P10##suf, \
106 AV_PIX_FMT_YUV420P12##suf, \
107 AV_PIX_FMT_YUV422P12##suf, \
108 AV_PIX_FMT_YUV444P12##suf, \
109 AV_PIX_FMT_YUV440P12##suf, \
110 AV_PIX_FMT_YUVA422P12##suf, \
111 AV_PIX_FMT_YUVA444P12##suf, \
112 AV_PIX_FMT_GBRP10##suf, AV_PIX_FMT_GBRAP10##suf, \
113 AV_PIX_FMT_GBRP12##suf, AV_PIX_FMT_GBRAP12##suf, \
114 AV_PIX_FMT_YUV420P9##suf, \
115 AV_PIX_FMT_YUV422P9##suf, \
116 AV_PIX_FMT_YUV444P9##suf, \
117 AV_PIX_FMT_YUVA420P9##suf, \
118 AV_PIX_FMT_YUVA422P9##suf, \
119 AV_PIX_FMT_YUVA444P9##suf, \
120 AV_PIX_FMT_GBRP9##suf, \
121 AV_PIX_FMT_GBRP14##suf, AV_PIX_FMT_GBRAP14##suf, \
122 AV_PIX_FMT_YUV420P14##suf, \
123 AV_PIX_FMT_YUV422P14##suf, \
124 AV_PIX_FMT_YUV444P14##suf
125
126 #define FLOAT_FORMATS(suf) \
127 AV_PIX_FMT_GRAYF32##suf, \
128 AV_PIX_FMT_RGBF32##suf, AV_PIX_FMT_RGBAF32##suf, \
129 AV_PIX_FMT_GBRPF32##suf, AV_PIX_FMT_GBRAPF32##suf \
130
132 {
138 };
144 };
161 int i,
ret, depth = 0,
be = 0;
162
163 if (!
ctx->inputs[0]->incfg.formats ||
164 !
ctx->inputs[0]->incfg.formats->nb_formats) {
166 }
167
168 avff =
ctx->inputs[0]->incfg.formats;
170 depth =
desc->comp[0].depth;
173 in_pixfmts = in_pixfmts_be;
174 } else {
175 in_pixfmts = in_pixfmts_le;
176 }
177 if (!
ctx->inputs[0]->outcfg.formats)
180
183 if (depth !=
desc->comp[0].depth ||
186 }
187 }
188
189 if (depth == 8)
190 out_pixfmts = out8_pixfmts;
191 else if (!
be && depth == 9)
192 out_pixfmts = out9le_pixfmts;
193 else if (
be && depth == 9)
194 out_pixfmts = out9be_pixfmts;
195 else if (!
be && depth == 10)
196 out_pixfmts = out10le_pixfmts;
197 else if (
be && depth == 10)
198 out_pixfmts = out10be_pixfmts;
199 else if (!
be && depth == 12)
200 out_pixfmts = out12le_pixfmts;
201 else if (
be && depth == 12)
202 out_pixfmts = out12be_pixfmts;
203 else if (!
be && depth == 14)
204 out_pixfmts = out14le_pixfmts;
205 else if (
be && depth == 14)
206 out_pixfmts = out14be_pixfmts;
207 else if (
be && depth == 16)
208 out_pixfmts = out16be_pixfmts;
209 else if (!
be && depth == 16)
210 out_pixfmts = out16le_pixfmts;
211 else if (
be && depth == 32)
212 out_pixfmts = out32be_pixfmts;
213 else
214 out_pixfmts = out32le_pixfmts;
215
216 /* Splitting planes apart only makes sense for straight alpha */
219
220 for (
i = 0;
i <
ctx->nb_outputs;
i++)
223 return 0;
224 }
225
227 {
231 int plane_avail,
ret,
i;
232 uint8_t rgba_map[4];
233
238 if (
s->requested_planes & ~plane_avail) {
241 }
244
245 s->depth =
desc->comp[0].depth >> 3;
248 (
desc->nb_components > 1);
251 for (
i = 0;
i < 4;
i++)
252 s->map[
i] = rgba_map[
s->map[
i]];
253 }
254
255 return 0;
256 }
257
259 {
265
269 }
270
271 return 0;
272 }
273
275 const uint8_t *
src,
int src_linesize,
278 {
279 int x, y;
280
281 for (y = 0; y <
height; y++) {
282 switch (depth) {
283 case 1:
284 for (x = 0; x <
width; x++)
286 break;
287 case 2:
288 for (x = 0; x <
width; x++) {
291 }
292 break;
293 case 4:
294 for (x = 0; x <
width; x++) {
299 }
300 break;
301 }
304 }
305 }
306
308 {
313
318 if (idx == 3 /* alpha */)
320
324 outlink->
w, outlink->
h,
327 } else {
330 s->linesize[idx], outlink->
h);
331 }
332
334 }
335
337 {
342
343 for (
int i = 0;
i <
ctx->nb_outputs;
i++) {
345 }
346
351 for (
int i = 0;
i <
ctx->nb_outputs;
i++) {
353 continue;
354
357 break;
358 }
359
363 }
364
366 for (
int i = 0;
i <
ctx->nb_outputs;
i++) {
368 continue;
370 }
371 return 0;
372 }
373
375
377 }
378
380 {
382 int planes = (
s->requested_planes & 0xf) | (
s->requested_planes >> 4);
384
385 for (
i = 0;
i < 4;
i++) {
388
390 continue;
391
395 s->map[
ctx->nb_outputs] =
i;
399
402 }
403
404 return 0;
405 }
406
408 {
412 },
413 };
414
416 .
p.
name =
"extractplanes",
418 .p.priv_class = &extractplanes_class,
426 };
427
428 #if CONFIG_ALPHAEXTRACT_FILTER
429
431 {
433
436
437 return 0;
438 }
439
440 static const AVFilterPad alphaextract_outputs[] = {
441 {
445 },
446 };
447
449 .
p.
name =
"alphaextract",
451 "grayscale image component."),
453 .
init = init_alphaextract,
458 };
459 #endif /* CONFIG_ALPHAEXTRACT_FILTER */