[FFmpeg-cvslog] avutil/pixdesc: Use av_strstart where appropriate

Andreas Rheinhardt git at videolan.org
Sun Feb 28 18:43:43 EET 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Wed Feb 24 03:26:36 2021 +0100| [114603d0b9ce5440be5efce773361fb96c290b08] | committer: Andreas Rheinhardt

avutil/pixdesc: Use av_strstart where appropriate

It makes the intent clearer and allows to avoid calculating the strlen
separately.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=114603d0b9ce5440be5efce773361fb96c290b08
---

 libavutil/pixdesc.c | 33 +++++++++++----------------------
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 8274713226..2a919461a5 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -2702,11 +2702,13 @@ static int get_color_type(const AVPixFmtDescriptor *desc) {
     if(desc->nb_components == 1 || desc->nb_components == 2)
         return FF_COLOR_GRAY;
 
-    if(desc->name && !strncmp(desc->name, "yuvj", 4))
-        return FF_COLOR_YUV_JPEG;
+    if (desc->name) {
+        if (av_strstart(desc->name, "yuvj", NULL))
+            return FF_COLOR_YUV_JPEG;
 
-    if(desc->name && !strncmp(desc->name, "xyz", 3))
-        return FF_COLOR_XYZ;
+        if (av_strstart(desc->name, "xyz", NULL))
+            return FF_COLOR_XYZ;
+    }
 
     if(desc->flags & AV_PIX_FMT_FLAG_RGB)
         return  FF_COLOR_RGB;
@@ -2907,8 +2909,7 @@ int av_color_range_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(color_range_names); i++) {
-        size_t len = strlen(color_range_names[i]);
-        if (!strncmp(color_range_names[i], name, len))
+        if (av_strstart(name, color_range_names[i], NULL))
             return i;
     }
 
@@ -2926,13 +2927,10 @@ int av_color_primaries_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(color_primaries_names); i++) {
-        size_t len;
-
         if (!color_primaries_names[i])
             continue;
 
-        len = strlen(color_primaries_names[i]);
-        if (!strncmp(color_primaries_names[i], name, len))
+        if (av_strstart(name, color_primaries_names[i], NULL))
             return i;
     }
 
@@ -2950,13 +2948,10 @@ int av_color_transfer_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(color_transfer_names); i++) {
-        size_t len;
-
         if (!color_transfer_names[i])
             continue;
 
-        len = strlen(color_transfer_names[i]);
-        if (!strncmp(color_transfer_names[i], name, len))
+        if (av_strstart(name, color_transfer_names[i], NULL))
             return i;
     }
 
@@ -2974,13 +2969,10 @@ int av_color_space_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(color_space_names); i++) {
-        size_t len;
-
         if (!color_space_names[i])
             continue;
 
-        len = strlen(color_space_names[i]);
-        if (!strncmp(color_space_names[i], name, len))
+        if (av_strstart(name, color_space_names[i], NULL))
             return i;
     }
 
@@ -2998,13 +2990,10 @@ int av_chroma_location_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(chroma_location_names); i++) {
-        size_t len;
-
         if (!chroma_location_names[i])
             continue;
 
-        len = strlen(chroma_location_names[i]);
-        if (!strncmp(chroma_location_names[i], name, len))
+        if (av_strstart(name, chroma_location_names[i], NULL))
             return i;
     }
 



More information about the ffmpeg-cvslog mailing list