video: Add GRAY10_LE32 support

This add a 10bit variant of gray scale packed into 32bits little endian
words. The MSB 2 bits are padding and should be ignored. This format is
used on Xilinx SoC and is identified with the FOURCC XV10.

https://bugzilla.gnome.org/show_bug.cgi?id=789876
This commit is contained in:
Nicolas Dufresne 2017-11-03 12:11:58 -04:00
parent 2b9725d0df
commit f7a27d7403
4 changed files with 92 additions and 1 deletions

View file

@ -5880,6 +5880,7 @@ get_scale_format (GstVideoFormat format, gint plane)
case GST_VIDEO_FORMAT_A444_10LE:
case GST_VIDEO_FORMAT_P010_10BE:
case GST_VIDEO_FORMAT_P010_10LE:
case GST_VIDEO_FORMAT_GRAY10_LE32:
case GST_VIDEO_FORMAT_NV12_10LE32:
res = format;
g_assert_not_reached ();

View file

@ -4549,6 +4549,83 @@ pack_P010_10LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
}
}
#define PACK_GRAY10_LE32 GST_VIDEO_FORMAT_AYUV64, unpack_GRAY10_LE32, 1, pack_GRAY10_LE32
static void
unpack_GRAY10_LE32 (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);
guint16 *restrict d = dest;
gint num_words = (width + 2) / 3;
/* Y data is packed into little endian 32bit words, with the 2 MSB being
* padding. There is only 1 pattern.
* -> padding | Y1 | Y2 | Y3
*/
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;
if (G_UNLIKELY (pix + c < x))
continue;
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE))
Yn |= Yn >> 10;
d[doff + 0] = 0xffff;
d[doff + 1] = Yn;
d[doff + 2] = 0x8000;
d[doff + 3] = 0x8000;
doff += 4;
}
}
}
static void
pack_GRAY10_LE32 (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);
const guint16 *restrict s = src;
gint num_words = (width + 2) / 3;
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;
}
GST_WRITE_UINT32_LE (dy + i, Y);
soff += 4;
}
}
#define PACK_NV12_10LE32 GST_VIDEO_FORMAT_AYUV64, unpack_NV12_10LE32, 1, pack_NV12_10LE32
static void
unpack_NV12_10LE32 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
@ -4828,6 +4905,8 @@ typedef struct
{ 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_GRAY, depth, pstride, plane, offs, sub, pack } }
#define MAKE_GRAY_LE_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
{ 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_GRAY | GST_VIDEO_FORMAT_FLAG_LE, depth, pstride, plane, offs, sub, pack } }
#define MAKE_GRAY_C_LE_FORMAT(name, desc, depth, pstride, plane, offs, sub, pack) \
{ 0x00000000, {GST_VIDEO_FORMAT_ ##name, G_STRINGIFY(name), desc, GST_VIDEO_FORMAT_FLAG_GRAY | GST_VIDEO_FORMAT_FLAG_COMPLEX | GST_VIDEO_FORMAT_FLAG_LE, depth, pstride, plane, offs, sub, pack } }
static const VideoFormat formats[] = {
{0x00000000, {GST_VIDEO_FORMAT_UNKNOWN, "UNKNOWN", "unknown video", 0, DPTH0,
@ -5013,6 +5092,8 @@ static const VideoFormat formats[] = {
PSTR222, PLANE012, OFFS0, SUB444, PACK_Y444_12BE),
MAKE_YUV_LE_FORMAT (Y444_12LE, "raw video", 0x00000000, DPTH12_12_12,
PSTR222, PLANE012, OFFS0, SUB444, PACK_Y444_12LE),
MAKE_GRAY_C_LE_FORMAT (GRAY10_LE32, "raw video", DPTH8, PSTR0, PLANE0, OFFS0,
SUB4, PACK_GRAY10_LE32),
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),
@ -5248,6 +5329,8 @@ gst_video_format_from_fourcc (guint32 fourcc)
return GST_VIDEO_FORMAT_IYU1;
case GST_MAKE_FOURCC ('A', 'Y', '6', '4'):
return GST_VIDEO_FORMAT_AYUV64;
case GST_MAKE_FOURCC ('X', 'V', '1', '0'):
return GST_VIDEO_FORMAT_GRAY10_LE32;
case GST_MAKE_FOURCC ('X', 'V', '1', '5'):
return GST_VIDEO_FORMAT_NV12_10LE32;
default:

View file

@ -60,6 +60,7 @@ G_BEGIN_DECLS
* @GST_VIDEO_FORMAT_NV21: planar 4:2:0 YUV with interleaved VU plane
* @GST_VIDEO_FORMAT_NV12_10LE32: 10-bit variant of @GST_VIDEO_FORMAT_NV12, packet in 32bit words (MSB 2 bits padding) (Since: 1.X)
* @GST_VIDEO_FORMAT_GRAY8: 8-bit grayscale
* @GST_VIDEO_FORMAT_GRAY10_LE32: 10-bit grayscale, packet in 32bit words (2 bits padding)
* @GST_VIDEO_FORMAT_GRAY16_BE: 16-bit grayscale, most significant byte first
* @GST_VIDEO_FORMAT_GRAY16_LE: 16-bit grayscale, least significant byte first
* @GST_VIDEO_FORMAT_v308: packed 4:4:4 YUV (Y-U-V ...)
@ -193,6 +194,7 @@ typedef enum {
GST_VIDEO_FORMAT_I422_12LE,
GST_VIDEO_FORMAT_Y444_12BE,
GST_VIDEO_FORMAT_Y444_12LE,
GST_VIDEO_FORMAT_GRAY10_LE32,
GST_VIDEO_FORMAT_NV12_10LE32,
} GstVideoFormat;
@ -545,7 +547,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, NV12_10LE32 }"
"Y444_12BE, Y444_12LE, GRAY10_LE32, NV12_10LE32 }"
/**
* GST_VIDEO_CAPS_MAKE:

View file

@ -1006,6 +1006,11 @@ fill_planes (GstVideoInfo * info)
cr_h = GST_ROUND_UP_2 (height) / 2;
info->size = info->offset[1] + info->stride[0] * cr_h;
break;
case GST_VIDEO_FORMAT_GRAY10_LE32:
info->stride[0] = (width + 2) / 3 * 4;
info->offset[0] = 0;
info->size = info->stride[0] * GST_ROUND_UP_2 (height);
break;
case GST_VIDEO_FORMAT_NV12_10LE32:
info->stride[0] = (width + 2) / 3 * 4;
info->stride[1] = info->stride[0];