Browse code

pixdesc: Add API to map color property names to enum values

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>

Vittorio Giovara authored on 2017/09/21 20:23:21
Showing 4 changed files
... ...
@@ -13,6 +13,11 @@ libavutil:     2017-03-23
13 13
 
14 14
 API changes, most recent first:
15 15
 
16
+2017-xx-xx - xxxxxxx - lavu 56.6.0 - pixdesc.h
17
+  Add av_color_range_from_name(), av_color_primaries_from_name(),
18
+  av_color_transfer_from_name(), av_color_space_from_name(), and
19
+  av_chroma_location_from_name().
20
+
16 21
 2016-xx-xx - xxxxxxx - lavf 58.1.0 - avio.h
17 22
   Add avio_read_partial().
18 23
 
... ...
@@ -2013,27 +2013,91 @@ const char *av_color_range_name(enum AVColorRange range)
2013 2013
         color_range_names[range] : NULL;
2014 2014
 }
2015 2015
 
2016
+int av_color_range_from_name(const char *name)
2017
+{
2018
+    int i;
2019
+
2020
+    for (i = 0; i < FF_ARRAY_ELEMS(color_range_names); i++) {
2021
+        size_t len = strlen(color_range_names[i]);
2022
+        if (!strncmp(color_range_names[i], name, len))
2023
+            return i;
2024
+    }
2025
+
2026
+    return AVERROR(EINVAL);
2027
+}
2028
+
2016 2029
 const char *av_color_primaries_name(enum AVColorPrimaries primaries)
2017 2030
 {
2018 2031
     return (unsigned) primaries < AVCOL_PRI_NB ?
2019 2032
         color_primaries_names[primaries] : NULL;
2020 2033
 }
2021 2034
 
2035
+int av_color_primaries_from_name(const char *name)
2036
+{
2037
+    int i;
2038
+
2039
+    for (i = 0; i < FF_ARRAY_ELEMS(color_primaries_names); i++) {
2040
+        size_t len = strlen(color_primaries_names[i]);
2041
+        if (!strncmp(color_primaries_names[i], name, len))
2042
+            return i;
2043
+    }
2044
+
2045
+    return AVERROR(EINVAL);
2046
+}
2047
+
2022 2048
 const char *av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
2023 2049
 {
2024 2050
     return (unsigned) transfer < AVCOL_TRC_NB ?
2025 2051
         color_transfer_names[transfer] : NULL;
2026 2052
 }
2027 2053
 
2054
+int av_color_transfer_from_name(const char *name)
2055
+{
2056
+    int i;
2057
+
2058
+    for (i = 0; i < FF_ARRAY_ELEMS(color_transfer_names); i++) {
2059
+        size_t len = strlen(color_transfer_names[i]);
2060
+        if (!strncmp(color_transfer_names[i], name, len))
2061
+            return i;
2062
+    }
2063
+
2064
+    return AVERROR(EINVAL);
2065
+}
2066
+
2028 2067
 const char *av_color_space_name(enum AVColorSpace space)
2029 2068
 {
2030 2069
     return (unsigned) space < AVCOL_SPC_NB ?
2031 2070
         color_space_names[space] : NULL;
2032 2071
 }
2033 2072
 
2073
+int av_color_space_from_name(const char *name)
2074
+{
2075
+    int i;
2076
+
2077
+    for (i = 0; i < FF_ARRAY_ELEMS(color_space_names); i++) {
2078
+        size_t len = strlen(color_space_names[i]);
2079
+        if (!strncmp(color_space_names[i], name, len))
2080
+            return i;
2081
+    }
2082
+
2083
+    return AVERROR(EINVAL);
2084
+}
2085
+
2034 2086
 const char *av_chroma_location_name(enum AVChromaLocation location)
2035 2087
 {
2036 2088
     return (unsigned) location < AVCHROMA_LOC_NB ?
2037 2089
         chroma_location_names[location] : NULL;
2038 2090
 }
2039 2091
 
2092
+int av_chroma_location_from_name(const char *name)
2093
+{
2094
+    int i;
2095
+
2096
+    for (i = 0; i < FF_ARRAY_ELEMS(chroma_location_names); i++) {
2097
+        size_t len = strlen(chroma_location_names[i]);
2098
+        if (!strncmp(chroma_location_names[i], name, len))
2099
+            return i;
2100
+    }
2101
+
2102
+    return AVERROR(EINVAL);
2103
+}
... ...
@@ -298,23 +298,48 @@ enum AVPixelFormat av_pix_fmt_swap_endianness(enum AVPixelFormat pix_fmt);
298 298
 const char *av_color_range_name(enum AVColorRange range);
299 299
 
300 300
 /**
301
+ * @return the AVColorRange value for name or an AVError if not found.
302
+ */
303
+int av_color_range_from_name(const char *name);
304
+
305
+/**
301 306
  * @return the name for provided color primaries or NULL if unknown.
302 307
  */
303 308
 const char *av_color_primaries_name(enum AVColorPrimaries primaries);
304 309
 
305 310
 /**
311
+ * @return the AVColorPrimaries value for name or an AVError if not found.
312
+ */
313
+int av_color_primaries_from_name(const char *name);
314
+
315
+/**
306 316
  * @return the name for provided color transfer or NULL if unknown.
307 317
  */
308 318
 const char *av_color_transfer_name(enum AVColorTransferCharacteristic transfer);
309 319
 
310 320
 /**
321
+ * @return the AVColorTransferCharacteristic value for name or an AVError if not found.
322
+ */
323
+int av_color_transfer_from_name(const char *name);
324
+
325
+/**
311 326
  * @return the name for provided color space or NULL if unknown.
312 327
  */
313 328
 const char *av_color_space_name(enum AVColorSpace space);
314 329
 
315 330
 /**
331
+ * @return the AVColorSpace value for name or an AVError if not found.
332
+ */
333
+int av_color_space_from_name(const char *name);
334
+
335
+/**
316 336
  * @return the name for provided chroma location or NULL if unknown.
317 337
  */
318 338
 const char *av_chroma_location_name(enum AVChromaLocation location);
319 339
 
340
+/**
341
+ * @return the AVChromaLocation value for name or an AVError if not found.
342
+ */
343
+int av_chroma_location_from_name(const char *name);
344
+
320 345
 #endif /* AVUTIL_PIXDESC_H */
... ...
@@ -54,7 +54,7 @@
54 54
  */
55 55
 
56 56
 #define LIBAVUTIL_VERSION_MAJOR 56
57
-#define LIBAVUTIL_VERSION_MINOR  5
57
+#define LIBAVUTIL_VERSION_MINOR  6
58 58
 #define LIBAVUTIL_VERSION_MICRO  0
59 59
 
60 60
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \