video: add support for Y212 format

Y212 is a packed 12 bits 4:2:2 format in the order Y, U, Y, V, 2 bytes
per component with the color value stored in the 12 most significant
bits

Refer to https://github.com/torvalds/linux/blob/master/include/uapi/drm/drm_fourcc.h#L174
for the LE variant
This commit is contained in:
Haihao Xiang 2020-03-11 10:58:00 +08:00 committed by GStreamer Merge Bot
parent 0e74e190ad
commit ea063721d2
4 changed files with 219 additions and 1 deletions

View file

@ -5930,6 +5930,8 @@ get_scale_format (GstVideoFormat format, gint plane)
case GST_VIDEO_FORMAT_P016_LE:
case GST_VIDEO_FORMAT_P012_BE:
case GST_VIDEO_FORMAT_P012_LE:
case GST_VIDEO_FORMAT_Y212_BE:
case GST_VIDEO_FORMAT_Y212_LE:
res = format;
g_assert_not_reached ();
break;

View file

@ -5956,6 +5956,212 @@ pack_P012_LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
}
}
#define PACK_Y212_BE GST_VIDEO_FORMAT_AYUV64, unpack_Y212_BE, 1, pack_Y212_BE
static void
unpack_Y212_BE (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;
const guint8 *restrict s = GET_LINE (y);
guint16 *restrict d = dest;
guint Y0, Y1, U, V;
s += GST_ROUND_DOWN_2 (x) * 4;
if (x & 1) {
Y1 = GST_READ_UINT16_BE (s + 4);
U = GST_READ_UINT16_BE (s + 2);
V = GST_READ_UINT16_BE (s + 6);
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
Y1 |= (Y1 >> 12);
U |= (U >> 12);
V |= (V >> 12);
}
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_BE (s + i * 8 + 0);
U = GST_READ_UINT16_BE (s + i * 8 + 2);
V = GST_READ_UINT16_BE (s + i * 8 + 6);
Y1 = GST_READ_UINT16_BE (s + i * 8 + 4);
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
Y0 |= (Y0 >> 12);
U |= (U >> 12);
V |= (V >> 12);
}
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) {
i = width - 1;
Y0 = GST_READ_UINT16_BE (s + i * 4 + 0);
U = GST_READ_UINT16_BE (s + i * 4 + 2);
V = GST_READ_UINT16_BE (s + i * 4 + 6);
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
Y0 |= (Y0 >> 12);
U |= (U >> 12);
V |= (V >> 12);
}
d[i * 4 + 0] = 0xffff;
d[i * 4 + 1] = Y0;
d[i * 4 + 2] = U;
d[i * 4 + 3] = V;
}
}
static void
pack_Y212_BE (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;
guint16 Y0, Y1, U, V;
guint8 *restrict d = GET_LINE (y);
const guint16 *restrict s = src;
for (i = 0; i < width; i += 2) {
Y0 = s[i * 4 + 1] & 0xfff0;
U = s[i * 4 + 2] & 0xfff0;
V = s[i * 4 + 3] & 0xfff0;
if (i == width - 1)
Y1 = s[i * 4 + 1] & 0xfff0;
else
Y1 = s[(i + 1) * 4 + 1] & 0xfff0;
GST_WRITE_UINT16_BE (d + i * 4 + 0, Y0);
GST_WRITE_UINT16_BE (d + i * 4 + 2, U);
GST_WRITE_UINT16_BE (d + i * 4 + 4, Y1);
GST_WRITE_UINT16_BE (d + i * 4 + 6, V);
}
}
#define PACK_Y212_LE GST_VIDEO_FORMAT_AYUV64, unpack_Y212_LE, 1, pack_Y212_LE
static void
unpack_Y212_LE (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;
const guint8 *restrict s = GET_LINE (y);
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 >> 12);
U |= (U >> 12);
V |= (V >> 12);
}
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);
V = GST_READ_UINT16_LE (s + i * 8 + 6);
Y1 = GST_READ_UINT16_LE (s + i * 8 + 4);
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
Y0 |= (Y0 >> 12);
U |= (U >> 12);
V |= (V >> 12);
}
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) {
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 >> 12);
U |= (U >> 12);
V |= (V >> 12);
}
d[i * 4 + 0] = 0xffff;
d[i * 4 + 1] = Y0;
d[i * 4 + 2] = U;
d[i * 4 + 3] = V;
}
}
static void
pack_Y212_LE (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;
guint16 Y0, Y1, U, V;
guint8 *restrict d = GET_LINE (y);
const guint16 *restrict s = src;
for (i = 0; i < width; i += 2) {
Y0 = s[i * 4 + 1] & 0xfff0;
U = s[i * 4 + 2] & 0xfff0;
V = s[i * 4 + 3] & 0xfff0;
if (i == width - 1)
Y1 = s[i * 4 + 1] & 0xfff0;
else
Y1 = s[(i + 1) * 4 + 1] & 0xfff0;
GST_WRITE_UINT16_LE (d + i * 4 + 0, Y0);
GST_WRITE_UINT16_LE (d + i * 4 + 2, U);
GST_WRITE_UINT16_LE (d + i * 4 + 4, Y1);
GST_WRITE_UINT16_LE (d + i * 4 + 6, V);
}
}
typedef struct
{
guint32 fourcc;
@ -6303,6 +6509,10 @@ static const VideoFormat formats[] = {
PSTR244, PLANE011, OFFS001, SUB420, PACK_P012_BE),
MAKE_YUV_LE_FORMAT (P012_LE, "raw video", 0x00000000, DPTH12_12_12_HI,
PSTR244, PLANE011, OFFS001, SUB420, PACK_P012_LE),
MAKE_YUV_FORMAT (Y212_BE, "raw video", 0x00000000, DPTH12_12_12_HI,
PSTR488, PLANE0, OFFS0, SUB422, PACK_Y212_BE),
MAKE_YUV_LE_FORMAT (Y212_LE, "raw video", 0x00000000, DPTH12_12_12_HI,
PSTR488, PLANE0, OFFS0, SUB422, PACK_Y212_LE),
};
static GstVideoFormat

