mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-31 03:29:50 +00:00
video: Add support for 8-bit and 16-bit grayscale formats
This commit is contained in:
parent
318fbf3310
commit
1e3a66f539
2 changed files with 121 additions and 1 deletions
|
@ -404,6 +404,24 @@ gst_video_format_parse_caps (GstCaps * caps, GstVideoFormat * format,
|
|||
} else {
|
||||
ok = FALSE;
|
||||
}
|
||||
} else if (gst_structure_has_name (structure, "video/x-raw-gray")) {
|
||||
int depth;
|
||||
int bpp;
|
||||
int endianness;
|
||||
|
||||
ok &= gst_structure_get_int (structure, "depth", &depth);
|
||||
ok &= gst_structure_get_int (structure, "bpp", &bpp);
|
||||
ok &= gst_structure_get_int (structure, "endianness", &endianness);
|
||||
|
||||
if (depth == 8 && bpp == 8) {
|
||||
*format = GST_VIDEO_FORMAT_GRAY8;
|
||||
} else if (depth == 16 && bpp == 16 && endianness == G_BIG_ENDIAN) {
|
||||
*format = GST_VIDEO_FORMAT_GRAY16_BE;
|
||||
} else if (depth == 16 && bpp == 16 && endianness == G_LITTLE_ENDIAN) {
|
||||
*format = GST_VIDEO_FORMAT_GRAY16_LE;
|
||||
} else {
|
||||
ok = FALSE;
|
||||
}
|
||||
} else {
|
||||
ok = FALSE;
|
||||
}
|
||||
|
@ -621,6 +639,53 @@ gst_video_format_new_caps (GstVideoFormat format, int width, int height,
|
|||
}
|
||||
return caps;
|
||||
}
|
||||
|
||||
if (gst_video_format_is_gray (format)) {
|
||||
GstCaps *caps;
|
||||
int bpp;
|
||||
int depth;
|
||||
int endianness;
|
||||
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_GRAY8:
|
||||
bpp = depth = 8;
|
||||
endianness = G_BIG_ENDIAN;
|
||||
break;
|
||||
case GST_VIDEO_FORMAT_GRAY16_BE:
|
||||
bpp = depth = 16;
|
||||
endianness = G_BIG_ENDIAN;
|
||||
break;
|
||||
case GST_VIDEO_FORMAT_GRAY16_LE:
|
||||
bpp = depth = 16;
|
||||
endianness = G_LITTLE_ENDIAN;
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bpp > 8) {
|
||||
caps = gst_caps_new_simple ("video/x-raw-gray",
|
||||
"bpp", G_TYPE_INT, bpp,
|
||||
"depth", G_TYPE_INT, depth,
|
||||
"width", G_TYPE_INT, width,
|
||||
"height", G_TYPE_INT, height,
|
||||
"framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
|
||||
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
|
||||
} else {
|
||||
caps = gst_caps_new_simple ("video/x-raw-gray",
|
||||
"bpp", G_TYPE_INT, bpp,
|
||||
"depth", G_TYPE_INT, depth,
|
||||
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
|
||||
"width", G_TYPE_INT, width,
|
||||
"height", G_TYPE_INT, height,
|
||||
"framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
|
||||
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
|
||||
}
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -881,6 +946,29 @@ gst_video_format_is_yuv (GstVideoFormat format)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_format_is_gray:
|
||||
* @format: a #GstVideoFormat
|
||||
*
|
||||
* Determine whether the video format is a grayscale format.
|
||||
*
|
||||
* Since: 0.10.29
|
||||
*
|
||||
* Returns: TRUE if @format represents grayscale video
|
||||
*/
|
||||
gboolean
|
||||
gst_video_format_is_gray (GstVideoFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_GRAY8:
|
||||
case GST_VIDEO_FORMAT_GRAY16_BE:
|
||||
case GST_VIDEO_FORMAT_GRAY16_LE:
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_format_has_alpha:
|
||||
* @format: a #GstVideoFormat
|
||||
|
@ -999,6 +1087,11 @@ gst_video_format_get_row_stride (GstVideoFormat format, int component,
|
|||
case GST_VIDEO_FORMAT_NV12:
|
||||
case GST_VIDEO_FORMAT_NV21:
|
||||
return GST_ROUND_UP_4 (width);
|
||||
case GST_VIDEO_FORMAT_GRAY8:
|
||||
return GST_ROUND_UP_4 (width);
|
||||
case GST_VIDEO_FORMAT_GRAY16_BE:
|
||||
case GST_VIDEO_FORMAT_GRAY16_LE:
|
||||
return GST_ROUND_UP_4 (width * 2);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -1068,6 +1161,11 @@ gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
|
|||
} else {
|
||||
return 2;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_GRAY8:
|
||||
return 1;
|
||||
case GST_VIDEO_FORMAT_GRAY16_BE:
|
||||
case GST_VIDEO_FORMAT_GRAY16_LE:
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -1129,6 +1227,9 @@ gst_video_format_get_component_width (GstVideoFormat format, int component,
|
|||
case GST_VIDEO_FORMAT_Y444:
|
||||
case GST_VIDEO_FORMAT_NV12:
|
||||
case GST_VIDEO_FORMAT_NV21:
|
||||
case GST_VIDEO_FORMAT_GRAY8:
|
||||
case GST_VIDEO_FORMAT_GRAY16_BE:
|
||||
case GST_VIDEO_FORMAT_GRAY16_LE:
|
||||
return width;
|
||||
default:
|
||||
return 0;
|
||||
|
@ -1186,6 +1287,9 @@ gst_video_format_get_component_height (GstVideoFormat format, int component,
|
|||
case GST_VIDEO_FORMAT_Y444:
|
||||
case GST_VIDEO_FORMAT_v210:
|
||||
case GST_VIDEO_FORMAT_v216:
|
||||
case GST_VIDEO_FORMAT_GRAY8:
|
||||
case GST_VIDEO_FORMAT_GRAY16_BE:
|
||||
case GST_VIDEO_FORMAT_GRAY16_LE:
|
||||
return height;
|
||||
default:
|
||||
return 0;
|
||||
|
@ -1379,6 +1483,10 @@ gst_video_format_get_component_offset (GstVideoFormat format, int component,
|
|||
return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) + 1;
|
||||
if (component == 2)
|
||||
return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
|
||||
case GST_VIDEO_FORMAT_GRAY8:
|
||||
case GST_VIDEO_FORMAT_GRAY16_BE:
|
||||
case GST_VIDEO_FORMAT_GRAY16_LE:
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -1444,6 +1552,11 @@ gst_video_format_get_size (GstVideoFormat format, int width, int height)
|
|||
case GST_VIDEO_FORMAT_NV12:
|
||||
case GST_VIDEO_FORMAT_NV21:
|
||||
return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) * 3 / 2;
|
||||
case GST_VIDEO_FORMAT_GRAY8:
|
||||
return GST_ROUND_UP_4 (width) * height;
|
||||
case GST_VIDEO_FORMAT_GRAY16_BE:
|
||||
case GST_VIDEO_FORMAT_GRAY16_LE:
|
||||
return GST_ROUND_UP_4 (width * 2) * height;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,9 @@ G_BEGIN_DECLS
|
|||
* @GST_VIDEO_FORMAT_v216: packed 4:2:2 16-bit YUV, Y0-U0-Y1-V1 order (Since: 0.10.24)
|
||||
* @GST_VIDEO_FORMAT_NV12: planar 4:2:0 YUV with interleaved UV plane (Since: 0.10.26)
|
||||
* @GST_VIDEO_FORMAT_NV21: planar 4:2:0 YUV with interleaved VU plane (Since: 0.10.26)
|
||||
* @GST_VIDEO_FORMAT_GRAY8: 8-bit grayscale (Since: 0.10.29)
|
||||
* @GST_VIDEO_FORMAT_GRAY16_BE: 16-bit grayscale, most significant byte first (Since: 0.10.29)
|
||||
* @GST_VIDEO_FORMAT_GRAY16_LE: 16-bit grayscale, least significant byte first (Since: 0.10.29)
|
||||
*
|
||||
* Enum value describing the most common video formats.
|
||||
*/
|
||||
|
@ -80,7 +83,10 @@ typedef enum {
|
|||
GST_VIDEO_FORMAT_v210,
|
||||
GST_VIDEO_FORMAT_v216,
|
||||
GST_VIDEO_FORMAT_NV12,
|
||||
GST_VIDEO_FORMAT_NV21
|
||||
GST_VIDEO_FORMAT_NV21,
|
||||
GST_VIDEO_FORMAT_GRAY8,
|
||||
GST_VIDEO_FORMAT_GRAY16_BE,
|
||||
GST_VIDEO_FORMAT_GRAY16_LE
|
||||
} GstVideoFormat;
|
||||
|
||||
#define GST_VIDEO_BYTE1_MASK_32 "0xFF000000"
|
||||
|
@ -303,6 +309,7 @@ GstVideoFormat gst_video_format_from_fourcc (guint32 fourcc);
|
|||
guint32 gst_video_format_to_fourcc (GstVideoFormat format);
|
||||
gboolean gst_video_format_is_rgb (GstVideoFormat format);
|
||||
gboolean gst_video_format_is_yuv (GstVideoFormat format);
|
||||
gboolean gst_video_format_is_gray (GstVideoFormat format);
|
||||
gboolean gst_video_format_has_alpha (GstVideoFormat format);
|
||||
int gst_video_format_get_row_stride (GstVideoFormat format, int component,
|
||||
int width);
|
||||
|
|
Loading…
Reference in a new issue