You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

480 lines
19KB

  1. /*
  2. * Copyright (c) 2010 Gordon Schmidt <gordon.schmidt <at> s2000.tu-chemnitz.de>
  3. * Copyright (c) 2013 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. #include "libavutil/avassert.h"
  22. #include "libavutil/imgutils.h"
  23. #include "libavutil/opt.h"
  24. #include "libavutil/parseutils.h"
  25. #include "libavutil/pixdesc.h"
  26. #include "avfilter.h"
  27. #include "formats.h"
  28. #include "internal.h"
  29. #include "video.h"
  30. enum StereoCode {
  31. ANAGLYPH_RC_GRAY, // anaglyph red/cyan gray
  32. ANAGLYPH_RC_HALF, // anaglyph red/cyan half colored
  33. ANAGLYPH_RC_COLOR, // anaglyph red/cyan colored
  34. ANAGLYPH_RC_DUBOIS, // anaglyph red/cyan dubois
  35. ANAGLYPH_GM_GRAY, // anaglyph green/magenta gray
  36. ANAGLYPH_GM_HALF, // anaglyph green/magenta half colored
  37. ANAGLYPH_GM_COLOR, // anaglyph green/magenta colored
  38. ANAGLYPH_GM_DUBOIS, // anaglyph green/magenta dubois
  39. ANAGLYPH_YB_GRAY, // anaglyph yellow/blue gray
  40. ANAGLYPH_YB_HALF, // anaglyph yellow/blue half colored
  41. ANAGLYPH_YB_COLOR, // anaglyph yellow/blue colored
  42. ANAGLYPH_YB_DUBOIS, // anaglyph yellow/blue dubois
  43. ANAGLYPH_RB_GRAY, // anaglyph red/blue gray
  44. ANAGLYPH_RG_GRAY, // anaglyph red/green gray
  45. MONO_L, // mono output for debugging (left eye only)
  46. MONO_R, // mono output for debugging (right eye only)
  47. INTERLEAVE_ROWS_LR, // row-interleave (left eye has top row)
  48. INTERLEAVE_ROWS_RL, // row-interleave (right eye has top row)
  49. SIDE_BY_SIDE_LR, // side by side parallel (left eye left, right eye right)
  50. SIDE_BY_SIDE_RL, // side by side crosseye (right eye left, left eye right)
  51. SIDE_BY_SIDE_2_LR, // side by side parallel with half width resolution
  52. SIDE_BY_SIDE_2_RL, // side by side crosseye with half width resolution
  53. ABOVE_BELOW_LR, // above-below (left eye above, right eye below)
  54. ABOVE_BELOW_RL, // above-below (right eye above, left eye below)
  55. ABOVE_BELOW_2_LR, // above-below with half height resolution
  56. ABOVE_BELOW_2_RL, // above-below with half height resolution
  57. STEREO_CODE_COUNT // TODO: needs autodetection
  58. };
  59. typedef struct StereoComponent {
  60. enum StereoCode format;
  61. int width, height;
  62. int off_left, off_right;
  63. int off_lstep, off_rstep;
  64. int row_left, row_right;
  65. } StereoComponent;
  66. static const int ana_coeff[][3][6] = {
  67. [ANAGLYPH_RB_GRAY] =
  68. {{19595, 38470, 7471, 0, 0, 0},
  69. { 0, 0, 0, 0, 0, 0},
  70. { 0, 0, 0, 19595, 38470, 7471}},
  71. [ANAGLYPH_RG_GRAY] =
  72. {{19595, 38470, 7471, 0, 0, 0},
  73. { 0, 0, 0, 19595, 38470, 7471},
  74. { 0, 0, 0, 0, 0, 0}},
  75. [ANAGLYPH_RC_GRAY] =
  76. {{19595, 38470, 7471, 0, 0, 0},
  77. { 0, 0, 0, 19595, 38470, 7471},
  78. { 0, 0, 0, 19595, 38470, 7471}},
  79. [ANAGLYPH_RC_HALF] =
  80. {{19595, 38470, 7471, 0, 0, 0},
  81. { 0, 0, 0, 0, 65536, 0},
  82. { 0, 0, 0, 0, 0, 65536}},
  83. [ANAGLYPH_RC_COLOR] =
  84. {{65536, 0, 0, 0, 0, 0},
  85. { 0, 0, 0, 0, 65536, 0},
  86. { 0, 0, 0, 0, 0, 65536}},
  87. [ANAGLYPH_RC_DUBOIS] =
  88. {{29891, 32800, 11559, -2849, -5763, -102},
  89. {-2627, -2479, -1033, 24804, 48080, -1209},
  90. { -997, -1350, -358, -4729, -7403, 80373}},
  91. [ANAGLYPH_GM_GRAY] =
  92. {{ 0, 0, 0, 19595, 38470, 7471},
  93. {19595, 38470, 7471, 0, 0, 0},
  94. { 0, 0, 0, 19595, 38470, 7471}},
  95. [ANAGLYPH_GM_HALF] =
  96. {{ 0, 0, 0, 65536, 0, 0},
  97. {19595, 38470, 7471, 0, 0, 0},
  98. { 0, 0, 0, 0, 0, 65536}},
  99. [ANAGLYPH_GM_COLOR] =
  100. {{ 0, 0, 0, 65536, 0, 0},
  101. { 0, 65536, 0, 0, 0, 0},
  102. { 0, 0, 0, 0, 0, 65536}},
  103. [ANAGLYPH_GM_DUBOIS] =
  104. {{-4063,-10354, -2556, 34669, 46203, 1573},
  105. {18612, 43778, 9372, -1049, -983, -4260},
  106. { -983, -1769, 1376, 590, 4915, 61407}},
  107. [ANAGLYPH_YB_GRAY] =
  108. {{ 0, 0, 0, 19595, 38470, 7471},
  109. { 0, 0, 0, 19595, 38470, 7471},
  110. {19595, 38470, 7471, 0, 0, 0}},
  111. [ANAGLYPH_YB_HALF] =
  112. {{ 0, 0, 0, 65536, 0, 0},
  113. { 0, 0, 0, 0, 65536, 0},
  114. {19595, 38470, 7471, 0, 0, 0}},
  115. [ANAGLYPH_YB_COLOR] =
  116. {{ 0, 0, 0, 65536, 0, 0},
  117. { 0, 0, 0, 0, 65536, 0},
  118. { 0, 0, 65536, 0, 0, 0}},
  119. [ANAGLYPH_YB_DUBOIS] =
  120. {{65535,-12650,18451, -987, -7590, -1049},
  121. {-1604, 56032, 4196, 370, 3826, -1049},
  122. {-2345,-10676, 1358, 5801, 11416, 56217}},
  123. };
  124. typedef struct Stereo3DContext {
  125. const AVClass *class;
  126. StereoComponent in, out;
  127. int width, height;
  128. int row_step;
  129. int ana_matrix[3][6];
  130. } Stereo3DContext;
  131. #define OFFSET(x) offsetof(Stereo3DContext, x)
  132. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  133. static const AVOption stereo3d_options[] = {
  134. { "in", "set input format", OFFSET(in.format), AV_OPT_TYPE_INT, {.i64=SIDE_BY_SIDE_LR}, SIDE_BY_SIDE_LR, ABOVE_BELOW_2_RL, FLAGS, "in"},
  135. { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "in" },
  136. { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "in" },
  137. { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "in" },
  138. { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "in" },
  139. { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "in" },
  140. { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "in" },
  141. { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "in" },
  142. { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "in" },
  143. { "out", "set output format", OFFSET(out.format), AV_OPT_TYPE_INT, {.i64=ANAGLYPH_RC_DUBOIS}, 0, STEREO_CODE_COUNT-1, FLAGS, "out"},
  144. { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "out" },
  145. { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "out" },
  146. { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "out" },
  147. { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "out" },
  148. { "agmc", "anaglyph green magenta color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_COLOR}, 0, 0, FLAGS, "out" },
  149. { "agmd", "anaglyph green magenta dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_DUBOIS}, 0, 0, FLAGS, "out" },
  150. { "agmg", "anaglyph green magenta gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_GRAY}, 0, 0, FLAGS, "out" },
  151. { "agmh", "anaglyph green magenta half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_HALF}, 0, 0, FLAGS, "out" },
  152. { "arbg", "anaglyph red blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RB_GRAY}, 0, 0, FLAGS, "out" },
  153. { "arcc", "anaglyph red cyan color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_COLOR}, 0, 0, FLAGS, "out" },
  154. { "arcd", "anaglyph red cyan dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_DUBOIS}, 0, 0, FLAGS, "out" },
  155. { "arcg", "anaglyph red cyan gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_GRAY}, 0, 0, FLAGS, "out" },
  156. { "arch", "anaglyph red cyan half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_HALF}, 0, 0, FLAGS, "out" },
  157. { "argg", "anaglyph red green gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RG_GRAY}, 0, 0, FLAGS, "out" },
  158. { "aybc", "anaglyph yellow blue color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_COLOR}, 0, 0, FLAGS, "out" },
  159. { "aybd", "anaglyph yellow blue dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_DUBOIS}, 0, 0, FLAGS, "out" },
  160. { "aybg", "anaglyph yellow blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_GRAY}, 0, 0, FLAGS, "out" },
  161. { "aybh", "anaglyph yellow blue half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_HALF}, 0, 0, FLAGS, "out" },
  162. { "irl", "interleave rows left first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_LR}, 0, 0, FLAGS, "out" },
  163. { "irr", "interleave rows right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_RL}, 0, 0, FLAGS, "out" },
  164. { "ml", "mono left", 0, AV_OPT_TYPE_CONST, {.i64=MONO_L}, 0, 0, FLAGS, "out" },
  165. { "mr", "mono right", 0, AV_OPT_TYPE_CONST, {.i64=MONO_R}, 0, 0, FLAGS, "out" },
  166. { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "out" },
  167. { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "out" },
  168. { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "out" },
  169. { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "out" },
  170. {NULL},
  171. };
  172. AVFILTER_DEFINE_CLASS(stereo3d);
  173. static int query_formats(AVFilterContext *ctx)
  174. {
  175. static const enum AVPixelFormat pix_fmts[] = {
  176. AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
  177. };
  178. ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
  179. return 0;
  180. }
  181. static int config_output(AVFilterLink *outlink)
  182. {
  183. AVFilterContext *ctx = outlink->src;
  184. AVFilterLink *inlink = ctx->inputs[0];
  185. Stereo3DContext *s = ctx->priv;
  186. AVRational aspect = inlink->sample_aspect_ratio;
  187. switch (s->in.format) {
  188. case SIDE_BY_SIDE_2_LR:
  189. case SIDE_BY_SIDE_LR:
  190. case SIDE_BY_SIDE_2_RL:
  191. case SIDE_BY_SIDE_RL:
  192. if (inlink->w & 1) {
  193. av_log(ctx, AV_LOG_ERROR, "width must be even\n");
  194. return AVERROR_INVALIDDATA;
  195. }
  196. break;
  197. case ABOVE_BELOW_2_LR:
  198. case ABOVE_BELOW_LR:
  199. case ABOVE_BELOW_2_RL:
  200. case ABOVE_BELOW_RL:
  201. if (s->out.format == INTERLEAVE_ROWS_LR ||
  202. s->out.format == INTERLEAVE_ROWS_RL) {
  203. if (inlink->h & 3) {
  204. av_log(ctx, AV_LOG_ERROR, "height must be multiple of 4\n");
  205. return AVERROR_INVALIDDATA;
  206. }
  207. }
  208. if (inlink->h & 1) {
  209. av_log(ctx, AV_LOG_ERROR, "height must be even\n");
  210. return AVERROR_INVALIDDATA;
  211. }
  212. break;
  213. }
  214. s->in.width =
  215. s->width = inlink->w;
  216. s->in.height =
  217. s->height = inlink->h;
  218. s->row_step = 1;
  219. s->in.off_lstep =
  220. s->in.off_rstep =
  221. s->in.off_left =
  222. s->in.off_right =
  223. s->in.row_left =
  224. s->in.row_right = 0;
  225. switch (s->in.format) {
  226. case SIDE_BY_SIDE_2_LR:
  227. aspect.num *= 2;
  228. case SIDE_BY_SIDE_LR:
  229. s->width = inlink->w / 2;
  230. s->in.off_right = s->width * 3;
  231. break;
  232. case SIDE_BY_SIDE_2_RL:
  233. aspect.num *= 2;
  234. case SIDE_BY_SIDE_RL:
  235. s->width = inlink->w / 2;
  236. s->in.off_left = s->width * 3;
  237. break;
  238. case ABOVE_BELOW_2_LR:
  239. aspect.den *= 2;
  240. case ABOVE_BELOW_LR:
  241. s->in.row_right =
  242. s->height = inlink->h / 2;
  243. break;
  244. case ABOVE_BELOW_2_RL:
  245. aspect.den *= 2;
  246. case ABOVE_BELOW_RL:
  247. s->in.row_left =
  248. s->height = inlink->h / 2;
  249. break;
  250. default:
  251. av_log(ctx, AV_LOG_ERROR, "input format %d is not supported\n", s->in.format);
  252. return AVERROR(EINVAL);
  253. }
  254. s->out.width = s->width;
  255. s->out.height = s->height;
  256. s->out.off_lstep =
  257. s->out.off_rstep =
  258. s->out.off_left =
  259. s->out.off_right =
  260. s->out.row_left =
  261. s->out.row_right = 0;
  262. switch (s->out.format) {
  263. case ANAGLYPH_RB_GRAY:
  264. case ANAGLYPH_RG_GRAY:
  265. case ANAGLYPH_RC_GRAY:
  266. case ANAGLYPH_RC_HALF:
  267. case ANAGLYPH_RC_COLOR:
  268. case ANAGLYPH_RC_DUBOIS:
  269. case ANAGLYPH_GM_GRAY:
  270. case ANAGLYPH_GM_HALF:
  271. case ANAGLYPH_GM_COLOR:
  272. case ANAGLYPH_GM_DUBOIS:
  273. case ANAGLYPH_YB_GRAY:
  274. case ANAGLYPH_YB_HALF:
  275. case ANAGLYPH_YB_COLOR:
  276. case ANAGLYPH_YB_DUBOIS:
  277. memcpy(s->ana_matrix, ana_coeff[s->out.format], sizeof(s->ana_matrix));
  278. break;
  279. case SIDE_BY_SIDE_2_LR:
  280. aspect.num /= 2;
  281. case SIDE_BY_SIDE_LR:
  282. s->out.width = s->width * 2;
  283. s->out.off_right = s->width * 3;
  284. break;
  285. case SIDE_BY_SIDE_2_RL:
  286. aspect.num /= 2;
  287. case SIDE_BY_SIDE_RL:
  288. s->out.width = s->width * 2;
  289. s->out.off_left = s->width * 3;
  290. break;
  291. case ABOVE_BELOW_2_LR:
  292. aspect.den /= 2;
  293. case ABOVE_BELOW_LR:
  294. s->out.height = s->height * 2;
  295. s->out.row_right = s->height;
  296. break;
  297. case ABOVE_BELOW_2_RL:
  298. aspect.den /= 2;
  299. case ABOVE_BELOW_RL:
  300. s->out.height = s->height * 2;
  301. s->out.row_left = s->height;
  302. break;
  303. case INTERLEAVE_ROWS_LR:
  304. s->row_step = 2;
  305. s->height = s->height / 2;
  306. s->out.off_rstep =
  307. s->in.off_rstep = 1;
  308. break;
  309. case INTERLEAVE_ROWS_RL:
  310. s->row_step = 2;
  311. s->height = s->height / 2;
  312. s->out.off_lstep =
  313. s->in.off_lstep = 1;
  314. break;
  315. case MONO_R:
  316. s->in.off_left = s->in.off_right;
  317. s->in.row_left = s->in.row_right;
  318. case MONO_L:
  319. break;
  320. default:
  321. av_log(ctx, AV_LOG_ERROR, "output format is not supported\n");
  322. return AVERROR(EINVAL);
  323. }
  324. outlink->w = s->out.width;
  325. outlink->h = s->out.height;
  326. outlink->sample_aspect_ratio = aspect;
  327. return 0;
  328. }
  329. static inline uint8_t ana_convert(const int *coeff, uint8_t *left, uint8_t *right)
  330. {
  331. int sum;
  332. sum = coeff[0] * left[0] + coeff[3] * right[0]; //red in
  333. sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in
  334. sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in
  335. return av_clip_uint8(sum >> 16);
  336. }
  337. static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
  338. {
  339. AVFilterContext *ctx = inlink->dst;
  340. Stereo3DContext *s = ctx->priv;
  341. AVFilterLink *outlink = ctx->outputs[0];
  342. AVFrame *out;
  343. int out_off_left, out_off_right;
  344. int in_off_left, in_off_right;
  345. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  346. if (!out) {
  347. av_frame_free(&inpicref);
  348. return AVERROR(ENOMEM);
  349. }
  350. av_frame_copy_props(out, inpicref);
  351. in_off_left = (s->in.row_left + s->in.off_lstep) * inpicref->linesize[0] + s->in.off_left;
  352. in_off_right = (s->in.row_right + s->in.off_rstep) * inpicref->linesize[0] + s->in.off_right;
  353. out_off_left = (s->out.row_left + s->out.off_lstep) * out->linesize[0] + s->out.off_left;
  354. out_off_right = (s->out.row_right + s->out.off_rstep) * out->linesize[0] + s->out.off_right;
  355. switch (s->out.format) {
  356. case SIDE_BY_SIDE_LR:
  357. case SIDE_BY_SIDE_RL:
  358. case SIDE_BY_SIDE_2_LR:
  359. case SIDE_BY_SIDE_2_RL:
  360. case ABOVE_BELOW_LR:
  361. case ABOVE_BELOW_RL:
  362. case ABOVE_BELOW_2_LR:
  363. case ABOVE_BELOW_2_RL:
  364. case INTERLEAVE_ROWS_LR:
  365. case INTERLEAVE_ROWS_RL:
  366. av_image_copy_plane(out->data[0] + out_off_left,
  367. out->linesize[0] * s->row_step,
  368. inpicref->data[0] + in_off_left,
  369. inpicref->linesize[0] * s->row_step,
  370. 3 * s->width, s->height);
  371. av_image_copy_plane(out->data[0] + out_off_right,
  372. out->linesize[0] * s->row_step,
  373. inpicref->data[0] + in_off_right,
  374. inpicref->linesize[0] * s->row_step,
  375. 3 * s->width, s->height);
  376. break;
  377. case MONO_L:
  378. case MONO_R:
  379. av_image_copy_plane(out->data[0], out->linesize[0],
  380. inpicref->data[0] + in_off_left,
  381. inpicref->linesize[0],
  382. 3 * s->width, s->height);
  383. break;
  384. case ANAGLYPH_RB_GRAY:
  385. case ANAGLYPH_RG_GRAY:
  386. case ANAGLYPH_RC_GRAY:
  387. case ANAGLYPH_RC_HALF:
  388. case ANAGLYPH_RC_COLOR:
  389. case ANAGLYPH_RC_DUBOIS:
  390. case ANAGLYPH_GM_GRAY:
  391. case ANAGLYPH_GM_HALF:
  392. case ANAGLYPH_GM_COLOR:
  393. case ANAGLYPH_GM_DUBOIS:
  394. case ANAGLYPH_YB_GRAY:
  395. case ANAGLYPH_YB_HALF:
  396. case ANAGLYPH_YB_COLOR:
  397. case ANAGLYPH_YB_DUBOIS: {
  398. int i, x, y, il, ir, o;
  399. uint8_t *src = inpicref->data[0];
  400. uint8_t *dst = out->data[0];
  401. int out_width = s->out.width;
  402. int *ana_matrix[3];
  403. for (i = 0; i < 3; i++)
  404. ana_matrix[i] = s->ana_matrix[i];
  405. for (y = 0; y < s->out.height; y++) {
  406. o = out->linesize[0] * y;
  407. il = in_off_left + y * inpicref->linesize[0];
  408. ir = in_off_right + y * inpicref->linesize[0];
  409. for (x = 0; x < out_width; x++, il += 3, ir += 3, o+= 3) {
  410. dst[o ] = ana_convert(ana_matrix[0], src + il, src + ir);
  411. dst[o + 1] = ana_convert(ana_matrix[1], src + il, src + ir);
  412. dst[o + 2] = ana_convert(ana_matrix[2], src + il, src + ir);
  413. }
  414. }
  415. break;
  416. }
  417. default:
  418. av_assert0(0);
  419. }
  420. av_frame_free(&inpicref);
  421. return ff_filter_frame(outlink, out);
  422. }
  423. static const AVFilterPad stereo3d_inputs[] = {
  424. {
  425. .name = "default",
  426. .type = AVMEDIA_TYPE_VIDEO,
  427. .filter_frame = filter_frame,
  428. },
  429. { NULL }
  430. };
  431. static const AVFilterPad stereo3d_outputs[] = {
  432. {
  433. .name = "default",
  434. .type = AVMEDIA_TYPE_VIDEO,
  435. .config_props = config_output,
  436. },
  437. { NULL }
  438. };
  439. AVFilter avfilter_vf_stereo3d = {
  440. .name = "stereo3d",
  441. .description = NULL_IF_CONFIG_SMALL("Convert video stereoscopic 3D view."),
  442. .priv_size = sizeof(Stereo3DContext),
  443. .query_formats = query_formats,
  444. .inputs = stereo3d_inputs,
  445. .outputs = stereo3d_outputs,
  446. .priv_class = &stereo3d_class,
  447. };