[MPlayer-dev-eng] [PATCH v2 1/5] vo_xv: Simplify plane swapping

Alexander Strasser eclipse7 at gmx.net
Mon Jul 10 00:26:36 EEST 2017


Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
---
 libvo/vo_xv.c | 54 +++++++++++++++++++++---------------------------------
 1 file changed, 21 insertions(+), 33 deletions(-)

diff --git a/libvo/vo_xv.c b/libvo/vo_xv.c
index 95600fc85..a39c8d504 100644
--- a/libvo/vo_xv.c
+++ b/libvo/vo_xv.c
@@ -386,12 +386,17 @@ static int draw_slice(uint8_t * image[], int stride[], int w, int h,
                            int x, int y)
 {
     uint8_t *dst;
+    int idx_p1 = 1, idx_p2 = 2;
 
     dst = xvimage[current_buf]->data + xvimage[current_buf]->offsets[0] +
         xvimage[current_buf]->pitches[0] * y + x;
     memcpy_pic(dst, image[0], w, h, xvimage[current_buf]->pitches[0],
                stride[0]);
 
+    switch (image_format) {
+    case IMGFMT_YV12:
+        idx_p1 = 2; idx_p2 = 1;
+    default:
     x /= 2;
     y /= 2;
     w /= 2;
@@ -399,21 +404,15 @@ static int draw_slice(uint8_t * image[], int stride[], int w, int h,
 
     dst = xvimage[current_buf]->data + xvimage[current_buf]->offsets[1] +
         xvimage[current_buf]->pitches[1] * y + x;
-    if (image_format != IMGFMT_YV12)
-        memcpy_pic(dst, image[1], w, h, xvimage[current_buf]->pitches[1],
-                   stride[1]);
-    else
-        memcpy_pic(dst, image[2], w, h, xvimage[current_buf]->pitches[1],
-                   stride[2]);
+        memcpy_pic(dst, image[idx_p1], w, h, xvimage[current_buf]->pitches[1],
+                   stride[idx_p1]);
 
     dst = xvimage[current_buf]->data + xvimage[current_buf]->offsets[2] +
         xvimage[current_buf]->pitches[2] * y + x;
-    if (image_format == IMGFMT_YV12)
-        memcpy_pic(dst, image[1], w, h, xvimage[current_buf]->pitches[1],
-                   stride[1]);
-    else
-        memcpy_pic(dst, image[2], w, h, xvimage[current_buf]->pitches[1],
-                   stride[2]);
+        memcpy_pic(dst, image[idx_p2], w, h, xvimage[current_buf]->pitches[1],
+                   stride[idx_p2]);
+        break;
+    }
 
     return 0;
 }
@@ -476,36 +475,25 @@ static uint32_t get_image(mp_image_t * mpi)
     if ((mpi->flags & (MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_ACCEPT_WIDTH))
         || (mpi->width * (mpi->bpp / 8) == xvimage[buf]->pitches[0]))
     {
+        int idx_p1 = 1, idx_p2 = 2;
         current_buf = buf;
         mpi->planes[0] =
             xvimage[current_buf]->data + xvimage[current_buf]->offsets[0];
         mpi->stride[0] = xvimage[current_buf]->pitches[0];
         mpi->width = mpi->stride[0] / (mpi->bpp / 8);
-        if (mpi->flags & MP_IMGFLAG_PLANAR)
-        {
-            if (mpi->flags & MP_IMGFLAG_SWAPPED)
-            {
-                // I420
+        switch (image_format) {
+        case IMGFMT_YV12:
+            idx_p1 = 2; idx_p2 = 1;
+        default:
                 mpi->planes[1] =
                     xvimage[current_buf]->data +
-                    xvimage[current_buf]->offsets[1];
+                    xvimage[current_buf]->offsets[idx_p1];
                 mpi->planes[2] =
                     xvimage[current_buf]->data +
-                    xvimage[current_buf]->offsets[2];
-                mpi->stride[1] = xvimage[current_buf]->pitches[1];
-                mpi->stride[2] = xvimage[current_buf]->pitches[2];
-            } else
-            {
-                // YV12
-                mpi->planes[1] =
-                    xvimage[current_buf]->data +
-                    xvimage[current_buf]->offsets[2];
-                mpi->planes[2] =
-                    xvimage[current_buf]->data +
-                    xvimage[current_buf]->offsets[1];
-                mpi->stride[1] = xvimage[current_buf]->pitches[2];
-                mpi->stride[2] = xvimage[current_buf]->pitches[1];
-            }
+                    xvimage[current_buf]->offsets[idx_p2];
+                mpi->stride[1] = xvimage[current_buf]->pitches[idx_p1];
+                mpi->stride[2] = xvimage[current_buf]->pitches[idx_p2];
+            break;
         }
         mpi->flags |= MP_IMGFLAG_DIRECT;
         mpi->priv = (void *)(intptr_t)current_buf;
-- 
2.13.2


  Alexander


More information about the MPlayer-dev-eng mailing list