diff options
author | Paul B Mahol <onemda@gmail.com> | 2020-06-14 12:39:31 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2020-06-15 19:27:20 +0200 |
commit | cb98483ea081c0ea7949a75f9776703f395f8e8d (patch) | |
tree | 54fbc0d82b3cce2bb834d20b6d2907d78b2dd4f7 /libavcodec | |
parent | ff3fad6b0edb13dd664403b01bc00309f035b110 (diff) | |
download | ffmpeg-cb98483ea081c0ea7949a75f9776703f395f8e8d.tar.gz |
avcodec/ccaption_dec: add support for colors
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/ccaption_dec.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c index 936e2db27f..a953181e53 100644 --- a/libavcodec/ccaption_dec.c +++ b/libavcodec/ccaption_dec.c @@ -32,10 +32,6 @@ static const AVRational ms_tb = {1, 1000}; -/* - * TODO list - * 1) handle font and color completely - */ enum cc_mode { CCMODE_POPON, CCMODE_PAINTON, @@ -319,11 +315,13 @@ static void write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch) uint8_t col = ctx->cursor_column; char *row = screen->characters[ctx->cursor_row]; char *font = screen->fonts[ctx->cursor_row]; + char *color = screen->colors[ctx->cursor_row]; char *charset = screen->charsets[ctx->cursor_row]; if (col < SCREEN_COLUMNS) { row[col] = ch; font[col] = ctx->cursor_font; + color[col] = ctx->cursor_color; charset[col] = ctx->cursor_charset; ctx->cursor_charset = CCSET_BASIC_AMERICAN; if (ch) ctx->cursor_column++; @@ -437,6 +435,7 @@ static int capture_screen(CCaptionSubContext *ctx) int i, j, tab = 0; struct Screen *screen = ctx->screen + ctx->active_screen; enum cc_font prev_font = CCFONT_REGULAR; + enum cc_color_code prev_color = CCCOL_WHITE; av_bprint_clear(&ctx->buffer); for (i = 0; screen->row_used && i < SCREEN_ROWS; i++) @@ -457,6 +456,7 @@ static int capture_screen(CCaptionSubContext *ctx) if (CHECK_FLAG(screen->row_used, i)) { const char *row = screen->characters[i]; const char *font = screen->fonts[i]; + const char *color = screen->colors[i]; const char *charset = screen->charsets[i]; const char *override; int x, y, seen_char = 0; @@ -471,7 +471,7 @@ static int capture_screen(CCaptionSubContext *ctx) av_bprintf(&ctx->buffer, "{\\an7}{\\pos(%d,%d)}", x, y); for (; j < SCREEN_COLUMNS; j++) { - const char *e_tag = "", *s_tag = ""; + const char *e_tag = "", *s_tag = "", *c_tag = ""; if (row[j] == 0) break; @@ -500,15 +500,42 @@ static int capture_screen(CCaptionSubContext *ctx) break; } } + if (prev_color != color[j]) { + switch (color[j]) { + case CCCOL_WHITE: + c_tag = "{\\c&HFFFFFF&}"; + break; + case CCCOL_GREEN: + c_tag = "{\\c&H00FF00&}"; + break; + case CCCOL_BLUE: + c_tag = "{\\c&HFF0000&}"; + break; + case CCCOL_CYAN: + c_tag = "{\\c&HFFFF00&}"; + break; + case CCCOL_RED: + c_tag = "{\\c&H0000FF&}"; + break; + case CCCOL_YELLOW: + c_tag = "{\\c&H00FFFF&}"; + break; + case CCCOL_MAGENTA: + c_tag = "{\\c&HFF00FF&}"; + break; + } + } + prev_font = font[j]; + prev_color = color[j]; override = charset_overrides[(int)charset[j]][(int)row[j]]; if (override) { - av_bprintf(&ctx->buffer, "%s%s%s", e_tag, s_tag, override); + av_bprintf(&ctx->buffer, "%s%s%s%s", e_tag, s_tag, c_tag, override); seen_char = 1; } else if (row[j] == ' ' && !seen_char) { - av_bprintf(&ctx->buffer, "%s%s\\h", e_tag, s_tag); + av_bprintf(&ctx->buffer, "%s%s%s\\h", e_tag, s_tag, c_tag); } else { - av_bprintf(&ctx->buffer, "%s%s%c", e_tag, s_tag, row[j]); + av_bprintf(&ctx->buffer, "%s%s%s%c", e_tag, s_tag, c_tag, row[j]); seen_char = 1; } |