[vlc-devel] [PATCH 2/2] modules: use plane_SwapUV()

Steve Lhomme robux4 at videolabs.io
Fri Dec 15 13:09:57 CET 2017


---
 modules/codec/dmo/dmo.c                |  8 ++------
 modules/hw/d3d11/d3d11_surface.c       | 14 ++++----------
 modules/hw/d3d9/dxa9.c                 | 14 ++++----------
 modules/video_chroma/copy.c            |  7 ++-----
 modules/video_output/android/display.c |  7 ++-----
 modules/video_output/xcb/xvideo.c      |  7 ++-----
 6 files changed, 16 insertions(+), 41 deletions(-)

diff --git a/modules/codec/dmo/dmo.c b/modules/codec/dmo/dmo.c
index 790617e74b..435f4fb284 100644
--- a/modules/codec/dmo/dmo.c
+++ b/modules/codec/dmo/dmo.c
@@ -989,9 +989,7 @@ static void CopyPicture( picture_t *p_pic, uint8_t *p_in )
     int i_plane, i_line, i_width, i_dst_stride;
     uint8_t *p_dst, *p_src = p_in;
 
-    p_dst = p_pic->p[1].p_pixels;
-    p_pic->p[1].p_pixels = p_pic->p[2].p_pixels;
-    p_pic->p[2].p_pixels = p_dst;
+    plane_SwapUV( p_pic->p );
 
     for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
     {
@@ -1007,9 +1005,7 @@ static void CopyPicture( picture_t *p_pic, uint8_t *p_in )
         }
     }
 
-    p_dst = p_pic->p[1].p_pixels;
-    p_pic->p[1].p_pixels = p_pic->p[2].p_pixels;
-    p_pic->p[2].p_pixels = p_dst;
+    plane_SwapUV( p_pic->p );
 }
 
 static void *DecoderThread( void *data )
diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index cf066ad6fc..e9c6483a50 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -346,11 +346,8 @@ static void D3D11_YUY2(filter_t *p_filter, picture_t *src, picture_t *dst)
         return;
     }
 
-    if (dst->format.i_chroma == VLC_CODEC_I420) {
-        uint8_t *tmp = dst->p[1].p_pixels;
-        dst->p[1].p_pixels = dst->p[2].p_pixels;
-        dst->p[2].p_pixels = tmp;
-    }
+    if (dst->format.i_chroma == VLC_CODEC_I420)
+        plane_SwapUV( dst->p );
 
     ID3D11Texture2D_GetDesc(sys->staging, &desc);
 
@@ -389,11 +386,8 @@ static void D3D11_YUY2(filter_t *p_filter, picture_t *src, picture_t *dst)
         msg_Err(p_filter, "Unsupported D3D11VA conversion from 0x%08X to YV12", desc.Format);
     }
 
-    if (dst->format.i_chroma == VLC_CODEC_I420) {
-        uint8_t *tmp = dst->p[1].p_pixels;
-        dst->p[1].p_pixels = dst->p[2].p_pixels;
-        dst->p[2].p_pixels = tmp;
-    }
+    if (dst->format.i_chroma == VLC_CODEC_I420)
+        plane_SwapUV( dst->p );
 
     /* */
     ID3D11DeviceContext_Unmap(p_sys->context, sys->staging_resource, 0);
diff --git a/modules/hw/d3d9/dxa9.c b/modules/hw/d3d9/dxa9.c
index 3f564e871a..64b87db093 100644
--- a/modules/hw/d3d9/dxa9.c
+++ b/modules/hw/d3d9/dxa9.c
@@ -81,11 +81,8 @@ static void DXA9_YV12(filter_t *p_filter, picture_t *src, picture_t *dst)
     if (desc.Format == MAKEFOURCC('Y','V','1','2') ||
         desc.Format == MAKEFOURCC('I','M','C','3')) {
 
-        if (dst->format.i_chroma == VLC_CODEC_I420) {
-            uint8_t *tmp = dst->p[1].p_pixels;
-            dst->p[1].p_pixels = dst->p[2].p_pixels;
-            dst->p[2].p_pixels = tmp;
-        }
+        if (dst->format.i_chroma == VLC_CODEC_I420)
+            plane_SwapUV( dst->p );
 
         bool imc3 = desc.Format == MAKEFOURCC('I','M','C','3');
         size_t chroma_pitch = imc3 ? lock.Pitch : (lock.Pitch / 2);
@@ -110,11 +107,8 @@ static void DXA9_YV12(filter_t *p_filter, picture_t *src, picture_t *dst)
         }
         Copy420_P_to_P(dst, plane, pitch, src->format.i_height, p_copy_cache);
 
