diff mbox series

[FFmpeg-devel,3/5] avcodec/avcodec: Update check for identical colorspace/primaries/trc names

Message ID 20210321094722.447294-3-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/5] avcodec/avcodec: Use dedicated pointer to access AVCodecInternal | expand


Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 21, 2021, 9:47 a.m. UTC
If the numerical constants for colorspace, transfer characteristics
and color primaries coincide, the current code presumes the
corresponding names to be identical and prints only one of them obtained
via av_get_colorspace_name(). There are two issues with this: The first
is that the underlying assumption is wrong: The names only coincide in
the 0-7 range, they differ for more recent additions. The second is that
av_get_colorspace_name() is outdated itself; it has not been updated
with the names of the newly defined colorspaces.

Fix both of this by using the names from
av_color_(space|primaries|transfer)_name() and comparing them via
strcmp; don't use av_get_colorspace_name() at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This was our last internal user of av_get_colorspace_name().

 libavcodec/avcodec.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series


diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 93383dc9fb..68a3179b07 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -655,15 +655,15 @@  void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
             if (enc->colorspace != AVCOL_SPC_UNSPECIFIED ||
                 enc->color_primaries != AVCOL_PRI_UNSPECIFIED ||
                 enc->color_trc != AVCOL_TRC_UNSPECIFIED) {
-                if (enc->colorspace != (int)enc->color_primaries ||
-                    enc->colorspace != (int)enc->color_trc) {
+                const char *col = av_x_if_null(av_color_space_name(enc->colorspace), "unknown");
+                const char *pri = av_x_if_null(av_color_primaries_name(enc->color_primaries), "unknown");
+                const char *trc = av_x_if_null(av_color_transfer_name(enc->color_trc), "unkown");
+                if (strcmp(col, pri) || strcmp(col, trc)) {
                     new_line = 1;
                     av_strlcatf(detail, sizeof(detail), "%s/%s/%s, ",
-                                av_x_if_null(av_color_space_name(enc->colorspace), "unknown"),
-                                av_x_if_null(av_color_primaries_name(enc->color_primaries), "unknown"),
-                                av_x_if_null(av_color_transfer_name(enc->color_trc), "unkown"));
-                 } else if (str = av_get_colorspace_name(enc->colorspace))
-                       av_strlcatf(detail, sizeof(detail), "%s, ", str);
+                                col, pri, trc);
+                } else
+                    av_strlcatf(detail, sizeof(detail), "%s, ", col);
             if (enc->field_order != AV_FIELD_UNKNOWN) {