mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
video: add support for P012 format
P012 is a semi-planar 4:2:0 format, 2bytes per component with the value stored in the 12 most significant bits
This commit is contained in:
parent
1c08a6088d
commit
e4e3fc5666
4 changed files with 260 additions and 1 deletions
|
@ -5928,6 +5928,8 @@ get_scale_format (GstVideoFormat format, gint plane)
|
|||
case GST_VIDEO_FORMAT_Y444_16LE:
|
||||
case GST_VIDEO_FORMAT_P016_BE:
|
||||
case GST_VIDEO_FORMAT_P016_LE:
|
||||
case GST_VIDEO_FORMAT_P012_BE:
|
||||
case GST_VIDEO_FORMAT_P012_LE:
|
||||
res = format;
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
|
|
|
@ -5710,6 +5710,252 @@ pack_P016_LE (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
|
|||
}
|
||||
}
|
||||
|
||||
#define PACK_P012_BE GST_VIDEO_FORMAT_AYUV64, unpack_P012_BE, 1, pack_P012_BE
|
||||
static void
|
||||
unpack_P012_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);
|
||||
|
||||
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
|
||||
Y0 |= (Y0 >> 12);
|
||||
U |= (U >> 12);
|
||||
V |= (V >> 12);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
|
||||
Y0 |= (Y0 >> 12);
|
||||
Y1 |= (Y1 >> 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) {
|
||||
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);
|
||||
|
||||
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_P012_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] & 0xfff0;
|
||||
Y1 = s[i * 8 + 5] & 0xfff0;
|
||||
U = s[i * 8 + 2] & 0xfff0;
|
||||
V = s[i * 8 + 3] & 0xfff0;
|
||||
|
||||
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] & 0xfff0;
|
||||
U = s[i * 4 + 2] & 0xfff0;
|
||||
V = s[i * 4 + 3] & 0xfff0;
|
||||
|
||||
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] & 0xfff0;
|
||||
GST_WRITE_UINT16_BE (dy + i, Y0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define PACK_P012_LE GST_VIDEO_FORMAT_AYUV64, unpack_P012_LE, 1, pack_P012_LE
|
||||
static void
|
||||
unpack_P012_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);
|
||||
|
||||
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
|
||||
Y0 |= (Y0 >> 12);
|
||||
U |= (U >> 12);
|
||||
V |= (V >> 12);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!(flags & GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE)) {
|
||||
Y0 |= (Y0 >> 12);
|
||||
Y1 |= (Y1 >> 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) {
|
||||
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);
|
||||
|
||||
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_P012_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] & 0xfff0;
|
||||
Y1 = s[i * 8 + 5] & 0xfff0;
|
||||
U = s[i * 8 + 2] & 0xfff0;
|
||||
V = s[i * 8 + 3] & 0xfff0;
|
||||
|
||||
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] & 0xfff0;
|
||||
U = s[i * 4 + 2] & 0xfff0;
|
||||
V = s[i * 4 + 3] & 0xfff0;
|
||||
|
||||
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] & 0xfff0;
|
||||
GST_WRITE_UINT16_LE (dy + i, Y0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
guint32 fourcc;
|
||||
|
@ -5729,6 +5975,7 @@ typedef struct
|
|||
#define DPTH10_10_10_HI 16, 3, { 6, 6, 6, 0 }, { 10, 10, 10, 0 }
|
||||
#define DPTH10_10_10_2 10, 4, { 0, 0, 0, 0 }, { 10, 10, 10, 2}
|
||||
#define DPTH12_12_12 12, 3, { 0, 0, 0, 0 }, { 12, 12, 12, 0 }
|
||||
#define DPTH12_12_12_HI 16, 3, { 4, 4, 4, 0 }, { 12, 12, 12, 0 }
|
||||
#define DPTH12_12_12_12 12, 4, { 0, 0, 0, 0 }, { 12, 12, 12, 12 }
|
||||
#define DPTH16 16, 1, { 0, 0, 0, 0 }, { 16, 0, 0, 0 }
|
||||
#define DPTH16_16_16 16, 3, { 0, 0, 0, 0 }, { 16, 16, 16, 0 }
|
||||
|
@ -6052,6 +6299,10 @@ static const VideoFormat formats[] = {
|
|||
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),
|
||||
MAKE_YUV_FORMAT (P012_BE, "raw video", 0x00000000, DPTH12_12_12_HI,
|
||||
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),
|
||||
};
|
||||
|
||||
static GstVideoFormat
|
||||
|
|
|
@ -123,6 +123,8 @@ G_BEGIN_DECLS
|
|||
* @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)
|
||||
* @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)
|
||||
*
|
||||
* Enum value describing the most common video formats.
|
||||
*
|
||||
|
@ -221,6 +223,8 @@ typedef enum {
|
|||
GST_VIDEO_FORMAT_Y444_16LE,
|
||||
GST_VIDEO_FORMAT_P016_BE,
|
||||
GST_VIDEO_FORMAT_P016_LE,
|
||||
GST_VIDEO_FORMAT_P012_BE,
|
||||
GST_VIDEO_FORMAT_P012_LE,
|
||||
} GstVideoFormat;
|
||||
|
||||
#define GST_VIDEO_MAX_PLANES 4
|
||||
|
@ -574,7 +578,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, I420_12BE, I420_12LE, I422_12BE, I422_12LE, " \
|
||||
"GBRA_12BE, GBRA_12LE, P012_BE, P012_LE, I420_12BE, I420_12LE, I422_12BE, I422_12LE, " \
|
||||
"Y444_12BE, Y444_12LE, GRAY10_LE32, NV12_10LE32, NV16_10LE32, NV12_10LE40, " \
|
||||
"Y444_16BE, Y444_16LE, P016_BE, P016_LE }"
|
||||
|
||||
|
|
|
@ -1088,6 +1088,8 @@ fill_planes (GstVideoInfo * info, gsize plane_size[GST_VIDEO_MAX_PLANES])
|
|||
case GST_VIDEO_FORMAT_P010_10BE:
|
||||
case GST_VIDEO_FORMAT_P016_LE:
|
||||
case GST_VIDEO_FORMAT_P016_BE:
|
||||
case GST_VIDEO_FORMAT_P012_LE:
|
||||
case GST_VIDEO_FORMAT_P012_BE:
|
||||
info->stride[0] = GST_ROUND_UP_4 (width * 2);
|
||||
info->stride[1] = info->stride[0];
|
||||
info->offset[0] = 0;
|
||||
|
|
Loading…
Reference in a new issue