View file

@ -125,6 +125,8 @@ G_BEGIN_DECLS
* @GST_VIDEO_FORMAT_P016_LE: planar 4:2:0 YUV with interleaved UV plane, 16 bits per channel (Since: 1.18)
* @GST_VIDEO_FORMAT_P012_BE: planar 4:2:0 YUV with interleaved UV plane, 12 bits per channel (Since: 1.18)
* @GST_VIDEO_FORMAT_P012_LE: planar 4:2:0 YUV with interleaved UV plane, 12 bits per channel (Since: 1.18)
* @GST_VIDEO_FORMAT_Y212_BE: packed 4:2:2 YUV, 12 bits per channel (Y-U-Y-V) (Since: 1.18)
* @GST_VIDEO_FORMAT_Y212_LE: packed 4:2:2 YUV, 12 bits per channel (Y-U-Y-V) (Since: 1.18)
*
* Enum value describing the most common video formats.
*
@ -225,6 +227,8 @@ typedef enum {
GST_VIDEO_FORMAT_P016_LE,
GST_VIDEO_FORMAT_P012_BE,
GST_VIDEO_FORMAT_P012_LE,
GST_VIDEO_FORMAT_Y212_BE,
GST_VIDEO_FORMAT_Y212_LE,
} GstVideoFormat;
#define GST_VIDEO_MAX_PLANES 4
@ -578,7 +582,7 @@ gconstpointer gst_video_format_get_palette (GstVideoFormat format, gsi
"Y444_10LE, GBR, GBR_10BE, GBR_10LE, NV16, NV24, NV12_64Z32, A420_10BE, " \
"A420_10LE, A422_10BE, A422_10LE, A444_10BE, A444_10LE, NV61, P010_10BE, " \
"P010_10LE, IYU2, VYUY, GBRA, GBRA_10BE, GBRA_10LE, BGR10A2_LE, RGB10A2_LE, GBR_12BE, GBR_12LE, " \
"GBRA_12BE, GBRA_12LE, P012_BE, P012_LE, I420_12BE, I420_12LE, I422_12BE, I422_12LE, " \
"GBRA_12BE, GBRA_12LE, P012_BE, P012_LE, I420_12BE, I420_12LE, Y212_BE, Y212_LE, I422_12BE, I422_12LE, " \
"Y444_12BE, Y444_12LE, GRAY10_LE32, NV12_10LE32, NV16_10LE32, NV12_10LE40, " \
"Y444_16BE, Y444_16LE, P016_BE, P016_LE }"

View file

@ -825,6 +825,8 @@ fill_planes (GstVideoInfo * info, gsize plane_size[GST_VIDEO_MAX_PLANES])
break;
case GST_VIDEO_FORMAT_v216:
case GST_VIDEO_FORMAT_Y210:
case GST_VIDEO_FORMAT_Y212_BE:
case GST_VIDEO_FORMAT_Y212_LE:
info->stride[0] = GST_ROUND_UP_8 (width * 4);
info->offset[0] = 0;
info->size = info->stride[0] * height;