From c52adc8fcccf691754ab762e667fffb5465c3354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Zanelli?= Date: Thu, 19 Mar 2015 10:50:22 +0100 Subject: [PATCH] video: add NV61 format support https://bugzilla.gnome.org/show_bug.cgi?id=746466 --- docs/design/part-mediatype-video-raw.txt | 1 + gst-libs/gst/video/video-converter.c | 4 ++ gst-libs/gst/video/video-format.c | 86 ++++++++++++++++++++++++ gst-libs/gst/video/video-format.h | 6 +- gst-libs/gst/video/video-info.c | 1 + gst-libs/gst/video/video-scaler.c | 1 + 6 files changed, 97 insertions(+), 2 deletions(-) diff --git a/docs/design/part-mediatype-video-raw.txt b/docs/design/part-mediatype-video-raw.txt index ad8f2564c6..541b36617a 100644 --- a/docs/design/part-mediatype-video-raw.txt +++ b/docs/design/part-mediatype-video-raw.txt @@ -1197,6 +1197,7 @@ Formats "GBR_10LE" planar 4:4:4 RGB, 10 bits per channel "NV16" planar 4:2:2 YUV with interleaved UV plane + "NV61" planar 4:2:2 YUV with interleaved VU plane "NV24" planar 4:4:4 YUV with interleaved UV plane diff --git a/gst-libs/gst/video/video-converter.c b/gst-libs/gst/video/video-converter.c index 50afefe9a4..44b7bcd471 100644 --- a/gst-libs/gst/video/video-converter.c +++ b/gst-libs/gst/video/video-converter.c @@ -3934,6 +3934,7 @@ get_scale_format (GstVideoFormat format, gint plane) case GST_VIDEO_FORMAT_NV12: case GST_VIDEO_FORMAT_NV21: case GST_VIDEO_FORMAT_NV16: + case GST_VIDEO_FORMAT_NV61: case GST_VIDEO_FORMAT_NV24: res = plane == 0 ? GST_VIDEO_FORMAT_GRAY8 : GST_VIDEO_FORMAT_NV12; break; @@ -4531,6 +4532,9 @@ static const VideoTransform transforms[] = { {GST_VIDEO_FORMAT_NV16, GST_VIDEO_FORMAT_NV24, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, + {GST_VIDEO_FORMAT_NV61, GST_VIDEO_FORMAT_NV61, TRUE, FALSE, FALSE, TRUE, + TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, + {GST_VIDEO_FORMAT_NV24, GST_VIDEO_FORMAT_NV12, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, {GST_VIDEO_FORMAT_NV24, GST_VIDEO_FORMAT_NV16, TRUE, FALSE, FALSE, TRUE, diff --git a/gst-libs/gst/video/video-format.c b/gst-libs/gst/video/video-format.c index 47c2ea852b..97a745ba85 100644 --- a/gst-libs/gst/video/video-format.c +++ b/gst-libs/gst/video/video-format.c @@ -1517,6 +1517,88 @@ pack_NV16 (const GstVideoFormatInfo * info, GstVideoPackFlags flags, } } +#define PACK_NV61 GST_VIDEO_FORMAT_AYUV, unpack_NV61, 1, pack_NV61 +static void +unpack_NV61 (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) +{ + const guint8 *restrict sy = GET_PLANE_LINE (0, y); + const guint8 *restrict svu = GET_PLANE_LINE (1, y); + guint8 *restrict d = dest; + + sy += x; + svu += (x & ~1); + + if (x & 1) { + d[0] = 0xff; + d[1] = *sy++; + d[2] = svu[1]; + d[3] = svu[0]; + width--; + d += 4; + svu += 2; + } + + if (IS_ALIGNED (d, 8)) { + video_orc_unpack_NV21 (d, sy, svu, width / 2); + } else { + gint i; + + for (i = 0; i < width / 2; i++) { + d[i * 8 + 0] = 0xff; + d[i * 8 + 1] = sy[i * 2 + 0]; + d[i * 8 + 2] = svu[i * 2 + 1]; + d[i * 8 + 3] = svu[i * 2 + 0]; + d[i * 8 + 4] = 0xff; + d[i * 8 + 5] = sy[i * 2 + 1]; + d[i * 8 + 6] = svu[i * 2 + 1]; + d[i * 8 + 7] = svu[i * 2 + 0]; + } + } + + if (width & 1) { + gint i = width - 1; + + d[i * 4 + 0] = 0xff; + d[i * 4 + 1] = sy[i]; + d[i * 4 + 2] = svu[i + 1]; + d[i * 4 + 3] = svu[i + 0]; + } +} + +static void +pack_NV61 (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) +{ + const guint8 *restrict s = src; + guint8 *restrict dy = GET_PLANE_LINE (0, y); + guint8 *restrict dvu = GET_PLANE_LINE (1, y); + + if (IS_ALIGNED (s, 8)) { + video_orc_pack_NV21 (dy, dvu, s, width / 2); + } else { + gint i; + + for (i = 0; i < width / 2; i++) { + dy[i * 2 + 0] = s[i * 8 + 1]; + dy[i * 2 + 1] = s[i * 8 + 5]; + dvu[i * 2 + 0] = s[i * 8 + 3]; + dvu[i * 2 + 1] = s[i * 8 + 2]; + } + } + + if (width & 1) { + gint i = width - 1; + + dy[i] = s[i * 4 + 1]; + dvu[i + 0] = s[i * 4 + 2]; + dvu[i + 1] = s[i * 4 + 3]; + } +} + #define PACK_NV24 GST_VIDEO_FORMAT_AYUV, unpack_NV24, 1, pack_NV24 static void unpack_NV24 (const GstVideoFormatInfo * info, GstVideoPackFlags flags, @@ -3488,6 +3570,8 @@ static const VideoFormat formats[] = { PSTR2222, PLANE0123, OFFS0, SUB4444, PACK_A444_10BE), MAKE_YUV_LE_FORMAT (A444_10LE, "raw video", 0x00000000, DPTH10_10_10_10, 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), }; static GstVideoFormat @@ -3692,6 +3776,8 @@ gst_video_format_from_fourcc (guint32 fourcc) return GST_VIDEO_FORMAT_NV21; case GST_MAKE_FOURCC ('N', 'V', '1', '6'): return GST_VIDEO_FORMAT_NV16; + case GST_MAKE_FOURCC ('N', 'V', '6', '1'): + return GST_VIDEO_FORMAT_NV61; case GST_MAKE_FOURCC ('N', 'V', '2', '4'): return GST_VIDEO_FORMAT_NV24; case GST_MAKE_FOURCC ('v', '3', '0', '8'): diff --git a/gst-libs/gst/video/video-format.h b/gst-libs/gst/video/video-format.h index e60f9ca340..343663f2eb 100644 --- a/gst-libs/gst/video/video-format.h +++ b/gst-libs/gst/video/video-format.h @@ -84,6 +84,7 @@ G_BEGIN_DECLS * @GST_VIDEO_FORMAT_GBR_10BE: planar 4:4:4 RGB, 10 bits per channel * @GST_VIDEO_FORMAT_GBR_10LE: planar 4:4:4 RGB, 10 bits per channel * @GST_VIDEO_FORMAT_NV16: planar 4:2:2 YUV with interleaved UV plane + * @GST_VIDEO_FORMAT_NV61: planar 4:2:2 YUV with interleaved VU plane (Since 1.6) * @GST_VIDEO_FORMAT_NV24: planar 4:4:4 YUV with interleaved UV plane * @GST_VIDEO_FORMAT_NV12_64Z32: NV12 with 64x32 tiling in zigzag pattern * @GST_VIDEO_FORMAT_A420_10BE: planar 4:4:2:0 YUV, 10 bits per channel @@ -156,6 +157,7 @@ typedef enum { GST_VIDEO_FORMAT_A422_10LE, GST_VIDEO_FORMAT_A444_10BE, GST_VIDEO_FORMAT_A444_10LE, + GST_VIDEO_FORMAT_NV61, } GstVideoFormat; #define GST_VIDEO_MAX_PLANES 4 @@ -476,8 +478,8 @@ gconstpointer gst_video_format_get_palette (GstVideoFormat format, gsi #define GST_VIDEO_FORMATS_ALL "{ I420, YV12, YUY2, UYVY, AYUV, RGBx, " \ "BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR, Y41B, Y42B, " \ - "YVYU, Y444, v210, v216, NV12, NV21, NV16, NV24, GRAY8, GRAY16_BE, GRAY16_LE, " \ - "v308, RGB16, BGR16, RGB15, BGR15, UYVP, A420, RGB8P, YUV9, YVU9, " \ + "YVYU, Y444, v210, v216, NV12, NV21, NV16, NV61, NV24, GRAY8, GRAY16_BE, " \ + "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 }" diff --git a/gst-libs/gst/video/video-info.c b/gst-libs/gst/video/video-info.c index 03e1476790..5b9b380cb4 100644 --- a/gst-libs/gst/video/video-info.c +++ b/gst-libs/gst/video/video-info.c @@ -589,6 +589,7 @@ fill_planes (GstVideoInfo * info) info->size = info->offset[1] + info->stride[0] * cr_h; break; case GST_VIDEO_FORMAT_NV16: + case GST_VIDEO_FORMAT_NV61: info->stride[0] = GST_ROUND_UP_4 (width); info->stride[1] = info->stride[0]; info->offset[0] = 0; diff --git a/gst-libs/gst/video/video-scaler.c b/gst-libs/gst/video/video-scaler.c index abef4af32f..17d03348ae 100644 --- a/gst-libs/gst/video/video-scaler.c +++ b/gst-libs/gst/video/video-scaler.c @@ -1195,6 +1195,7 @@ get_functions (GstVideoScaler * hscale, GstVideoScaler * vscale, case GST_VIDEO_FORMAT_NV16: case GST_VIDEO_FORMAT_NV21: case GST_VIDEO_FORMAT_NV24: + case GST_VIDEO_FORMAT_NV61: bits = 8; *n_elems = 2; break;