video: Add NV12_10LE40 pixel format

This pixel format is a fully packed variant of NV12, a luma
pixel would take 10bits in memory, without any filled bits
between pixels in a stride. The color range follows
the BT.2020 standard.

In order to get a performance in hardware memory
operation, it may expend the stride, append zero data at the
end of echo lines.

Signed-off-by: ayaka <ayaka@soulik.info>

https://bugzilla.gnome.org/show_bug.cgi?id=795462
This commit is contained in:
ayaka 2017-03-26 04:54:42 +08:00 committed by Nicolas Dufresne
parent 710990d5cf
commit 35d0783fca
4 changed files with 132 additions and 2 deletions

View file

@ -5883,6 +5883,7 @@ get_scale_format (GstVideoFormat format, gint plane)
case GST_VIDEO_FORMAT_GRAY10_LE32:
case GST_VIDEO_FORMAT_NV12_10LE32:
case GST_VIDEO_FORMAT_NV16_10LE32:
case GST_VIDEO_FORMAT_NV12_10LE40:
res = format;
g_assert_not_reached ();
break;

View file

@ -4927,6 +4927,119 @@ pack_NV16_10LE32 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
}
}
#define PACK_NV12_10LE40 GST_VIDEO_FORMAT_AYUV64, unpack_NV12_10LE40, 1, pack_NV12_10LE40
static void
unpack_NV12_10LE40 (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);
guint16 *restrict d = dest;
const guint8 *restrict sy = GET_PLANE_LINE (0, y);
const guint8 *restrict suv = GET_PLANE_LINE (1, uv);
guint16 Y0, Y1, Yn, Un, Vn;
guint32 UV;
for (i = 0; i < width; i++) {
switch (i & 3) {
case 0:
Y0 = GST_READ_UINT16_LE (sy);
Yn = Y0 & 0x3ff;
sy += 2;
UV = GST_READ_UINT32_LE (suv);
Un = UV & 0x3ff;
Vn = (UV >> 10) & 0x3ff;
suv += 4;
break;
case 1:
Y1 = GST_READ_UINT16_LE (sy);
Yn = (Y0 >> 10) | ((Y1 & 0xf) << 6);
sy += 2;
break;
case 2:
Y0 = GST_READ_UINT8 (sy);
Yn = (Y1 >> 4) & 0x3ff;
sy++;
Un = (UV >> 20) & 0x3ff;
Vn = (UV >> 30);
UV = GST_READ_UINT8 (suv);
Vn |= (UV << 2);
suv++;
break;
case 3:
Yn = (Y1 >> 14) | (Y0 << 2);
break;
}
Yn <<= 6;
Un <<= 6;
Vn <<= 6;
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
Yn |= Yn >> 10;
Un |= Un >> 10;
Vn |= Vn >> 10;
}
d[i * 4 + 0] = 0xffff;
d[i * 4 + 1] = Yn;
d[i * 4 + 2] = Un;
d[i * 4 + 3] = Vn;
}
}
static void
pack_NV12_10LE40 (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);
guint8 *restrict dy = GET_PLANE_LINE (0, y);
guint8 *restrict duv = GET_PLANE_LINE (1, uv);
guint16 Y0, Y1, Y2, Y3, U0, V0, U1, V1;
const guint16 *restrict s = src;
if (IS_CHROMA_LINE_420 (y, flags)) {
for (i = 0; i < width / 4; i++) {
Y0 = s[i * 16 + 1] >> 6;
Y1 = s[i * 16 + 5] >> 6;
Y2 = s[i * 16 + 9] >> 6;
Y3 = s[i * 16 + 13] >> 6;
U0 = s[i * 16 + 2] >> 6;
V0 = s[i * 16 + 3] >> 6;
U1 = s[i * 16 + 6] >> 6;
V1 = s[i * 16 + 7] >> 6;
GST_WRITE_UINT8 (dy + i * 5 + 0, Y0 & 0xff);
GST_WRITE_UINT8 (dy + i * 5 + 1, (Y0 >> 8) | ((Y1 & 0x3f) << 2));
GST_WRITE_UINT8 (dy + i * 5 + 2, (Y1 >> 6) | ((Y2 & 0xf) << 4));
GST_WRITE_UINT8 (dy + i * 5 + 3, (Y2 >> 4) | ((Y3 & 0x3) << 6));
GST_WRITE_UINT8 (dy + i * 5 + 4, Y3 >> 2);
GST_WRITE_UINT8 (duv + i * 5 + 0, U0 & 0xff);
GST_WRITE_UINT8 (duv + i * 5 + 1, (U0 >> 8) | ((V0 & 0x3f) << 2));
GST_WRITE_UINT8 (duv + i * 5 + 2, (V0 >> 6) | ((U1 & 0xf) << 4));
GST_WRITE_UINT8 (duv + i * 5 + 3, (U1 >> 4) | ((V1 & 0x3) << 6));
GST_WRITE_UINT8 (duv + i * 5 + 4, V1 >> 2);
}
} else {
for (i = 0; i < width / 4; i++) {
Y0 = s[i * 16 + 1] >> 6;
Y1 = s[i * 16 + 5] >> 6;
Y2 = s[i * 16 + 9] >> 6;
Y3 = s[i * 16 + 13] >> 6;
GST_WRITE_UINT8 (dy + i * 5 + 0, Y0 & 0xff);
GST_WRITE_UINT8 (dy + i * 5 + 1, (Y0 >> 8) | ((Y1 & 0x3f) << 2));
GST_WRITE_UINT8 (dy + i * 5 + 2, (Y1 >> 6) | ((Y2 & 0xf) << 4));
GST_WRITE_UINT8 (dy + i * 5 + 3, (Y2 >> 4) | ((Y3 & 0x3) << 6));
GST_WRITE_UINT8 (dy + i * 5 + 4, Y3 >> 2);
}
}
}
typedef struct
{
@ -5248,6 +5361,9 @@ static const VideoFormat formats[] = {
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),
MAKE_YUV_C_LE_FORMAT (NV12_10LE40, "raw video",
GST_MAKE_FOURCC ('R', 'K', '2', '0'), DPTH10_10_10, PSTR0, PLANE011,
OFFS0, SUB420, PACK_NV12_10LE40),
};
static GstVideoFormat
@ -5486,6 +5602,8 @@ gst_video_format_from_fourcc (guint32 fourcc)
return GST_VIDEO_FORMAT_NV12_10LE32;
case GST_MAKE_FOURCC ('X', 'V', '2', '0'):
return GST_VIDEO_FORMAT_NV16_10LE32;
case GST_MAKE_FOURCC ('R', 'K', '2', '0'):
return GST_VIDEO_FORMAT_NV12_10LE40;
default:
return GST_VIDEO_FORMAT_UNKNOWN;
}

