summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott D Phillips <scott.d.phillips@intel.com>2016-03-29 11:16:42 +0300
committerSreerenj Balachandran <sreerenj.balachandran@intel.com>2016-03-29 11:16:42 +0300
commit079ceb894cd73bde243820231f714a5b6a7801f9 (patch)
tree3790f3f86533741c10e0ccf3e4a7d366b95d5d14
parent38a5a3614e6d220c69b7206e8cf6a5e25115d5f2 (diff)
video: add P010 format support
P010 is a YUV420 format with an interleaved U-V plane and 2-bytes per component with the the color value stored in the 10 most significant bits. https://bugzilla.gnome.org/show_bug.cgi?id=761607 --- Changes since v2: - Set bits=16 in DPTH10_10_10_HI Changes since v1: - Fixed x-offset calculation in uv. - Added 6-bit shifts to FormatInfo.
-rw-r--r--gst-libs/gst/video/video-converter.c2
-rw-r--r--gst-libs/gst/video/video-format.c251
-rw-r--r--gst-libs/gst/video/video-format.h6
-rw-r--r--gst-libs/gst/video/video-info.c9
4 files changed, 267 insertions, 1 deletions
diff --git a/gst-libs/gst/video/video-converter.c b/gst-libs/gst/video/video-converter.c
index f29278d02..7835c40ce 100644
--- a/gst-libs/gst/video/video-converter.c
+++ b/gst-libs/gst/video/video-converter.c
@@ -4008,6 +4008,8 @@ get_scale_format (GstVideoFormat format, gint plane)
case GST_VIDEO_FORMAT_A422_10LE:
case GST_VIDEO_FORMAT_A444_10BE:
case GST_VIDEO_FORMAT_A444_10LE:
+ case GST_VIDEO_FORMAT_P010_10BE:
+ case GST_VIDEO_FORMAT_P010_10LE:
res = format;
g_assert_not_reached ();
break;
diff --git a/gst-libs/gst/video/video-format.c b/gst-libs/gst/video/video-format.c
index cff818901..f75772575 100644
--- a/gst-libs/gst/video/video-format.c
+++ b/gst-libs/gst/video/video-format.c
@@ -3306,6 +3306,252 @@ pack_NV12_64Z32 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
}
}
+#define PACK_P010_10BE GST_VIDEO_FORMAT_AYUV64, unpack_P010_10BE, 1, pack_P010_10BE
+static void
+unpack_P010_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
+ gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
+ const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
+{
+ int i;
+ gint uv = GET_UV_420 (y, flags);
+ const guint16 *restrict sy = GET_PLANE_LINE (0, y);
+ const guint16 *restrict suv = GET_PLANE_LINE (1, uv);
+ guint16 *restrict d = dest, Y0, Y1, U, V;
+
+ sy += x;
+ suv += (x & ~1);
+
+ if (x & 1) {
+ Y0 = GST_READ_UINT16_BE (sy);
+ U = GST_READ_UINT16_BE (suv);
+ V = GST_READ_UINT16_BE (suv + 1);
+
+ if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
+ Y0 |= (Y0 >> 10);
+ U |= (U >> 10);
+ V |= (V >> 10);
+ }
+
+ d[0] = 0xffff;
+ d[1] = Y0;
+ d[2] = U;
+ d[3] = V;
+ width--;
+ d += 4;
+ sy += 1;
+ suv += 2;
+ }
+
+ for (i = 0; i < width / 2; i++) {
+ Y0 = GST_READ_UINT16_BE (sy + 2 * i);
+ Y1 = GST_READ_UINT16_BE (sy + 2 * i + 1);
+ U = GST_READ_UINT16_BE (suv + 2 * i);
+ V = GST_READ_UINT16_BE (suv + 2 * i + 1);
+
+ if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
+ Y0 |= (Y0 >> 10);
+ Y1 |= (Y1 >> 10);
+ U |= (U >> 10);
+ V |= (V >> 10);
+ }
+
+ d[i * 8 + 0] = 0xffff;
+ d[i * 8 + 1] = Y0;
+ d[i * 8 + 2] = U;
+ d[i * 8 + 3] = V;
+ d[i * 8 + 4] = 0xffff;
+ d[i * 8 + 5] = Y1;
+ d[i * 8 + 6] = U;
+ d[i * 8 + 7] = V;
+ }
+
+ if (width & 1) {
+ gint i = width - 1;
+
+ Y0 = GST_READ_UINT16_BE (sy + i);
+ U = GST_READ_UINT16_BE (suv + i);
+ V = GST_READ_UINT16_BE (suv + i + 1);
+
+ 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
+pack_P010_10BE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
+ const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
+ const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
+ gint y, gint width)
+{
+ int i;
+ gint uv = GET_UV_420 (y, flags);
+ guint16 *restrict dy = GET_PLANE_LINE (0, y);
+ guint16 *restrict duv = GET_PLANE_LINE (1, uv);
+ guint16 Y0, Y1, U, V;
+ const guint16 *restrict s = src;
+
+ if (IS_CHROMA_LINE_420 (y, flags)) {
+ for (i = 0; i < width / 2; i++) {
+ Y0 = s[i * 8 + 1] & 0xffc0;
+ Y1 = s[i * 8 + 5] & 0xffc0;
+ U = s[i * 8 + 2] & 0xffc0;
+ V = s[i * 8 + 3] & 0xffc0;
+
+ GST_WRITE_UINT16_BE (dy + i * 2 + 0, Y0);
+ GST_WRITE_UINT16_BE (dy + i * 2 + 1, Y1);
+ GST_WRITE_UINT16_BE (duv + i * 2 + 0, U);
+ GST_WRITE_UINT16_BE (duv + i * 2 + 1, V);
+ }
+ if (width & 1) {
+ gint i = width - 1;
+
+ Y0 = s[i * 4 + 1] & 0xffc0;
+ U = s[i * 4 + 2] & 0xffc0;
+ V = s[i * 4 + 3] & 0xffc0;
+
+ GST_WRITE_UINT16_BE (dy + i, Y0);
+ GST_WRITE_UINT16_BE (duv + i + 0, U);
+ GST_WRITE_UINT16_BE (duv + i + 1, V);
+ }
+ } else {
+ for (i = 0; i < width; i++) {
+ Y0 = s[i * 4 + 1] & 0xffc0;
+ GST_WRITE_UINT16_BE (dy + i, Y0);
+ }
+ }
+}
+
+#define PACK_P010_10LE GST_VIDEO_FORMAT_AYUV64, unpack_P010_10LE, 1, pack_P010_10LE
+static void
+unpack_P010_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
+ gpointer dest, const gpointer data[GST_VIDEO_MAX_PLANES],
+ const gint stride[GST_VIDEO_MAX_PLANES], gint x, gint y, gint width)
+{
+ int i;
+ gint uv = GET_UV_420 (y, flags);
+ const guint16 *restrict sy = GET_PLANE_LINE (0, y);
+ const guint16 *restrict suv = GET_PLANE_LINE (1, uv);
+ guint16 *restrict d = dest, Y0, Y1, U, V;
+
+ sy += x;
+ suv += (x & ~1);
+
+ if (x & 1) {
+ Y0 = GST_READ_UINT16_LE (sy);
+ U = GST_READ_UINT16_LE (suv);
+ V = GST_READ_UINT16_LE (suv + 1);
+
+ if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
+ Y0 |= (Y0 >> 10);
+ U |= (U >> 10);
+ V |= (V >> 10);
+ }
+
+ d[0] = 0xffff;
+ d[1] = Y0;
+ d[2] = U;
+ d[3] = V;
+ width--;
+ d += 4;
+ sy += 1;
+ suv += 2;
+ }
+
+ for (i = 0; i < width / 2; i++) {
+ Y0 = GST_READ_UINT16_LE (sy + 2 * i);
+ Y1 = GST_READ_UINT16_LE (sy + 2 * i + 1);
+ U = GST_READ_UINT16_LE (suv + 2 * i);
+ V = GST_READ_UINT16_LE (suv + 2 * i + 1);
+
+ if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
+ Y0 |= (Y0 >> 10);
+ Y1 |= (Y1 >> 10);
+ U |= (U >> 10);
+ V |= (V >> 10);
+ }
+
+ d[i * 8 + 0] = 0xffff;
+ d[i * 8 + 1] = Y0;
+ d[i * 8 + 2] = U;
+ d[i * 8 + 3] = V;
+ d[i * 8 + 4] = 0xffff;
+ d[i * 8 + 5] = Y1;
+ d[i * 8 + 6] = U;
+ d[i * 8 + 7] = V;
+ }
+
+ if (width & 1) {
+ gint i = width - 1;
+
+ Y0 = GST_READ_UINT16_LE (sy + i);
+ U = GST_READ_UINT16_LE (suv + i);
+ V = GST_READ_UINT16_LE (suv + i + 1);
+
+ 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
+pack_P010_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
+ const gpointer src, gint sstride, gpointer data[GST_VIDEO_MAX_PLANES],
+ const gint stride[GST_VIDEO_MAX_PLANES], GstVideoChromaSite chroma_site,
+ gint y, gint width)
+{
+ int i;
+ gint uv = GET_UV_420 (y, flags);
+ guint16 *restrict dy = GET_PLANE_LINE (0, y);
+ guint16 *restrict duv = GET_PLANE_LINE (1, uv);
+ guint16 Y0, Y1, U, V;
+ const guint16 *restrict s = src;
+
+ if (IS_CHROMA_LINE_420 (y, flags)) {
+ for (i = 0; i < width / 2; i++) {
+ Y0 = s[i * 8 + 1] & 0xffc0;
+ Y1 = s[i * 8 + 5] & 0xffc0;
+ U = s[i * 8 + 2] & 0xffc0;
+ V = s[i * 8 + 3] & 0xffc0;
+
+ GST_WRITE_UINT16_LE (dy + i * 2 + 0, Y0);
+ GST_WRITE_UINT16_LE (dy + i * 2 + 1, Y1);
+ GST_WRITE_UINT16_LE (duv + i * 2 + 0, U);
+ GST_WRITE_UINT16_LE (duv + i * 2 + 1, V);
+ }
+ if (width & 1) {
+ gint i = width - 1;
+
+ Y0 = s[i * 4 + 1] & 0xffc0;
+ U = s[i * 4 + 2] & 0xffc0;
+ V = s[i * 4 + 3] & 0xffc0;
+
+ GST_WRITE_UINT16_LE (dy + i, Y0);
+ GST_WRITE_UINT16_LE (duv + i + 0, U);
+ GST_WRITE_UINT16_LE (duv + i + 1, V);
+ }
+ } else {
+ for (i = 0; i < width; i++) {
+ Y0 = s[i * 4 + 1] & 0xffc0;
+ GST_WRITE_UINT16_LE (dy + i, Y0);
+ }
+ }
+}
+
typedef struct
{
guint32 fourcc;
@@ -3321,6 +3567,7 @@ typedef struct
#define DPTH8880 8, 4, { 0, 0, 0, 0 }, { 8, 8, 8, 0 }
#define DPTH10_10_10 10, 3, { 0, 0, 0, 0 }, { 10, 10, 10, 0 }
#define DPTH10_10_10_10 10, 4, { 0, 0, 0, 0 }, { 10, 10, 10, 10 }
+#define DPTH10_10_10_HI 16, 3, { 6, 6, 6, 0 }, { 10, 10, 10, 0 }
#define DPTH16 16, 1, { 0, 0, 0, 0 }, { 16, 0, 0, 0 }
#define DPTH16_16_16 16, 3, { 0, 0, 0, 0 }, { 16, 16, 16, 0 }
#define DPTH16_16_16_16 16, 4, { 0, 0, 0, 0 }, { 16, 16, 16, 16 }
@@ -3574,6 +3821,10 @@ static const VideoFormat formats[] = {
PSTR2222, PLANE0123, OFFS0, SUB4444, PACK_A444_10LE),
MAKE_YUV_FORMAT (NV61, "raw video", GST_MAKE_FOURCC ('N', 'V', '6', '1'),
DPTH888, PSTR122, PLANE011, OFFS010, SUB422, PACK_NV61),
+ MAKE_YUV_FORMAT (P010_10BE, "raw video", 0x00000000, DPTH10_10_10_HI,
+ PSTR244, PLANE011, OFFS001, SUB420, PACK_P010_10BE),
+ MAKE_YUV_LE_FORMAT (P010_10LE, "raw video", 0x00000000, DPTH10_10_10_HI,
+ PSTR244, PLANE011, OFFS001, SUB420, PACK_P010_10LE),
};
static GstVideoFormat
diff --git a/gst-libs/gst/video/video-format.h b/gst-libs/gst/video/video-format.h
index 86fe297bd..8fdab4069 100644
--- a/gst-libs/gst/video/video-format.h
+++ b/gst-libs/gst/video/video-format.h
@@ -93,6 +93,8 @@ G_BEGIN_DECLS
* @GST_VIDEO_FORMAT_A422_10LE: planar 4:4:2:2 YUV, 10 bits per channel
* @GST_VIDEO_FORMAT_A444_10BE: planar 4:4:4:4 YUV, 10 bits per channel
* @GST_VIDEO_FORMAT_A444_10LE: planar 4:4:4:4 YUV, 10 bits per channel
+ * @GST_VIDEO_FORMAT_P010_10BE: planar 4:2:0 YUV with interleaved UV plane, 10 bits per channel
+ * @GST_VIDEO_FORMAT_P010_10LE: planar 4:2:0 YUV with interleaved UV plane, 10 bits per channel
*
* Enum value describing the most common video formats.
*/
@@ -158,6 +160,8 @@ typedef enum {
GST_VIDEO_FORMAT_A444_10BE,
GST_VIDEO_FORMAT_A444_10LE,
GST_VIDEO_FORMAT_NV61,
+ GST_VIDEO_FORMAT_P010_10BE,
+ GST_VIDEO_FORMAT_P010_10LE,
} GstVideoFormat;
#define GST_VIDEO_MAX_PLANES 4
@@ -496,7 +500,7 @@ gconstpointer gst_video_format_get_palette (GstVideoFormat format, gsi
"GRAY16_LE, v308, RGB16, BGR16, RGB15, BGR15, UYVP, A420, RGB8P, YUV9, YVU9, " \
"IYU1, ARGB64, AYUV64, r210, I420_10LE, I420_10BE, I422_10LE, I422_10BE, " \
" Y444_10LE, Y444_10BE, GBR, GBR_10LE, GBR_10BE, NV12_64Z32, A420_10LE, "\
- " A420_10BE, A422_10LE, A422_10BE, A444_10LE, A444_10BE }"
+ " A420_10BE, A422_10LE, A422_10BE, A444_10LE, A444_10BE, P010_10LE, P010_10BE }"
/**
* GST_VIDEO_CAPS_MAKE:
diff --git a/gst-libs/gst/video/video-info.c b/gst-libs/gst/video/video-info.c
index cb9c777c6..91e50f2af 100644
--- a/gst-libs/gst/video/video-info.c
+++ b/gst-libs/gst/video/video-info.c
@@ -878,6 +878,15 @@ fill_planes (GstVideoInfo * info)
info->offset[3] = info->offset[1] * 3;
info->size = info->stride[0] * height * 4;
break;
+ case GST_VIDEO_FORMAT_P010_10LE:
+ case GST_VIDEO_FORMAT_P010_10BE:
+ info->stride[0] = GST_ROUND_UP_4 (width * 2);
+ info->stride[1] = info->stride[0];
+ info->offset[0] = 0;
+ info->offset[1] = info->stride[0] * GST_ROUND_UP_2 (height);
+ cr_h = GST_ROUND_UP_2 (height) / 2;
+ info->size = info->offset[1] + info->stride[0] * cr_h;
+ break;
case GST_VIDEO_FORMAT_ENCODED:
break;