提交 cb98483e 编写于 作者: P Paul B Mahol

avcodec/ccaption_dec: add support for colors

上级 ff3fad6b
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册