29 #define TEXT_MAXSZ (25 * (56 + 1) * 4 + 2)
30 #define VBI_NB_COLORS 40
31 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
32 #define VBI_R(rgba) (((rgba) >> 0) & 0xFF)
33 #define VBI_G(rgba) (((rgba) >> 8) & 0xFF)
34 #define VBI_B(rgba) (((rgba) >> 16) & 0xFF)
35 #define VBI_A(rgba) (((rgba) >> 24) & 0xFF)
36 #define MAX_BUFFERED_PAGES 25
37 #define BITMAP_CHAR_WIDTH 12
38 #define BITMAP_CHAR_HEIGHT 10
78 if (*--t !=
' ' || (len-1 > 0 && *(t-1) & 0x80))
87 av_freep(&(*sub_rect)->pict.data[0]);
88 av_freep(&(*sub_rect)->pict.data[1]);
136 sz = vbi_print_page_region(page, vbi_text,
TEXT_MAXSZ-1,
"UTF-8",
139 page->columns, page->rows-chop_top);
154 in += strspn(in,
" \n");
156 for (nl = 0; in[nl]; ++nl)
157 if (in[nl] ==
'\n' && (nl==0 || !(in[nl-1] & 0x80)))
193 int chop_top,
uint8_t transparent_color,
int resx,
int resy)
198 for (iy = 0; iy < resy; iy++) {
201 vbi_char *vcnext = vc + page->columns;
202 for (; vc < vcnext; vc++) {
204 switch (vc->opacity) {
205 case VBI_TRANSPARENT_SPACE:
206 memset(pixel, transparent_color, BITMAP_CHAR_WIDTH);
209 case VBI_SEMI_TRANSPARENT:
212 case VBI_TRANSPARENT_FULL:
213 for(; pixel < pixelnext; pixel++)
214 if (*pixel == vc->background)
215 *pixel = transparent_color;
230 vbi_char *vc = page->text + (chop_top * page->columns);
231 vbi_char *vcend = page->text + (page->rows * page->columns);
233 for (; vc < vcend; vc++) {
234 if (vc->opacity != VBI_TRANSPARENT_SPACE) {
251 vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,
253 0, chop_top, page->columns, page->rows - chop_top,
267 for (ci = 0; ci < cmax; ci++) {
270 r =
VBI_R(page->color_map[ci]);
271 g =
VBI_G(page->color_map[ci]);
272 b =
VBI_B(page->color_map[ci]);
273 a =
VBI_A(page->color_map[ci]);
274 ((uint32_t *)sub_rect->
pict.
data[1])[ci] =
RGBA(r, g, b, a);
277 ((uint32_t *)sub_rect->
pict.
data[1])[ci]);
280 ((uint32_t *)sub_rect->
pict.
data[1])[cmax] =
RGBA(0, 0, 0, 0);
297 snprintf(pgno_str,
sizeof pgno_str,
"%03x", ev->ev.ttx_page.pgno);
299 pgno_str, ev->ev.ttx_page.subno & 0xFF);
301 if (strcmp(ctx->
pgno,
"*") && !strstr(ctx->
pgno, pgno_str))
306 res = vbi_fetch_vt_page(ctx->
vbi, &page,
307 ev->ev.ttx_page.pgno,
308 ev->ev.ttx_page.subno,
309 VBI_WST_LEVEL_3p5, 25,
TRUE);
315 fprintf(stderr,
"\nSaving res=%d dy0=%d dy1=%d...\n",
316 res, page.dirty.y0, page.dirty.y1);
319 if (!vbi_export_stdio(ctx->ex, stderr, &page))
320 fprintf(stderr,
"failed: %s\n", vbi_export_errstr(ctx->ex));
323 vpt = vbi_classify_page(ctx->
vbi, ev->ev.ttx_page.pgno, &subno, &lang);
325 ((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE));
328 page.columns, page.rows, chop_top);
333 ctx->
pages = new_pages;
336 cur_page->
pgno = ev->ev.ttx_page.pgno;
337 cur_page->
subno = ev->ev.ttx_page.subno;
360 vbi_unref_page(&page);
368 int left = pkt->
size;
369 uint8_t pesheader[45] = {0x00, 0x00, 0x01, 0xbd, 0x00, 0x00, 0x85, 0x80, 0x24, 0x21, 0x00, 0x01, 0x00, 0x01};
370 int pesheader_size =
sizeof(pesheader);
371 const uint8_t *pesheader_buf = pesheader;
375 if (!(ctx->
vbi = vbi_decoder_new()))
377 if (!vbi_event_handler_add(ctx->
vbi, VBI_EVENT_TTX_PAGE,
handler, ctx)) {
378 vbi_decoder_delete(ctx->
vbi);
383 if (!ctx->
dx && (!(ctx->
dx = vbi_dvb_pes_demux_new ( NULL, NULL))))
391 if ((pesheader_size + left) < 184 || (pesheader_size + left) > 65504 || (pesheader_size + left) % 184 != 0)
394 memset(pesheader + 14, 0xff, pesheader_size - 14);
395 AV_WB16(pesheader + 4, left + pesheader_size - 6);
400 vbi_dvb_demux_cor(ctx->
dx, ctx->
sliced, 64, NULL, &pesheader_buf, &pesheader_size);
406 unsigned int lines = vbi_dvb_demux_cor(ctx->
dx, ctx->
sliced, 64, &pts, &buf, &left);
409 "ctx=%p buf_size=%d left=%u lines=%u pts=%f pkt_pts=%f\n",
410 ctx, pkt->
size, left, lines, (
double)pts/90000.0, (
double)pkt->
pts/90000.0);
415 for(i=0; i<lines; ++i)
417 "lines=%d id=%x\n", i, ctx->
sliced[i].id);
419 vbi_decode(ctx->
vbi, ctx->
sliced, lines, (
double)pts/90000.0);
454 for (i = 0; i < ctx->
nb_pages - 1; i++)
469 unsigned int maj,
min, rev;
471 vbi_version(&maj, &min, &rev);
472 if (!(maj > 0 || min > 2 || min == 2 && rev >= 26)) {
489 ctx->ex = vbi_export_new(
"text", &t);
507 vbi_dvb_demux_delete(ctx->
dx);
508 vbi_decoder_delete(ctx->
vbi);
520 #define OFFSET(x) offsetof(TeletextContext, x)
521 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
525 {
"txt_format",
"format of the subtitles (bitmap or text)",
OFFSET(format_id),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD,
"txt_format"},
530 {
"txt_chop_spaces",
"chops leading and trailing spaces from text",
OFFSET(chop_spaces),
AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1,
SD},
531 {
"txt_duration",
"display duration of teletext pages in msecs",
OFFSET(sub_duration),
AV_OPT_TYPE_INT, {.i64 = 30000}, 0, 86400000,
SD},
532 {
"txt_transparent",
"force transparent background of the teletext",
OFFSET(transparent_bg),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD},
544 .
name =
"libzvbi_teletextdec",
554 .priv_class= &teletext_class,