Merge commit 'c9943f00cfa2471d1b8a3a9ddc7a21049a71090e'
authorHendrik Leppkes <h.leppkes@gmail.com>
Tue, 29 Sep 2015 13:44:14 +0000 (15:44 +0200)
committerHendrik Leppkes <h.leppkes@gmail.com>
Tue, 29 Sep 2015 13:44:14 +0000 (15:44 +0200)
* commit 'c9943f00cfa2471d1b8a3a9ddc7a21049a71090e':
  vf_framepack: Use av_image_copy() where appropriate

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
1  2 
libavfilter/vf_framepack.c

@@@ -143,45 -130,67 +143,67 @@@ static int config_output(AVFilterLink *
      return 0;
  }
  
- static void horizontal_frame_pack(FramepackContext *s,
-                                   AVFrame *dst,
+ static void horizontal_frame_pack(AVFilterLink *outlink,
+                                   AVFrame *out,
                                    int interleaved)
  {
-     int plane, i;
-     int length = dst->width / 2;
-     int lines  = dst->height;
-     for (plane = 0; plane < s->pix_desc->nb_components; plane++) {
-         const uint8_t *leftp  = s->input_views[LEFT]->data[plane];
-         const uint8_t *rightp = s->input_views[RIGHT]->data[plane];
-         uint8_t *dstp         = dst->data[plane];
-         if (plane == 1 || plane == 2) {
-             length = FF_CEIL_RSHIFT(dst->width / 2, s->pix_desc->log2_chroma_w);
-             lines  = FF_CEIL_RSHIFT(dst->height,    s->pix_desc->log2_chroma_h);
-         }
-         if (interleaved) {
+     AVFilterContext *ctx = outlink->src;
+     FramepackContext *s = ctx->priv;
+     int i, plane;
+     if (interleaved) {
+         const uint8_t *leftp  = s->input_views[LEFT]->data[0];
+         const uint8_t *rightp = s->input_views[RIGHT]->data[0];
+         uint8_t *dstp         = out->data[0];
+         int length = out->width / 2;
+         int lines  = out->height;
+         for (plane = 0; plane < s->pix_desc->nb_components; plane++) {
+             if (plane == 1 || plane == 2) {
 -                length = -(-(out->width / 2) >> s->pix_desc->log2_chroma_w);
 -                lines  = -(-(out->height)    >> s->pix_desc->log2_chroma_h);
++                length = FF_CEIL_RSHIFT(out->width / 2, s->pix_desc->log2_chroma_w);
++                lines  = FF_CEIL_RSHIFT(out->height,    s->pix_desc->log2_chroma_h);
+             }
              for (i = 0; i < lines; i++) {
                  int j;
-                 int k = 0;
+                 leftp  = s->input_views[LEFT]->data[plane] +
+                          s->input_views[LEFT]->linesize[plane] * i;
+                 rightp = s->input_views[RIGHT]->data[plane] +
+                          s->input_views[RIGHT]->linesize[plane] * i;
+                 dstp   = out->data[plane] + out->linesize[plane] * i;
                  for (j = 0; j < length; j++) {
-                     dstp[k++] = leftp[j];
-                     dstp[k++] = rightp[j];
+                     // interpolate chroma as necessary
+                     if ((s->pix_desc->log2_chroma_w ||
+                          s->pix_desc->log2_chroma_h) &&
+                         (plane == 1 || plane == 2)) {
+                         *dstp++ = (*leftp + *rightp) / 2;
+                         *dstp++ = (*leftp + *rightp) / 2;
+                     } else {
+                         *dstp++ = *leftp;
+                         *dstp++ = *rightp;
+                     }
+                     leftp += 1;
+                     rightp += 1;
                  }
-                 dstp   += dst->linesize[plane];
-                 leftp  += s->input_views[LEFT]->linesize[plane];
-                 rightp += s->input_views[RIGHT]->linesize[plane];
              }
-         } else {
-             av_image_copy_plane(dst->data[plane], dst->linesize[plane],
-                                 leftp, s->input_views[LEFT]->linesize[plane],
-                                 length, lines);
-             av_image_copy_plane(dst->data[plane] + length, dst->linesize[plane],
-                                 rightp, s->input_views[RIGHT]->linesize[plane],
-                                 length, lines);
+         }
+     } else {
+         for (i = 0; i < 2; i++) {
+             const uint8_t *src[4];
+             uint8_t *dst[4];
+             int sub_w = s->input_views[i]->width >> s->pix_desc->log2_chroma_w;
+             src[0] = s->input_views[i]->data[0];
+             src[1] = s->input_views[i]->data[1];
+             src[2] = s->input_views[i]->data[2];
+             dst[0] = out->data[0] + i * s->input_views[i]->width;
+             dst[1] = out->data[1] + i * sub_w;
+             dst[2] = out->data[2] + i * sub_w;
+             av_image_copy(dst, out->linesize, src, s->input_views[i]->linesize,
+                           s->input_views[i]->format,
+                           s->input_views[i]->width,
+                           s->input_views[i]->height);
          }
      }
  }