[vlc-devel] [PATCH] vlc_es: add mapping for all known colorspaces

Francois Cartegnie fcvlcdev at free.fr
Mon Dec 26 16:27:20 CET 2016


Do not do early fallback/subjective mapping. We need
to keep original values as long as we can for use with
non decoded output or encoders.
Vout should late map to 'undefined'.

Might break some builds.

---
 include/vlc_es.h                  |  59 +++++++++++-----
 modules/codec/aom.c               |   2 +-
 modules/codec/avcodec/chroma.c    |  98 ++++++++++++++++++++++++++
 modules/codec/avcodec/chroma.h    |   9 +++
 modules/codec/avcodec/encoder.c   |  68 +-----------------
 modules/codec/avcodec/video.c     |  58 +---------------
 modules/codec/videotoolbox.m      |   2 +-
 modules/codec/vpx.c               |   2 +-
 modules/codec/x264.c              |   2 +-
 modules/demux/mp4/essetup.c       |   6 +-
 modules/hw/vdpau/chroma.c         |   2 +-
 modules/packetizer/hxxx_nal.h     | 140 ++++++++++++++++++--------------------
 modules/packetizer/mpegvideo.c    |   2 +-
 modules/packetizer/vc1.c          |   4 +-
 modules/video_output/xcb/xvideo.c |   2 +-
 src/input/es_out.c                |  42 +++++++++---
 16 files changed, 264 insertions(+), 234 deletions(-)

diff --git a/include/vlc_es.h b/include/vlc_es.h
index c8dd4c4..c4ced3a 100644
--- a/include/vlc_es.h
+++ b/include/vlc_es.h
@@ -233,19 +233,23 @@ typedef enum video_projection_mode_t
 typedef enum video_color_primaries_t
 {
     COLOR_PRIMARIES_UNDEF,
-    COLOR_PRIMARIES_BT601_525,
-    COLOR_PRIMARIES_BT601_625,
     COLOR_PRIMARIES_BT709,
+    COLOR_PRIMARIES_BT470_M,
+    COLOR_PRIMARIES_BT470_BG,
+    COLOR_PRIMARIES_BT601_525,
+    // COLOR_PRIMARIES_SMTPE_240
     COLOR_PRIMARIES_BT2020,
     COLOR_PRIMARIES_DCI_P3,
-    COLOR_PRIMARIES_FCC1953,
+    COLOR_PRIMARIES_SMPTE_ST428,
+    COLOR_PRIMARIES_SMPTE_431,
+    COLOR_PRIMARIES_SMPTE_432,
 #define COLOR_PRIMARIES_SRGB            COLOR_PRIMARIES_BT709
 #define COLOR_PRIMARIES_SMTPE_170       COLOR_PRIMARIES_BT601_525
 #define COLOR_PRIMARIES_SMTPE_240       COLOR_PRIMARIES_BT601_525 /* Only differs from 1e10-4 in white Y */
 #define COLOR_PRIMARIES_SMTPE_RP145     COLOR_PRIMARIES_BT601_525
 #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_BT601_625       COLOR_PRIMARIES_BT470_BG
+#define COLOR_PRIMARIES_FCC1953         COLOR_PRIMARIES_BT470_M
 } video_color_primaries_t;
 
 /**
@@ -254,18 +258,28 @@ typedef enum video_color_primaries_t
 typedef enum video_transfer_func_t
 {
     TRANSFER_FUNC_UNDEF,
-    TRANSFER_FUNC_LINEAR,
-    TRANSFER_FUNC_SRGB /*< Gamma 2.2 */,
-    TRANSFER_FUNC_BT470_BG,
-    TRANSFER_FUNC_BT470_M,
     TRANSFER_FUNC_BT709,
-    TRANSFER_FUNC_SMPTE_ST2084,
+    TRANSFER_FUNC_BT470_M,  /*< Gamma 2.2 */
+    TRANSFER_FUNC_BT470_BG, /*< Gamma 2.8 */
+    TRANSFER_FUNC_BT601,
     TRANSFER_FUNC_SMPTE_240,
-#define TRANSFER_FUNC_BT2020            TRANSFER_FUNC_BT709
-#define TRANSFER_FUNC_SMPTE_170         TRANSFER_FUNC_BT709
+    TRANSFER_FUNC_LINEAR,
+    TRANSFER_FUNC_LOG,
+    TRANSFER_FUNC_LOG_SQRT,
+    TRANSFER_FUNC_IEC61966_2_4,
+    TRANSFER_FUNC_BT1361,
+    TRANSFER_FUNC_IEC61966_2_1,
+    TRANSFER_FUNC_BT2020_V14,
+    TRANSFER_FUNC_BT2020_V15,
+    TRANSFER_FUNC_SMPTE_ST2084,
+    TRANSFER_FUNC_SMPTE_ST428,
+    TRANSFER_FUNC_ARIB_STD_B67,
+#define TRANSFER_FUNC_SRGB              TRANSFER_FUNC_BT470_M
+#define TRANSFER_FUNC_SMPTE_170         TRANSFER_FUNC_BT601
 #define TRANSFER_FUNC_SMPTE_274         TRANSFER_FUNC_BT709
 #define TRANSFER_FUNC_SMPTE_293         TRANSFER_FUNC_BT709
 #define TRANSFER_FUNC_SMPTE_296         TRANSFER_FUNC_BT709
