From c5d69bd0149f61ff4389007afab3a278609a1afd Mon Sep 17 00:00:00 2001 From: Ke Gong Date: Thu, 23 Nov 2017 00:50:45 +0000 Subject: caption: fixed caption decoder [1/1] PD #145949 Change-Id: Ibeb3f7b345a876f03d9c504757a32b9f7ac4b4f3 --- diff --git a/src/caption.c b/src/caption.c index 3d7508c..040a658 100644 --- a/src/caption.c +++ b/src/caption.c @@ -908,7 +908,7 @@ erase_memory(struct caption *cc, cc_channel *ch, int page) { vbi_page *pg = ch->pg + page; vbi_char *acp = pg->text; - memset(pg->text, 0, 1056*sizeof(vbi_char)); + memset(pg->text, 0, sizeof(pg->text)); #if 0 //vbi_char c = cc->transp_space[ch >= &cc->channel[4]]; vbi_char c = {0}; @@ -980,6 +980,7 @@ caption_command(vbi_decoder *vbi, struct caption *cc, set_cursor(ch, 1, row); if (c2 & 0x10) { + /* col = ch->col; for (i = (c2 & 14) * 2; i > 0 && col < COLUMNS - 1; i--) @@ -987,6 +988,9 @@ caption_command(vbi_decoder *vbi, struct caption *cc, if (col > ch->col) ch->col = ch->col1 = col; + */ + + ch->col = (c2 & 14) * 2 + 1; ch->attr.italic = FALSE; ch->attr.foreground = VBI_WHITE; @@ -1054,6 +1058,19 @@ caption_command(vbi_decoder *vbi, struct caption *cc, case 2: /* Optional Extended Characters 001 c01f 01x xxxx */ case 3: /* Send specs to the maintainer of this code */ + { + vbi_char c; + + c = ch->attr; + c.unicode = vbi_caption_unicode((c1 << 8) | c2 | 0x1000, 0); + + if (c.unicode) { + if (ch->col > 1) + ch->col --; + + put_char(cc, ch, c); + } + } return; case 4: /* Misc Control Codes 001 c10f 010 xxxx */ @@ -1143,8 +1160,10 @@ caption_command(vbi_decoder *vbi, struct caption *cc, // not verified if (ch->mode) { if (ch->col > 1) { + if (ch->line[ch->col - 1].unicode == 0) + return; ch->col --; - } else if (ch->row > 1) { + } else if (ch->row > 0) { vbi_char *acp; ch->row --; @@ -1153,9 +1172,9 @@ caption_command(vbi_decoder *vbi, struct caption *cc, ch->col = COLUMNS - 1; acp = ch->line + COLUMNS - 1; - while (ch->col > 0) { + while (ch->col > 1) { if (acp->unicode != 0) - break; + break; acp --; ch->col --; @@ -1194,13 +1213,12 @@ caption_command(vbi_decoder *vbi, struct caption *cc, word_break(cc, ch, 1); ch->update = 1; - if (ch->mode == MODE_ROLL_UP) - { - memmove(acp, acp + COLUMNS, sizeof(*acp) * (ch->roll - 1) * COLUMNS); - - for (i = 0; i <= COLUMNS; i++) - ch->line[i] = cc->transp_space[chan >> 2]; - } + if (ch->mode == MODE_ROLL_UP) { + memmove(acp, acp + COLUMNS, sizeof(*acp) * (ch->roll - 1) * COLUMNS); + for (i = 0; i <= COLUMNS; i++) { + memset(&ch->line[i], 0, sizeof(vbi_char)); + } + } if (ch->mode != MODE_POP_ON) { ch->update = 1; @@ -1217,8 +1235,9 @@ caption_command(vbi_decoder *vbi, struct caption *cc, if (!ch->mode) return; - for (i = ch->col; i <= COLUMNS - 1; i++) - ch->line[i] = cc->transp_space[chan >> 2]; + for (i = ch->col; i <= COLUMNS - 1; i++) { + memset(&ch->line[i], 0, sizeof(vbi_char)); + } word_break(cc, ch, 0); @@ -1227,6 +1246,7 @@ caption_command(vbi_decoder *vbi, struct caption *cc, render(ch->pg + (ch->hidden ^ 1), ch->row); } + ch->update = 1; return; case 12: /* Erase Displayed Memory 001 c10f 010 1100 */ @@ -1253,12 +1273,16 @@ caption_command(vbi_decoder *vbi, struct caption *cc, clear(ch->pg + (ch->hidden ^ 1)); } + ch->update = 1; return; case 14: /* Erase Non-Displayed Memory 001 c10f 010 1110 */ // not verified if (ch->mode == MODE_POP_ON) erase_memory(cc, ch, ch->hidden); + erase_memory(cc, ch, ch->hidden ^ 1); + + ch->update = 1; return; } @@ -1273,13 +1297,18 @@ caption_command(vbi_decoder *vbi, struct caption *cc, switch (c2) { case 0x21 ... 0x23: /* Misc Control Codes, Tabs 001 c111 010 00xx */ // not verified + /* col = ch->col; for (i = c2 & 3; i > 0 && col < COLUMNS - 1; i--) ch->line[col++] = cc->transp_space[chan >> 2]; if (col > ch->col) - ch->col = ch->col1 = col; + ch->col = ch->col1 = col;*/ + + ch->col += (c2 & 3); + if (ch->col >= COLUMNS) + ch->col = COLUMNS - 1; return; @@ -1391,15 +1420,15 @@ vbi_decode_caption(vbi_decoder *vbi, int line, uint8_t *buf) vbi_char c; case 0x01 ... 0x0F: - if (!field2) + /*if (!field2)*/ cc->last[0] = 0; break; /* XDS field 1?? */ case 0x10 ... 0x1F: //if ( (buf[1]) >= 0) { // vbi_unpar8 (buf[1]) if ( vbi_unpar8 (buf[1]) >= 0) { - if (!field2 - && buf[0] == cc->last[0] + if (/*!field2 + &&*/ buf[0] == cc->last[0] && buf[1] == cc->last[1]) { /* cmd repetition F1: already executed */ cc->last[0] = 0; /* one rep */ @@ -1408,11 +1437,11 @@ vbi_decode_caption(vbi_decoder *vbi, int line, uint8_t *buf) caption_command(vbi, cc, c1, buf[1] & 0x7F, field2); - if (!field2) { + /*if (!field2)*/ { cc->last[0] = buf[0]; cc->last[1] = buf[1]; } - } else if (!field2) + } else /*if (!field2)*/ cc->last[0] = 0; break; @@ -1440,7 +1469,7 @@ vbi_decode_caption(vbi_decoder *vbi, int line, uint8_t *buf) break; } - if (!field2) + /*if (!field2)*/ cc->last[0] = 0; ch->nul_ct = 0; -- cgit