Signed-off-by: Paul B Mahol <onemda@gmail.com>
Paul B Mahol authored on 2013/04/20 23:25:17... | ... |
@@ -132,6 +132,9 @@ typedef struct Stereo3DContext { |
132 | 132 |
int width, height; |
133 | 133 |
int row_step; |
134 | 134 |
int ana_matrix[3][6]; |
135 |
+ int nb_planes; |
|
136 |
+ int linesize[4]; |
|
137 |
+ int pixstep[4]; |
|
135 | 138 |
} Stereo3DContext; |
136 | 139 |
|
137 | 140 |
#define OFFSET(x) offsetof(Stereo3DContext, x) |
... | ... |
@@ -179,11 +182,61 @@ static const AVOption stereo3d_options[] = { |
179 | 179 |
|
180 | 180 |
AVFILTER_DEFINE_CLASS(stereo3d); |
181 | 181 |
|
182 |
+static const enum AVPixelFormat anaglyph_pix_fmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE }; |
|
183 |
+static const enum AVPixelFormat other_pix_fmts[] = { |
|
184 |
+ AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, |
|
185 |
+ AV_PIX_FMT_RGB48BE, AV_PIX_FMT_BGR48BE, |
|
186 |
+ AV_PIX_FMT_RGB48LE, AV_PIX_FMT_BGR48LE, |
|
187 |
+ AV_PIX_FMT_RGBA64BE, AV_PIX_FMT_BGRA64BE, |
|
188 |
+ AV_PIX_FMT_RGBA64LE, AV_PIX_FMT_BGRA64LE, |
|
189 |
+ AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, |
|
190 |
+ AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, |
|
191 |
+ AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0, |
|
192 |
+ AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR, |
|
193 |
+ AV_PIX_FMT_GBRP, |
|
194 |
+ AV_PIX_FMT_GBRP9BE, AV_PIX_FMT_GBRP9LE, |
|
195 |
+ AV_PIX_FMT_GBRP10BE, AV_PIX_FMT_GBRP10LE, |
|
196 |
+ AV_PIX_FMT_GBRP12BE, AV_PIX_FMT_GBRP12LE, |
|
197 |
+ AV_PIX_FMT_GBRP14BE, AV_PIX_FMT_GBRP14LE, |
|
198 |
+ AV_PIX_FMT_GBRP16BE, AV_PIX_FMT_GBRP16LE, |
|
199 |
+ AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA444P, |
|
200 |
+ AV_PIX_FMT_YUVJ444P, |
|
201 |
+ AV_PIX_FMT_YUV444P9LE, AV_PIX_FMT_YUVA444P9LE, |
|
202 |
+ AV_PIX_FMT_YUV444P9BE, AV_PIX_FMT_YUVA444P9BE, |
|
203 |
+ AV_PIX_FMT_YUV444P10LE, AV_PIX_FMT_YUVA444P10LE, |
|
204 |
+ AV_PIX_FMT_YUV444P10BE, AV_PIX_FMT_YUVA444P10BE, |
|
205 |
+ AV_PIX_FMT_YUV444P12BE, AV_PIX_FMT_YUV444P12LE, |
|
206 |
+ AV_PIX_FMT_YUV444P14BE, AV_PIX_FMT_YUV444P14LE, |
|
207 |
+ AV_PIX_FMT_YUV444P16LE, AV_PIX_FMT_YUVA444P16LE, |
|
208 |
+ AV_PIX_FMT_YUV444P16BE, AV_PIX_FMT_YUVA444P16BE, |
|
209 |
+ AV_PIX_FMT_NONE |
|
210 |
+}; |
|
211 |
+ |
|
182 | 212 |
static int query_formats(AVFilterContext *ctx) |
183 | 213 |
{ |
184 |
- static const enum AVPixelFormat pix_fmts[] = { |
|
185 |
- AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE |
|
186 |
- }; |
|
214 |
+ Stereo3DContext *s = ctx->priv; |
|
215 |
+ const enum AVPixelFormat *pix_fmts; |
|
216 |
+ |
|
217 |
+ switch (s->out.format) { |
|
218 |
+ case ANAGLYPH_GM_COLOR: |
|
219 |
+ case ANAGLYPH_GM_DUBOIS: |
|
220 |
+ case ANAGLYPH_GM_GRAY: |
|
221 |
+ case ANAGLYPH_GM_HALF: |
|
222 |
+ case ANAGLYPH_RB_GRAY: |
|
223 |
+ case ANAGLYPH_RC_COLOR: |
|
224 |
+ case ANAGLYPH_RC_DUBOIS: |
|
225 |
+ case ANAGLYPH_RC_GRAY: |
|
226 |
+ case ANAGLYPH_RC_HALF: |
|
227 |
+ case ANAGLYPH_RG_GRAY: |
|
228 |
+ case ANAGLYPH_YB_COLOR: |
|
229 |
+ case ANAGLYPH_YB_DUBOIS: |
|
230 |
+ case ANAGLYPH_YB_GRAY: |
|
231 |
+ case ANAGLYPH_YB_HALF: |
|
232 |
+ pix_fmts = anaglyph_pix_fmts; |
|
233 |
+ break; |
|
234 |
+ default: |
|
235 |
+ pix_fmts = other_pix_fmts; |
|
236 |
+ } |
|
187 | 237 |
|
188 | 238 |
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts)); |
189 | 239 |
|
... | ... |
@@ -196,6 +249,8 @@ static int config_output(AVFilterLink *outlink) |
196 | 196 |
AVFilterLink *inlink = ctx->inputs[0]; |
197 | 197 |
Stereo3DContext *s = ctx->priv; |
198 | 198 |
AVRational aspect = inlink->sample_aspect_ratio; |
199 |
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format); |
|
200 |
+ int ret; |
|
199 | 201 |
|
200 | 202 |
switch (s->in.format) { |
201 | 203 |
case SIDE_BY_SIDE_2_LR: |
... | ... |
@@ -242,13 +297,13 @@ static int config_output(AVFilterLink *outlink) |
242 | 242 |
aspect.num *= 2; |
243 | 243 |
case SIDE_BY_SIDE_LR: |
244 | 244 |
s->width = inlink->w / 2; |
245 |
- s->in.off_right = s->width * 3; |
|
245 |
+ s->in.off_right = s->width; |
|
246 | 246 |
break; |
247 | 247 |
case SIDE_BY_SIDE_2_RL: |
248 | 248 |
aspect.num *= 2; |
249 | 249 |
case SIDE_BY_SIDE_RL: |
250 | 250 |
s->width = inlink->w / 2; |
251 |
- s->in.off_left = s->width * 3; |
|
251 |
+ s->in.off_left = s->width; |
|
252 | 252 |
break; |
253 | 253 |
case ABOVE_BELOW_2_LR: |
254 | 254 |
aspect.den *= 2; |
... | ... |
@@ -297,13 +352,13 @@ static int config_output(AVFilterLink *outlink) |
297 | 297 |
aspect.num /= 2; |
298 | 298 |
case SIDE_BY_SIDE_LR: |
299 | 299 |
s->out.width = s->width * 2; |
300 |
- s->out.off_right = s->width * 3; |
|
300 |
+ s->out.off_right = s->width; |
|
301 | 301 |
break; |
302 | 302 |
case SIDE_BY_SIDE_2_RL: |
303 | 303 |
aspect.num /= 2; |
304 | 304 |
case SIDE_BY_SIDE_RL: |
305 | 305 |
s->out.width = s->width * 2; |
306 |
- s->out.off_left = s->width * 3; |
|
306 |
+ s->out.off_left = s->width; |
|
307 | 307 |
break; |
308 | 308 |
case ABOVE_BELOW_2_LR: |
309 | 309 |
aspect.den /= 2; |
... | ... |
@@ -343,6 +398,11 @@ static int config_output(AVFilterLink *outlink) |
343 | 343 |
outlink->h = s->out.height; |
344 | 344 |
outlink->sample_aspect_ratio = aspect; |
345 | 345 |
|
346 |
+ if ((ret = av_image_fill_linesizes(s->linesize, outlink->format, s->width)) < 0) |
|
347 |
+ return ret; |
|
348 |
+ s->nb_planes = av_pix_fmt_count_planes(outlink->format); |
|
349 |
+ av_image_fill_max_pixsteps(s->pixstep, NULL, desc); |
|
350 |
+ |
|
346 | 351 |
return 0; |
347 | 352 |
} |
348 | 353 |
|
... | ... |
@@ -363,8 +423,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) |
363 | 363 |
Stereo3DContext *s = ctx->priv; |
364 | 364 |
AVFilterLink *outlink = ctx->outputs[0]; |
365 | 365 |
AVFrame *out; |
366 |
- int out_off_left, out_off_right; |
|
367 |
- int in_off_left, in_off_right; |
|
366 |
+ int out_off_left[4], out_off_right[4]; |
|
367 |
+ int in_off_left[4], in_off_right[4]; |
|
368 |
+ int i; |
|
368 | 369 |
|
369 | 370 |
out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
370 | 371 |
if (!out) { |
... | ... |
@@ -373,10 +434,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) |
373 | 373 |
} |
374 | 374 |
av_frame_copy_props(out, inpicref); |
375 | 375 |
|
376 |
- in_off_left = (s->in.row_left + s->in.off_lstep) * inpicref->linesize[0] + s->in.off_left; |
|
377 |
- in_off_right = (s->in.row_right + s->in.off_rstep) * inpicref->linesize[0] + s->in.off_right; |
|
378 |
- out_off_left = (s->out.row_left + s->out.off_lstep) * out->linesize[0] + s->out.off_left; |
|
379 |
- out_off_right = (s->out.row_right + s->out.off_rstep) * out->linesize[0] + s->out.off_right; |
|
376 |
+ for (i = 0; i < 4; i++) { |
|
377 |
+ in_off_left[i] = (s->in.row_left + s->in.off_lstep) * inpicref->linesize[i] + s->in.off_left * s->pixstep[i]; |
|
378 |
+ in_off_right[i] = (s->in.row_right + s->in.off_rstep) * inpicref->linesize[i] + s->in.off_right * s->pixstep[i]; |
|
379 |
+ out_off_left[i] = (s->out.row_left + s->out.off_lstep) * out->linesize[i] + s->out.off_left * s->pixstep[i]; |
|
380 |
+ out_off_right[i] = (s->out.row_right + s->out.off_rstep) * out->linesize[i] + s->out.off_right * s->pixstep[i]; |
|
381 |
+ } |
|
380 | 382 |
|
381 | 383 |
switch (s->out.format) { |
382 | 384 |
case SIDE_BY_SIDE_LR: |
... | ... |
@@ -389,23 +452,27 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) |
389 | 389 |
case ABOVE_BELOW_2_RL: |
390 | 390 |
case INTERLEAVE_ROWS_LR: |
391 | 391 |
case INTERLEAVE_ROWS_RL: |
392 |
- av_image_copy_plane(out->data[0] + out_off_left, |
|
393 |
- out->linesize[0] * s->row_step, |
|
394 |
- inpicref->data[0] + in_off_left, |
|
395 |
- inpicref->linesize[0] * s->row_step, |
|
396 |
- 3 * s->width, s->height); |
|
397 |
- av_image_copy_plane(out->data[0] + out_off_right, |
|
398 |
- out->linesize[0] * s->row_step, |
|
399 |
- inpicref->data[0] + in_off_right, |
|
400 |
- inpicref->linesize[0] * s->row_step, |
|
401 |
- 3 * s->width, s->height); |
|
392 |
+ for (i = 0; i < s->nb_planes; i++) { |
|
393 |
+ av_image_copy_plane(out->data[i] + out_off_left[i], |
|
394 |
+ out->linesize[i] * s->row_step, |
|
395 |
+ inpicref->data[i] + in_off_left[i], |
|
396 |
+ inpicref->linesize[i] * s->row_step, |
|
397 |
+ s->linesize[i], s->height); |
|
398 |
+ av_image_copy_plane(out->data[i] + out_off_right[i], |
|
399 |
+ out->linesize[i] * s->row_step, |
|
400 |
+ inpicref->data[i] + in_off_right[i], |
|
401 |
+ inpicref->linesize[i] * s->row_step, |
|
402 |
+ s->linesize[i], s->height); |
|
403 |
+ } |
|
402 | 404 |
break; |
403 | 405 |
case MONO_L: |
404 | 406 |
case MONO_R: |
405 |
- av_image_copy_plane(out->data[0], out->linesize[0], |
|
406 |
- inpicref->data[0] + in_off_left, |
|
407 |
- inpicref->linesize[0], |
|
408 |
- 3 * s->width, s->height); |
|
407 |
+ for (i = 0; i < s->nb_planes; i++) { |
|
408 |
+ av_image_copy_plane(out->data[i], out->linesize[i], |
|
409 |
+ inpicref->data[i] + in_off_left[i], |
|
410 |
+ inpicref->linesize[i], |
|
411 |
+ s->linesize[i], s->height); |
|
412 |
+ } |
|
409 | 413 |
break; |
410 | 414 |
case ANAGLYPH_RB_GRAY: |
411 | 415 |
case ANAGLYPH_RG_GRAY: |
... | ... |
@@ -432,8 +499,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) |
432 | 432 |
|
433 | 433 |
for (y = 0; y < s->out.height; y++) { |
434 | 434 |
o = out->linesize[0] * y; |
435 |
- il = in_off_left + y * inpicref->linesize[0]; |
|
436 |
- ir = in_off_right + y * inpicref->linesize[0]; |
|
435 |
+ il = in_off_left[0] + y * inpicref->linesize[0]; |
|
436 |
+ ir = in_off_right[0] + y * inpicref->linesize[0]; |
|
437 | 437 |
for (x = 0; x < out_width; x++, il += 3, ir += 3, o+= 3) { |
438 | 438 |
dst[o ] = ana_convert(ana_matrix[0], src + il, src + ir); |
439 | 439 |
dst[o + 1] = ana_convert(ana_matrix[1], src + il, src + ir); |