Commit c28721d8 authored by Seungha Yang's avatar Seungha Yang 🐑 Committed by Sebastian Dröge

video: Add P016 LE/BE formats

Add semi-planar 4:2:0 16 bits format.
parent 79c33043
......@@ -5903,6 +5903,8 @@ get_scale_format (GstVideoFormat format, gint plane)
case GST_VIDEO_FORMAT_RGB10A2_LE:
case GST_VIDEO_FORMAT_Y444_16BE:
case GST_VIDEO_FORMAT_Y444_16LE:
case GST_VIDEO_FORMAT_P016_BE:
case GST_VIDEO_FORMAT_P016_LE:
res = format;
g_assert_not_reached ();
break;
......
......@@ -5502,6 +5502,214 @@ pack_Y444_16LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
}
}
#define PACK_P016_BE GST_VIDEO_FORMAT_AYUV64, unpack_P016_BE, 1, pack_P016_BE
static void
unpack_P016_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;
gint uv = GET_UV_420 (y, flags);
const guint16 *restrict sy = GET_PLANE_LINE (0, y);
const guint16 *restrict suv = GET_PLANE_LINE (1, uv);
guint16 *restrict d = dest, Y0, Y1, U, V;
sy += x;
suv += (x & ~1);
if (x & 1) {
Y0 = GST_READ_UINT16_BE (sy);
U = GST_READ_UINT16_BE (suv);
V = GST_READ_UINT16_BE (suv + 1);
d[0] = 0xffff;
d[1] = Y0;
d[2] = U;
d[3] = V;
width--;
d += 4;
sy += 1;
suv += 2;
}
for (i = 0; i < width / 2; i++) {
Y0 = GST_READ_UINT16_BE (sy + 2 * i);
Y1 = GST_READ_UINT16_BE (sy + 2 * i + 1);
U = GST_READ_UINT16_BE (suv + 2 * i);
V = GST_READ_UINT16_BE (suv + 2 * i + 1);
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) {
gint i = width - 1;
Y0 = GST_READ_UINT16_BE (sy + i);
U = GST_READ_UINT16_BE (suv + i);
V = GST_READ_UINT16_BE (suv + i + 1);
d[i * 4 + 0] = 0xffff;
d[i * 4 + 1] = Y0;
d[i * 4 + 2] = U;
d[i * 4 + 3] = V;
}
}
static void
pack_P016_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;
gint uv = GET_UV_420 (y, flags);
guint16 *restrict dy = GET_PLANE_LINE (0, y);
guint16 *restrict duv = GET_PLANE_LINE (1, uv);
guint16 Y0, Y1, U, V;
const guint16 *restrict s = src;
if (IS_CHROMA_LINE_420 (y, flags)) {
for (i = 0; i < width / 2; i++) {
Y0 = s[i * 8 + 1];
Y1 = s[i * 8 + 5];
U = s[i * 8 + 2];
V = s[i * 8 + 3];
GST_WRITE_UINT16_BE (dy + i * 2 + 0, Y0);
GST_WRITE_UINT16_BE (dy + i * 2 + 1, Y1);
GST_WRITE_UINT16_BE (duv + i * 2 + 0, U);
GST_WRITE_UINT16_BE (duv + i * 2 + 1, V);
}
if (width & 1) {
gint i = width - 1;
Y0 = s[i * 4 + 1];
U = s[i * 4 + 2];
V = s[i * 4 + 3];
GST_WRITE_UINT16_BE (dy + i, Y0);
GST_WRITE_UINT16_BE (duv + i + 0, U);
GST_WRITE_UINT16_BE (duv + i + 1, V);
}
} else {
for (i = 0; i < width; i++) {
Y0 = s[i * 4 + 1];
GST_WRITE_UINT16_BE (dy + i, Y0);
}
}
}
#define PACK_P016_LE GST_VIDEO_FORMAT_AYUV64, unpack_P016_LE, 1, pack_P016_LE
static void
unpack_P016_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;
gint uv = GET_UV_420 (y, flags);
const guint16 *restrict sy = GET_PLANE_LINE (0, y);
const guint16 *restrict suv = GET_PLANE_LINE (1, uv);
guint16 *restrict d = dest, Y0, Y1, U, V;
sy += x;
suv += (x & ~1);
if (x & 1) {
Y0 = GST_READ_UINT16_LE (sy);
U = GST_READ_UINT16_LE (suv);
V = GST_READ_UINT16_LE (suv + 1);
d[0] = 0xffff;
d[1] = Y0;
d[2] = U;
d[3] = V;
width--;
d += 4;
sy += 1;
suv += 2;
}
for (i = 0; i < width / 2; i++) {
Y0 = GST_READ_UINT16_LE (sy + 2 * i);
Y1 = GST_READ_UINT16_LE (sy + 2 * i + 1);
U = GST_READ_UINT16_LE (suv + 2 * i);
V = GST_READ_UINT16_LE (suv + 2 * i + 1);
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) {
gint i = width - 1;
Y0 = GST_READ_UINT16_LE (sy + i);
U = GST_READ_UINT16_LE (suv + i);
V = GST_READ_UINT16_LE (suv + i + 1);
d[i * 4 + 0] = 0xffff;
d[i * 4 + 1] = Y0;
d[i * 4 + 2] = U;
d[i * 4 + 3] = V;
}
}
static void
pack_P016_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;
gint uv = GET_UV_420 (y, flags);
guint16 *restrict dy = GET_PLANE_LINE (0, y);
guint16 *restrict duv = GET_PLANE_LINE (1, uv);
guint16 Y0, Y1, U, V;
const guint16 *restrict s = src;
if (IS_CHROMA_LINE_420 (y, flags)) {
for (i = 0; i < width / 2; i++) {
Y0 = s[i * 8 + 1];
Y1 = s[i * 8 + 5];
U = s[i * 8 + 2];
V = s[i * 8 + 3];
GST_WRITE_UINT16_LE (dy + i * 2 + 0, Y0);
GST_WRITE_UINT16_LE (dy + i * 2 + 1, Y1);
GST_WRITE_UINT16_LE (duv + i * 2 + 0, U);
GST_WRITE_UINT16_LE (duv + i * 2 + 1, V);
}
if (width & 1) {
gint i = width - 1;
Y0 = s[i * 4 + 1];
U = s[i * 4 + 2];
V = s[i * 4 + 3];
GST_WRITE_UINT16_LE (dy + i, Y0);
GST_WRITE_UINT16_LE (duv + i + 0, U);
GST_WRITE_UINT16_LE (duv + i + 1, V);
}
} else {
for (i = 0; i < width; i++) {
Y0 = s[i * 4 + 1];
GST_WRITE_UINT16_LE (dy + i, Y0);
}
}
}
typedef struct
{
guint32 fourcc;
......@@ -5840,6 +6048,10 @@ static const VideoFormat formats[] = {
PSTR222, PLANE012, OFFS0, SUB444, PACK_Y444_16BE),
MAKE_YUV_LE_FORMAT (Y444_16LE, "raw video", 0x00000000, DPTH16_16_16,
PSTR222, PLANE012, OFFS0, SUB444, PACK_Y444_16LE),
MAKE_YUV_FORMAT (P016_BE, "raw video", 0x00000000, DPTH16_16_16,
PSTR244, PLANE011, OFFS001, SUB420, PACK_P016_BE),
MAKE_YUV_LE_FORMAT (P016_LE, "raw video", 0x00000000, DPTH16_16_16,
PSTR244, PLANE011, OFFS001, SUB420, PACK_P016_LE),
};
static GstVideoFormat
......
......@@ -121,6 +121,8 @@ G_BEGIN_DECLS
* @GST_VIDEO_FORMAT_RGB10A2_LE: packed 4:4:4 RGB with alpha channel(R-G-B-A), 10 bits for R/G/B channel and MSB 2 bits for alpha channel (Since: 1.18)
* @GST_VIDEO_FORMAT_Y444_16BE: planar 4:4:4 YUV, 16 bits per channel (Since: 1.18)
* @GST_VIDEO_FORMAT_Y444_16LE: planar 4:4:4 YUV, 16 bits per channel (Since: 1.18)
* @GST_VIDEO_FORMAT_P016_BE: planar 4:2:0 YUV with interleaved UV plane, 16 bits per channel (Since: 1.18)
* @GST_VIDEO_FORMAT_P016_LE: planar 4:2:0 YUV with interleaved UV plane, 16 bits per channel (Since: 1.18)
*
* Enum value describing the most common video formats.
*
......@@ -217,6 +219,8 @@ typedef enum {
GST_VIDEO_FORMAT_RGB10A2_LE,
GST_VIDEO_FORMAT_Y444_16BE,
GST_VIDEO_FORMAT_Y444_16LE,
GST_VIDEO_FORMAT_P016_BE,
GST_VIDEO_FORMAT_P016_LE,
} GstVideoFormat;
#define GST_VIDEO_MAX_PLANES 4
......@@ -572,7 +576,7 @@ gconstpointer gst_video_format_get_palette (GstVideoFormat format, gsi
"P010_10LE, IYU2, VYUY, GBRA, GBRA_10BE, GBRA_10LE, BGR10A2_LE, RGB10A2_LE, 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, NV12_10LE40, " \
"Y444_16BE, Y444_16LE }"
"Y444_16BE, Y444_16LE, P016_BE, P016_LE }"
/**
* GST_VIDEO_CAPS_MAKE:
......
......@@ -1085,6 +1085,8 @@ fill_planes (GstVideoInfo * info)
break;
case GST_VIDEO_FORMAT_P010_10LE:
case GST_VIDEO_FORMAT_P010_10BE:
case GST_VIDEO_FORMAT_P016_LE:
case GST_VIDEO_FORMAT_P016_BE:
info->stride[0] = GST_ROUND_UP_4 (width * 2);
info->stride[1] = info->stride[0];
info->offset[0] = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment