[vlc-commits] es_out: fix video format tables

Rémi Denis-Courmont git at videolan.org
Tue Oct 3 20:39:44 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Oct  3 21:35:41 2017 +0300| [5cb3ee0b3667434768e6db95536e13ec2cdfa9f7] | committer: Rémi Denis-Courmont

es_out: fix video format tables

 - Fix missing const (and eliminate relocs)
 - Remove tautology comparison, use static assertion
 - Use named indices

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5cb3ee0b3667434768e6db95536e13ec2cdfa9f7
---

 include/vlc_es.h   |  4 +++
 src/input/es_out.c | 89 +++++++++++++++++++++++++++++-------------------------
 2 files changed, 52 insertions(+), 41 deletions(-)

diff --git a/include/vlc_es.h b/include/vlc_es.h
index 478940bdca..c03fca394a 100644
--- a/include/vlc_es.h
+++ b/include/vlc_es.h
@@ -263,6 +263,7 @@ typedef enum video_color_primaries_t
 #define COLOR_PRIMARIES_EBU_3213        COLOR_PRIMARIES_BT601_625
 #define COLOR_PRIMARIES_BT470_BG        COLOR_PRIMARIES_BT601_625
 #define COLOR_PRIMARIES_BT470_M         COLOR_PRIMARIES_FCC1953