View file

@ -113,6 +113,7 @@ G_BEGIN_DECLS
* @GST_VIDEO_FORMAT_I422_12LE: planar 4:2:2 YUV, 12 bits per channel (Since: 1.12)
* @GST_VIDEO_FORMAT_Y444_12BE: planar 4:4:4 YUV, 12 bits per channel (Since: 1.12)
* @GST_VIDEO_FORMAT_Y444_12LE: planar 4:4:4 YUV, 12 bits per channel (Since: 1.12)
* @GST_VIDEO_FORMAT_NV12_10LE40: Fully packed variant of NV12_10LE32
*
* Enum value describing the most common video formats.
*/
@ -198,6 +199,7 @@ typedef enum {
GST_VIDEO_FORMAT_GRAY10_LE32,
GST_VIDEO_FORMAT_NV12_10LE32,
GST_VIDEO_FORMAT_NV16_10LE32,
GST_VIDEO_FORMAT_NV12_10LE40,
} GstVideoFormat;
#define GST_VIDEO_MAX_PLANES 4
@ -549,7 +551,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, NV16_10LE32 }"
"Y444_12BE, Y444_12LE, GRAY10_LE32, NV12_10LE32, NV16_10LE32, NV12_10LE40 }"
/**
* GST_VIDEO_CAPS_MAKE:

View file

@ -1028,7 +1028,16 @@ fill_planes (GstVideoInfo * info)
info->offset[1] = info->stride[0] * height;
info->size = info->stride[0] * height * 2;
break;
case GST_VIDEO_FORMAT_NV12_10LE40:
info->stride[0] = ((width * 5 >> 2) + 4) & (~4);
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;
if (GST_VIDEO_INFO_IS_INTERLACED (info))
cr_h = GST_ROUND_UP_2 (cr_h);
info->size = info->offset[1] + info->stride[0] * cr_h;
break;
case GST_VIDEO_FORMAT_ENCODED:
break;
case GST_VIDEO_FORMAT_UNKNOWN: