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,19 +145,44 @@ gst_video_colorimetry_from_string (GstVideoColorimetry * cinfo,
*/
gchar *
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;
if (IS_UNKNOWN (cinfo))
return NULL;
for (i = 0; colorimetry[i].name; i++) {
if (IS_EQUAL (&colorimetry[i], cinfo)) {
return g_strdup (colorimetry[i].name);
}
}
if (!IS_UNKNOWN (cinfo)) {
return g_strdup_printf ("%d:%d:%d:%d", cinfo->range, cinfo->matrix,
cinfo->transfer, cinfo->primaries);
}
return NULL;
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,
cinfo->transfer, cinfo->primaries);
}
/**

View file

@ -193,16 +193,17 @@ typedef struct {
#define GST_VIDEO_COLORIMETRY_SRGB "sRGB"
#define GST_VIDEO_COLORIMETRY_BT2020 "bt2020"
gboolean gst_video_colorimetry_matches (const 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);
gboolean gst_video_colorimetry_is_equal (const GstVideoColorimetry *cinfo, const GstVideoColorimetry *other);
gboolean gst_video_colorimetry_matches (const 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_full (const GstVideoColorimetry *cinfo, gboolean allow_unknown);
gboolean gst_video_colorimetry_is_equal (const GstVideoColorimetry *cinfo, const GstVideoColorimetry *other);
/* compute offset and scale */
void gst_video_color_range_offsets (GstVideoColorRange range,
const GstVideoFormatInfo *info,
gint offset[GST_VIDEO_MAX_COMPONENTS],
gint scale[GST_VIDEO_MAX_COMPONENTS]);
void gst_video_color_range_offsets (GstVideoColorRange range,
const GstVideoFormatInfo *info,
gint offset[GST_VIDEO_MAX_COMPONENTS],
gint scale[GST_VIDEO_MAX_COMPONENTS]);
G_END_DECLS

View file

@ -178,7 +178,7 @@ set_default_colorimetry (GstVideoInfo * info)
}
static gboolean
validate_colorimetry (GstVideoInfo * info)
validate_colorimetry (const GstVideoInfo * info)
{
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->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_ENCODED, NULL);
format = gst_video_format_to_string (info->finfo->format);
g_return_val_if_fail (format != NULL, NULL);
@ -644,7 +645,7 @@ gst_video_info_to_caps (GstVideoInfo * info)
colorimetry.matrix);
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);
g_free (color);
}