+#define COLOR_PRIMARIES_MAX             COLOR_PRIMARIES_FCC1953
 } video_color_primaries_t;
 
 /**
@@ -285,6 +286,7 @@ typedef enum video_transfer_func_t
 #define TRANSFER_FUNC_SMPTE_293         TRANSFER_FUNC_BT709
 #define TRANSFER_FUNC_SMPTE_296         TRANSFER_FUNC_BT709
 #define TRANSFER_FUNC_ARIB_B67          TRANSFER_FUNC_HLG
+#define TRANSFER_FUNC_MAX               TRANSFER_FUNC_HLG
 } video_transfer_func_t;
 
 /**
@@ -299,6 +301,7 @@ typedef enum video_color_space_t
 #define COLOR_SPACE_SRGB      COLOR_SPACE_BT709
 #define COLOR_SPACE_SMPTE_170 COLOR_SPACE_BT601
 #define COLOR_SPACE_SMPTE_240 COLOR_SPACE_SMPTE_170
+#define COLOR_SPACE_MAX       COLOR_SPACE_BT2020
 } video_color_space_t;
 
 /**
@@ -313,6 +316,7 @@ typedef enum video_chroma_location_t
     CHROMA_LOCATION_TOP_CENTER,
     CHROMA_LOCATION_BOTTOM_LEFT,
     CHROMA_LOCATION_BOTTOM_CENTER,
+#define CHROMA_LOCATION_MAX CHROMA_LOCATION_BOTTOM_CENTER
 } video_chroma_location_t;
 
 /**
diff --git a/src/input/es_out.c b/src/input/es_out.c
index b19c500068..9d406d9ef7 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -3146,60 +3146,67 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
        }
        if( fmt->video.primaries != COLOR_PRIMARIES_UNDEF )
        {
-           static const char *primaries_names[] = { N_("Undefined"),
-               N_("ITU-R BT.601 (525 lines, 60 Hz)"),
-               N_("ITU-R BT.601 (625 lines, 50 Hz)"),
-               "ITU-R BT.709",
-               "ITU-R BT.2020",
-               "DCI/P3 D65",
-               "ITU-R BT.470 M",
+           static const char primaries_names[][32] = {
+               [COLOR_PRIMARIES_UNDEF] = N_("Undefined"),
+               [COLOR_PRIMARIES_BT601_525] =
+                   N_("ITU-R BT.601 (525 lines, 60 Hz)"),
+               [COLOR_PRIMARIES_BT601_625] =
+                   N_("ITU-R BT.601 (625 lines, 50 Hz)"),
+               [COLOR_PRIMARIES_BT709] = "ITU-R BT.709",
+               [COLOR_PRIMARIES_BT2020] = "ITU-R BT.2020",
+               [COLOR_PRIMARIES_DCI_P3] = "DCI/P3 D65",
+               [COLOR_PRIMARIES_BT470_M] = "ITU-R BT.470 M",
            };
-           if( fmt->video.primaries < ARRAY_SIZE(primaries_names) )
-                info_category_AddInfo( p_cat, _("Color primaries"), "%s",
-                                      _(primaries_names[fmt->video.primaries]) );
+           static_assert(ARRAY_SIZE(primaries_names) == COLOR_PRIMARIES_MAX+1,
+                         "Color primiaries table mismatch");
+           info_category_AddInfo( p_cat, _("Color primaries"), "%s",
+                                  _(primaries_names[fmt->video.primaries]) );
        }
        if( fmt->video.transfer != TRANSFER_FUNC_UNDEF )
        {
-           static const char *func_names[] = { N_("Undefined"),
-               N_("Linear"),
-               "sRGB",
-               "ITU-R BT.470 BG",
-               "ITU-R BT.470 M",
-               "ITU-R BT.709, ITU-R BT.2020",
-               "SMPTE ST2084",
-               "SMPTE 240M",
-               "Hybrid Log-Gamma",
+           static const char func_names[][20] = {
+               [TRANSFER_FUNC_UNDEF] = N_("Undefined"),
+               [TRANSFER_FUNC_LINEAR] = N_("Linear"),
+               [TRANSFER_FUNC_SRGB] = "sRGB",
+               [TRANSFER_FUNC_BT470_BG] = "ITU-R BT.470 BG",
+               [TRANSFER_FUNC_BT470_M] = "ITU-R BT.470 M",
+               [TRANSFER_FUNC_BT709] = "ITU-R BT.709",
+               [TRANSFER_FUNC_SMPTE_ST2084] = "SMPTE ST2084",
+               [TRANSFER_FUNC_SMPTE_240] = "SMPTE 240M",
+               [TRANSFER_FUNC_HLG] = N_("Hybrid Log-Gamma"),
            };
-           if( fmt->video.transfer < ARRAY_SIZE(func_names) )
-                info_category_AddInfo( p_cat, _("Color transfer function"), "%s",
-                                      _(func_names[fmt->video.transfer]) );
+           static_assert(ARRAY_SIZE(func_names) == TRANSFER_FUNC_MAX+1,
+                         "Transfer functions table mismatch");
+           info_category_AddInfo( p_cat, _("Color transfer function"), "%s",
+                                  _(func_names[fmt->video.transfer]) );
        }
        if( fmt->video.space != COLOR_SPACE_UNDEF )
        {
-           static const char *space_names[] = { N_("Undefined"),
-               "ITU-R BT.601",
-               "ITU-R BT.709",
-               "ITU-R BT.2020",
+           static const char space_names[][16] = {
+               [COLOR_SPACE_UNDEF] = N_("Undefined"),
+               [COLOR_SPACE_BT601] = "ITU-R BT.601",
+               [COLOR_SPACE_BT709] = "ITU-R BT.709",
+               [COLOR_SPACE_BT2020] = "ITU-R BT.2020",
            };
-           static const char *range_names[] = {
-               N_("Limited Range"),
-               N_("Full Range"),
-           };
-           if( fmt->video.space < ARRAY_SIZE(space_names) )
-                info_category_AddInfo( p_cat, _("Color space"), "%s %s",
-                                      _(space_names[fmt->video.space]),
-                                      _(range_names[fmt->video.b_color_range_full]) );
+           static_assert(ARRAY_SIZE(space_names) == COLOR_SPACE_MAX+1,
+                         "Color space table mismatch");
+           info_category_AddInfo( p_cat, _("Color space"), _("%s Range"),
+                                  _(space_names[fmt->video.space]),
+                       _(fmt->video.b_color_range_full ? "Full" : "Limited") );
        }
        if( fmt->video.chroma_location != CHROMA_LOCATION_UNDEF )
        {
-           static const char *c_loc_names[] = { N_("Undefined"),
-               N_("Left"),
-               N_("Center"),
-               N_("Top Left"),
-               N_("Top Center"),
-               N_("Bottom Left"),
-               N_("Bottom Center"),
+           static const char c_loc_names[][16] = {
+               [CHROMA_LOCATION_UNDEF] = N_("Undefined"),
+               [CHROMA_LOCATION_LEFT] = N_("Left"),
+               [CHROMA_LOCATION_CENTER] = N_("Center"),
+               [CHROMA_LOCATION_TOP_LEFT] = N_("Top Left"),
+               [CHROMA_LOCATION_TOP_CENTER] = N_("Top Center"),
+               [CHROMA_LOCATION_BOTTOM_LEFT] =N_("Bottom Left"),
+               [CHROMA_LOCATION_BOTTOM_CENTER] = N_("Bottom Center"),
            };
+           static_assert(ARRAY_SIZE(c_loc_names) == CHROMA_LOCATION_MAX+1,
+                         "Chroma location table mismatch");
            info_category_AddInfo( p_cat, _("Chroma location"), "%s",
                    _(c_loc_names[fmt->video.chroma_location]) );
        }



More information about the vlc-commits mailing list