video: fix unpack_Y210
authorHaihao Xiang <haihao.xiang@intel.com>
Mon, 25 Mar 2019 06:07:08 +0000 (14:07 +0800)
committerHaihao Xiang <haihao.xiang@intel.com>
Tue, 26 Mar 2019 02:24:35 +0000 (10:24 +0800)
It should handle data starting from x and width may be an odd

gst-libs/gst/video/video-format.c

index ff813d0..fe587fa 100644 (file)
@@ -795,6 +795,28 @@ unpack_Y210 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint16 *restrict d = dest;
   guint Y0, Y1, U, V;
 
+  s += GST_ROUND_DOWN_2 (x) * 4;
+
+  if (x & 1) {
+    Y1 = GST_READ_UINT16_LE (s + 4);
+    U = GST_READ_UINT16_LE (s + 2);
+    V = GST_READ_UINT16_LE (s + 6);
+
+    if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
+      Y1 |= (Y1 >> 10);
+      U |= (U >> 10);
+      V |= (V >> 10);
+    }
+
+    d[0] = 0xffff;
+    d[1] = Y1;
+    d[2] = U;
+    d[3] = V;
+    s += 8;
+    d += 4;
+    width--;
+  }
+
   for (i = 0; i < width / 2; i++) {
     Y0 = GST_READ_UINT16_LE (s + i * 8 + 0);
     U = GST_READ_UINT16_LE (s + i * 8 + 2);
@@ -817,6 +839,25 @@ unpack_Y210 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
     d[i * 8 + 6] = U;
     d[i * 8 + 7] = V;
   }
+
+  if (width & 1) {
+    i = width - 1;
+
+    Y0 = GST_READ_UINT16_LE (s + i * 4 + 0);
+    U = GST_READ_UINT16_LE (s + i * 4 + 2);
+    V = GST_READ_UINT16_LE (s + i * 4 + 6);
+
+    if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
+      Y0 |= (Y0 >> 10);
+      U |= (U >> 10);
+      V |= (V >> 10);
+    }
+
+    d[i * 4 + 0] = 0xffff;
+    d[i * 4 + 1] = Y0;
+    d[i * 4 + 2] = U;
+    d[i * 4 + 3] = V;
+  }
 }
 
 static void