27 #define TEXT_MAXSZ (25 * (56 + 1) * 4 + 2)
28 #define VBI_NB_COLORS 40
29 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
30 #define VBI_R(rgba) (((rgba) >> 0) & 0xFF)
31 #define VBI_G(rgba) (((rgba) >> 8) & 0xFF)
32 #define VBI_B(rgba) (((rgba) >> 16) & 0xFF)
33 #define VBI_A(rgba) (((rgba) >> 24) & 0xFF)
68 if (*--t !=
' ' || (len-1 > 0 && *(t-1) & 0x80))
89 sz = vbi_print_page_region(page, vbi_text,
TEXT_MAXSZ-1,
"UTF-8",
92 page->columns, page->rows-chop_top);
110 in += strspn(in,
" \n");
112 for (nl = 0; in[nl]; ++nl)
113 if (in[nl] ==
'\n' && (nl==0 || !(in[nl-1] & 0x80)))
125 strcpy(text, vbi_text);
133 sub_rect->
text = text;
149 for (iy = 0; iy < resy; iy++) {
151 vbi_char *vc = page->text + (iy / 10 + chop_top) * page->columns;
152 vbi_char *vcnext = vc + page->columns;
153 for (; vc < vcnext; vc++) {
154 uint8_t *pixelnext = pixel + 12;
155 switch (vc->opacity) {
156 case VBI_TRANSPARENT_SPACE:
157 memset(pixel, transparent_color, 12);
160 case VBI_SEMI_TRANSPARENT:
163 case VBI_TRANSPARENT_FULL:
164 for(; pixel < pixelnext; pixel++)
165 if (*pixel == vc->background)
166 *pixel = transparent_color;
179 int resx = page->columns * 12;
180 int resy = (page->rows - chop_top) * 10;
183 vbi_char *vc = page->text + (chop_top * page->columns);
184 vbi_char *vcend = page->text + (page->rows * page->columns);
186 for (; vc < vcend; vc++) {
187 if (vc->opacity != VBI_TRANSPARENT_SPACE) {
204 vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,
206 0, chop_top, page->columns, page->rows - chop_top,
220 for (ci = 0; ci < cmax; ci++) {
223 r =
VBI_R(page->color_map[ci]);
224 g =
VBI_G(page->color_map[ci]);
225 b =
VBI_B(page->color_map[ci]);
226 a =
VBI_A(page->color_map[ci]);
227 ((uint32_t *)sub_rect->
pict.
data[1])[ci] =
RGBA(r, g, b, a);
230 ((uint32_t *)sub_rect->
pict.
data[1])[ci]);
233 ((uint32_t *)sub_rect->
pict.
data[1])[cmax] =
RGBA(0, 0, 0, 0);
250 snprintf(pgno_str,
sizeof pgno_str,
"%03x", ev->ev.ttx_page.pgno);
252 pgno_str, ev->ev.ttx_page.subno & 0xFF);
254 if (strcmp(ctx->
pgno,
"*") && !strstr(ctx->
pgno, pgno_str))
258 res = vbi_fetch_vt_page(ctx->
vbi, &page,
259 ev->ev.ttx_page.pgno,
260 ev->ev.ttx_page.subno,
261 VBI_WST_LEVEL_3p5, 25,
TRUE);
267 fprintf(stderr,
"\nSaving res=%d dy0=%d dy1=%d...\n",
268 res, page.dirty.y0, page.dirty.y1);
271 if (!vbi_export_stdio(ctx->ex, stderr, &page))
272 fprintf(stderr,
"failed: %s\n", vbi_export_errstr(ctx->ex));
275 vpt = vbi_classify_page(ctx->
vbi, ev->ev.ttx_page.pgno, &subno, &lang);
277 ((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE));
280 page.columns, page.rows, chop_top);
296 vbi_unref_page(&page);
301 void *
data,
int *data_size,
307 unsigned int left = pkt->
size;
308 uint8_t pesheader[45] = {0x00, 0x00, 0x01, 0xbd, 0x00, 0x00, 0x85, 0x80, 0x24, 0x21, 0x00, 0x01, 0x00, 0x01};
309 int pesheader_size =
sizeof(pesheader);
310 const uint8_t *pesheader_buf = pesheader;
313 if (!(ctx->
vbi = vbi_decoder_new()))
315 if (!vbi_event_handler_add(ctx->
vbi, VBI_EVENT_TTX_PAGE,
handler, ctx)) {
316 vbi_decoder_delete(ctx->
vbi);
321 if (!ctx->
dx && (!(ctx->
dx = vbi_dvb_pes_demux_new ( NULL, NULL))))
325 if ((pesheader_size + left) < 184 || (pesheader_size + left) > 65504 || (pesheader_size + left) % 184 != 0)
328 memset(pesheader + 14, 0xff, pesheader_size - 14);
329 AV_WB16(pesheader + 4, left + pesheader_size - 6);
334 vbi_dvb_demux_cor(ctx->
dx, ctx->
sliced, 64, NULL, &pesheader_buf, &pesheader_size);
338 unsigned int lines = vbi_dvb_demux_cor(ctx->
dx, ctx->
sliced, 64, &pts, &buf, &left);
341 "ctx=%p buf_size=%d left=%u lines=%u pts=%f pkt_pts=%f\n",
342 ctx, pkt->
size, left, lines, (
double)pts/90000.0, (
double)pkt->
pts/90000.0);
347 for(i=0; i<lines; ++i)
349 "lines=%d id=%x\n", i, ctx->
sliced[i].id);
351 vbi_decode(ctx->
vbi, ctx->
sliced, lines, (
double)pts/90000.0);
387 unsigned int maj,
min, rev;
389 vbi_version(&maj, &min, &rev);
390 if (!(maj > 0 || min > 2 || min == 2 && rev >= 26)) {
398 if (!strcmp(ctx->
format,
"bitmap")) {
400 }
else if (!strcmp(ctx->
format,
"text")) {
410 ctx->ex = vbi_export_new(
"text", &t);
425 vbi_dvb_demux_delete(ctx->
dx);
426 vbi_decoder_delete(ctx->
vbi);
437 #define OFFSET(x) offsetof(TeletextContext, x)
438 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
445 {
"txt_chop_spaces",
"chops leading and trailing spaces from text",
OFFSET(chop_spaces),
AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1,
SD},
446 {
"txt_duration",
"display duration of teletext pages in msecs",
OFFSET(sub_duration),
AV_OPT_TYPE_INT, {.i64 = 30000}, 0, 86400000,
SD},
447 {
"txt_transparent",
"force transparent background of the teletext",
OFFSET(transparent_bg),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD},
459 .
name =
"libzvbi_teletextdec",
468 .priv_class= &teletext_class,