FFmpeg  4.4.9
vf_stereo3d.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Gordon Schmidt <gordon.schmidt <at> s2000.tu-chemnitz.de>
3  * Copyright (c) 2013-2015 Paul B Mahol
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 General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 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
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * 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 #include "libavutil/avassert.h"
23 #include "libavutil/imgutils.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/parseutils.h"
27 #include "libavutil/pixdesc.h"
28 #include "avfilter.h"
29 #include "filters.h"
30 #include "drawutils.h"
31 #include "formats.h"
32 #include "internal.h"
33 #include "video.h"
34 #include "stereo3d.h"
35 
36 enum StereoCode {
37  ANAGLYPH_RC_GRAY, // anaglyph red/cyan gray
38  ANAGLYPH_RC_HALF, // anaglyph red/cyan half colored
39  ANAGLYPH_RC_COLOR, // anaglyph red/cyan colored
40  ANAGLYPH_RC_DUBOIS, // anaglyph red/cyan dubois
41  ANAGLYPH_GM_GRAY, // anaglyph green/magenta gray
42  ANAGLYPH_GM_HALF, // anaglyph green/magenta half colored
43  ANAGLYPH_GM_COLOR, // anaglyph green/magenta colored
44  ANAGLYPH_GM_DUBOIS, // anaglyph green/magenta dubois
45  ANAGLYPH_YB_GRAY, // anaglyph yellow/blue gray
46  ANAGLYPH_YB_HALF, // anaglyph yellow/blue half colored
47  ANAGLYPH_YB_COLOR, // anaglyph yellow/blue colored
48  ANAGLYPH_YB_DUBOIS, // anaglyph yellow/blue dubois
49  ANAGLYPH_RB_GRAY, // anaglyph red/blue gray
50  ANAGLYPH_RG_GRAY, // anaglyph red/green gray
51  MONO_L, // mono output for debugging (left eye only)
52  MONO_R, // mono output for debugging (right eye only)
53  INTERLEAVE_ROWS_LR, // row-interleave (left eye has top row)
54  INTERLEAVE_ROWS_RL, // row-interleave (right eye has top row)
55  SIDE_BY_SIDE_LR, // side by side parallel (left eye left, right eye right)
56  SIDE_BY_SIDE_RL, // side by side crosseye (right eye left, left eye right)
57  SIDE_BY_SIDE_2_LR, // side by side parallel with half width resolution
58  SIDE_BY_SIDE_2_RL, // side by side crosseye with half width resolution
59  ABOVE_BELOW_LR, // above-below (left eye above, right eye below)
60  ABOVE_BELOW_RL, // above-below (right eye above, left eye below)
61  ABOVE_BELOW_2_LR, // above-below with half height resolution
62  ABOVE_BELOW_2_RL, // above-below with half height resolution
63  ALTERNATING_LR, // alternating frames (left eye first, right eye second)
64  ALTERNATING_RL, // alternating frames (right eye first, left eye second)
65  CHECKERBOARD_LR, // checkerboard pattern (left eye first, right eye second)
66  CHECKERBOARD_RL, // checkerboard pattern (right eye first, left eye second)
67  INTERLEAVE_COLS_LR, // column-interleave (left eye first, right eye second)
68  INTERLEAVE_COLS_RL, // column-interleave (right eye first, left eye second)
69  HDMI, // HDMI frame pack (left eye first, right eye second)
70  STEREO_CODE_COUNT // TODO: needs autodetection
71 };
72 
73 typedef struct StereoComponent {
74  int format; ///< StereoCode
75  int width, height;
79  int row_step;
81 
82 static const int ana_coeff[][3][6] = {
84  {{19595, 38470, 7471, 0, 0, 0},
85  { 0, 0, 0, 0, 0, 0},
86  { 0, 0, 0, 19595, 38470, 7471}},
88  {{19595, 38470, 7471, 0, 0, 0},
89  { 0, 0, 0, 19595, 38470, 7471},
90  { 0, 0, 0, 0, 0, 0}},
92  {{19595, 38470, 7471, 0, 0, 0},
93  { 0, 0, 0, 19595, 38470, 7471},
94  { 0, 0, 0, 19595, 38470, 7471}},
96  {{19595, 38470, 7471, 0, 0, 0},
97  { 0, 0, 0, 0, 65536, 0},
98  { 0, 0, 0, 0, 0, 65536}},
100  {{65536, 0, 0, 0, 0, 0},
101  { 0, 0, 0, 0, 65536, 0},
102  { 0, 0, 0, 0, 0, 65536}},
104  {{29884, 32768, 11534, -2818, -5767, -131},
105  {-2621, -2490, -1049, 24773, 48103, -1180},
106  { -983, -1376, -328, -4719, -7406, 80347}},
107  [ANAGLYPH_GM_GRAY] =
108  {{ 0, 0, 0, 19595, 38470, 7471},
109  {19595, 38470, 7471, 0, 0, 0},
110  { 0, 0, 0, 19595, 38470, 7471}},
111  [ANAGLYPH_GM_HALF] =
112  {{ 0, 0, 0, 65536, 0, 0},
113  {19595, 38470, 7471, 0, 0, 0},
114  { 0, 0, 0, 0, 0, 65536}},
116  {{ 0, 0, 0, 65536, 0, 0},
117  { 0, 65536, 0, 0, 0, 0},
118  { 0, 0, 0, 0, 0, 65536}},
120  {{-4063,-10354, -2556, 34669, 46203, 1573},
121  {18612, 43778, 9372, -1049, -983, -4260},
122  { -983, -1769, 1376, 590, 4915, 61407}},
123  [ANAGLYPH_YB_GRAY] =
124  {{ 0, 0, 0, 19595, 38470, 7471},
125  { 0, 0, 0, 19595, 38470, 7471},
126  {19595, 38470, 7471, 0, 0, 0}},
127  [ANAGLYPH_YB_HALF] =
128  {{ 0, 0, 0, 65536, 0, 0},
129  { 0, 0, 0, 0, 65536, 0},
130  {19595, 38470, 7471, 0, 0, 0}},
132  {{ 0, 0, 0, 65536, 0, 0},
133  { 0, 0, 0, 0, 65536, 0},
134  { 0, 0, 65536, 0, 0, 0}},
136  {{69599,-13435,19595, -1048, -8061, -1114},
137  {-1704, 59507, 4456, 393, 4063, -1114},
138  {-2490,-11338, 1442, 6160, 12124, 59703}},
139 };
140 
141 typedef struct Stereo3DContext {
142  const AVClass *class;
144  int width, height;
145  const int *ana_matrix[3];
147  int linesize[4];
148  int pheight[4];
149  int hsub, vsub;
150  int pixstep[4];
152  int blanks;
157 
158 #define OFFSET(x) offsetof(Stereo3DContext, x)
159 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
160 
161 static const AVOption stereo3d_options[] = {
162  { "in", "set input format", OFFSET(in.format), AV_OPT_TYPE_INT, {.i64=SIDE_BY_SIDE_LR}, INTERLEAVE_ROWS_LR, STEREO_CODE_COUNT-1, FLAGS, "in"},
163  { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "in" },
164  { "tb2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "in" },
165  { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "in" },
166  { "tb2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "in" },
167  { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "in" },
168  { "tbl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "in" },
169  { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "in" },
170  { "tbr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "in" },
171  { "al", "alternating frames left first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_LR}, 0, 0, FLAGS, "in" },
172  { "ar", "alternating frames right first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_RL}, 0, 0, FLAGS, "in" },
173  { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "in" },
174  { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "in" },
175  { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "in" },
176  { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "in" },
177  { "irl", "interleave rows left first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_LR}, 0, 0, FLAGS, "in" },
178  { "irr", "interleave rows right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_RL}, 0, 0, FLAGS, "in" },
179  { "icl", "interleave columns left first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_COLS_LR}, 0, 0, FLAGS, "in" },
180  { "icr", "interleave columns right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_COLS_RL}, 0, 0, FLAGS, "in" },
181  { "out", "set output format", OFFSET(out.format), AV_OPT_TYPE_INT, {.i64=ANAGLYPH_RC_DUBOIS}, 0, STEREO_CODE_COUNT-1, FLAGS, "out"},
182  { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "out" },
183  { "tb2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "out" },
184  { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "out" },
185  { "tb2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "out" },
186  { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "out" },
187  { "tbl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "out" },
188  { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "out" },
189  { "tbr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "out" },
190  { "agmc", "anaglyph green magenta color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_COLOR}, 0, 0, FLAGS, "out" },
191  { "agmd", "anaglyph green magenta dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_DUBOIS}, 0, 0, FLAGS, "out" },
192  { "agmg", "anaglyph green magenta gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_GRAY}, 0, 0, FLAGS, "out" },
193  { "agmh", "anaglyph green magenta half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_HALF}, 0, 0, FLAGS, "out" },
194  { "al", "alternating frames left first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_LR}, 0, 0, FLAGS, "out" },
195  { "ar", "alternating frames right first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_RL}, 0, 0, FLAGS, "out" },
196  { "arbg", "anaglyph red blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RB_GRAY}, 0, 0, FLAGS, "out" },
197  { "arcc", "anaglyph red cyan color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_COLOR}, 0, 0, FLAGS, "out" },
198  { "arcd", "anaglyph red cyan dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_DUBOIS}, 0, 0, FLAGS, "out" },
199  { "arcg", "anaglyph red cyan gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_GRAY}, 0, 0, FLAGS, "out" },
200  { "arch", "anaglyph red cyan half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_HALF}, 0, 0, FLAGS, "out" },
201  { "argg", "anaglyph red green gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RG_GRAY}, 0, 0, FLAGS, "out" },
202  { "aybc", "anaglyph yellow blue color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_COLOR}, 0, 0, FLAGS, "out" },
203  { "aybd", "anaglyph yellow blue dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_DUBOIS}, 0, 0, FLAGS, "out" },
204  { "aybg", "anaglyph yellow blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_GRAY}, 0, 0, FLAGS, "out" },
205  { "aybh", "anaglyph yellow blue half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_HALF}, 0, 0, FLAGS, "out" },
206  { "irl", "interleave rows left first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_LR}, 0, 0, FLAGS, "out" },
207  { "irr", "interleave rows right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_RL}, 0, 0, FLAGS, "out" },
208  { "ml", "mono left", 0, AV_OPT_TYPE_CONST, {.i64=MONO_L}, 0, 0, FLAGS, "out" },
209  { "mr", "mono right", 0, AV_OPT_TYPE_CONST, {.i64=MONO_R}, 0, 0, FLAGS, "out" },
210  { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "out" },
211  { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "out" },
212  { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "out" },
213  { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "out" },
214  { "chl", "checkerboard left first", 0, AV_OPT_TYPE_CONST, {.i64=CHECKERBOARD_LR}, 0, 0, FLAGS, "out" },
215  { "chr", "checkerboard right first", 0, AV_OPT_TYPE_CONST, {.i64=CHECKERBOARD_RL}, 0, 0, FLAGS, "out" },
216  { "icl", "interleave columns left first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_COLS_LR}, 0, 0, FLAGS, "out" },
217  { "icr", "interleave columns right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_COLS_RL}, 0, 0, FLAGS, "out" },
218  { "hdmi", "HDMI frame pack", 0, AV_OPT_TYPE_CONST, {.i64=HDMI}, 0, 0, FLAGS, "out" },
219  { NULL }
220 };
221 
223 
224 static const enum AVPixelFormat anaglyph_pix_fmts[] = {
227 };
228 
229 static const enum AVPixelFormat other_pix_fmts[] = {
281 };
282 
284 {
285  Stereo3DContext *s = ctx->priv;
286  const enum AVPixelFormat *pix_fmts;
287  AVFilterFormats *fmts_list;
288 
289  switch (s->out.format) {
290  case ANAGLYPH_GM_COLOR:
291  case ANAGLYPH_GM_DUBOIS:
292  case ANAGLYPH_GM_GRAY:
293  case ANAGLYPH_GM_HALF:
294  case ANAGLYPH_RB_GRAY:
295  case ANAGLYPH_RC_COLOR:
296  case ANAGLYPH_RC_DUBOIS:
297  case ANAGLYPH_RC_GRAY:
298  case ANAGLYPH_RC_HALF:
299  case ANAGLYPH_RG_GRAY:
300  case ANAGLYPH_YB_COLOR:
301  case ANAGLYPH_YB_DUBOIS:
302  case ANAGLYPH_YB_GRAY:
303  case ANAGLYPH_YB_HALF:
305  break;
306  default:
308  }
309 
310  fmts_list = ff_make_format_list(pix_fmts);
311  if (!fmts_list)
312  return AVERROR(ENOMEM);
313  return ff_set_common_formats(ctx, fmts_list);
314 }
315 
316 static inline uint8_t ana_convert(const int *coeff, const uint8_t *left, const uint8_t *right)
317 {
318  int sum;
319 
320  sum = coeff[0] * left[0] + coeff[3] * right[0]; //red in
321  sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in
322  sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in
323 
324  return av_clip_uint8(sum >> 16);
325 }
326 
327 static void anaglyph_ic(uint8_t *dst, uint8_t *lsrc, uint8_t *rsrc,
328  ptrdiff_t dst_linesize, ptrdiff_t l_linesize, ptrdiff_t r_linesize,
329  int width, int height,
330  const int *ana_matrix_r, const int *ana_matrix_g, const int *ana_matrix_b)
331 {
332  int x, y, o;
333 
334  for (y = 0; y < height; y++) {
335  for (o = 0, x = 0; x < width; x++, o+= 3) {
336  dst[o ] = ana_convert(ana_matrix_r, lsrc + o * 2, rsrc + o * 2);
337  dst[o + 1] = ana_convert(ana_matrix_g, lsrc + o * 2, rsrc + o * 2);
338  dst[o + 2] = ana_convert(ana_matrix_b, lsrc + o * 2, rsrc + o * 2);
339  }
340 
341  dst += dst_linesize;
342  lsrc += l_linesize;
343  rsrc += r_linesize;
344  }
345 }
346 
347 static void anaglyph(uint8_t *dst, uint8_t *lsrc, uint8_t *rsrc,
348  ptrdiff_t dst_linesize, ptrdiff_t l_linesize, ptrdiff_t r_linesize,
349  int width, int height,
350  const int *ana_matrix_r, const int *ana_matrix_g, const int *ana_matrix_b)
351 {
352  int x, y, o;
353 
354  for (y = 0; y < height; y++) {
355  for (o = 0, x = 0; x < width; x++, o+= 3) {
356  dst[o ] = ana_convert(ana_matrix_r, lsrc + o, rsrc + o);
357  dst[o + 1] = ana_convert(ana_matrix_g, lsrc + o, rsrc + o);
358  dst[o + 2] = ana_convert(ana_matrix_b, lsrc + o, rsrc + o);
359  }
360 
361  dst += dst_linesize;
362  lsrc += l_linesize;
363  rsrc += r_linesize;
364  }
365 }
366 
367 static int config_output(AVFilterLink *outlink)
368 {
369  AVFilterContext *ctx = outlink->src;
370  AVFilterLink *inlink = ctx->inputs[0];
371  Stereo3DContext *s = ctx->priv;
372  AVRational fps = inlink->frame_rate;
373  AVRational tb = inlink->time_base;
375  int ret;
376  s->aspect = inlink->sample_aspect_ratio;
377 
378  switch (s->in.format) {
379  case INTERLEAVE_COLS_LR:
380  case INTERLEAVE_COLS_RL:
381  case SIDE_BY_SIDE_2_LR:
382  case SIDE_BY_SIDE_LR:
383  case SIDE_BY_SIDE_2_RL:
384  case SIDE_BY_SIDE_RL:
385  if (inlink->w & 1) {
386  av_log(ctx, AV_LOG_ERROR, "width must be even\n");
387  return AVERROR_INVALIDDATA;
388  }
389  break;
390  case INTERLEAVE_ROWS_LR:
391  case INTERLEAVE_ROWS_RL:
392  case ABOVE_BELOW_2_LR:
393  case ABOVE_BELOW_LR:
394  case ABOVE_BELOW_2_RL:
395  case ABOVE_BELOW_RL:
396  if (inlink->h & 1) {
397  av_log(ctx, AV_LOG_ERROR, "height must be even\n");
398  return AVERROR_INVALIDDATA;
399  }
400  if (AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h) & 1) {
401  av_log(ctx, AV_LOG_ERROR, "chroma height must be even\n");
402  return AVERROR_INVALIDDATA;
403  }
404  break;
405  }
406 
407  s->in.width =
408  s->width = inlink->w;
409  s->in.height =
410  s->height = inlink->h;
411  s->in.off_lstep =
412  s->in.off_rstep =
413  s->in.off_left =
414  s->in.off_right =
415  s->in.row_left =
416  s->in.row_right = 0;
417  s->in.row_step = 1;
418 
419  switch (s->in.format) {
420  case SIDE_BY_SIDE_2_LR:
421  s->aspect.num *= 2;
422  case SIDE_BY_SIDE_LR:
423  s->width = inlink->w / 2;
424  s->in.off_right = s->width;
425  break;
426  case SIDE_BY_SIDE_2_RL:
427  s->aspect.num *= 2;
428  case SIDE_BY_SIDE_RL:
429  s->width = inlink->w / 2;
430  s->in.off_left = s->width;
431  break;
432  case ABOVE_BELOW_2_LR:
433  s->aspect.den *= 2;
434  case ABOVE_BELOW_LR:
435  s->in.row_right =
436  s->height = inlink->h / 2;
437  break;
438  case ABOVE_BELOW_2_RL:
439  s->aspect.den *= 2;
440  case ABOVE_BELOW_RL:
441  s->in.row_left =
442  s->height = inlink->h / 2;
443  break;
444  case ALTERNATING_RL:
445  case ALTERNATING_LR:
446  fps.den *= 2;
447  tb.num *= 2;
448  break;
449  case INTERLEAVE_COLS_RL:
450  case INTERLEAVE_COLS_LR:
451  s->width = inlink->w / 2;
452  break;
453  case INTERLEAVE_ROWS_LR:
454  case INTERLEAVE_ROWS_RL:
455  s->in.row_step = 2;
456  if (s->in.format == INTERLEAVE_ROWS_RL)
457  s->in.off_lstep = 1;
458  else
459  s->in.off_rstep = 1;
460  if (s->out.format != CHECKERBOARD_LR &&
461  s->out.format != CHECKERBOARD_RL)
462  s->height = inlink->h / 2;
463  break;
464  default:
465  av_log(ctx, AV_LOG_ERROR, "input format %d is not supported\n", s->in.format);
466  return AVERROR(EINVAL);
467  }
468 
469  s->out.width = s->width;
470  s->out.height = s->height;
471  s->out.off_lstep =
472  s->out.off_rstep =
473  s->out.off_left =
474  s->out.off_right =
475  s->out.row_left =
476  s->out.row_right = 0;
477  s->out.row_step = 1;
478 
479  switch (s->out.format) {
480  case ANAGLYPH_RB_GRAY:
481  case ANAGLYPH_RG_GRAY:
482  case ANAGLYPH_RC_GRAY:
483  case ANAGLYPH_RC_HALF:
484  case ANAGLYPH_RC_COLOR:
485  case ANAGLYPH_RC_DUBOIS:
486  case ANAGLYPH_GM_GRAY:
487  case ANAGLYPH_GM_HALF:
488  case ANAGLYPH_GM_COLOR:
489  case ANAGLYPH_GM_DUBOIS:
490  case ANAGLYPH_YB_GRAY:
491  case ANAGLYPH_YB_HALF:
492  case ANAGLYPH_YB_COLOR:
493  case ANAGLYPH_YB_DUBOIS: {
494  uint8_t rgba_map[4];
495 
496  ff_fill_rgba_map(rgba_map, outlink->format);
497  s->ana_matrix[rgba_map[0]] = &ana_coeff[s->out.format][0][0];
498  s->ana_matrix[rgba_map[1]] = &ana_coeff[s->out.format][1][0];
499  s->ana_matrix[rgba_map[2]] = &ana_coeff[s->out.format][2][0];
500  break;
501  }
502  case SIDE_BY_SIDE_2_LR:
503  s->aspect.den *= 2;
504  case SIDE_BY_SIDE_LR:
505  s->out.width = s->width * 2;
506  s->out.off_right = s->width;
507  break;
508  case SIDE_BY_SIDE_2_RL:
509  s->aspect.den *= 2;
510  case SIDE_BY_SIDE_RL:
511  s->out.width = s->width * 2;
512  s->out.off_left = s->width;
513  break;
514  case ABOVE_BELOW_2_LR:
515  s->aspect.num *= 2;
516  case ABOVE_BELOW_LR:
517  s->out.height = s->height * 2;
518  s->out.row_right = s->height;
519  break;
520  case HDMI:
521  if (s->height != 720 && s->height != 1080) {
522  av_log(ctx, AV_LOG_ERROR, "Only 720 and 1080 height supported\n");
523  return AVERROR(EINVAL);
524  }
525 
526  s->blanks = s->height / 24;
527  s->out.height = s->height * 2 + s->blanks;
528  s->out.row_right = s->height + s->blanks;
529  break;
530  case ABOVE_BELOW_2_RL:
531  s->aspect.num *= 2;
532  case ABOVE_BELOW_RL:
533  s->out.height = s->height * 2;
534  s->out.row_left = s->height;
535  break;
536  case INTERLEAVE_ROWS_LR:
537  s->in.row_step = 1 + (s->in.format == INTERLEAVE_ROWS_RL);
538  s->out.row_step = 2;
539  s->out.height = s->height * 2;
540  s->out.off_rstep = 1;
541  break;
542  case INTERLEAVE_ROWS_RL:
543  s->in.row_step = 1 + (s->in.format == INTERLEAVE_ROWS_LR);
544  s->out.row_step = 2;
545  s->out.height = s->height * 2;
546  s->out.off_lstep = 1;
547  break;
548  case MONO_R:
549  if (s->in.format != INTERLEAVE_COLS_LR) {
550  s->in.off_left = s->in.off_right;
551  s->in.row_left = s->in.row_right;
552  }
553  if (s->in.format == INTERLEAVE_ROWS_LR)
554  FFSWAP(int, s->in.off_lstep, s->in.off_rstep);
555  break;
556  case MONO_L:
557  if (s->in.format == INTERLEAVE_ROWS_RL)
558  FFSWAP(int, s->in.off_lstep, s->in.off_rstep);
559  break;
560  case ALTERNATING_RL:
561  case ALTERNATING_LR:
562  fps.num *= 2;
563  tb.den *= 2;
564  break;
565  case CHECKERBOARD_LR:
566  case CHECKERBOARD_RL:
567  case INTERLEAVE_COLS_LR:
568  case INTERLEAVE_COLS_RL:
569  s->out.width = s->width * 2;
570  break;
571  default:
572  av_log(ctx, AV_LOG_ERROR, "output format %d is not supported\n", s->out.format);
573  return AVERROR(EINVAL);
574  }
575 
576  if (s->in.format == INTERLEAVE_COLS_LR || s->in.format == INTERLEAVE_COLS_RL) {
577  if ((s->in.format & 1) != (s->out.format & 1)) {
578  FFSWAP(int, s->in.row_left, s->in.row_right);
579  FFSWAP(int, s->in.off_lstep, s->in.off_rstep);
580  FFSWAP(int, s->in.off_left, s->in.off_right);
581  FFSWAP(int, s->out.row_left, s->out.row_right);
582  FFSWAP(int, s->out.off_lstep, s->out.off_rstep);
583  FFSWAP(int, s->out.off_left, s->out.off_right);
584  }
585  }
586 
587  outlink->w = s->out.width;
588  outlink->h = s->out.height;
589  outlink->frame_rate = fps;
590  outlink->time_base = tb;
591  outlink->sample_aspect_ratio = s->aspect;
592 
593  if ((ret = av_image_fill_linesizes(s->linesize, outlink->format, s->width)) < 0)
594  return ret;
595  s->nb_planes = av_pix_fmt_count_planes(outlink->format);
597  s->pheight[1] = s->pheight[2] = AV_CEIL_RSHIFT(s->height, desc->log2_chroma_h);
598  s->pheight[0] = s->pheight[3] = s->height;
599  s->hsub = desc->log2_chroma_w;
600  s->vsub = desc->log2_chroma_h;
601 
602  s->dsp.anaglyph = anaglyph;
603  if (ARCH_X86)
604  ff_stereo3d_init_x86(&s->dsp);
605 
606  return 0;
607 }
608 
609 typedef struct ThreadData {
611  AVFrame *out;
612 } ThreadData;
613 
614 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
615 {
616  Stereo3DContext *s = ctx->priv;
617  ThreadData *td = arg;
618  AVFrame *ileft = td->ileft;
619  AVFrame *iright = td->iright;
620  AVFrame *out = td->out;
621  int height = s->out.height;
622  int start = ff_slice_pos(height, jobnr, nb_jobs);
623  int end = ff_slice_pos(height, jobnr + 1, nb_jobs);
624  const int **ana_matrix = s->ana_matrix;
625 
626  s->dsp.anaglyph(out->data[0] + out->linesize[0] * start,
627  ileft ->data[0] + s->in_off_left [0] + ileft->linesize[0] * start * s->in.row_step,
628  iright->data[0] + s->in_off_right[0] + iright->linesize[0] * start * s->in.row_step,
629  out->linesize[0],
630  ileft->linesize[0] * s->in.row_step,
631  iright->linesize[0] * s->in.row_step,
632  s->out.width, end - start,
633  ana_matrix[0], ana_matrix[1], ana_matrix[2]);
634 
635  return 0;
636 }
637 
638 static void interleave_cols_to_any(Stereo3DContext *s, int *out_off, int p, AVFrame *in, AVFrame *out, int d)
639 {
640  int y, x;
641 
642  for (y = 0; y < s->pheight[p]; y++) {
643  const uint8_t *src = (const uint8_t*)in->data[p] + y * in->linesize[p] + d * s->pixstep[p];
644  uint8_t *dst = out->data[p] + out_off[p] + y * out->linesize[p] * s->out.row_step;
645 
646  switch (s->pixstep[p]) {
647  case 1:
648  for (x = 0; x < s->linesize[p]; x++)
649  dst[x] = src[x * 2];
650  break;
651  case 2:
652  for (x = 0; x < s->linesize[p]; x+=2)
653  AV_WN16(&dst[x], AV_RN16(&src[x * 2]));
654  break;
655  case 3:
656  for (x = 0; x < s->linesize[p]; x+=3)
657  AV_WB24(&dst[x], AV_RB24(&src[x * 2]));
658  break;
659  case 4:
660  for (x = 0; x < s->linesize[p]; x+=4)
661  AV_WN32(&dst[x], AV_RN32(&src[x * 2]));
662  break;
663  case 6:
664  for (x = 0; x < s->linesize[p]; x+=6)
665  AV_WB48(&dst[x], AV_RB48(&src[x * 2]));
666  break;
667  case 8:
668  for (x = 0; x < s->linesize[p]; x+=8)
669  AV_WN64(&dst[x], AV_RN64(&src[x * 2]));
670  break;
671  }
672  }
673 }
674 
675 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
676 {
677  AVFilterContext *ctx = inlink->dst;
678  Stereo3DContext *s = ctx->priv;
679  AVFilterLink *outlink = ctx->outputs[0];
680  AVFrame *out = NULL, *oleft, *oright, *ileft, *iright;
681  int out_off_left[4], out_off_right[4];
682  int i, ret;
683 
684  if (s->in.format == s->out.format)
685  return ff_filter_frame(outlink, inpicref);
686 
687  switch (s->out.format) {
688  case ALTERNATING_LR:
689  case ALTERNATING_RL:
690  if (!s->prev) {
691  s->prev = inpicref;
692  return 0;
693  }
694  break;
695  };
696 
697  switch (s->in.format) {
698  case ALTERNATING_LR:
699  case ALTERNATING_RL:
700  if (!s->prev) {
701  s->prev = inpicref;
702  return 0;
703  }
704  ileft = s->prev;
705  iright = inpicref;
706  if (s->in.format == ALTERNATING_RL)
707  FFSWAP(AVFrame *, ileft, iright);
708  break;
709  default:
710  ileft = iright = inpicref;
711  };
712 
713  if ((s->out.format == ALTERNATING_LR ||
714  s->out.format == ALTERNATING_RL) &&
715  (s->in.format == SIDE_BY_SIDE_LR ||
716  s->in.format == SIDE_BY_SIDE_RL ||
717  s->in.format == SIDE_BY_SIDE_2_LR ||
718  s->in.format == SIDE_BY_SIDE_2_RL ||
719  s->in.format == ABOVE_BELOW_LR ||
720  s->in.format == ABOVE_BELOW_RL ||
721  s->in.format == ABOVE_BELOW_2_LR ||
722  s->in.format == ABOVE_BELOW_2_RL ||
723  s->in.format == INTERLEAVE_ROWS_LR ||
724  s->in.format == INTERLEAVE_ROWS_RL)) {
725  oright = av_frame_clone(s->prev);
726  oleft = av_frame_clone(s->prev);
727  if (!oright || !oleft) {
728  av_frame_free(&oright);
729  av_frame_free(&oleft);
730  av_frame_free(&s->prev);
731  av_frame_free(&inpicref);
732  return AVERROR(ENOMEM);
733  }
734  } else if ((s->out.format == MONO_L ||
735  s->out.format == MONO_R) &&
736  (s->in.format == SIDE_BY_SIDE_LR ||
737  s->in.format == SIDE_BY_SIDE_RL ||
738  s->in.format == SIDE_BY_SIDE_2_LR ||
739  s->in.format == SIDE_BY_SIDE_2_RL ||
740  s->in.format == ABOVE_BELOW_LR ||
741  s->in.format == ABOVE_BELOW_RL ||
742  s->in.format == ABOVE_BELOW_2_LR ||
743  s->in.format == ABOVE_BELOW_2_RL ||
744  s->in.format == INTERLEAVE_ROWS_LR ||
745  s->in.format == INTERLEAVE_ROWS_RL)) {
746  out = oleft = oright = av_frame_clone(inpicref);
747  if (!out) {
748  av_frame_free(&s->prev);
749  av_frame_free(&inpicref);
750  return AVERROR(ENOMEM);
751  }
752  } else if ((s->out.format == MONO_L && s->in.format == ALTERNATING_LR) ||
753  (s->out.format == MONO_R && s->in.format == ALTERNATING_RL)) {
754  s->prev->pts /= 2;
755  ret = ff_filter_frame(outlink, s->prev);
756  av_frame_free(&inpicref);
757  s->prev = NULL;
758  return ret;
759  } else if ((s->out.format == MONO_L && s->in.format == ALTERNATING_RL) ||
760  (s->out.format == MONO_R && s->in.format == ALTERNATING_LR)) {
761  av_frame_free(&s->prev);
762  inpicref->pts /= 2;
763  return ff_filter_frame(outlink, inpicref);
764  } else if ((s->out.format == ALTERNATING_LR && s->in.format == ALTERNATING_RL) ||
765  (s->out.format == ALTERNATING_RL && s->in.format == ALTERNATING_LR)) {
766  FFSWAP(int64_t, s->prev->pts, inpicref->pts);
767  ff_filter_frame(outlink, inpicref);
768  ret = ff_filter_frame(outlink, s->prev);
769  s->prev = NULL;
770  return ret;
771  } else {
772  out = oleft = oright = ff_get_video_buffer(outlink, outlink->w, outlink->h);
773  if (!out) {
774  av_frame_free(&s->prev);
775  av_frame_free(&inpicref);
776  return AVERROR(ENOMEM);
777  }
778  av_frame_copy_props(out, inpicref);
779 
780  if (s->out.format == ALTERNATING_LR ||
781  s->out.format == ALTERNATING_RL) {
782  oright = ff_get_video_buffer(outlink, outlink->w, outlink->h);
783  if (!oright) {
784  av_frame_free(&oleft);
785  av_frame_free(&s->prev);
786  av_frame_free(&inpicref);
787  return AVERROR(ENOMEM);
788  }
789  av_frame_copy_props(oright, s->prev);
790  }
791  }
792 
793  for (i = 0; i < 4; i++) {
794  int hsub = i == 1 || i == 2 ? s->hsub : 0;
795  int vsub = i == 1 || i == 2 ? s->vsub : 0;
796  s->in_off_left[i] = (AV_CEIL_RSHIFT(s->in.row_left, vsub) + s->in.off_lstep) * ileft->linesize[i] + AV_CEIL_RSHIFT(s->in.off_left * s->pixstep[i], hsub);
797  s->in_off_right[i] = (AV_CEIL_RSHIFT(s->in.row_right, vsub) + s->in.off_rstep) * iright->linesize[i] + AV_CEIL_RSHIFT(s->in.off_right * s->pixstep[i], hsub);
798  out_off_left[i] = (AV_CEIL_RSHIFT(s->out.row_left, vsub) + s->out.off_lstep) * oleft->linesize[i] + AV_CEIL_RSHIFT(s->out.off_left * s->pixstep[i], hsub);
799  out_off_right[i] = (AV_CEIL_RSHIFT(s->out.row_right, vsub) + s->out.off_rstep) * oright->linesize[i] + AV_CEIL_RSHIFT(s->out.off_right * s->pixstep[i], hsub);
800  }
801 
802  switch (s->out.format) {
803  case ALTERNATING_LR:
804  case ALTERNATING_RL:
805  switch (s->in.format) {
806  case INTERLEAVE_ROWS_LR:
807  case INTERLEAVE_ROWS_RL:
808  for (i = 0; i < s->nb_planes; i++) {
809  oleft->linesize[i] *= 2;
810  oright->linesize[i] *= 2;
811  }
812  case ABOVE_BELOW_LR:
813  case ABOVE_BELOW_RL:
814  case ABOVE_BELOW_2_LR:
815  case ABOVE_BELOW_2_RL:
816  case SIDE_BY_SIDE_LR:
817  case SIDE_BY_SIDE_RL:
818  case SIDE_BY_SIDE_2_LR:
819  case SIDE_BY_SIDE_2_RL:
820  oleft->width = outlink->w;
821  oright->width = outlink->w;
822  oleft->height = outlink->h;
823  oright->height = outlink->h;
824 
825  for (i = 0; i < s->nb_planes; i++) {
826  oleft->data[i] += s->in_off_left[i];
827  oright->data[i] += s->in_off_right[i];
828  }
829  break;
830  default:
831  goto copy;
832  break;
833  }
834  break;
835  case HDMI:
836  for (i = 0; i < s->nb_planes; i++) {
837  int j, h = s->height >> ((i == 1 || i == 2) ? s->vsub : 0);
838  int b = (s->blanks) >> ((i == 1 || i == 2) ? s->vsub : 0);
839 
840  for (j = h; j < h + b; j++)
841  memset(oleft->data[i] + j * s->linesize[i], 0, s->linesize[i]);
842  }
843  case SIDE_BY_SIDE_LR:
844  case SIDE_BY_SIDE_RL:
845  case SIDE_BY_SIDE_2_LR:
846  case SIDE_BY_SIDE_2_RL:
847  case ABOVE_BELOW_LR:
848  case ABOVE_BELOW_RL:
849  case ABOVE_BELOW_2_LR:
850  case ABOVE_BELOW_2_RL:
851  case INTERLEAVE_ROWS_LR:
852  case INTERLEAVE_ROWS_RL:
853 copy:
854  if (s->in.format == INTERLEAVE_COLS_LR ||
855  s->in.format == INTERLEAVE_COLS_RL) {
856  for (i = 0; i < s->nb_planes; i++) {
857  int d = (s->in.format & 1) != (s->out.format & 1);
858 
859  interleave_cols_to_any(s, out_off_left, i, ileft, oleft, d);
860  interleave_cols_to_any(s, out_off_right, i, iright, oright, !d);
861  }
862  } else {
863  for (i = 0; i < s->nb_planes; i++) {
864  av_image_copy_plane(oleft->data[i] + out_off_left[i],
865  oleft->linesize[i] * s->out.row_step,
866  ileft->data[i] + s->in_off_left[i],
867  ileft->linesize[i] * s->in.row_step,
868  s->linesize[i], s->pheight[i]);
869  av_image_copy_plane(oright->data[i] + out_off_right[i],
870  oright->linesize[i] * s->out.row_step,
871  iright->data[i] + s->in_off_right[i],
872  iright->linesize[i] * s->in.row_step,
873  s->linesize[i], s->pheight[i]);
874  }
875  }
876  break;
877  case MONO_L:
878  iright = ileft;
879  case MONO_R:
880  switch (s->in.format) {
881  case INTERLEAVE_ROWS_LR:
882  case INTERLEAVE_ROWS_RL:
883  for (i = 0; i < s->nb_planes; i++) {
884  out->linesize[i] *= 2;
885  }
886  case ABOVE_BELOW_LR:
887  case ABOVE_BELOW_RL:
888  case ABOVE_BELOW_2_LR:
889  case ABOVE_BELOW_2_RL:
890  case SIDE_BY_SIDE_LR:
891  case SIDE_BY_SIDE_RL:
892  case SIDE_BY_SIDE_2_LR:
893  case SIDE_BY_SIDE_2_RL:
894  out->width = outlink->w;
895  out->height = outlink->h;
896 
897  for (i = 0; i < s->nb_planes; i++) {
898  out->data[i] += s->in_off_left[i];
899  }
900  break;
901  case INTERLEAVE_COLS_LR:
902  case INTERLEAVE_COLS_RL:
903  for (i = 0; i < s->nb_planes; i++) {
904  const int d = (s->in.format & 1) != (s->out.format & 1);
905 
906  interleave_cols_to_any(s, out_off_right, i, iright, out, d);
907  }
908  break;
909  default:
910  for (i = 0; i < s->nb_planes; i++) {
911  av_image_copy_plane(out->data[i], out->linesize[i],
912  iright->data[i] + s->in_off_left[i],
913  iright->linesize[i] * s->in.row_step,
914  s->linesize[i], s->pheight[i]);
915  }
916  break;
917  }
918  break;
919  case ANAGLYPH_RB_GRAY:
920  case ANAGLYPH_RG_GRAY:
921  case ANAGLYPH_RC_GRAY:
922  case ANAGLYPH_RC_HALF:
923  case ANAGLYPH_RC_COLOR:
924  case ANAGLYPH_RC_DUBOIS:
925  case ANAGLYPH_GM_GRAY:
926  case ANAGLYPH_GM_HALF:
927  case ANAGLYPH_GM_COLOR:
928  case ANAGLYPH_GM_DUBOIS:
929  case ANAGLYPH_YB_GRAY:
930  case ANAGLYPH_YB_HALF:
931  case ANAGLYPH_YB_COLOR:
932  case ANAGLYPH_YB_DUBOIS: {
933  if (s->in.format == INTERLEAVE_COLS_LR ||
934  s->in.format == INTERLEAVE_COLS_RL) {
935  const int d = (s->in.format & 1);
936 
937  anaglyph_ic(out->data[0],
938  ileft ->data[0] + s->in_off_left [0] + d * 3,
939  iright->data[0] + s->in_off_right[0] + (!d) * 3,
940  out->linesize[0],
941  ileft->linesize[0] * s->in.row_step,
942  iright->linesize[0] * s->in.row_step,
943  s->out.width, s->out.height,
944  s->ana_matrix[0], s->ana_matrix[1], s->ana_matrix[2]);
945  } else {
946  ThreadData td;
947 
948  td.ileft = ileft; td.iright = iright; td.out = out;
949  ctx->internal->execute(ctx, filter_slice, &td, NULL,
950  FFMIN(s->out.height, ff_filter_get_nb_threads(ctx)));
951  }
952  break;
953  }
954  case CHECKERBOARD_RL:
955  case CHECKERBOARD_LR:
956  for (i = 0; i < s->nb_planes; i++) {
957  int x, y;
958 
959  for (y = 0; y < s->pheight[i]; y++) {
960  uint8_t *dst = out->data[i] + out->linesize[i] * y;
961  const int d1 = (s->in.format == INTERLEAVE_COLS_LR || s->in.format == INTERLEAVE_COLS_RL) && (s->in.format & 1) != (s->out.format & 1);
962  const int d2 = (s->in.format == INTERLEAVE_COLS_LR || s->in.format == INTERLEAVE_COLS_RL) ? !d1 : 0;
963  const int m = 1 + (s->in.format == INTERLEAVE_COLS_LR || s->in.format == INTERLEAVE_COLS_RL);
964  const int in_y = y / s->in.row_step * s->in.row_step;
965  uint8_t *left = ileft->data[i] + ileft->linesize[i] * in_y + s->in_off_left[i] + d1 * s->pixstep[i];
966  uint8_t *right = iright->data[i] + iright->linesize[i] * in_y + s->in_off_right[i] + d2 * s->pixstep[i];
967  int p, b;
968 
969  if (s->out.format == CHECKERBOARD_RL && s->in.format != INTERLEAVE_COLS_LR && s->in.format != INTERLEAVE_COLS_RL)
970  FFSWAP(uint8_t*, left, right);
971  switch (s->pixstep[i]) {
972  case 1:
973  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=2, p++, b+=2) {
974  dst[x ] = (b&1) == (y&1) ? left[p*m] : right[p*m];
975  dst[x+1] = (b&1) != (y&1) ? left[p*m] : right[p*m];
976  }
977  break;
978  case 2:
979  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=4, p+=2, b+=2) {
980  AV_WN16(&dst[x ], (b&1) == (y&1) ? AV_RN16(&left[p*m]) : AV_RN16(&right[p*m]));
981  AV_WN16(&dst[x+2], (b&1) != (y&1) ? AV_RN16(&left[p*m]) : AV_RN16(&right[p*m]));
982  }
983  break;
984  case 3:
985  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=6, p+=3, b+=2) {
986  AV_WB24(&dst[x ], (b&1) == (y&1) ? AV_RB24(&left[p*m]) : AV_RB24(&right[p*m]));
987  AV_WB24(&dst[x+3], (b&1) != (y&1) ? AV_RB24(&left[p*m]) : AV_RB24(&right[p*m]));
988  }
989  break;
990  case 4:
991  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=8, p+=4, b+=2) {
992  AV_WN32(&dst[x ], (b&1) == (y&1) ? AV_RN32(&left[p*m]) : AV_RN32(&right[p*m]));
993  AV_WN32(&dst[x+4], (b&1) != (y&1) ? AV_RN32(&left[p*m]) : AV_RN32(&right[p*m]));
994  }
995  break;
996  case 6:
997  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=12, p+=6, b+=2) {
998  AV_WB48(&dst[x ], (b&1) == (y&1) ? AV_RB48(&left[p*m]) : AV_RB48(&right[p*m]));
999  AV_WB48(&dst[x+6], (b&1) != (y&1) ? AV_RB48(&left[p*m]) : AV_RB48(&right[p*m]));
1000  }
1001  break;
1002  case 8:
1003  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=16, p+=8, b+=2) {
1004  AV_WN64(&dst[x ], (b&1) == (y&1) ? AV_RN64(&left[p*m]) : AV_RN64(&right[p*m]));
1005  AV_WN64(&dst[x+8], (b&1) != (y&1) ? AV_RN64(&left[p*m]) : AV_RN64(&right[p*m]));
1006  }
1007  break;
1008  }
1009  }
1010  }
1011  break;
1012  case INTERLEAVE_COLS_LR:
1013  case INTERLEAVE_COLS_RL:
1014  for (i = 0; i < s->nb_planes; i++) {
1015  const int d = (s->in.format == INTERLEAVE_COLS_LR || s->in.format == INTERLEAVE_COLS_RL);
1016  const int m = 1 + d;
1017  int x, y;
1018 
1019  for (y = 0; y < s->pheight[i]; y++) {
1020  uint8_t *dst = out->data[i] + out->linesize[i] * y;
1021  uint8_t *left = ileft->data[i] + ileft->linesize[i] * y * s->in.row_step + s->in_off_left[i] + d * s->pixstep[i];
1022  uint8_t *right = iright->data[i] + iright->linesize[i] * y * s->in.row_step + s->in_off_right[i];
1023  int p, b;
1024 
1025  if (s->out.format == INTERLEAVE_COLS_LR)
1026  FFSWAP(uint8_t*, left, right);
1027 
1028  switch (s->pixstep[i]) {
1029  case 1:
1030  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=2, p++, b+=2) {
1031  dst[x ] = b&1 ? left[p*m] : right[p*m];
1032  dst[x+1] = !(b&1) ? left[p*m] : right[p*m];
1033  }
1034  break;
1035  case 2:
1036  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=4, p+=2, b+=2) {
1037  AV_WN16(&dst[x ], b&1 ? AV_RN16(&left[p*m]) : AV_RN16(&right[p*m]));
1038  AV_WN16(&dst[x+2], !(b&1) ? AV_RN16(&left[p*m]) : AV_RN16(&right[p*m]));
1039  }
1040  break;
1041  case 3:
1042  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=6, p+=3, b+=2) {
1043  AV_WB24(&dst[x ], b&1 ? AV_RB24(&left[p*m]) : AV_RB24(&right[p*m]));
1044  AV_WB24(&dst[x+3], !(b&1) ? AV_RB24(&left[p*m]) : AV_RB24(&right[p*m]));
1045  }
1046  break;
1047  case 4:
1048  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=8, p+=4, b+=2) {
1049  AV_WN32(&dst[x ], b&1 ? AV_RN32(&left[p*m]) : AV_RN32(&right[p*m]));
1050  AV_WN32(&dst[x+4], !(b&1) ? AV_RN32(&left[p*m]) : AV_RN32(&right[p*m]));
1051  }
1052  break;
1053  case 6:
1054  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=12, p+=6, b+=2) {
1055  AV_WB48(&dst[x ], b&1 ? AV_RB48(&left[p*m]) : AV_RB48(&right[p*m]));
1056  AV_WB48(&dst[x+6], !(b&1) ? AV_RB48(&left[p*m]) : AV_RB48(&right[p*m]));
1057  }
1058  break;
1059  case 8:
1060  for (x = 0, b = 0, p = 0; x < s->linesize[i] * 2; x+=16, p+=8, b+=2) {
1061  AV_WN64(&dst[x ], b&1 ? AV_RN64(&left[p*m]) : AV_RN64(&right[p*m]));
1062  AV_WN64(&dst[x+8], !(b&1) ? AV_RN64(&left[p*m]) : AV_RN64(&right[p*m]));
1063  }
1064  break;
1065  }
1066  }
1067  }
1068  break;
1069  default:
1070  av_assert0(0);
1071  }
1072 
1073  if (oright != oleft) {
1074  if (s->out.format == ALTERNATING_LR)
1075  FFSWAP(AVFrame *, oleft, oright);
1076  oright->pts = s->prev->pts * 2;
1077  ff_filter_frame(outlink, oright);
1078  out = oleft;
1079  oleft->pts = s->prev->pts + inpicref->pts;
1080  av_frame_free(&s->prev);
1081  s->prev = inpicref;
1082  } else if (s->in.format == ALTERNATING_LR ||
1083  s->in.format == ALTERNATING_RL) {
1084  out->pts = s->prev->pts / 2;
1085  av_frame_free(&s->prev);
1086  av_frame_free(&inpicref);
1087  } else {
1088  av_frame_free(&s->prev);
1089  av_frame_free(&inpicref);
1090  }
1091  av_assert0(out);
1092  out->sample_aspect_ratio = s->aspect;
1093  return ff_filter_frame(outlink, out);
1094 }
1095 
1097 {
1098  Stereo3DContext *s = ctx->priv;
1099 
1100  av_frame_free(&s->prev);
1101 }
1102 
1103 static const AVFilterPad stereo3d_inputs[] = {
1104  {
1105  .name = "default",
1106  .type = AVMEDIA_TYPE_VIDEO,
1107  .filter_frame = filter_frame,
1108  },
1109  { NULL }
1110 };
1111 
1112 static const AVFilterPad stereo3d_outputs[] = {
1113  {
1114  .name = "default",
1115  .type = AVMEDIA_TYPE_VIDEO,
1116  .config_props = config_output,
1117  },
1118  { NULL }
1119 };
1120 
1122  .name = "stereo3d",
1123  .description = NULL_IF_CONFIG_SMALL("Convert video stereoscopic 3D view."),
1124  .priv_size = sizeof(Stereo3DContext),
1125  .uninit = uninit,
1129  .priv_class = &stereo3d_class,
1131 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define av_cold
Definition: attributes.h:88
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
uint8_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:805
Main libavfilter public API header.
#define AV_RB24
Definition: intreadwrite.h:64
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
#define FFSWAP(type, a, b)
Definition: common.h:108
#define FFMIN(a, b)
Definition: common.h:105
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define av_clip_uint8
Definition: common.h:128
#define ARCH_X86
Definition: config.h:39
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:35
misc drawing utilities
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
Definition: filters.h:282
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:540
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:376
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:89
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
Definition: imgutils.c:35
misc image utilities
RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT RGB2YUV_SHIFT uint8_t const uint8_t const uint8_t const uint8_t * rsrc
Definition: input.c:399
int i
Definition: input.c:407
#define AV_WB24(p, d)
Definition: intreadwrite.h:450
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
#define AV_RN64(p)
Definition: intreadwrite.h:368
#define AV_RN32(p)
Definition: intreadwrite.h:364
#define AV_WB48(p, darg)
Definition: intreadwrite.h:481
#define AV_WN64(p, v)
Definition: intreadwrite.h:380
#define AV_WN16(p, v)
Definition: intreadwrite.h:372
#define AV_RN16(p)
Definition: intreadwrite.h:360
#define AV_RB48(x)
Definition: intreadwrite.h:472
const char * arg
Definition: jacosubdec.c:67
void ff_stereo3d_init_x86(Stereo3DDSPContext *dsp)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
Stereoscopic video.
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
const char * desc
Definition: libsvtav1.c:83
AVOptions.
misc parsing utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2613
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_YUV444P16BE
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:136
@ AV_PIX_FMT_YUV420P16BE
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:132
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
@ AV_PIX_FMT_GBRP10BE
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:172
@ AV_PIX_FMT_YUVA420P9BE
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), big-endian
Definition: pixfmt.h:178
@ AV_PIX_FMT_YUV420P14LE
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:245
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
@ AV_PIX_FMT_YUVA444P9LE
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:183
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
@ AV_PIX_FMT_YUVA444P10LE
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:189
@ AV_PIX_FMT_GBRP9LE
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:171
@ AV_PIX_FMT_YUV444P14BE
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:252
@ AV_PIX_FMT_YUVA420P10BE
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:184
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
@ AV_PIX_FMT_GBRP12BE
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:254
@ AV_PIX_FMT_YUVA422P9LE
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian
Definition: pixfmt.h:181
@ AV_PIX_FMT_YUV420P9LE
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:157
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
@ AV_PIX_FMT_BGR48BE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:148
@ AV_PIX_FMT_YUVA420P10LE
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:185
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:102
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
@ AV_PIX_FMT_YUV422P10BE
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:160
@ AV_PIX_FMT_YUVA422P10LE
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:187
@ AV_PIX_FMT_YUV420P10LE
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:159
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:205
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:206
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:239
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
@ AV_PIX_FMT_YUV422P16LE
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:133
@ AV_PIX_FMT_YUV420P14BE
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:244
@ AV_PIX_FMT_YUV444P14LE
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:253
@ AV_PIX_FMT_YUVA444P9BE
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), big-endian
Definition: pixfmt.h:182
@ AV_PIX_FMT_YUV422P12LE
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:247
@ AV_PIX_FMT_YUV444P10BE
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:164
@ AV_PIX_FMT_YUVA420P9LE
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian
Definition: pixfmt.h:179
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ AV_PIX_FMT_YUV444P9LE
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:163
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
@ AV_PIX_FMT_GBRP12LE
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:255
@ AV_PIX_FMT_YUVA444P16LE
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:195
@ AV_PIX_FMT_YUVA422P10BE
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:186
@ AV_PIX_FMT_YUVA422P16BE
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:192
@ AV_PIX_FMT_BGRA64BE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:207
@ AV_PIX_FMT_GBRP16BE
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:174
@ AV_PIX_FMT_GBRP9BE
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:170
@ AV_PIX_FMT_YUVA420P16LE
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:191
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:103
@ AV_PIX_FMT_YUVA420P16BE
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:190
@ AV_PIX_FMT_YUV420P12LE
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:243
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
@ AV_PIX_FMT_YUV444P9BE
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:162
@ AV_PIX_FMT_YUV422P9LE
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:167
@ AV_PIX_FMT_YUV422P9BE
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:166
@ AV_PIX_FMT_BGR48LE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:149
@ AV_PIX_FMT_GBRP14LE
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:257
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
@ AV_PIX_FMT_YUV422P10LE
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:161
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
@ AV_PIX_FMT_GBRP10LE
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:173
@ AV_PIX_FMT_YUV420P12BE
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:242
@ AV_PIX_FMT_BGRA64LE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:208
@ AV_PIX_FMT_YUV422P16BE
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:134
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
@ AV_PIX_FMT_YUV422P14LE
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:249
@ AV_PIX_FMT_YUV420P10BE
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:158
@ AV_PIX_FMT_YUV420P9BE
The following 12 formats have the disadvantage of needing 1 format for each bit depth.
Definition: pixfmt.h:156
@ AV_PIX_FMT_YUVA444P10BE
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:188
@ AV_PIX_FMT_YUV444P16LE
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:135
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:237
@ AV_PIX_FMT_GBRP14BE
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:256
@ AV_PIX_FMT_YUV422P14BE
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:248
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
@ AV_PIX_FMT_YUV444P12BE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:250
@ AV_PIX_FMT_YUVA444P16BE
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:194
@ AV_PIX_FMT_YUVA422P16LE
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:193
@ AV_PIX_FMT_GBRP16LE
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:175
@ AV_PIX_FMT_YUVA422P9BE
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), big-endian
Definition: pixfmt.h:180
@ AV_PIX_FMT_YUV444P10LE
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:165
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
@ AV_PIX_FMT_YUV422P12BE
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:246
@ AV_PIX_FMT_YUV420P16LE
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:131
@ AV_PIX_FMT_YUV444P12LE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:251
#define tb
Definition: regdef.h:68
#define td
Definition: regdef.h:70
Describe the class of an AVClass context structure.
Definition: log.h:67
An instance of a filter.
Definition: avfilter.h:341
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
AVOption.
Definition: opt.h:248
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
Rational number (pair of numerator and denominator).
Definition: rational.h:58
int num
Numerator.
Definition: rational.h:59
int den
Denominator.
Definition: rational.h:60
int in_off_right[4]
Definition: vf_stereo3d.c:153
StereoComponent in
Definition: vf_stereo3d.c:143
int in_off_left[4]
Definition: vf_stereo3d.c:153
const int * ana_matrix[3]
Definition: vf_stereo3d.c:145
AVFrame * prev
Definition: vf_stereo3d.c:151
StereoComponent out
Definition: vf_stereo3d.c:143
AVRational aspect
Definition: vf_stereo3d.c:154
Stereo3DDSPContext dsp
Definition: vf_stereo3d.c:155
int format
StereoCode.
Definition: vf_stereo3d.c:74
Used for passing data between threads.
Definition: dsddec.c:67
AVFrame * out
Definition: af_adeclick.c:505
AVFrame * ileft
Definition: vf_stereo3d.c:610
AVFrame * iright
Definition: vf_stereo3d.c:610
#define av_log(a,...)
#define src
Definition: vp8dsp.c:255
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
#define height
#define width
const char * b
Definition: vf_curves.c:119
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:76
static const double coeff[2][5]
Definition: vf_owdenoise.c:73
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_stereo3d.c:614
static enum AVPixelFormat anaglyph_pix_fmts[]
Definition: vf_stereo3d.c:224
static uint8_t ana_convert(const int *coeff, const uint8_t *left, const uint8_t *right)
Definition: vf_stereo3d.c:316
static void interleave_cols_to_any(Stereo3DContext *s, int *out_off, int p, AVFrame *in, AVFrame *out, int d)
Definition: vf_stereo3d.c:638
static void anaglyph_ic(uint8_t *dst, uint8_t *lsrc, uint8_t *rsrc, ptrdiff_t dst_linesize, ptrdiff_t l_linesize, ptrdiff_t r_linesize, int width, int height, const int *ana_matrix_r, const int *ana_matrix_g, const int *ana_matrix_b)
Definition: vf_stereo3d.c:327
static void anaglyph(uint8_t *dst, uint8_t *lsrc, uint8_t *rsrc, ptrdiff_t dst_linesize, ptrdiff_t l_linesize, ptrdiff_t r_linesize, int width, int height, const int *ana_matrix_r, const int *ana_matrix_g, const int *ana_matrix_b)
Definition: vf_stereo3d.c:347
static const int ana_coeff[][3][6]
Definition: vf_stereo3d.c:82
StereoCode
Definition: vf_stereo3d.c:36
@ ANAGLYPH_GM_GRAY
Definition: vf_stereo3d.c:41
@ INTERLEAVE_ROWS_RL
Definition: vf_stereo3d.c:54
@ INTERLEAVE_COLS_LR
Definition: vf_stereo3d.c:67
@ SIDE_BY_SIDE_LR
Definition: vf_stereo3d.c:55
@ ANAGLYPH_GM_HALF
Definition: vf_stereo3d.c:42
@ ANAGLYPH_YB_DUBOIS
Definition: vf_stereo3d.c:48
@ ANAGLYPH_GM_COLOR
Definition: vf_stereo3d.c:43
@ ANAGLYPH_RG_GRAY
Definition: vf_stereo3d.c:50
@ ANAGLYPH_RC_HALF
Definition: vf_stereo3d.c:38
@ ANAGLYPH_RC_GRAY
Definition: vf_stereo3d.c:37
@ INTERLEAVE_ROWS_LR
Definition: vf_stereo3d.c:53
@ STEREO_CODE_COUNT
Definition: vf_stereo3d.c:70
@ ANAGLYPH_YB_COLOR
Definition: vf_stereo3d.c:47
@ ANAGLYPH_RB_GRAY
Definition: vf_stereo3d.c:49
@ CHECKERBOARD_LR
Definition: vf_stereo3d.c:65
@ HDMI
Definition: vf_stereo3d.c:69
@ SIDE_BY_SIDE_2_LR
Definition: vf_stereo3d.c:57
@ CHECKERBOARD_RL
Definition: vf_stereo3d.c:66
@ SIDE_BY_SIDE_RL
Definition: vf_stereo3d.c:56
@ INTERLEAVE_COLS_RL
Definition: vf_stereo3d.c:68
@ ABOVE_BELOW_LR
Definition: vf_stereo3d.c:59
@ ANAGLYPH_YB_GRAY
Definition: vf_stereo3d.c:45
@ SIDE_BY_SIDE_2_RL
Definition: vf_stereo3d.c:58
@ ANAGLYPH_RC_COLOR
Definition: vf_stereo3d.c:39
@ ABOVE_BELOW_2_RL
Definition: vf_stereo3d.c:62
@ MONO_L
Definition: vf_stereo3d.c:51
@ ANAGLYPH_RC_DUBOIS
Definition: vf_stereo3d.c:40
@ MONO_R
Definition: vf_stereo3d.c:52
@ ABOVE_BELOW_2_LR
Definition: vf_stereo3d.c:61
@ ANAGLYPH_YB_HALF
Definition: vf_stereo3d.c:46
@ ALTERNATING_RL
Definition: vf_stereo3d.c:64
@ ABOVE_BELOW_RL
Definition: vf_stereo3d.c:60
@ ALTERNATING_LR
Definition: vf_stereo3d.c:63
@ ANAGLYPH_GM_DUBOIS
Definition: vf_stereo3d.c:44
static int query_formats(AVFilterContext *ctx)
Definition: vf_stereo3d.c:283
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_stereo3d.c:675
#define FLAGS
Definition: vf_stereo3d.c:159
static const AVFilterPad stereo3d_inputs[]
Definition: vf_stereo3d.c:1103
AVFILTER_DEFINE_CLASS(stereo3d)
AVFilter ff_vf_stereo3d
Definition: vf_stereo3d.c:1121
static const AVOption stereo3d_options[]
Definition: vf_stereo3d.c:161
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_stereo3d.c:1096
#define OFFSET(x)
Definition: vf_stereo3d.c:158
static int config_output(AVFilterLink *outlink)
Definition: vf_stereo3d.c:367
static const AVFilterPad stereo3d_outputs[]
Definition: vf_stereo3d.c:1112
static enum AVPixelFormat other_pix_fmts[]
Definition: vf_stereo3d.c:229
static void copy(const float *p1, float *p2, const int length)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104