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]);
 
  138     sz = vbi_print_page_region(page, vbi_text, 
TEXT_MAXSZ-1, 
"UTF-8",
 
  141                                    page->columns, page->rows-chop_top);
 
  156             in += strspn(in, 
" \n");
 
  158             for (nl = 0; in[nl]; ++nl)
 
  159                 if (in[nl] == 
'\n' && (nl==0 || !(in[nl-1] & 0x80)))
 
  195                              int chop_top, 
uint8_t transparent_color, 
int resx, 
int resy)
 
  200     for (iy = 0; iy < resy; iy++) {
 
  203         vbi_char *vcnext = vc + page->columns;
 
  204         for (; vc < vcnext; vc++) {
 
  206             switch (vc->opacity) {
 
  207                 case VBI_TRANSPARENT_SPACE:
 
  208                     memset(pixel, transparent_color, BITMAP_CHAR_WIDTH);
 
  211                 case VBI_SEMI_TRANSPARENT:
 
  214                 case VBI_TRANSPARENT_FULL:
 
  215                     for(; pixel < pixelnext; pixel++)
 
  216                         if (*pixel == vc->background)
 
  217                             *pixel = transparent_color;
 
  232     vbi_char *vc = page->text + (chop_top * page->columns);
 
  233     vbi_char *vcend = page->text + (page->rows * page->columns);
 
  235     for (; vc < vcend; vc++) {
 
  236         if (vc->opacity != VBI_TRANSPARENT_SPACE) {
 
  253     vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,
 
  255                             0, chop_top, page->columns, page->rows - chop_top,
 
  269     for (ci = 0; ci < cmax; ci++) {
 
  272         r = 
VBI_R(page->color_map[ci]);
 
  273         g = 
VBI_G(page->color_map[ci]);
 
  274         b = 
VBI_B(page->color_map[ci]);
 
  275         a = 
VBI_A(page->color_map[ci]);
 
  276         ((uint32_t *)sub_rect->
pict.
data[1])[ci] = 
RGBA(r, g, b, a);
 
  277         av_dlog(ctx, 
"palette %0x\n", ((uint32_t *)sub_rect->
pict.
data[1])[ci]);
 
  279     ((uint32_t *)sub_rect->
pict.
data[1])[cmax] = 
RGBA(0, 0, 0, 0);
 
  296     snprintf(pgno_str, 
sizeof pgno_str, 
"%03x", ev->ev.ttx_page.pgno);
 
  298            pgno_str, ev->ev.ttx_page.subno & 0xFF);
 
  300     if (strcmp(ctx->
pgno, 
"*") && !strstr(ctx->
pgno, pgno_str))
 
  305     res = vbi_fetch_vt_page(ctx->
vbi, &page,
 
  306                             ev->ev.ttx_page.pgno,
 
  307                             ev->ev.ttx_page.subno,
 
  308                             VBI_WST_LEVEL_3p5, 25, 
TRUE);
 
  314     fprintf(stderr, 
"\nSaving res=%d dy0=%d dy1=%d...\n",
 
  315             res, page.dirty.y0, page.dirty.y1);
 
  318     if (!vbi_export_stdio(ctx->ex, stderr, &page))
 
  319         fprintf(stderr, 
"failed: %s\n", vbi_export_errstr(ctx->ex));
 
  322     vpt = vbi_classify_page(ctx->
vbi, ev->ev.ttx_page.pgno, &subno, &lang);
 
  324         ((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE));
 
  327            page.columns, page.rows, chop_top);
 
  332             ctx->
pages = new_pages;
 
  335             cur_page->
pgno = ev->ev.ttx_page.pgno;
 
  336             cur_page->
subno = ev->ev.ttx_page.subno;
 
  359     vbi_unref_page(&page);
 
  364     return (data_identifier >= 0x10 && data_identifier <= 0x1F ||
 
  365             data_identifier >= 0x99 && data_identifier <= 0x9B);
 
  372         int data_unit_id     = buf[0];
 
  373         int data_unit_length = buf[1];
 
  374         if (data_unit_length + 2 > size)
 
  376         if (data_unit_id == 0x02 || data_unit_id == 0x03) {
 
  377             if (data_unit_length != 0x2c)
 
  380                 int line_offset  = buf[2] & 0x1f;
 
  381                 int field_parity = buf[2] & 0x20;
 
  383                 ctx->
sliced[lines].id = VBI_SLICED_TELETEXT_B;
 
  384                 ctx->
sliced[lines].line = (line_offset > 0 ? (line_offset + (field_parity ? 0 : 313)) : 0);
 
  385                 for (i = 0; i < 42; i++)
 
  386                     ctx->
sliced[lines].data[i] = vbi_rev8(buf[4 + i]);
 
  390         size -= data_unit_length + 2;
 
  391         buf += data_unit_length + 2;
 
  405         if (!(ctx->
vbi = vbi_decoder_new()))
 
  407         if (!vbi_event_handler_add(ctx->
vbi, VBI_EVENT_TTX_PAGE, 
handler, ctx)) {
 
  408             vbi_decoder_delete(ctx->
vbi);
 
  419         const int full_pes_size = pkt->
size + 45; 
 
  422         if (full_pes_size < 184 || full_pes_size > 65504 || full_pes_size % 184 != 0)
 
  430             av_dlog(avctx, 
"ctx=%p buf_size=%d lines=%u pkt_pts=%7.3f\n",
 
  431                     ctx, pkt->
size, lines, (
double)pkt->
pts/90000.0);
 
  436                 for(i = 0; i < lines; i++)
 
  440                 vbi_decode(ctx->
vbi, ctx->
sliced, lines, 0.0);
 
  475         for (i = 0; i < ctx->
nb_pages - 1; i++)
 
  490     unsigned int maj, 
min, rev;
 
  492     vbi_version(&maj, &min, &rev);
 
  493     if (!(maj > 0 || min > 2 || min == 2 && rev >= 26)) {
 
  509         ctx->ex = vbi_export_new(
"text", &t);
 
  525     vbi_decoder_delete(ctx->
vbi);
 
  536 #define OFFSET(x) offsetof(TeletextContext, x) 
  537 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM 
  541     {
"txt_format",      
"format of the subtitles (bitmap or text)",          
OFFSET(format_id),      
AV_OPT_TYPE_INT,    {.i64 = 0},        0, 1,        
SD,  
"txt_format"},
 
  546     {
"txt_chop_spaces", 
"chops leading and trailing spaces from text",       
OFFSET(chop_spaces),    
AV_OPT_TYPE_INT,    {.i64 = 1},        0, 1,        
SD},
 
  547     {
"txt_duration",    
"display duration of teletext pages in msecs",       
OFFSET(sub_duration),   
AV_OPT_TYPE_INT,    {.i64 = 30000},    0, 86400000, 
SD},
 
  548     {
"txt_transparent", 
"force transparent background of the teletext",      
OFFSET(transparent_bg), 
AV_OPT_TYPE_INT,    {.i64 = 0},        0, 1,        
SD},
 
  560     .
name      = 
"libzvbi_teletextdec",
 
  570     .priv_class= &teletext_class,