diff --git a/gst-libs/gst/video/video-converter.c b/gst-libs/gst/video/video-converter.c index 1b66ed22b0..31e866a796 100644 --- a/gst-libs/gst/video/video-converter.c +++ b/gst-libs/gst/video/video-converter.c @@ -5882,6 +5882,7 @@ get_scale_format (GstVideoFormat format, gint plane) case GST_VIDEO_FORMAT_P010_10LE: case GST_VIDEO_FORMAT_GRAY10_LE32: case GST_VIDEO_FORMAT_NV12_10LE32: + case GST_VIDEO_FORMAT_NV16_10LE32: 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 859453589e..4360ead29c 100644 --- a/gst-libs/gst/video/video-format.c +++ b/gst-libs/gst/video/video-format.c @@ -4781,6 +4781,157 @@ pack_NV12_10LE32 (const GstVideoFormatInfo * info, GstVideoPackFlags flags, } } +#define PACK_NV16_10LE32 GST_VIDEO_FORMAT_AYUV64, unpack_NV16_10LE32, 1, pack_NV16_10LE32 +static void +unpack_NV16_10LE32 (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) +{ + gint i; + const guint32 *restrict sy = GET_PLANE_LINE (0, y); + const guint32 *restrict suv = GET_PLANE_LINE (1, y); + guint16 *restrict d = dest; + gint num_words = (width + 2) / 3; + guint32 UV = 0; + guint16 Un = 0, Vn = 0; + + /* Y data is packed into little endian 32bit words, with the 2 MSB being + * padding. There is only 1 pattern. + * -> padding | Y1 | Y2 | Y3 + * + * UV is packed the same way, though we end up with 2 patterns: + * -> U | V | U | padding + * -> V | U | V | padding + */ + + /* FIXME unroll the 6 states ? */ + + for (i = 0; i < num_words; i++) { + gint num_comps = MIN (3, width - i * 3); + guint pix = i * 3; + gsize doff = pix * 4; + gint c; + guint32 Y; + + Y = GST_READ_UINT32_LE (sy + i); + + for (c = 0; c < num_comps; c++) { + guint16 Yn; + + /* For Y, we simply read 10 bit and shift it out */ + Yn = (Y & 0x03ff) << 6; + Y >>= 10; + + /* Unpacking UV has been reduced to a cycle of 6 states. The following + * code is a reduce version of: + * 0: - Read first UV word (UVU) + * Unpack U and V + * 1: - Resued U/V from 1 (sub-sampling) + * 2: - Unpack remaining U value + * - Read following UV word (VUV) + * - Unpack V value + * 3: - Reuse U/V from 2 (sub-sampling) + * 4: - Unpack remaining U + * - Unpack remaining V + * 5: - Reuse UV/V from 4 (sub-sampling) + */ + switch ((pix + c) % 6) { + case 0: + UV = GST_READ_UINT32_LE (suv + i); + /* fallthrough */ + case 4: + Un = (UV & 0x03ff) << 6; + UV >>= 10; + Vn = (UV & 0x03ff) << 6; + UV >>= 10; + break; + case 2: + Un = (UV & 0x03ff) << 6; + UV = GST_READ_UINT32_LE (suv + i + 1); + Vn = (UV & 0x03ff) << 6; + UV >>= 10; + break; + default: + /* keep value */ + break; + } + + if (G_UNLIKELY (pix + c < x)) + continue; + + if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) { + Yn |= Yn >> 10; + Un |= Un >> 10; + Vn |= Vn >> 10; + } + + d[doff + 0] = 0xffff; + d[doff + 1] = Yn; + d[doff + 2] = Un; + d[doff + 3] = Vn; + + doff += 4; + } + } +} + +static void +pack_NV16_10LE32 (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) +{ + gint i; + guint32 *restrict dy = GET_PLANE_LINE (0, y); + guint32 *restrict duv = GET_PLANE_LINE (1, y); + const guint16 *restrict s = src; + gint num_words = (width + 2) / 3; + guint32 UV = 0; + + /* FIXME unroll the 6 states ? */ + + for (i = 0; i < num_words; i++) { + gint num_comps = MIN (3, width - i * 3); + guint pix = i * 3; + gsize soff = pix * 4; + gint c; + guint32 Y = 0; + + for (c = 0; c < num_comps; c++) { + Y <<= 10; + Y |= s[soff + 1] >> 6; + + switch ((pix + c) % 6) { + case 0: + UV = s[soff + 2] >> 6; + UV |= s[soff + 3] >> 6 << 10; + break; + case 2: + UV |= s[soff + 2] >> 6 << 20; + GST_WRITE_UINT32_LE (duv + i, UV); + UV = s[soff + 3] >> 6; + break; + case 4: + UV |= s[soff + 2] >> 6 << 10; + UV |= s[soff + 3] >> 6 << 20; + GST_WRITE_UINT32_LE (duv + i, UV); + break; + default: + /* keep value */ + break; + } + } + + GST_WRITE_UINT32_LE (dy + i, Y); + + if (num_comps < 3) + GST_WRITE_UINT32_LE (duv + i, UV); + + soff += 4; + } +} + + typedef struct { guint32 fourcc; @@ -5097,6 +5248,9 @@ static const VideoFormat formats[] = { MAKE_YUV_C_LE_FORMAT (NV12_10LE32, "raw video", GST_MAKE_FOURCC ('X', 'V', '1', '5'), DPTH10_10_10, PSTR0, PLANE011, OFFS001, SUB420, PACK_NV12_10LE32), + MAKE_YUV_C_LE_FORMAT (NV16_10LE32, "raw video", + GST_MAKE_FOURCC ('X', 'V', '2', '0'), DPTH10_10_10, PSTR0, PLANE011, + OFFS001, SUB422, PACK_NV16_10LE32), }; static GstVideoFormat @@ -5333,6 +5487,8 @@ gst_video_format_from_fourcc (guint32 fourcc) return GST_VIDEO_FORMAT_GRAY10_LE32; case GST_MAKE_FOURCC ('X', 'V', '1', '5'): return GST_VIDEO_FORMAT_NV12_10LE32; + case GST_MAKE_FOURCC ('X', 'V', '2', '0'): + return GST_VIDEO_FORMAT_NV16_10LE32; default: return GST_VIDEO_FORMAT_UNKNOWN; } diff --git a/gst-libs/gst/video/video-format.h b/gst-libs/gst/video/video-format.h index 8b117392c6..cf2c101aa1 100644 --- a/gst-libs/gst/video/video-format.h +++ b/gst-libs/gst/video/video-format.h @@ -88,6 +88,7 @@ G_BEGIN_DECLS * @GST_VIDEO_FORMAT_GBR_10BE: planar 4:4:4 RGB, 10 bits per channel (Since: 1.2) * @GST_VIDEO_FORMAT_GBR_10LE: planar 4:4:4 RGB, 10 bits per channel (Since: 1.2) * @GST_VIDEO_FORMAT_NV16: planar 4:2:2 YUV with interleaved UV plane (Since: 1.2) + * @GST_VIDEO_FORMAT_NV16_10LE32: 10-bit variant of @GST_VIDEO_FORMAT_NV16, packet in 32bit words (MSB 2 bits padding) (Since: 1.X) * @GST_VIDEO_FORMAT_NV24: planar 4:4:4 YUV with interleaved UV plane (Since: 1.2) * @GST_VIDEO_FORMAT_NV12_64Z32: NV12 with 64x32 tiling in zigzag pattern (Since: 1.4) * @GST_VIDEO_FORMAT_A420_10BE: planar 4:4:2:0 YUV, 10 bits per channel (Since: 1.6) @@ -196,6 +197,7 @@ typedef enum { GST_VIDEO_FORMAT_Y444_12LE, GST_VIDEO_FORMAT_GRAY10_LE32, GST_VIDEO_FORMAT_NV12_10LE32, + GST_VIDEO_FORMAT_NV16_10LE32, } GstVideoFormat; #define GST_VIDEO_MAX_PLANES 4 @@ -547,7 +549,7 @@ gconstpointer gst_video_format_get_palette (GstVideoFormat format, gsi "A420_10LE, A422_10BE, A422_10LE, A444_10BE, A444_10LE, NV61, P010_10BE, " \ "P010_10LE, IYU2, VYUY, GBRA, GBRA_10BE, GBRA_10LE, GBR_12BE, GBR_12LE, " \ "GBRA_12BE, GBRA_12LE, I420_12BE, I420_12LE, I422_12BE, I422_12LE, " \ - "Y444_12BE, Y444_12LE, GRAY10_LE32, NV12_10LE32 }" + "Y444_12BE, Y444_12LE, GRAY10_LE32, NV12_10LE32, NV16_10LE32 }" /** * GST_VIDEO_CAPS_MAKE: diff --git a/gst-libs/gst/video/video-info.c b/gst-libs/gst/video/video-info.c index 0ee47e6980..fb70ad3a23 100644 --- a/gst-libs/gst/video/video-info.c +++ b/gst-libs/gst/video/video-info.c @@ -1021,6 +1021,13 @@ fill_planes (GstVideoInfo * info) cr_h = GST_ROUND_UP_2 (cr_h); info->size = info->offset[1] + info->stride[0] * cr_h; break; + case GST_VIDEO_FORMAT_NV16_10LE32: + info->stride[0] = (width + 2) / 3 * 4; + info->stride[1] = info->stride[0]; + info->offset[0] = 0; + info->offset[1] = info->stride[0] * height; + info->size = info->stride[0] * height * 2; + break; case GST_VIDEO_FORMAT_ENCODED: break;