From 158eae7e7e3da3545712dd7d6121492c53085fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 30 Sep 2016 15:03:52 +0300 Subject: [PATCH] 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 --- gst-libs/gst/video/video-color.c | 35 +++++++++++++++++++++++++++----- gst-libs/gst/video/video-color.h | 17 ++++++++-------- gst-libs/gst/video/video-info.c | 5 +++-- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/gst-libs/gst/video/video-color.c b/gst-libs/gst/video/video-color.c index 08513c8b7c..1197baef8f 100644 --- a/gst-libs/gst/video/video-color.c +++ b/gst-libs/gst/video/video-color.c @@ -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); } /** diff --git a/gst-libs/gst/video/video-color.h b/gst-libs/gst/video/video-color.h index 6dafdea2a4..1a86b14bb6 100644 --- a/gst-libs/gst/video/video-color.h +++ b/gst-libs/gst/video/video-color.h @@ -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 diff --git a/gst-libs/gst/video/video-info.c b/gst-libs/gst/video/video-info.c index 0c4edab0b3..3c38a15041 100644 --- a/gst-libs/gst/video/video-info.c +++ b/gst-libs/gst/video/video-info.c @@ -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); }