Browse code

avfilter/vf_stereo3d: rewrite in preparation for SIMD

Also slightly faster.

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2015/10/04 05:12:17
Showing 1 changed files
... ...
@@ -531,6 +531,26 @@ static inline uint8_t ana_convert(const int *coeff, const uint8_t *left, const u
531 531
     return av_clip_uint8(sum >> 16);
532 532
 }
533 533
 
534
+static void anaglyph(uint8_t *dst, uint8_t *lsrc, uint8_t *rsrc,
535
+                     ptrdiff_t dst_linesize, ptrdiff_t l_linesize, ptrdiff_t r_linesize,
536
+                     int width, int height,
537
+                     const int *ana_matrix_r, const int *ana_matrix_g, const int *ana_matrix_b)
538
+{
539
+    int x, y, o;
540
+
541
+    for (y = 0; y < height; y++) {
542
+        for (o = 0, x = 0; x < width; x++, o+= 3) {
543
+            dst[o    ] = ana_convert(ana_matrix_r, lsrc + o, rsrc + o);
544
+            dst[o + 1] = ana_convert(ana_matrix_g, lsrc + o, rsrc + o);
545
+            dst[o + 2] = ana_convert(ana_matrix_b, lsrc + o, rsrc + o);
546
+        }
547
+
548
+        dst  += dst_linesize;
549
+        lsrc += l_linesize;
550
+        rsrc += r_linesize;
551
+    }
552
+}
553
+
534 554
 typedef struct ThreadData {
535 555
     AVFrame *ileft, *iright;
536 556
     AVFrame *out;
... ...
@@ -546,23 +566,16 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
546 546
     int height = s->out.height;
547 547
     int start = (height *  jobnr   ) / nb_jobs;
548 548
     int end   = (height * (jobnr+1)) / nb_jobs;
549
-    uint8_t *dst = out->data[0];
550 549
     const int **ana_matrix = s->ana_matrix;
551
-    int x, y, il, ir, o;
552
-    const uint8_t *lsrc = ileft->data[0];
553
-    const uint8_t *rsrc = iright->data[0];
554
-    int out_width = s->out.width;
555
-
556
-    for (y = start; y < end; y++) {
557
-        o   = out->linesize[0] * y;
558
-        il  = s->in_off_left[0]  + y * ileft->linesize[0] * s->in.row_step;
559
-        ir  = s->in_off_right[0] + y * iright->linesize[0] * s->in.row_step;
560
-        for (x = 0; x < out_width; x++, il += 3, ir += 3, o+= 3) {
561
-            dst[o    ] = ana_convert(ana_matrix[0], lsrc + il, rsrc + ir);
562
-            dst[o + 1] = ana_convert(ana_matrix[1], lsrc + il, rsrc + ir);
563
-            dst[o + 2] = ana_convert(ana_matrix[2], lsrc + il, rsrc + ir);
564
-        }
565
-    }
550
+
551
+    anaglyph(out->data[0] + out->linesize[0] * start,
552
+             ileft ->data[0] + s->in_off_left [0]  + ileft->linesize[0] * start * s->in.row_step,
553
+             iright->data[0] + s->in_off_right[0] + iright->linesize[0] * start * s->in.row_step,
554
+             out->linesize[0],
555
+             ileft->linesize[0] * s->in.row_step,
556
+             iright->linesize[0] * s->in.row_step,
557
+             s->out.width, end - start,
558
+             ana_matrix[0], ana_matrix[1], ana_matrix[2]);
566 559
 
567 560
     return 0;
568 561
 }