30 #define TEXT_MAXSZ (25 * (56 + 1) * 4 + 2)
31 #define VBI_NB_COLORS 40
32 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
33 #define VBI_R(rgba) (((rgba) >> 0) & 0xFF)
34 #define VBI_G(rgba) (((rgba) >> 8) & 0xFF)
35 #define VBI_B(rgba) (((rgba) >> 16) & 0xFF)
36 #define VBI_A(rgba) (((rgba) >> 24) & 0xFF)
37 #define MAX_BUFFERED_PAGES 25
38 #define BITMAP_CHAR_WIDTH 12
39 #define BITMAP_CHAR_HEIGHT 10
79 if (*--t !=
' ' || (len-1 > 0 && *(t-1) & 0x80))
88 av_freep(&(*sub_rect)->pict.data[0]);
89 av_freep(&(*sub_rect)->pict.data[1]);
137 sz = vbi_print_page_region(page, vbi_text,
TEXT_MAXSZ-1,
"UTF-8",
140 page->columns, page->rows-chop_top);
155 in += strspn(in,
" \n");
157 for (nl = 0; in[nl]; ++nl)
158 if (in[nl] ==
'\n' && (nl==0 || !(in[nl-1] & 0x80)))
194 int chop_top,
uint8_t transparent_color,
int resx,
int resy)
199 for (iy = 0; iy < resy; iy++) {
202 vbi_char *vcnext = vc + page->columns;
203 for (; vc < vcnext; vc++) {
205 switch (vc->opacity) {
206 case VBI_TRANSPARENT_SPACE:
207 memset(pixel, transparent_color, BITMAP_CHAR_WIDTH);
210 case VBI_SEMI_TRANSPARENT:
213 case VBI_TRANSPARENT_FULL:
214 for(; pixel < pixelnext; pixel++)
215 if (*pixel == vc->background)
216 *pixel = transparent_color;
231 vbi_char *vc = page->text + (chop_top * page->columns);
232 vbi_char *vcend = page->text + (page->rows * page->columns);
234 for (; vc < vcend; vc++) {
235 if (vc->opacity != VBI_TRANSPARENT_SPACE) {
252 vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,
254 0, chop_top, page->columns, page->rows - chop_top,
268 for (ci = 0; ci < cmax; ci++) {
271 r =
VBI_R(page->color_map[ci]);
272 g =
VBI_G(page->color_map[ci]);
273 b =
VBI_B(page->color_map[ci]);
274 a =
VBI_A(page->color_map[ci]);
275 ((uint32_t *)sub_rect->
pict.
data[1])[ci] =
RGBA(r, g, b, a);
276 av_dlog(ctx,
"palette %0x\n", ((uint32_t *)sub_rect->
pict.
data[1])[ci]);
278 ((uint32_t *)sub_rect->
pict.
data[1])[cmax] =
RGBA(0, 0, 0, 0);
295 snprintf(pgno_str,
sizeof pgno_str,
"%03x", ev->ev.ttx_page.pgno);
297 pgno_str, ev->ev.ttx_page.subno & 0xFF);
299 if (strcmp(ctx->
pgno,
"*") && !strstr(ctx->
pgno, pgno_str))
304 res = vbi_fetch_vt_page(ctx->
vbi, &page,
305 ev->ev.ttx_page.pgno,
306 ev->ev.ttx_page.subno,
307 VBI_WST_LEVEL_3p5, 25,
TRUE);
313 fprintf(stderr,
"\nSaving res=%d dy0=%d dy1=%d...\n",
314 res, page.dirty.y0, page.dirty.y1);
317 if (!vbi_export_stdio(ctx->ex, stderr, &page))
318 fprintf(stderr,
"failed: %s\n", vbi_export_errstr(ctx->ex));
321 vpt = vbi_classify_page(ctx->
vbi, ev->ev.ttx_page.pgno, &subno, &lang);
323 ((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE));
326 page.columns, page.rows, chop_top);
331 ctx->
pages = new_pages;
334 cur_page->
pgno = ev->ev.ttx_page.pgno;
335 cur_page->
subno = ev->ev.ttx_page.subno;
358 vbi_unref_page(&page);
363 return (data_identifier >= 0x10 && data_identifier <= 0x1F ||
364 data_identifier >= 0x99 && data_identifier <= 0x9B);
371 int data_unit_id = buf[0];
372 int data_unit_length = buf[1];
373 if (data_unit_length + 2 > size)
375 if (data_unit_id == 0x02 || data_unit_id == 0x03) {
376 if (data_unit_length != 0x2c)
379 int line_offset = buf[2] & 0x1f;
380 int field_parity = buf[2] & 0x20;
382 ctx->
sliced[lines].id = VBI_SLICED_TELETEXT_B;
383 ctx->
sliced[lines].line = (line_offset > 0 ? (line_offset + (field_parity ? 0 : 313)) : 0);
384 for (i = 0; i < 42; i++)
385 ctx->
sliced[lines].data[i] = vbi_rev8(buf[4 + i]);
389 size -= data_unit_length + 2;
390 buf += data_unit_length + 2;
404 if (!(ctx->
vbi = vbi_decoder_new()))
406 if (!vbi_event_handler_add(ctx->
vbi, VBI_EVENT_TTX_PAGE,
handler, ctx)) {
407 vbi_decoder_delete(ctx->
vbi);
418 const int full_pes_size = pkt->
size + 45;
421 if (full_pes_size < 184 || full_pes_size > 65504 || full_pes_size % 184 != 0)
429 av_dlog(avctx,
"ctx=%p buf_size=%d lines=%u pkt_pts=%7.3f\n",
430 ctx, pkt->
size, lines, (
double)pkt->
pts/90000.0);
435 for(i = 0; i < lines; i++)
439 vbi_decode(ctx->
vbi, ctx->
sliced, lines, 0.0);
474 for (i = 0; i < ctx->
nb_pages - 1; i++)
489 unsigned int maj,
min, rev;
491 vbi_version(&maj, &min, &rev);
492 if (!(maj > 0 || min > 2 || min == 2 && rev >= 26)) {
508 ctx->ex = vbi_export_new(
"text", &t);
524 vbi_decoder_delete(ctx->
vbi);
535 #define OFFSET(x) offsetof(TeletextContext, x)
536 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
540 {
"txt_format",
"format of the subtitles (bitmap or text)",
OFFSET(format_id),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD,
"txt_format"},
545 {
"txt_chop_spaces",
"chops leading and trailing spaces from text",
OFFSET(chop_spaces),
AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1,
SD},
546 {
"txt_duration",
"display duration of teletext pages in msecs",
OFFSET(sub_duration),
AV_OPT_TYPE_INT, {.i64 = 30000}, 0, 86400000,
SD},
547 {
"txt_transparent",
"force transparent background of the teletext",
OFFSET(transparent_bg),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD},
559 .
name =
"libzvbi_teletextdec",
569 .priv_class= &teletext_class,