+#define TRANSFER_FUNC_BT2020            TRANSFER_FUNC_BT2020_V14
 } video_transfer_func_t;
 
 /**
@@ -274,12 +288,21 @@ typedef enum video_transfer_func_t
 typedef enum video_color_space_t
 {
     COLOR_SPACE_UNDEF,
-    COLOR_SPACE_BT601,
+    COLOR_SPACE_RGB,
     COLOR_SPACE_BT709,
-    COLOR_SPACE_BT2020,
-#define COLOR_SPACE_SRGB      COLOR_SPACE_BT709
-#define COLOR_SPACE_SMPTE_170 COLOR_SPACE_BT601
-#define COLOR_SPACE_SMPTE_240 COLOR_SPACE_SMPTE_170
+    COLOR_SPACE_FCC,
+    COLOR_SPACE_BT470BG,
+    COLOR_SPACE_BT601_525,
+    COLOR_SPACE_SMPTE_240M,
+    COLOR_SPACE_YCOCG,
+    COLOR_SPACE_BT2020_NCL,
+    COLOR_SPACE_BT2020_CL,
+    COLOR_SPACE_SMPTE_2085,
+#define COLOR_SPACE_SRGB      COLOR_SPACE_RGB
+#define COLOR_SPACE_BT601     COLOR_SPACE_BT601_525
+#define COLOR_SPACE_SMPTE_170 COLOR_SPACE_BT601_525
+#define COLOR_SPACE_BT2020    COLOR_SPACE_BT2020_NCL
+#define COLOR_SPACE_YCGCO     COLOR_SPACE_YCOCG
 } video_color_space_t;
 
 /**
@@ -401,7 +424,7 @@ static inline void video_format_AdjustColorSpace( video_format_t *p_fmt )
         if ( p_fmt->i_visible_height > 576 ) // HD
             p_fmt->space = COLOR_SPACE_BT709;
         else
-            p_fmt->space = COLOR_SPACE_BT601;
+            p_fmt->space = COLOR_SPACE_BT601_525;
     }
 }
 
diff --git a/modules/codec/aom.c b/modules/codec/aom.c
index fb818f1..5056452 100644
--- a/modules/codec/aom.c
+++ b/modules/codec/aom.c
@@ -209,7 +209,7 @@ static picture_t *Decode(decoder_t *dec, block_t **pp_block)
         case AOM_CS_BT_601:
         case AOM_CS_SMPTE_170:
         case AOM_CS_SMPTE_240:
-            v->space = COLOR_SPACE_BT601;
+            v->space = COLOR_SPACE_BT601_525;
             break;
         case AOM_CS_BT_2020:
             v->space = COLOR_SPACE_BT2020;
diff --git a/modules/codec/avcodec/chroma.c b/modules/codec/avcodec/chroma.c
index e700eb1..a76d67e 100644
--- a/modules/codec/avcodec/chroma.c
+++ b/modules/codec/avcodec/chroma.c
@@ -218,3 +218,101 @@ int FindFfmpegChroma( vlc_fourcc_t fourcc )
             return chroma_table[i].i_chroma_id;
     return AV_PIX_FMT_NONE;
 }
+
+#define RETURN_TABLE_LOOKUP( table, var, matchmbr, retmbr )\
+    for( unsigned i=0; i<ARRAY_SIZE(table); i++ )\
+    {\
+        if( table[i].matchmbr == var )\
+            return table[i].retmbr;\
+    }\
+    return table[0].retmbr;
+
+static const struct
+{
+    enum video_color_primaries_t vlc;
+    enum AVColorPrimaries ff;
+} color_primaries_table[] = {
+    { COLOR_PRIMARIES_UNDEF,        AVCOL_PRI_UNSPECIFIED   },
+    { COLOR_PRIMARIES_UNDEF,        AVCOL_PRI_NB            },
+    { COLOR_PRIMARIES_BT709,        AVCOL_PRI_BT709         },
+    { COLOR_PRIMARIES_BT470_M,      AVCOL_PRI_BT470M        },
+    { COLOR_PRIMARIES_BT470_BG,     AVCOL_PRI_BT470BG       },
+    { COLOR_PRIMARIES_BT601_525,    AVCOL_PRI_SMPTE170M     },
+    { COLOR_PRIMARIES_BT2020,       AVCOL_PRI_BT2020        },
+    { COLOR_PRIMARIES_DCI_P3,       AVCOL_PRI_NB            },
+    { COLOR_PRIMARIES_SMPTE_ST428,  AVCOL_PRI_SMPTEST428_1  },
+    { COLOR_PRIMARIES_SMPTE_431,    AVCOL_PRI_SMPTE431      },
+    { COLOR_PRIMARIES_SMPTE_432,    AVCOL_PRI_SMPTE432      },
+};
+
+video_color_primaries_t GetVlcColorPrimaries( enum AVColorPrimaries ff )
+{
+    RETURN_TABLE_LOOKUP(color_primaries_table, ff, ff, vlc);
+}
+
+enum AVColorPrimaries GetFfColorPrimaries( video_color_primaries_t vlc )
+{
+    RETURN_TABLE_LOOKUP(color_primaries_table, vlc, vlc, ff);
+}
+
+static const struct
+{
+    enum video_transfer_func_t vlc;
+    enum AVColorTransferCharacteristic ff;
+} color_transfert_table[] = {
+    { TRANSFER_FUNC_UNDEF,         AVCOL_TRC_UNSPECIFIED   },
+    { TRANSFER_FUNC_BT709,         AVCOL_TRC_BT709         },
+    { TRANSFER_FUNC_BT470_M,       AVCOL_TRC_GAMMA22       },
+    { TRANSFER_FUNC_BT470_BG,      AVCOL_TRC_GAMMA28       },
+    { TRANSFER_FUNC_BT601,         AVCOL_TRC_SMPTE170M     },
+    { TRANSFER_FUNC_SMPTE_240,     AVCOL_TRC_SMPTE240M     },
+    { TRANSFER_FUNC_LINEAR,        AVCOL_TRC_LINEAR        },
+    { TRANSFER_FUNC_LOG,           AVCOL_TRC_LOG           },
+    { TRANSFER_FUNC_LOG_SQRT,      AVCOL_TRC_LOG_SQRT      },
+    { TRANSFER_FUNC_IEC61966_2_4,  AVCOL_TRC_IEC61966_2_4  },
+    { TRANSFER_FUNC_BT1361,        AVCOL_TRC_BT1361_ECG    },
+    { TRANSFER_FUNC_IEC61966_2_1,  AVCOL_TRC_IEC61966_2_1  },
+    { TRANSFER_FUNC_BT2020_V14,    AVCOL_TRC_BT2020_10     },
+    { TRANSFER_FUNC_BT2020_V15,    AVCOL_TRC_BT2020_12     },
+    { TRANSFER_FUNC_SMPTE_ST2084,  AVCOL_TRC_SMPTEST2084   },
+    { TRANSFER_FUNC_SMPTE_ST428,   AVCOL_TRC_SMPTEST428_1  },
+    { TRANSFER_FUNC_ARIB_STD_B67,  AVCOL_TRC_ARIB_STD_B67  },
+};
+
+video_transfer_func_t GetVlcColorTransfert( enum AVColorTransferCharacteristic ff )
+{
+    RETURN_TABLE_LOOKUP(color_transfert_table, ff, ff, vlc);
+}
+
+enum AVColorTransferCharacteristic GetFfColorTransfert( video_transfer_func_t vlc )
+{
+    RETURN_TABLE_LOOKUP(color_transfert_table, vlc, vlc, ff);
+}
+
+static const struct
+{
+    enum video_color_space_t vlc;
+    enum AVColorSpace ff;
+} color_spaces_table[] = {
+    { COLOR_SPACE_UNDEF,            AVCOL_SPC_UNSPECIFIED   },
+    { COLOR_SPACE_RGB,              AVCOL_SPC_RGB           },
+    { COLOR_SPACE_BT709,            AVCOL_SPC_BT709         },
+    { COLOR_SPACE_FCC,              AVCOL_SPC_FCC           },
+    { COLOR_SPACE_BT470BG,          AVCOL_SPC_BT470BG       },
+    { COLOR_SPACE_BT601_525,        AVCOL_SPC_SMPTE170M     },
+    { COLOR_SPACE_SMPTE_240M,       AVCOL_SPC_SMPTE240M     },
+    { COLOR_SPACE_YCOCG,            AVCOL_SPC_YCOCG         },
+    { COLOR_SPACE_BT2020_NCL,       AVCOL_SPC_BT2020_NCL    },
+    { COLOR_SPACE_BT2020_CL,        AVCOL_SPC_BT2020_CL     },
+    { COLOR_SPACE_SMPTE_2085,       AVCOL_SPC_SMPTE2085     },
+};
+
+video_color_space_t GetVlcColorSpace( enum AVColorSpace ff )
+{
+    RETURN_TABLE_LOOKUP(color_spaces_table, ff, ff, vlc);
+}
+
+enum AVColorSpace GetFfColorSpace( video_color_space_t vlc )
+{
+    RETURN_TABLE_LOOKUP(color_spaces_table, vlc, vlc, ff);
+}
diff --git a/modules/codec/avcodec/chroma.h b/modules/codec/avcodec/chroma.h
index 99dc1d6..857d9ab 100644
--- a/modules/codec/avcodec/chroma.h
+++ b/modules/codec/avcodec/chroma.h
@@ -32,4 +32,13 @@ int GetFfmpegChroma( int *i_ffmpeg_chroma, const video_format_t *fmt );
 vlc_fourcc_t FindVlcChroma( int );
 int GetVlcChroma( video_format_t *fmt, int i_ffmpeg_chroma );
 
+video_color_primaries_t GetVlcColorPrimaries( enum AVColorPrimaries ff );
+enum AVColorPrimaries GetFfColorPrimaries( video_color_primaries_t vlc );
+
+video_transfer_func_t GetVlcColorTransfert( enum AVColorTransferCharacteristic ff );
+enum AVColorTransferCharacteristic GetFfColorTransfert( video_transfer_func_t vlc );
+
+video_color_space_t GetVlcColorSpace( enum AVColorSpace ff );
+enum AVColorSpace GetFfColorSpace( video_color_space_t vlc );
+
 #endif
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index af8cacb..a009222 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -234,7 +234,6 @@ static const uint16_t mpeg4_default_non_intra_matrix[64] = {
 
 static const int DEFAULT_ALIGN = 0;
 
-
 /*****************************************************************************
  * OpenEncoder: probe the encoder
  *****************************************************************************/
