},
};
+static const unsigned char bg_attribs[8] = // Color
+{
+ CCCOL_WHITE,
+ CCCOL_GREEN,
+ CCCOL_BLUE,
+ CCCOL_CYAN,
+ CCCOL_RED,
+ CCCOL_YELLOW,
+ CCCOL_MAGENTA,
+ CCCOL_BLACK,
+};
+
static const unsigned char pac2_attribs[32][3] = // Color, font, ident
{
{ CCCOL_WHITE, CCFONT_REGULAR, 0 }, // 0x40 || 0x60
uint8_t characters[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
uint8_t charsets[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
uint8_t colors[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
+ uint8_t bgs[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
uint8_t fonts[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
/*
* Bitmask of used rows; if a bit is not set, the
uint8_t cursor_row;
uint8_t cursor_column;
uint8_t cursor_color;
+ uint8_t bg_color;
uint8_t cursor_font;
uint8_t cursor_charset;
AVBPrint buffer[2];
int64_t buffer_time[2];
int screen_touched;
int64_t last_real_time;
- char prev_cmd[2];
+ uint8_t prev_cmd[2];
int readorder;
} CCaptionSubContext;
av_bprint_init(&ctx->buffer[1], 0, AV_BPRINT_SIZE_UNLIMITED);
/* taking by default roll up to 2 */
ctx->mode = CCMODE_ROLLUP;
+ ctx->bg_color = CCCOL_BLACK;
ctx->rollup = 2;
ctx->cursor_row = 10;
ret = ff_ass_subtitle_header(avctx, "Monospace",
ctx->cursor_column = 0;
ctx->cursor_font = 0;
ctx->cursor_color = 0;
+ ctx->bg_color = CCCOL_BLACK;
ctx->cursor_charset = 0;
ctx->active_screen = 0;
ctx->last_real_time = 0;
char *row = screen->characters[ctx->cursor_row];
char *font = screen->fonts[ctx->cursor_row];
char *color = screen->colors[ctx->cursor_row];
+ char *bg = screen->bgs[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;
+ bg[col] = ctx->bg_color;
charset[col] = ctx->cursor_charset;
ctx->cursor_charset = CCSET_BASIC_AMERICAN;
if (ch) ctx->cursor_column++;
* If the second byte doesn't pass parity, it returns INVALIDDATA
* user can ignore the whole pair and pass the other pair.
*/
-static int validate_cc_data_pair(uint8_t *cc_data_pair)
+static int validate_cc_data_pair(const uint8_t *cc_data_pair, uint8_t *hi)
{
uint8_t cc_valid = (*cc_data_pair & 4) >>2;
uint8_t cc_type = *cc_data_pair & 3;
+ *hi = cc_data_pair[1];
+
if (!cc_valid)
return AVERROR_INVALIDDATA;
return AVERROR_INVALIDDATA;
}
if (!av_parity(cc_data_pair[1])) {
- cc_data_pair[1]=0x7F;
+ *hi = 0x7F;
}
}
memcpy(screen->characters[i_row], screen->characters[i_row+1], SCREEN_COLUMNS);
memcpy(screen->colors[i_row], screen->colors[i_row+1], SCREEN_COLUMNS);
+ memcpy(screen->bgs[i_row], screen->bgs[i_row+1], SCREEN_COLUMNS);
memcpy(screen->fonts[i_row], screen->fonts[i_row+1], SCREEN_COLUMNS);
memcpy(screen->charsets[i_row], screen->charsets[i_row+1], SCREEN_COLUMNS);
if (CHECK_FLAG(screen->row_used, i_row + 1))
struct Screen *screen = ctx->screen + ctx->active_screen;
enum cc_font prev_font = CCFONT_REGULAR;
enum cc_color_code prev_color = CCCOL_WHITE;
+ enum cc_color_code prev_bg_color = CCCOL_BLACK;
const int bidx = ctx->buffer_index;
av_bprint_clear(&ctx->buffer[bidx]);
if (CHECK_FLAG(screen->row_used, i)) {
const char *row = screen->characters[i];
const char *font = screen->fonts[i];
+ const char *bg = screen->bgs[i];
const char *color = screen->colors[i];
const char *charset = screen->charsets[i];
const char *override;
av_bprintf(&ctx->buffer[bidx], "{\\an7}{\\pos(%d,%d)}", x, y);
for (; j < SCREEN_COLUMNS; j++) {
- const char *e_tag = "", *s_tag = "", *c_tag = "";
+ const char *e_tag = "", *s_tag = "", *c_tag = "", *b_tag = "";
if (row[j] == 0)
break;
break;
}
}
+ if (prev_bg_color != bg[j]) {
+ switch (bg[j]) {
+ case CCCOL_WHITE:
+ b_tag = "{\\3c&HFFFFFF&}";
+ break;
+ case CCCOL_GREEN:
+ b_tag = "{\\3c&H00FF00&}";
+ break;
+ case CCCOL_BLUE:
+ b_tag = "{\\3c&HFF0000&}";
+ break;
+ case CCCOL_CYAN:
+ b_tag = "{\\3c&HFFFF00&}";
+ break;
+ case CCCOL_RED:
+ b_tag = "{\\3c&H0000FF&}";
+ break;
+ case CCCOL_YELLOW:
+ b_tag = "{\\3c&H00FFFF&}";
+ break;
+ case CCCOL_MAGENTA:
+ b_tag = "{\\3c&HFF00FF&}";
+ break;
+ case CCCOL_BLACK:
+ b_tag = "{\\3c&H000000&}";
+ break;
+ }
+ }
prev_font = font[j];
prev_color = color[j];
+ prev_bg_color = bg[j];
override = charset_overrides[(int)charset[j]][(int)row[j]];
if (override) {
- av_bprintf(&ctx->buffer[bidx], "%s%s%s%s", e_tag, s_tag, c_tag, override);
+ av_bprintf(&ctx->buffer[bidx], "%s%s%s%s%s", e_tag, s_tag, c_tag, b_tag, override);
seen_char = 1;
} else if (row[j] == ' ' && !seen_char) {
- av_bprintf(&ctx->buffer[bidx], "%s%s%s\\h", e_tag, s_tag, c_tag);
+ av_bprintf(&ctx->buffer[bidx], "%s%s%s%s\\h", e_tag, s_tag, c_tag, b_tag);
} else {
- av_bprintf(&ctx->buffer[bidx], "%s%s%s%c", e_tag, s_tag, c_tag, row[j]);
+ av_bprintf(&ctx->buffer[bidx], "%s%s%s%s%c", e_tag, s_tag, c_tag, b_tag, row[j]);
seen_char = 1;
}
ctx->buffer_time[1] = pts;
}
+static void handle_bgattr(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
+{
+ const int i = (lo & 0xf) >> 1;
+
+ ctx->bg_color = bg_attribs[i];
+}
+
static void handle_textattr(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
{
int i = lo - 0x20;
ret = capture_screen(ctx);
screen->row_used = 0;
+ ctx->bg_color = CCCOL_BLACK;
// In realtime mode, emit an empty caption so the last one doesn't
// stay on the screen.
} else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
handle_textattr(ctx, hi, lo);
+ } else if ((hi == 0x10 && lo >= 0x20 && lo <= 0x2f)) {
+ handle_bgattr(ctx, hi, lo);
} else if (hi == 0x14 || hi == 0x15 || hi == 0x1c) {
switch (lo) {
case 0x20:
int64_t start_time;
int64_t end_time;
int bidx = ctx->buffer_index;
- uint8_t *bptr = NULL;
+ const uint8_t *bptr = avpkt->data;
int len = avpkt->size;
int ret = 0;
int i;
- bptr = avpkt->data;
-
for (i = 0; i < len; i += 3) {
- uint8_t cc_type = bptr[i] & 1;
+ uint8_t hi, cc_type = bptr[i] & 1;
if (ctx->data_field < 0)
ctx->data_field = cc_type;
- if (validate_cc_data_pair(bptr + i))
+ if (validate_cc_data_pair(bptr + i, &hi))
continue;
if (cc_type != ctx->data_field)
continue;
- ret = process_cc608(ctx, bptr[i + 1] & 0x7f, bptr[i + 2] & 0x7f);
+ ret = process_cc608(ctx, hi & 0x7f, bptr[i + 2] & 0x7f);
if (ret < 0)
return ret;
.version = LIBAVUTIL_VERSION_INT,
};
-AVCodec ff_ccaption_decoder = {
+const AVCodec ff_ccaption_decoder = {
.name = "cc_dec",
.long_name = NULL_IF_CONFIG_SMALL("Closed Caption (EIA-608 / CEA-708)"),
.type = AVMEDIA_TYPE_SUBTITLE,