-        if (dst->format.i_chroma == VLC_CODEC_I420) {
-            uint8_t *tmp = dst->p[1].p_pixels;
-            dst->p[1].p_pixels = dst->p[2].p_pixels;
-            dst->p[2].p_pixels = tmp;
-        }
+        if (dst->format.i_chroma == VLC_CODEC_I420)
+            plane_SwapUV( dst->p );
     } else if (desc.Format == MAKEFOURCC('N','V','1','2')) {
         const uint8_t *plane[2] = {
             lock.pBits,
diff --git a/modules/video_chroma/copy.c b/modules/video_chroma/copy.c
index 811e77df49..67e147637b 100644
--- a/modules/video_chroma/copy.c
+++ b/modules/video_chroma/copy.c
@@ -883,11 +883,8 @@ int picture_UpdatePlanes(picture_t *picture, uint8_t *data, unsigned pitch)
             p->i_lines  = picture->format.i_height / 2;
         }
         /* The dx/d3d buffer is always allocated as YV12 */
-        if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
-            uint8_t *p_tmp = picture->p[1].p_pixels;
-            picture->p[1].p_pixels = picture->p[2].p_pixels;
-            picture->p[2].p_pixels = p_tmp;
-        }
+        if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12))
+            plane_SwapUV( picture->p );
     }
     return VLC_SUCCESS;
 }
diff --git a/modules/video_output/android/display.c b/modules/video_output/android/display.c
index a5b9c39738..3bdf41478b 100644
--- a/modules/video_output/android/display.c
+++ b/modules/video_output/android/display.c
@@ -316,11 +316,8 @@ static void SetupPictureYV12(picture_t *p_picture, uint32_t i_in_stride)
     }
 
     if (vlc_fourcc_AreUVPlanesSwapped(p_picture->format.i_chroma,
-                                      VLC_CODEC_YV12)) {
-        uint8_t *p_tmp = p_picture->p[1].p_pixels;
-        p_picture->p[1].p_pixels = p_picture->p[2].p_pixels;
-        p_picture->p[2].p_pixels = p_tmp;
-    }
+                                      VLC_CODEC_YV12))
+        plane_SwapUV( p_picture->p );
 }
 
 static void AndroidWindow_DisconnectSurface(vout_display_sys_t *sys,
diff --git a/modules/video_output/xcb/xvideo.c b/modules/video_output/xcb/xvideo.c
index e79b013b69..46d4fb2b29 100644
--- a/modules/video_output/xcb/xvideo.c
+++ b/modules/video_output/xcb/xvideo.c
@@ -628,11 +628,8 @@ static void PoolAlloc (vout_display_t *vd, unsigned requested_count)
             res.p[i].p_pixels = res.p[0].p_pixels + offsets[i];
 
         if (p_sys->swap_uv)
-        {   /* YVU: swap U and V planes */
-            uint8_t *buf = res.p[2].p_pixels;
-            res.p[2].p_pixels = res.p[1].p_pixels;
-            res.p[1].p_pixels = buf;
-        }
+            /* YVU: swap U and V planes */
+            plane_SwapUV( res.p );
 
         pic_array[count] = XCB_picture_NewFromResource (&vd->fmt, &res,
                                                         p_sys->conn);
-- 
2.14.2



More information about the vlc-devel mailing list