video-color: Allow converting incomplete colorimetry to a string

This is only a good idea for non-raw caps.

https://bugzilla.gnome.org/show_bug.cgi?id=771376
This commit is contained in:
Sebastian Dröge 2016-09-30 15:03:52 +03:00
parent ad06b54443
commit 158eae7e7e
3 changed files with 42 additions and 15 deletions

View file

@ -145,20 +145,45 @@ gst_video_colorimetry_from_string (GstVideoColorimetry * cinfo,
*/ */
gchar * gchar *
gst_video_colorimetry_to_string (const GstVideoColorimetry * cinfo) gst_video_colorimetry_to_string (const GstVideoColorimetry * cinfo)
{
return gst_video_colorimetry_to_string_full (cinfo, FALSE);
}
/**
* gst_video_colorimetry_to_string_full:
* @cinfo: a #GstVideoColorimetry
* @allow_unknown: Allow unknown fields
*
* Make a string representation of @cinfo. If @allow_unknown is TRUE,
* colorimetry is even returned if some but not all fields of @cinfo are
* UNKNOWN.
*
* Returns: a string representation of @cinfo.
*
* Since: 1.12
*/
gchar *
gst_video_colorimetry_to_string_full (const GstVideoColorimetry * cinfo,
gboolean allow_unknown)
{ {
gint i; gint i;
if (IS_UNKNOWN (cinfo))
return NULL;
for (i = 0; colorimetry[i].name; i++) { for (i = 0; colorimetry[i].name; i++) {
if (IS_EQUAL (&colorimetry[i], cinfo)) { if (IS_EQUAL (&colorimetry[i], cinfo)) {
return g_strdup (colorimetry[i].name); return g_strdup (colorimetry[i].name);
} }
} }
if (!IS_UNKNOWN (cinfo)) {
if (!allow_unknown && (!cinfo->range || !cinfo->matrix || !cinfo->transfer
|| !cinfo->primaries))
return NULL;
return g_strdup_printf ("%d:%d:%d:%d", cinfo->range, cinfo->matrix, return g_strdup_printf ("%d:%d:%d:%d", cinfo->range, cinfo->matrix,
cinfo->transfer, cinfo->primaries); cinfo->transfer, cinfo->primaries);
} }
return NULL;
}
/** /**
* gst_video_colorimetry_matches: * gst_video_colorimetry_matches:

View file

@ -196,6 +196,7 @@ typedef struct {
gboolean gst_video_colorimetry_matches (const GstVideoColorimetry *cinfo, const gchar *color); gboolean gst_video_colorimetry_matches (const GstVideoColorimetry *cinfo, const gchar *color);
gboolean gst_video_colorimetry_from_string (GstVideoColorimetry *cinfo, const gchar *color); gboolean gst_video_colorimetry_from_string (GstVideoColorimetry *cinfo, const gchar *color);
gchar * gst_video_colorimetry_to_string (const GstVideoColorimetry *cinfo); gchar * gst_video_colorimetry_to_string (const GstVideoColorimetry *cinfo);
gchar * gst_video_colorimetry_to_string_full (const GstVideoColorimetry *cinfo, gboolean allow_unknown);
gboolean gst_video_colorimetry_is_equal (const GstVideoColorimetry *cinfo, const GstVideoColorimetry *other); gboolean gst_video_colorimetry_is_equal (const GstVideoColorimetry *cinfo, const GstVideoColorimetry *other);
/* compute offset and scale */ /* compute offset and scale */

View file

@ -178,7 +178,7 @@ set_default_colorimetry (GstVideoInfo * info)
} }
static gboolean static gboolean
validate_colorimetry (GstVideoInfo * info) validate_colorimetry (const GstVideoInfo * info)
{ {
const GstVideoFormatInfo *finfo = info->finfo; const GstVideoFormatInfo *finfo = info->finfo;
@ -571,6 +571,7 @@ gst_video_info_to_caps (GstVideoInfo * info)
g_return_val_if_fail (info != NULL, NULL); g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (info->finfo != NULL, NULL); g_return_val_if_fail (info->finfo != NULL, NULL);
g_return_val_if_fail (info->finfo->format != GST_VIDEO_FORMAT_UNKNOWN, NULL); g_return_val_if_fail (info->finfo->format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
g_return_val_if_fail (info->finfo->format != GST_VIDEO_FORMAT_ENCODED, NULL);
format = gst_video_format_to_string (info->finfo->format); format = gst_video_format_to_string (info->finfo->format);
g_return_val_if_fail (format != NULL, NULL); g_return_val_if_fail (format != NULL, NULL);
@ -644,7 +645,7 @@ gst_video_info_to_caps (GstVideoInfo * info)
colorimetry.matrix); colorimetry.matrix);
colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB; colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB;
} }
if ((color = gst_video_colorimetry_to_string (&colorimetry))) { if ((color = gst_video_colorimetry_to_string_full (&colorimetry, FALSE))) {
gst_caps_set_simple (caps, "colorimetry", G_TYPE_STRING, color, NULL); gst_caps_set_simple (caps, "colorimetry", G_TYPE_STRING, color, NULL);
g_free (color); g_free (color);
} }