diff options
author | Oleg Oshmyan <chortos@inbox.lv> | 2013-02-01 23:35:02 +0000 |
---|---|---|
committer | Grigori Goronzy <greg@blackbox> | 2013-03-03 23:17:53 +0100 |
commit | 1ae86d2390b3e64b5f6574fa1628461bc403ae14 (patch) | |
tree | 9027365853409126cb33d4c64dd907718819219e /libass/ass_utils.c | |
parent | 0e1702ad7a6a827d400c87b7a98aea11e54d2127 (diff) | |
download | libass-1ae86d2390b3e64b5f6574fa1628461bc403ae14.tar.bz2 libass-1ae86d2390b3e64b5f6574fa1628461bc403ae14.tar.xz |
Support reading the YCbCr Matrix header
The value is parsed and stored as an enum constant that the consumer
can read from ASS_Track. All output images are still plain RGB,
and the consumer is expected to perform its own color correction.
Supported header values: (TV|PC).(601|709|240M|FCC) and None.
If the header is missing, a special compatibility value is used
that should be treated as TV.601 if the accompanying video stream
is YCbCr and as None otherwise. If the header is present but has
an invalid/unknown value, a different special value is substituted.
Diffstat (limited to 'libass/ass_utils.c')
-rw-r--r-- | libass/ass_utils.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/libass/ass_utils.c b/libass/ass_utils.c index 222e99a..df7c447 100644 --- a/libass/ass_utils.c +++ b/libass/ass_utils.c @@ -122,6 +122,46 @@ char parse_bool(char *str) return 0; } +int parse_ycbcr_matrix(char *str) +{ + while (*str == ' ' || *str == '\t') + str++; + if (*str == '\0') + return YCBCR_DEFAULT; + + char *end = str + strlen(str); + while (end[-1] == ' ' || end[-1] == '\t') + end--; + + // Trim a local copy of the input that we know is safe to + // modify. The buffer is larger than any valid string + NUL, + // so we can simply chop off the rest of the input. + char buffer[16]; + size_t n = FFMIN(end - str, sizeof buffer - 1); + strncpy(buffer, str, n); + buffer[n] = '\0'; + + if (!strcasecmp(buffer, "none")) + return YCBCR_NONE; + if (!strcasecmp(buffer, "tv.601")) + return YCBCR_BT601_TV; + if (!strcasecmp(buffer, "pc.601")) + return YCBCR_BT601_PC; + if (!strcasecmp(buffer, "tv.709")) + return YCBCR_BT709_TV; + if (!strcasecmp(buffer, "pc.709")) + return YCBCR_BT709_PC; + if (!strcasecmp(buffer, "tv.240m")) + return YCBCR_SMPTE240M_TV; + if (!strcasecmp(buffer, "pc.240m")) + return YCBCR_SMPTE240M_PC; + if (!strcasecmp(buffer, "tv.fcc")) + return YCBCR_FCC_TV; + if (!strcasecmp(buffer, "pc.fcc")) + return YCBCR_FCC_PC; + return YCBCR_UNKNOWN; +} + void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...) { va_list va; |