2 * Copyright (c) 2010 Gordon Schmidt <gordon.schmidt <at> s2000.tu-chemnitz.de>
3 * Copyright (c) 2013 Paul B Mahol
5 * This file is part of FFmpeg.
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.
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.
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
22 #include "libavutil/avassert.h"
23 #include "libavutil/imgutils.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/parseutils.h"
26 #include "libavutil/pixdesc.h"
33 ANAGLYPH_RC_GRAY, // anaglyph red/cyan gray
34 ANAGLYPH_RC_HALF, // anaglyph red/cyan half colored
35 ANAGLYPH_RC_COLOR, // anaglyph red/cyan colored
36 ANAGLYPH_RC_DUBOIS, // anaglyph red/cyan dubois
37 ANAGLYPH_GM_GRAY, // anaglyph green/magenta gray
38 ANAGLYPH_GM_HALF, // anaglyph green/magenta half colored
39 ANAGLYPH_GM_COLOR, // anaglyph green/magenta colored
40 ANAGLYPH_GM_DUBOIS, // anaglyph green/magenta dubois
41 ANAGLYPH_YB_GRAY, // anaglyph yellow/blue gray
42 ANAGLYPH_YB_HALF, // anaglyph yellow/blue half colored
43 ANAGLYPH_YB_COLOR, // anaglyph yellow/blue colored
44 ANAGLYPH_YB_DUBOIS, // anaglyph yellow/blue dubois
45 ANAGLYPH_RB_GRAY, // anaglyph red/blue gray
46 ANAGLYPH_RG_GRAY, // anaglyph red/green gray
47 MONO_L, // mono output for debugging (left eye only)
48 MONO_R, // mono output for debugging (right eye only)
49 INTERLEAVE_ROWS_LR, // row-interleave (left eye has top row)
50 INTERLEAVE_ROWS_RL, // row-interleave (right eye has top row)
51 SIDE_BY_SIDE_LR, // side by side parallel (left eye left, right eye right)
52 SIDE_BY_SIDE_RL, // side by side crosseye (right eye left, left eye right)
53 SIDE_BY_SIDE_2_LR, // side by side parallel with half width resolution
54 SIDE_BY_SIDE_2_RL, // side by side crosseye with half width resolution
55 ABOVE_BELOW_LR, // above-below (left eye above, right eye below)
56 ABOVE_BELOW_RL, // above-below (right eye above, left eye below)
57 ABOVE_BELOW_2_LR, // above-below with half height resolution
58 ABOVE_BELOW_2_RL, // above-below with half height resolution
59 ALTERNATING_LR, // alternating frames (left eye first, right eye second)
60 ALTERNATING_RL, // alternating frames (right eye first, left eye second)
61 STEREO_CODE_COUNT // TODO: needs autodetection
64 typedef struct StereoComponent {
65 enum StereoCode format;
67 int off_left, off_right;
68 int off_lstep, off_rstep;
69 int row_left, row_right;
72 static const int ana_coeff[][3][6] = {
74 {{19595, 38470, 7471, 0, 0, 0},
76 { 0, 0, 0, 19595, 38470, 7471}},
78 {{19595, 38470, 7471, 0, 0, 0},
79 { 0, 0, 0, 19595, 38470, 7471},
82 {{19595, 38470, 7471, 0, 0, 0},
83 { 0, 0, 0, 19595, 38470, 7471},
84 { 0, 0, 0, 19595, 38470, 7471}},
86 {{19595, 38470, 7471, 0, 0, 0},
87 { 0, 0, 0, 0, 65536, 0},
88 { 0, 0, 0, 0, 0, 65536}},
90 {{65536, 0, 0, 0, 0, 0},
91 { 0, 0, 0, 0, 65536, 0},
92 { 0, 0, 0, 0, 0, 65536}},
93 [ANAGLYPH_RC_DUBOIS] =
94 {{29891, 32800, 11559, -2849, -5763, -102},
95 {-2627, -2479, -1033, 24804, 48080, -1209},
96 { -997, -1350, -358, -4729, -7403, 80373}},
98 {{ 0, 0, 0, 19595, 38470, 7471},
99 {19595, 38470, 7471, 0, 0, 0},
100 { 0, 0, 0, 19595, 38470, 7471}},
102 {{ 0, 0, 0, 65536, 0, 0},
103 {19595, 38470, 7471, 0, 0, 0},
104 { 0, 0, 0, 0, 0, 65536}},
105 [ANAGLYPH_GM_COLOR] =
106 {{ 0, 0, 0, 65536, 0, 0},
107 { 0, 65536, 0, 0, 0, 0},
108 { 0, 0, 0, 0, 0, 65536}},
109 [ANAGLYPH_GM_DUBOIS] =
110 {{-4063,-10354, -2556, 34669, 46203, 1573},
111 {18612, 43778, 9372, -1049, -983, -4260},
112 { -983, -1769, 1376, 590, 4915, 61407}},
114 {{ 0, 0, 0, 19595, 38470, 7471},
115 { 0, 0, 0, 19595, 38470, 7471},
116 {19595, 38470, 7471, 0, 0, 0}},
118 {{ 0, 0, 0, 65536, 0, 0},
119 { 0, 0, 0, 0, 65536, 0},
120 {19595, 38470, 7471, 0, 0, 0}},
121 [ANAGLYPH_YB_COLOR] =
122 {{ 0, 0, 0, 65536, 0, 0},
123 { 0, 0, 0, 0, 65536, 0},
124 { 0, 0, 65536, 0, 0, 0}},
125 [ANAGLYPH_YB_DUBOIS] =
126 {{65535,-12650,18451, -987, -7590, -1049},
127 {-1604, 56032, 4196, 370, 3826, -1049},
128 {-2345,-10676, 1358, 5801, 11416, 56217}},
131 typedef struct Stereo3DContext {
132 const AVClass *class;
133 StereoComponent in, out;
136 int ana_matrix[3][6];
144 #define OFFSET(x) offsetof(Stereo3DContext, x)
145 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
147 static const AVOption stereo3d_options[] = {
148 { "in", "set input format", OFFSET(in.format), AV_OPT_TYPE_INT, {.i64=SIDE_BY_SIDE_LR}, SIDE_BY_SIDE_LR, STEREO_CODE_COUNT-1, FLAGS, "in"},
149 { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "in" },
150 { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "in" },
151 { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "in" },
152 { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "in" },
153 { "al", "alternating frames left first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_LR}, 0, 0, FLAGS, "in" },
154 { "ar", "alternating frames right first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_RL}, 0, 0, FLAGS, "in" },
155 { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "in" },
156 { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "in" },
157 { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "in" },
158 { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "in" },
159 { "out", "set output format", OFFSET(out.format), AV_OPT_TYPE_INT, {.i64=ANAGLYPH_RC_DUBOIS}, 0, STEREO_CODE_COUNT-1, FLAGS, "out"},
160 { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "out" },
161 { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "out" },
162 { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "out" },
163 { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "out" },
164 { "agmc", "anaglyph green magenta color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_COLOR}, 0, 0, FLAGS, "out" },
165 { "agmd", "anaglyph green magenta dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_DUBOIS}, 0, 0, FLAGS, "out" },
166 { "agmg", "anaglyph green magenta gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_GRAY}, 0, 0, FLAGS, "out" },
167 { "agmh", "anaglyph green magenta half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_HALF}, 0, 0, FLAGS, "out" },
168 { "al", "alternating frames left first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_LR}, 0, 0, FLAGS, "out" },
169 { "ar", "alternating frames right first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_RL}, 0, 0, FLAGS, "out" },
170 { "arbg", "anaglyph red blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RB_GRAY}, 0, 0, FLAGS, "out" },
171 { "arcc", "anaglyph red cyan color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_COLOR}, 0, 0, FLAGS, "out" },
172 { "arcd", "anaglyph red cyan dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_DUBOIS}, 0, 0, FLAGS, "out" },
173 { "arcg", "anaglyph red cyan gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_GRAY}, 0, 0, FLAGS, "out" },
174 { "arch", "anaglyph red cyan half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_HALF}, 0, 0, FLAGS, "out" },
175 { "argg", "anaglyph red green gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RG_GRAY}, 0, 0, FLAGS, "out" },
176 { "aybc", "anaglyph yellow blue color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_COLOR}, 0, 0, FLAGS, "out" },
177 { "aybd", "anaglyph yellow blue dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_DUBOIS}, 0, 0, FLAGS, "out" },
178 { "aybg", "anaglyph yellow blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_GRAY}, 0, 0, FLAGS, "out" },
179 { "aybh", "anaglyph yellow blue half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_HALF}, 0, 0, FLAGS, "out" },
180 { "irl", "interleave rows left first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_LR}, 0, 0, FLAGS, "out" },
181 { "irr", "interleave rows right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_RL}, 0, 0, FLAGS, "out" },
182 { "ml", "mono left", 0, AV_OPT_TYPE_CONST, {.i64=MONO_L}, 0, 0, FLAGS, "out" },
183 { "mr", "mono right", 0, AV_OPT_TYPE_CONST, {.i64=MONO_R}, 0, 0, FLAGS, "out" },
184 { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "out" },
185 { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "out" },
186 { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "out" },
187 { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "out" },
191 AVFILTER_DEFINE_CLASS(stereo3d);
193 static const enum AVPixelFormat anaglyph_pix_fmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE };
194 static const enum AVPixelFormat other_pix_fmts[] = {
195 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
196 AV_PIX_FMT_RGB48BE, AV_PIX_FMT_BGR48BE,
197 AV_PIX_FMT_RGB48LE, AV_PIX_FMT_BGR48LE,
198 AV_PIX_FMT_RGBA64BE, AV_PIX_FMT_BGRA64BE,
199 AV_PIX_FMT_RGBA64LE, AV_PIX_FMT_BGRA64LE,
200 AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
201 AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
202 AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,
203 AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR,
205 AV_PIX_FMT_GBRP9BE, AV_PIX_FMT_GBRP9LE,
206 AV_PIX_FMT_GBRP10BE, AV_PIX_FMT_GBRP10LE,
207 AV_PIX_FMT_GBRP12BE, AV_PIX_FMT_GBRP12LE,
208 AV_PIX_FMT_GBRP14BE, AV_PIX_FMT_GBRP14LE,
209 AV_PIX_FMT_GBRP16BE, AV_PIX_FMT_GBRP16LE,
210 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA444P,
212 AV_PIX_FMT_YUV444P9LE, AV_PIX_FMT_YUVA444P9LE,
213 AV_PIX_FMT_YUV444P9BE, AV_PIX_FMT_YUVA444P9BE,
214 AV_PIX_FMT_YUV444P10LE, AV_PIX_FMT_YUVA444P10LE,
215 AV_PIX_FMT_YUV444P10BE, AV_PIX_FMT_YUVA444P10BE,
216 AV_PIX_FMT_YUV444P12BE, AV_PIX_FMT_YUV444P12LE,
217 AV_PIX_FMT_YUV444P14BE, AV_PIX_FMT_YUV444P14LE,
218 AV_PIX_FMT_YUV444P16LE, AV_PIX_FMT_YUVA444P16LE,
219 AV_PIX_FMT_YUV444P16BE, AV_PIX_FMT_YUVA444P16BE,
223 static int query_formats(AVFilterContext *ctx)
225 Stereo3DContext *s = ctx->priv;
226 const enum AVPixelFormat *pix_fmts;
228 switch (s->out.format) {
229 case ANAGLYPH_GM_COLOR:
230 case ANAGLYPH_GM_DUBOIS:
231 case ANAGLYPH_GM_GRAY:
232 case ANAGLYPH_GM_HALF:
233 case ANAGLYPH_RB_GRAY:
234 case ANAGLYPH_RC_COLOR:
235 case ANAGLYPH_RC_DUBOIS:
236 case ANAGLYPH_RC_GRAY:
237 case ANAGLYPH_RC_HALF:
238 case ANAGLYPH_RG_GRAY:
239 case ANAGLYPH_YB_COLOR:
240 case ANAGLYPH_YB_DUBOIS:
241 case ANAGLYPH_YB_GRAY:
242 case ANAGLYPH_YB_HALF:
243 pix_fmts = anaglyph_pix_fmts;
246 pix_fmts = other_pix_fmts;
249 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
254 static int config_output(AVFilterLink *outlink)
256 AVFilterContext *ctx = outlink->src;
257 AVFilterLink *inlink = ctx->inputs[0];
258 Stereo3DContext *s = ctx->priv;
259 AVRational aspect = inlink->sample_aspect_ratio;
260 AVRational fps = inlink->frame_rate;
261 AVRational tb = inlink->time_base;
262 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
265 switch (s->in.format) {
266 case SIDE_BY_SIDE_2_LR:
267 case SIDE_BY_SIDE_LR:
268 case SIDE_BY_SIDE_2_RL:
269 case SIDE_BY_SIDE_RL:
271 av_log(ctx, AV_LOG_ERROR, "width must be even\n");
272 return AVERROR_INVALIDDATA;
275 case ABOVE_BELOW_2_LR:
277 case ABOVE_BELOW_2_RL:
279 if (s->out.format == INTERLEAVE_ROWS_LR ||
280 s->out.format == INTERLEAVE_ROWS_RL) {
282 av_log(ctx, AV_LOG_ERROR, "height must be multiple of 4\n");
283 return AVERROR_INVALIDDATA;
287 av_log(ctx, AV_LOG_ERROR, "height must be even\n");
288 return AVERROR_INVALIDDATA;
294 s->width = inlink->w;
296 s->height = inlink->h;
305 switch (s->in.format) {
306 case SIDE_BY_SIDE_2_LR:
308 case SIDE_BY_SIDE_LR:
309 s->width = inlink->w / 2;
310 s->in.off_right = s->width;
312 case SIDE_BY_SIDE_2_RL:
314 case SIDE_BY_SIDE_RL:
315 s->width = inlink->w / 2;
316 s->in.off_left = s->width;
318 case ABOVE_BELOW_2_LR:
322 s->height = inlink->h / 2;
324 case ABOVE_BELOW_2_RL:
328 s->height = inlink->h / 2;
332 outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
337 av_log(ctx, AV_LOG_ERROR, "input format %d is not supported\n", s->in.format);
338 return AVERROR(EINVAL);
341 s->out.width = s->width;
342 s->out.height = s->height;
348 s->out.row_right = 0;
350 switch (s->out.format) {
351 case ANAGLYPH_RB_GRAY:
352 case ANAGLYPH_RG_GRAY:
353 case ANAGLYPH_RC_GRAY:
354 case ANAGLYPH_RC_HALF:
355 case ANAGLYPH_RC_COLOR:
356 case ANAGLYPH_RC_DUBOIS:
357 case ANAGLYPH_GM_GRAY:
358 case ANAGLYPH_GM_HALF:
359 case ANAGLYPH_GM_COLOR:
360 case ANAGLYPH_GM_DUBOIS:
361 case ANAGLYPH_YB_GRAY:
362 case ANAGLYPH_YB_HALF:
363 case ANAGLYPH_YB_COLOR:
364 case ANAGLYPH_YB_DUBOIS:
365 memcpy(s->ana_matrix, ana_coeff[s->out.format], sizeof(s->ana_matrix));
367 case SIDE_BY_SIDE_2_LR:
369 case SIDE_BY_SIDE_LR:
370 s->out.width = s->width * 2;
371 s->out.off_right = s->width;
373 case SIDE_BY_SIDE_2_RL:
375 case SIDE_BY_SIDE_RL:
376 s->out.width = s->width * 2;
377 s->out.off_left = s->width;
379 case ABOVE_BELOW_2_LR:
382 s->out.height = s->height * 2;
383 s->out.row_right = s->height;
385 case ABOVE_BELOW_2_RL:
388 s->out.height = s->height * 2;
389 s->out.row_left = s->height;
391 case INTERLEAVE_ROWS_LR:
393 s->height = s->height / 2;
397 case INTERLEAVE_ROWS_RL:
399 s->height = s->height / 2;
404 s->in.off_left = s->in.off_right;
405 s->in.row_left = s->in.row_right;
414 av_log(ctx, AV_LOG_ERROR, "output format %d is not supported\n", s->out.format);
415 return AVERROR(EINVAL);
418 outlink->w = s->out.width;
419 outlink->h = s->out.height;
420 outlink->frame_rate = fps;
421 outlink->time_base = tb;
422 outlink->sample_aspect_ratio = aspect;
424 if ((ret = av_image_fill_linesizes(s->linesize, outlink->format, s->width)) < 0)
426 s->nb_planes = av_pix_fmt_count_planes(outlink->format);
427 av_image_fill_max_pixsteps(s->pixstep, NULL, desc);
428 s->ts_unit = av_q2d(av_inv_q(av_mul_q(outlink->frame_rate, outlink->time_base)));
433 static inline uint8_t ana_convert(const int *coeff, uint8_t *left, uint8_t *right)
437 sum = coeff[0] * left[0] + coeff[3] * right[0]; //red in
438 sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in
439 sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in
441 return av_clip_uint8(sum >> 16);
444 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
446 AVFilterContext *ctx = inlink->dst;
447 Stereo3DContext *s = ctx->priv;
448 AVFilterLink *outlink = ctx->outputs[0];
449 AVFrame *out, *oleft, *oright, *ileft, *iright;
450 int out_off_left[4], out_off_right[4];
451 int in_off_left[4], in_off_right[4];
454 switch (s->in.format) {
463 if (s->in.format == ALTERNATING_RL)
464 FFSWAP(AVFrame *, ileft, iright);
467 ileft = iright = inpicref;
470 out = oleft = oright = ff_get_video_buffer(outlink, outlink->w, outlink->h);
472 av_frame_free(&s->prev);
473 av_frame_free(&inpicref);
474 return AVERROR(ENOMEM);
476 av_frame_copy_props(out, inpicref);
478 if (s->out.format == ALTERNATING_LR ||
479 s->out.format == ALTERNATING_RL) {
480 oright = ff_get_video_buffer(outlink, outlink->w, outlink->h);
482 av_frame_free(&oleft);
483 av_frame_free(&s->prev);
484 av_frame_free(&inpicref);
485 return AVERROR(ENOMEM);
487 av_frame_copy_props(oright, inpicref);
490 for (i = 0; i < 4; i++) {
491 in_off_left[i] = (s->in.row_left + s->in.off_lstep) * ileft->linesize[i] + s->in.off_left * s->pixstep[i];
492 in_off_right[i] = (s->in.row_right + s->in.off_rstep) * iright->linesize[i] + s->in.off_right * s->pixstep[i];
493 out_off_left[i] = (s->out.row_left + s->out.off_lstep) * oleft->linesize[i] + s->out.off_left * s->pixstep[i];
494 out_off_right[i] = (s->out.row_right + s->out.off_rstep) * oright->linesize[i] + s->out.off_right * s->pixstep[i];
497 switch (s->out.format) {
500 case SIDE_BY_SIDE_LR:
501 case SIDE_BY_SIDE_RL:
502 case SIDE_BY_SIDE_2_LR:
503 case SIDE_BY_SIDE_2_RL:
506 case ABOVE_BELOW_2_LR:
507 case ABOVE_BELOW_2_RL:
508 case INTERLEAVE_ROWS_LR:
509 case INTERLEAVE_ROWS_RL:
510 for (i = 0; i < s->nb_planes; i++) {
511 av_image_copy_plane(oleft->data[i] + out_off_left[i],
512 oleft->linesize[i] * s->row_step,
513 ileft->data[i] + in_off_left[i],
514 ileft->linesize[i] * s->row_step,
515 s->linesize[i], s->height);
516 av_image_copy_plane(oright->data[i] + out_off_right[i],
517 oright->linesize[i] * s->row_step,
518 iright->data[i] + in_off_right[i],
519 iright->linesize[i] * s->row_step,
520 s->linesize[i], s->height);
526 for (i = 0; i < s->nb_planes; i++) {
527 av_image_copy_plane(out->data[i], out->linesize[i],
528 iright->data[i] + in_off_left[i],
530 s->linesize[i], s->height);
533 case ANAGLYPH_RB_GRAY:
534 case ANAGLYPH_RG_GRAY:
535 case ANAGLYPH_RC_GRAY:
536 case ANAGLYPH_RC_HALF:
537 case ANAGLYPH_RC_COLOR:
538 case ANAGLYPH_RC_DUBOIS:
539 case ANAGLYPH_GM_GRAY:
540 case ANAGLYPH_GM_HALF:
541 case ANAGLYPH_GM_COLOR:
542 case ANAGLYPH_GM_DUBOIS:
543 case ANAGLYPH_YB_GRAY:
544 case ANAGLYPH_YB_HALF:
545 case ANAGLYPH_YB_COLOR:
546 case ANAGLYPH_YB_DUBOIS: {
547 int i, x, y, il, ir, o;
548 uint8_t *lsrc = ileft->data[0];
549 uint8_t *rsrc = iright->data[0];
550 uint8_t *dst = out->data[0];
551 int out_width = s->out.width;
554 for (i = 0; i < 3; i++)
555 ana_matrix[i] = s->ana_matrix[i];
557 for (y = 0; y < s->out.height; y++) {
558 o = out->linesize[0] * y;
559 il = in_off_left[0] + y * ileft->linesize[0];
560 ir = in_off_right[0] + y * iright->linesize[0];
561 for (x = 0; x < out_width; x++, il += 3, ir += 3, o+= 3) {
562 dst[o ] = ana_convert(ana_matrix[0], lsrc + il, rsrc + ir);
563 dst[o + 1] = ana_convert(ana_matrix[1], lsrc + il, rsrc + ir);
564 dst[o + 2] = ana_convert(ana_matrix[2], lsrc + il, rsrc + ir);
573 av_frame_free(&inpicref);
574 av_frame_free(&s->prev);
575 if (oright != oleft) {
576 if (s->out.format == ALTERNATING_LR)
577 FFSWAP(AVFrame *, oleft, oright);
578 oright->pts = outlink->frame_count * s->ts_unit;
579 ff_filter_frame(outlink, oright);
581 oleft->pts = outlink->frame_count * s->ts_unit;
582 } else if (s->in.format == ALTERNATING_LR ||
583 s->in.format == ALTERNATING_RL) {
584 out->pts = outlink->frame_count * s->ts_unit;
586 return ff_filter_frame(outlink, out);
589 static av_cold void uninit(AVFilterContext *ctx)
591 Stereo3DContext *s = ctx->priv;
593 av_frame_free(&s->prev);
596 static const AVFilterPad stereo3d_inputs[] = {
599 .type = AVMEDIA_TYPE_VIDEO,
600 .filter_frame = filter_frame,
605 static const AVFilterPad stereo3d_outputs[] = {
608 .type = AVMEDIA_TYPE_VIDEO,
609 .config_props = config_output,
614 AVFilter avfilter_vf_stereo3d = {
616 .description = NULL_IF_CONFIG_SMALL("Convert video stereoscopic 3D view."),
617 .priv_size = sizeof(Stereo3DContext),
619 .query_formats = query_formats,
620 .inputs = stereo3d_inputs,
621 .outputs = stereo3d_outputs,
622 .priv_class = &stereo3d_class,