@@ -282,70 +281,9 @@ static void set_video_color_settings( encoder_t *p_enc, AVCodecContext *p_contex
     if( p_enc->fmt_in.video.b_color_range_full )
         p_context->color_range = AVCOL_RANGE_JPEG;
 
-    switch( p_enc->fmt_in.video.space )
-    {
-        case COLOR_SPACE_BT709:
-            p_context->colorspace = AVCOL_SPC_BT709;
-            break;
-        case COLOR_SPACE_BT601:
-            p_context->colorspace = AVCOL_SPC_BT470BG;
-            break;
-        case COLOR_SPACE_BT2020:
-            p_context->colorspace = AVCOL_SPC_BT2020_CL;
-            break;
-        default:
-            p_context->colorspace = AVCOL_SPC_UNSPECIFIED;
-            break;
-    }
-
-    switch( p_enc->fmt_in.video.transfer )
-    {
-        case TRANSFER_FUNC_LINEAR:
-            p_context->color_trc = AVCOL_TRC_LINEAR;
-            break;
-        case TRANSFER_FUNC_SRGB:
-            p_context->color_trc = AVCOL_TRC_GAMMA22;
-            break;
-        case TRANSFER_FUNC_BT470_BG:
-            p_context->color_trc = AVCOL_TRC_GAMMA28;
-            break;
-        case TRANSFER_FUNC_BT470_M:
-            p_context->color_trc = AVCOL_TRC_GAMMA22;
-            break;
-        case TRANSFER_FUNC_BT709:
-            p_context->color_trc = AVCOL_TRC_BT709;
-            break;
-        case TRANSFER_FUNC_SMPTE_ST2084:
-            p_context->color_trc = AVCOL_TRC_SMPTEST2084;
-            break;
-        case TRANSFER_FUNC_SMPTE_240:
-            p_context->color_trc = AVCOL_TRC_SMPTE240M;
-            break;
-        default:
-            p_context->color_trc = AVCOL_TRC_UNSPECIFIED;
-            break;
-    }
-    switch( p_enc->fmt_in.video.primaries )
-    {
-        case COLOR_PRIMARIES_BT601_525:
-            p_context->color_primaries = AVCOL_PRI_SMPTE170M;
-            break;
-        case COLOR_PRIMARIES_BT601_625:
-            p_context->color_primaries = AVCOL_PRI_BT470BG;
-            break;
-        case COLOR_PRIMARIES_BT709:
-            p_context->color_primaries = AVCOL_PRI_BT709;
-            break;
-        case COLOR_PRIMARIES_BT2020:
-            p_context->color_primaries = AVCOL_PRI_BT2020;
-            break;
-        case COLOR_PRIMARIES_FCC1953:
-            p_context->color_primaries = AVCOL_PRI_BT470M;
-            break;
-        default:
-            p_context->color_primaries = AVCOL_PRI_UNSPECIFIED;
-            break;
-    }
+    p_context->color_primaries = GetFfColorPrimaries( p_enc->fmt_in.video.primaries );
+    p_context->color_trc = GetFfColorTransfert( p_enc->fmt_in.video.transfer );
+    p_context->colorspace = GetFfColorSpace( p_enc->fmt_in.video.space );
 }
 
 int OpenEncoder( vlc_object_t *p_this )
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 461057d..d2f4258 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -198,61 +198,9 @@ static int lavc_GetVideoFormat(decoder_t *dec, video_format_t *restrict fmt,
     if( ctx->color_range == AVCOL_RANGE_JPEG )
         fmt->b_color_range_full = true;
 
-    switch( ctx->colorspace )
-    {
-        case AVCOL_SPC_BT709:
-            fmt->space = COLOR_SPACE_BT709;
-            break;
-        case AVCOL_SPC_SMPTE170M:
-        case AVCOL_SPC_BT470BG:
-            fmt->space = COLOR_SPACE_BT601;
-            break;
-        case AVCOL_SPC_BT2020_NCL:
-        case AVCOL_SPC_BT2020_CL:
-            fmt->space = COLOR_SPACE_BT2020;
-            break;
-        default:
-            break;
-    }
-
-    switch( ctx->color_trc )
-    {
-        case AVCOL_TRC_LINEAR:
-            fmt->transfer = TRANSFER_FUNC_LINEAR;
-            break;
-        case AVCOL_TRC_GAMMA22:
-            fmt->transfer = TRANSFER_FUNC_SRGB;
-            break;
-        case AVCOL_TRC_BT709:
-            fmt->transfer = TRANSFER_FUNC_BT709;
-            break;
-        case AVCOL_TRC_SMPTE170M:
-        case AVCOL_TRC_BT2020_10:
-        case AVCOL_TRC_BT2020_12:
-            fmt->transfer = TRANSFER_FUNC_BT2020;
-            break;
-        default:
-            break;
-    }
-
-    switch( ctx->color_primaries )
-    {
-        case AVCOL_PRI_BT709:
-            fmt->primaries = COLOR_PRIMARIES_BT709;
-            break;
-        case AVCOL_PRI_BT470BG:
-            fmt->primaries = COLOR_PRIMARIES_BT601_625;
-            break;
-        case AVCOL_PRI_SMPTE170M:
-        case AVCOL_PRI_SMPTE240M:
-            fmt->primaries = COLOR_PRIMARIES_BT601_525;
-            break;
-        case AVCOL_PRI_BT2020:
-            fmt->primaries = COLOR_PRIMARIES_BT2020;
-            break;
-        default:
-            break;
-    }
+    fmt->primaries = GetVlcColorPrimaries( ctx->color_primaries );
+    fmt->transfer = GetVlcColorTransfert( ctx->color_trc );
+    fmt->space = GetVlcColorSpace( ctx->colorspace );
 
     switch( ctx->chroma_sample_location )
     {
diff --git a/modules/codec/videotoolbox.m b/modules/codec/videotoolbox.m
index 3bbf035..e58ca18 100644
--- a/modules/codec/videotoolbox.m
+++ b/modules/codec/videotoolbox.m
@@ -1195,7 +1195,7 @@ static void DecoderCallback(void *decompressionOutputRefCon,
                 NSString *colorSpace = attachmentDict[(NSString *)kCVImageBufferYCbCrMatrixKey];
                 if (colorSpace != nil) {
                     if ([colorSpace isEqualToString:(NSString *)kCVImageBufferYCbCrMatrix_ITU_R_601_4])
-                        p_dec->fmt_out.video.space = COLOR_SPACE_BT601;
+                        p_dec->fmt_out.video.space = COLOR_SPACE_BT601_525;
                     else if ([colorSpace isEqualToString:(NSString *)kCVImageBufferYCbCrMatrix_ITU_R_709_2])
                         p_dec->fmt_out.video.space = COLOR_SPACE_BT709;
                     else
diff --git a/modules/codec/vpx.c b/modules/codec/vpx.c
index 14c7fd4..1ae2cab 100644
--- a/modules/codec/vpx.c
+++ b/modules/codec/vpx.c
@@ -237,7 +237,7 @@ static picture_t *Decode(decoder_t *dec, block_t **pp_block)
         case VPX_CS_BT_601:
         case VPX_CS_SMPTE_170:
         case VPX_CS_SMPTE_240:
-            v->space = COLOR_SPACE_BT601;
+            v->space = COLOR_SPACE_BT601_525;
             break;
         case VPX_CS_BT_2020:
             v->space = COLOR_SPACE_BT2020;
diff --git a/modules/codec/x264.c b/modules/codec/x264.c
index 27d9bc0..642462f 100644
--- a/modules/codec/x264.c
+++ b/modules/codec/x264.c
@@ -925,7 +925,7 @@ static int  Open ( vlc_object_t *p_this )
 
     switch( p_enc->fmt_in.video.space )
     {
-        case COLOR_SPACE_BT601:
+        case COLOR_SPACE_BT601_525:
             p_sys->param.vui.i_colmatrix = 5; /* bt470bg*/
             break;
         case COLOR_SPACE_BT709:
diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
index c06d475..0d80f6e 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -475,7 +475,7 @@ int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
             switch ( BOXDATA( p_colr )->nclc.i_matrix_idx )
             {
             case 1: p_track->fmt.video.space = COLOR_SPACE_BT709; break;
-            case 2: p_track->fmt.video.space = COLOR_SPACE_BT601; break;
+            case 2: p_track->fmt.video.space = COLOR_SPACE_BT601_525; break;
             }
             p_track->fmt.video.b_color_range_full = BOXDATA(p_colr)->i_type == VLC_FOURCC( 'n', 'c', 'l', 'x' ) &&
                     (BOXDATA(p_colr)->nclc.i_full_range >> 7) != 0;
@@ -632,10 +632,10 @@ int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
                 const uint8_t colorspacesmapping[] =
                 {
                     COLOR_SPACE_UNDEF,
-                    COLOR_SPACE_BT601,
+                    COLOR_SPACE_BT601_525,
                     COLOR_SPACE_BT709,
                     COLOR_SPACE_SMPTE_170,
-                    COLOR_SPACE_SMPTE_240,
+                    COLOR_SPACE_SMPTE_240M,
                     COLOR_SPACE_BT2020,
                     COLOR_SPACE_BT2020,
                     COLOR_SPACE_SRGB,
diff --git a/modules/hw/vdpau/chroma.c b/modules/hw/vdpau/chroma.c
index ae0d3eb..71efcaf 100644
--- a/modules/hw/vdpau/chroma.c
+++ b/modules/hw/vdpau/chroma.c
@@ -71,7 +71,7 @@ static VdpStatus MixerSetupColors(filter_t *filter, const VdpProcamp *procamp,
 
     switch (filter->fmt_in.video.space)
     {
-        case COLOR_SPACE_BT601:
+        case COLOR_SPACE_BT601_525:
             std = VDP_COLOR_STANDARD_ITUR_BT_601;
             break;
         case COLOR_SPACE_BT709:
diff --git a/modules/packetizer/hxxx_nal.h b/modules/packetizer/hxxx_nal.h
index 39823ac..ea10555 100644
--- a/modules/packetizer/hxxx_nal.h
+++ b/modules/packetizer/hxxx_nal.h
@@ -43,33 +43,30 @@ enum hxxx_colour_primaries
     HXXX_PRIMARIES_SMPTE_ST_428     = 10,
 };
 
+static const struct
+{
+    enum hxxx_colour_primaries i_hxxx_val;
+    video_color_primaries_t i_vlc_val;
+} hxxx_color_primaries_mapping[] = {
+    { HXXX_PRIMARIES_BT709,         COLOR_PRIMARIES_BT709       },
+    { HXXX_PRIMARIES_BT470M,        COLOR_PRIMARIES_BT470_M     },
+    { HXXX_PRIMARIES_BT470BG,       COLOR_PRIMARIES_BT470_BG    },
+    { HXXX_PRIMARIES_BT601_525,     COLOR_PRIMARIES_BT601_625   },
+    { HXXX_PRIMARIES_SMTPE_240M,    COLOR_PRIMARIES_SMTPE_240   },
+    { HXXX_PRIMARIES_GENERIC_FILM,  COLOR_PRIMARIES_UNDEF       },
+    { HXXX_PRIMARIES_BT2020,        COLOR_PRIMARIES_BT2020      },
+    { HXXX_PRIMARIES_SMPTE_ST_428,  COLOR_PRIMARIES_SMPTE_ST428 },
+};
+
 static inline video_color_primaries_t
 hxxx_colour_primaries_to_vlc( enum hxxx_colour_primaries i_colour )
 {
-    switch( i_colour )
+    for( unsigned i=0; i<ARRAY_SIZE(hxxx_color_primaries_mapping); i++ )
     {
-    case HXXX_PRIMARIES_BT470BG:
-        return COLOR_PRIMARIES_BT601_625;
-
-    case HXXX_PRIMARIES_BT601_525:
-    case HXXX_PRIMARIES_SMTPE_240M:
-        return COLOR_PRIMARIES_BT601_625;
-
-    case HXXX_PRIMARIES_BT709:
-        return COLOR_PRIMARIES_BT709;
-
-    case HXXX_PRIMARIES_BT2020:
-        return COLOR_PRIMARIES_BT2020;
-
-    case HXXX_PRIMARIES_BT470M:
-    case HXXX_PRIMARIES_RESERVED0:
-    case HXXX_PRIMARIES_UNSPECIFIED:
-    case HXXX_PRIMARIES_RESERVED3:
-    case HXXX_PRIMARIES_GENERIC_FILM:
-    case HXXX_PRIMARIES_SMPTE_ST_428:
-    default:
-        return COLOR_PRIMARIES_UNDEF;
+        if( hxxx_color_primaries_mapping[i].i_hxxx_val == i_colour )
+            return hxxx_color_primaries_mapping[i].i_vlc_val;
     }
+    return COLOR_PRIMARIES_UNDEF;
 }
 
 /* Annex E: Transfer characteristics */
@@ -95,40 +92,37 @@ enum hxxx_transfer_characteristics
     HXXX_TRANSFER_SMPTE_ST_428      = 17,
 };
 
+static const struct
+{
+    enum hxxx_transfer_characteristics i_hxxx_val;
+    video_transfer_func_t i_vlc_val;
+} hxxx_transfer_characteristics_mapping[] = {
+    { HXXX_TRANSFER_BT709,         TRANSFER_FUNC_BT709       },
+    { HXXX_TRANSFER_BT470M,        TRANSFER_FUNC_BT470_M     },
+    { HXXX_TRANSFER_BT470BG,       TRANSFER_FUNC_BT470_BG    },
+    { HXXX_TRANSFER_BT601_525,     TRANSFER_FUNC_BT601       },
+    { HXXX_TRANSFER_SMTPE_240M,    TRANSFER_FUNC_SMPTE_240   },
+    { HXXX_TRANSFER_LINEAR,        TRANSFER_FUNC_LINEAR      },
+    { HXXX_TRANSFER_LOG,           TRANSFER_FUNC_LOG         },
+    { HXXX_TRANSFER_LOG_SQRT,      TRANSFER_FUNC_LOG_SQRT    },
+    { HXXX_TRANSFER_IEC61966_2_4,  TRANSFER_FUNC_IEC61966_2_4},
+    { HXXX_TRANSFER_BT1361,        TRANSFER_FUNC_BT1361      },
+    { HXXX_TRANSFER_IEC61966_2_1,  TRANSFER_FUNC_IEC61966_2_1},
+    { HXXX_TRANSFER_BT2020_V14,    TRANSFER_FUNC_BT2020_V14  },
+    { HXXX_TRANSFER_BT2020_V15,    TRANSFER_FUNC_BT2020_V15  },
+    { HXXX_TRANSFER_SMPTE_ST_2084, TRANSFER_FUNC_SMPTE_ST2084},
+    { HXXX_TRANSFER_SMPTE_ST_428,  TRANSFER_FUNC_SMPTE_ST428 },
+};
+
 static inline video_transfer_func_t
 hxxx_transfer_characteristics_to_vlc( enum hxxx_transfer_characteristics i_transfer )
 {
-    switch( i_transfer )
+    for( unsigned i=0; i<ARRAY_SIZE(hxxx_transfer_characteristics_mapping); i++ )
     {
-    case HXXX_TRANSFER_LINEAR:
-        return TRANSFER_FUNC_LINEAR;
-
-    case HXXX_TRANSFER_BT470M:
-        return TRANSFER_FUNC_SRGB;
-
-    case HXXX_TRANSFER_BT709:
-    case HXXX_TRANSFER_BT601_525:
-    case HXXX_TRANSFER_BT2020_V14:
-    case HXXX_TRANSFER_BT2020_V15:
-        return TRANSFER_FUNC_BT709;
-
-    case HXXX_TRANSFER_SMPTE_ST_2084:
-        return TRANSFER_FUNC_SMPTE_ST2084;
-
-    case HXXX_TRANSFER_RESERVED0:
-    case HXXX_TRANSFER_UNSPECIFIED:
-    case HXXX_TRANSFER_RESERVED3:
-    case HXXX_TRANSFER_BT470BG:
-    case HXXX_TRANSFER_SMTPE_240M:
-    case HXXX_TRANSFER_LOG:
-    case HXXX_TRANSFER_LOG_SQRT:
-    case HXXX_TRANSFER_IEC61966_2_4:
-    case HXXX_TRANSFER_BT1361:
-    case HXXX_TRANSFER_IEC61966_2_1:
-    case HXXX_TRANSFER_SMPTE_ST_428:
-    default:
-        return TRANSFER_FUNC_UNDEF;
-    };
+        if( hxxx_transfer_characteristics_mapping[i].i_hxxx_val == i_transfer )
+            return hxxx_transfer_characteristics_mapping[i].i_vlc_val;
+    }
+    return TRANSFER_FUNC_UNDEF;
 }
 
 /* Annex E: Matrix coefficients */
@@ -147,31 +141,31 @@ enum hxxx_matrix_coeffs
     HXXX_MATRIX_BT2020_CL           = 10,
 };
 
+static const struct
+{
+    enum hxxx_matrix_coeffs i_hxxx_val;
+    video_color_space_t i_vlc_val;
+} hxxx_matrix_coeffs_mapping[] = {
+    { HXXX_MATRIX_IDENTITY,      COLOR_SPACE_RGB        },
+    { HXXX_MATRIX_BT709,         COLOR_SPACE_BT709      },
+    { HXXX_MATRIX_FCC,           COLOR_SPACE_FCC        },
+    { HXXX_MATRIX_BT470BG,       COLOR_SPACE_BT470BG    },
+    { HXXX_MATRIX_BT601_525,     COLOR_SPACE_BT601_525  },
+    { HXXX_MATRIX_SMTPE_240M,    COLOR_SPACE_SMPTE_240M },
+    { HXXX_MATRIX_YCGCO,         COLOR_SPACE_YCGCO      },
+    { HXXX_MATRIX_BT2020_NCL,    COLOR_SPACE_BT2020_NCL },
+    { HXXX_MATRIX_BT2020_CL,     COLOR_SPACE_BT2020_CL  },
+};
+
 static inline video_color_space_t
-hxxx_matrix_coeffs_to_vlc( enum hxxx_matrix_coeffs i_transfer )
+hxxx_matrix_coeffs_to_vlc( enum hxxx_matrix_coeffs i_matrix )
 {
-    switch( i_transfer )
+    for( unsigned i=0; i<ARRAY_SIZE(hxxx_matrix_coeffs_mapping); i++ )
     {
-    case HXXX_MATRIX_BT470BG:
-    case HXXX_MATRIX_BT601_525:
-        return COLOR_SPACE_BT601;
-
-    case HXXX_MATRIX_BT709:
-        return COLOR_SPACE_BT709;
-
-    case HXXX_MATRIX_BT2020_NCL:
-    case HXXX_MATRIX_BT2020_CL:
-        return COLOR_SPACE_BT2020;
-
-    case HXXX_MATRIX_IDENTITY:
-    case HXXX_MATRIX_UNSPECIFIED:
-    case HXXX_MATRIX_RESERVED:
-    case HXXX_MATRIX_FCC:
-    case HXXX_MATRIX_SMTPE_240M:
-    case HXXX_MATRIX_YCGCO:
-    default:
-        return COLOR_SPACE_UNDEF;
+        if( hxxx_matrix_coeffs_mapping[i].i_hxxx_val == i_matrix )
+            return hxxx_matrix_coeffs_mapping[i].i_vlc_val;
     }
+    return COLOR_SPACE_UNDEF;
 }
 
 /* strips any AnnexB startcode [0] 0 0 1 */
diff --git a/modules/packetizer/mpegvideo.c b/modules/packetizer/mpegvideo.c
index fc205d7..d905bd6 100644
--- a/modules/packetizer/mpegvideo.c
+++ b/modules/packetizer/mpegvideo.c
@@ -691,7 +691,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
                         break;
                     case 5: /* BT.470BG */
                     case 6: /* SMPTE 170 M */
-                        p_dec->fmt_out.video.space = COLOR_SPACE_BT601;
+                        p_dec->fmt_out.video.space = COLOR_SPACE_BT601_525;
                         break;
                     default:
                         break;
diff --git a/modules/packetizer/vc1.c b/modules/packetizer/vc1.c
index fab961b..d562b49 100644
--- a/modules/packetizer/vc1.c
+++ b/modules/packetizer/vc1.c
@@ -600,8 +600,8 @@ static block_t *ParseIDU( decoder_t *p_dec, bool *pb_ts_used, block_t *p_frag )
                 switch( bs_read( &s, 8 ) ) /* Matrix Coef */
                 {
                     case 1:  p_es->video.space = COLOR_SPACE_BT709; break;
-                    case 6:  p_es->video.space = COLOR_SPACE_BT601; break;
-                    case 7:  p_es->video.space = COLOR_SPACE_SMPTE_240; break;
+                    case 6:  p_es->video.space = COLOR_SPACE_BT601_525; break;
+                    case 7:  p_es->video.space = COLOR_SPACE_SMPTE_240M; break;
                     default: p_es->video.space = COLOR_SPACE_UNDEF; break;
                 }
             }
diff --git a/modules/video_output/xcb/xvideo.c b/modules/video_output/xcb/xvideo.c
index 14c245c..1c497a6 100644
--- a/modules/video_output/xcb/xvideo.c
+++ b/modules/video_output/xcb/xvideo.c
@@ -532,7 +532,7 @@ static int Open (vlc_object_t *obj)
     }
 
     /* Colour space */
-    fmt.space = COLOR_SPACE_BT601;
+    fmt.space = COLOR_SPACE_BT601_525;
     {
         xcb_intern_atom_reply_t *r =
             xcb_intern_atom_reply (conn,
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 2efecd4..ffa56f2 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -3042,12 +3042,15 @@ 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.470 M",
+                N_("ITU-R BT.601 (625 lines, 50 Hz)"),
+                N_("ITU-R BT.601 (525 lines, 60 Hz)"),
                "ITU-R BT.2020",
                "DCI/P3 D65",
-               "ITU-R BT.470 M",
+               "SMPTE ST428-1",
+               "SMPTE ST431",
+               "SMPTE ST432",
            };
            if( fmt->video.primaries < ARRAY_SIZE(primaries_names) )
                 info_category_AddInfo( p_cat, _("Color primaries"), "%s",
@@ -3057,12 +3060,22 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
        {
            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",
+               "ITU-R BT.709",
+                "ITU-R BT.470 M",
+                "ITU-R BT.470 BG",
+                "ITU-R BT.601",
+                "SMPTE 240M",
+                "sRGB",
+                "Logarithmic",
+                "Logarithmic sqrt(10)",
+                "IEC61966 2.4",
+                "ITU-R BT.1361",
+                "IEC61966 2.1",
+                "ITU-R BT.2020 V14",
+                "ITU-R BT.2020 V15",
+                "SMPTE ST2084",
+                "SMPTE ST428",
+                "ARIB STD B67",
            };
            if( fmt->video.transfer < ARRAY_SIZE(func_names) )
                 info_category_AddInfo( p_cat, _("Color transfer function"), "%s",
@@ -3071,9 +3084,16 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
        if( fmt->video.space != COLOR_SPACE_UNDEF )
        {
            static const char *space_names[] = { N_("Undefined"),
-               "ITU-R BT.601",
+               "RGB",
                "ITU-R BT.709",
-               "ITU-R BT.2020",
+               "FCC",
+               N_("ITU-R BT.601 (625 lines, 50 Hz)"),
+               N_("ITU-R BT.601 (525 lines, 60 Hz)"),
+               "SMPTE 240M",
+               "YCGCO",
+               "ITU-R BT.2020 NCL",
+               "ITU-R BT.2020 CL",
+               "SMPTE ST2085",
            };
            static const char *range_names[] = {
                N_("Limited Range"),
-- 
2.7.4



More information about the vlc-devel mailing list