From 0d8a3656ba4c0ae8e4e0c91ff6b07d72a317f9f6 Mon Sep 17 00:00:00 2001 From: Vittorio Giovara Date: Thu, 2 Oct 2014 14:28:35 +0100 Subject: [PATCH] mov: support the Color Parameter Atoms 'colr' --- libavformat/mov.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 3734689fd1..d4281dc90d 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -887,6 +887,74 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + char color_parameter_type[5] = { 0 }; + int color_primaries, color_trc, color_matrix; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams - 1]; + + avio_read(pb, color_parameter_type, 4); + if (strncmp(color_parameter_type, "nclx", 4) && + strncmp(color_parameter_type, "nclc", 4)) { + av_log(c->fc, AV_LOG_WARNING, "unsupported color_parameter_type %s\n", + color_parameter_type); + return 0; + } + + color_primaries = avio_rb16(pb); + color_trc = avio_rb16(pb); + color_matrix = avio_rb16(pb); + + av_dlog(c->fc, "%s: pri %"PRIu16" trc %"PRIu16" matrix %"PRIu16"", + color_parameter_type, color_primaries, color_trc, color_matrix); + + if (c->isom) { + uint8_t color_range = avio_r8(pb) >> 7; + av_dlog(c->fc, " full %"PRIu8"", color_range) + if (color_range) + st->codec->color_range = AVCOL_RANGE_JPEG; + else + st->codec->color_range = AVCOL_RANGE_MPEG; + /* 14496-12 references JPEG XR specs (rather than the more complete + * 23001-8) so some adjusting is required */ + if (color_primaries >= AVCOL_PRI_FILM) + color_primaries = AVCOL_PRI_UNSPECIFIED; + if (color_trc >= AVCOL_TRC_LINEAR || color_trc <= AVCOL_TRC_LOG_SQRT || + color_trc >= AVCOL_TRC_BT2020_10) + color_trc = AVCOL_TRC_UNSPECIFIED; + if (color_matrix >= AVCOL_SPC_BT2020_NCL) + color_matrix = AVCOL_SPC_UNSPECIFIED; + st->codec->color_primaries = color_primaries; + st->codec->color_trc = color_trc; + st->codec->colorspace = color_matrix; + } else { + /* color primaries, Table 4-4 */ + switch (color_primaries) { + case 1: st->codec->color_primaries = AVCOL_PRI_BT709; break; + case 5: st->codec->color_primaries = AVCOL_PRI_SMPTE170M; break; + case 6: st->codec->color_primaries = AVCOL_PRI_SMPTE240M; break; + } + /* color transfer, Table 4-5 */ + switch (color_trc) { + case 1: st->codec->color_trc = AVCOL_TRC_BT709; break; + case 7: st->codec->color_trc = AVCOL_TRC_SMPTE240M; break; + } + /* color matrix, Table 4-6 */ + switch (color_matrix) { + case 1: st->codec->colorspace = AVCOL_SPC_BT709; break; + case 6: st->codec->colorspace = AVCOL_SPC_BT470BG; break; + case 7: st->codec->colorspace = AVCOL_SPC_SMPTE240M; break; + } + } + av_dlog(c->fc, "\n") + + return 0; +} + static int mov_read_fiel(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; @@ -2765,6 +2833,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('a','v','s','s'), mov_read_extradata }, { MKTAG('c','h','p','l'), mov_read_chpl }, { MKTAG('c','o','6','4'), mov_read_stco }, +{ MKTAG('c','o','l','r'), mov_read_colr }, { MKTAG('c','t','t','s'), mov_read_ctts }, /* composition time to sample */ { MKTAG('d','i','n','f'), mov_read_default }, { MKTAG('d','r','e','f'), mov_read_dref },