Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
create colored teletext subs
no dedicated configuration setting, since if color is not needed/wanted,
~all playback software that support colored subs allow to override it.
And playback software that doesn't support colored subs just will ignore
the font-tags.
  • Loading branch information
cloph authored and perexg committed Oct 14, 2014
1 parent dc5d042 commit cef28a6
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions src/parsers/parser_teletext.c
Expand Up @@ -481,6 +481,19 @@ hebrew_g0[37] = {
/* 0x78 */ 0x05E8, 0x05E9, 0x05EA, 0x20AA, 0x2016, 0x00BE, 0x00F7, 0x25A0
};

static const uint8_t* COLOR_MAP[8] = {
// black (grey for visibility), red, green, yellow, blue, magenta, cyan, white
(uint8_t*) "<font color=\"#888888\">",
(uint8_t*) "<font color=\"#ff0000\">",
(uint8_t*) "<font color=\"#00ff00\">",
(uint8_t*) "<font color=\"#ffff00\">",
(uint8_t*) "<font color=\"#0000ff\">",
(uint8_t*) "<font color=\"#ff00ff\">",
(uint8_t*) "<font color=\"#00ffff\">",
(uint8_t*) "<font color=\"#ffffff\">"
};
static const uint8_t* CLOSE_FONT = (uint8_t*) "</font>";

/**
* cs Teletext character set as listed in ETS 300 706 section 15.
* ss National character subset as listed in section 15, only
Expand Down Expand Up @@ -686,23 +699,45 @@ extract_subtitle(mpegts_service_t *t, elementary_stream_t *st,
tt_mag_t *ttm, int64_t pts)
{
int i, j, start, off = 0;
int k, current_color, is_font_tag_open, use_color_subs = 1;
uint8_t sub[2000];
uint8_t *cset, ch;
int is_box = 0;
uint8_t first = 0;

if ((cset = get_cset((ttm->ttm_charset[0] & ~7) + ttm->ttm_national)) == NULL)
if ((cset = get_cset(ttm->ttm_charset[0])) == NULL)
cset = char_table[0]; /* fallback */

for (i = 0; i < 23; i++) {
is_font_tag_open = 0;
current_color = 7; /* white = default */
start = off;

for (j = 0; j < 40; j++) {
ch = ttm->ttm_page[40 * i + j];

switch(ch) {
case 0 ... 7:
if (use_color_subs) {
if (ch != current_color) {
if (is_font_tag_open) {
for (k = 0; k < 7; k++) {
if (off < sizeof(sub))
sub[off++] = CLOSE_FONT[k];
}
is_font_tag_open = 0;
}
/* no need for font-tag for default-color */
if (ch != 7) {
for (k = 0; k < 22; k++) {
if (off < sizeof(sub))
sub[off++] = COLOR_MAP[ch][k];
}
is_font_tag_open = 1;
}
current_color = ch;
}
}
break;

case 0x0a:
Expand All @@ -716,9 +751,6 @@ extract_subtitle(mpegts_service_t *t, elementary_stream_t *st,
default:
if (ch >= 0x20 && is_box && (start != off || ch > 0x20)) {

if (!first)
first = ch;

uint16_t ucs2 = teletext_to_ucs2(cset[0], cset[2], ch);

/* ucs2 -> utf8 conversion */
Expand All @@ -743,6 +775,13 @@ extract_subtitle(mpegts_service_t *t, elementary_stream_t *st,
}
}
}
if (use_color_subs && is_font_tag_open) {
for (k = 0; k < 7; k++) {
if (off < sizeof(sub))
sub[off++] = CLOSE_FONT[k];
}
is_font_tag_open = 0;
}
if(start != off && off < sizeof(sub))
sub[off++] = '\n';
}
Expand Down

0 comments on commit cef28a6

Please sign in to comment.