lavc/libzvbi-teletextdec: add support for setting background opacity
Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
		
							parent
							
								
									92f2a9dbc5
								
							
						
					
					
						commit
						73e4565dff
					
				| @ -282,7 +282,13 @@ Sets the display duration of the decoded teletext pages or subtitles in | |||||||
| miliseconds. Default value is 30000 which is 30 seconds. | miliseconds. Default value is 30000 which is 30 seconds. | ||||||
| @item txt_transparent | @item txt_transparent | ||||||
| Force transparent background of the generated teletext bitmaps. Default value | Force transparent background of the generated teletext bitmaps. Default value | ||||||
| is 0 which means an opaque (black) background. | is 0 which means an opaque background. | ||||||
|  | @item txt_opacity | ||||||
|  | Sets the opacity (0-255) of the teletext background. If | ||||||
|  | @option{txt_transparent} is not set, it only affects characters between a start | ||||||
|  | box and an end box, typically subtitles. Default value is 0 if | ||||||
|  | @option{txt_transparent} is set, 255 otherwise. | ||||||
|  | 
 | ||||||
| @end table | @end table | ||||||
| 
 | 
 | ||||||
| @c man end SUBTILES DECODERS | @c man end SUBTILES DECODERS | ||||||
|  | |||||||
| @ -59,6 +59,7 @@ typedef struct TeletextContext | |||||||
|     int             chop_top; |     int             chop_top; | ||||||
|     int             sub_duration; /* in msec */ |     int             sub_duration; /* in msec */ | ||||||
|     int             transparent_bg; |     int             transparent_bg; | ||||||
|  |     int             opacity; | ||||||
|     int             chop_spaces; |     int             chop_spaces; | ||||||
| 
 | 
 | ||||||
|     int             lines_processed; |     int             lines_processed; | ||||||
| @ -210,9 +211,16 @@ static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi | |||||||
|                     memset(pixel, VBI_TRANSPARENT_BLACK, BITMAP_CHAR_WIDTH); |                     memset(pixel, VBI_TRANSPARENT_BLACK, BITMAP_CHAR_WIDTH); | ||||||
|                     break; |                     break; | ||||||
|                 case VBI_OPAQUE: |                 case VBI_OPAQUE: | ||||||
|                 case VBI_SEMI_TRANSPARENT: |  | ||||||
|                     if (!ctx->transparent_bg) |                     if (!ctx->transparent_bg) | ||||||
|                         break; |                         break; | ||||||
|  |                 case VBI_SEMI_TRANSPARENT: | ||||||
|  |                     if (ctx->opacity > 0) { | ||||||
|  |                         if (ctx->opacity < 255) | ||||||
|  |                             for(; pixel < pixelnext; pixel++) | ||||||
|  |                                 if (*pixel == vc->background) | ||||||
|  |                                     *pixel += VBI_NB_COLORS; | ||||||
|  |                         break; | ||||||
|  |                     } | ||||||
|                 case VBI_TRANSPARENT_FULL: |                 case VBI_TRANSPARENT_FULL: | ||||||
|                     for(; pixel < pixelnext; pixel++) |                     for(; pixel < pixelnext; pixel++) | ||||||
|                         if (*pixel == vc->background) |                         if (*pixel == vc->background) | ||||||
| @ -259,7 +267,7 @@ static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_pa | |||||||
|     sub_rect->y = ctx->y_offset + chop_top * BITMAP_CHAR_HEIGHT; |     sub_rect->y = ctx->y_offset + chop_top * BITMAP_CHAR_HEIGHT; | ||||||
|     sub_rect->w = resx; |     sub_rect->w = resx; | ||||||
|     sub_rect->h = resy; |     sub_rect->h = resy; | ||||||
|     sub_rect->nb_colors = VBI_NB_COLORS; |     sub_rect->nb_colors = ctx->opacity > 0 && ctx->opacity < 255 ? 2 * VBI_NB_COLORS : VBI_NB_COLORS; | ||||||
|     sub_rect->data[1] = av_mallocz(AVPALETTE_SIZE); |     sub_rect->data[1] = av_mallocz(AVPALETTE_SIZE); | ||||||
|     if (!sub_rect->data[1]) { |     if (!sub_rect->data[1]) { | ||||||
|         av_freep(&sub_rect->data[0]); |         av_freep(&sub_rect->data[0]); | ||||||
| @ -273,9 +281,11 @@ static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_pa | |||||||
|         b = VBI_B(page->color_map[ci]); |         b = VBI_B(page->color_map[ci]); | ||||||
|         a = VBI_A(page->color_map[ci]); |         a = VBI_A(page->color_map[ci]); | ||||||
|         ((uint32_t *)sub_rect->data[1])[ci] = RGBA(r, g, b, a); |         ((uint32_t *)sub_rect->data[1])[ci] = RGBA(r, g, b, a); | ||||||
|  |         ((uint32_t *)sub_rect->data[1])[ci + VBI_NB_COLORS] = RGBA(r, g, b, ctx->opacity); | ||||||
|         ff_dlog(ctx, "palette %0x\n", ((uint32_t *)sub_rect->data[1])[ci]); |         ff_dlog(ctx, "palette %0x\n", ((uint32_t *)sub_rect->data[1])[ci]); | ||||||
|     } |     } | ||||||
|     ((uint32_t *)sub_rect->data[1])[VBI_TRANSPARENT_BLACK] = RGBA(0, 0, 0, 0); |     ((uint32_t *)sub_rect->data[1])[VBI_TRANSPARENT_BLACK] = RGBA(0, 0, 0, 0); | ||||||
|  |     ((uint32_t *)sub_rect->data[1])[VBI_TRANSPARENT_BLACK + VBI_NB_COLORS] = RGBA(0, 0, 0, 0); | ||||||
|     sub_rect->type = SUBTITLE_BITMAP; |     sub_rect->type = SUBTITLE_BITMAP; | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
| @ -511,6 +521,9 @@ static int teletext_init_decoder(AVCodecContext *avctx) | |||||||
|     ctx->vbi = NULL; |     ctx->vbi = NULL; | ||||||
|     ctx->pts = AV_NOPTS_VALUE; |     ctx->pts = AV_NOPTS_VALUE; | ||||||
| 
 | 
 | ||||||
|  |     if (ctx->opacity == -1) | ||||||
|  |         ctx->opacity = ctx->transparent_bg ? 0 : 255; | ||||||
|  | 
 | ||||||
| #ifdef DEBUG | #ifdef DEBUG | ||||||
|     { |     { | ||||||
|         char *t; |         char *t; | ||||||
| @ -554,6 +567,7 @@ static const AVOption options[] = { | |||||||
|     {"txt_chop_spaces", "chops leading and trailing spaces from text",       OFFSET(chop_spaces),    AV_OPT_TYPE_INT,    {.i64 = 1},        0, 1,        SD}, |     {"txt_chop_spaces", "chops leading and trailing spaces from text",       OFFSET(chop_spaces),    AV_OPT_TYPE_INT,    {.i64 = 1},        0, 1,        SD}, | ||||||
|     {"txt_duration",    "display duration of teletext pages in msecs",       OFFSET(sub_duration),   AV_OPT_TYPE_INT,    {.i64 = 30000},    0, 86400000, SD}, |     {"txt_duration",    "display duration of teletext pages in msecs",       OFFSET(sub_duration),   AV_OPT_TYPE_INT,    {.i64 = 30000},    0, 86400000, SD}, | ||||||
|     {"txt_transparent", "force transparent background of the teletext",      OFFSET(transparent_bg), AV_OPT_TYPE_INT,    {.i64 = 0},        0, 1,        SD}, |     {"txt_transparent", "force transparent background of the teletext",      OFFSET(transparent_bg), AV_OPT_TYPE_INT,    {.i64 = 0},        0, 1,        SD}, | ||||||
|  |     {"txt_opacity",     "set opacity of the transparent background",         OFFSET(opacity),        AV_OPT_TYPE_INT,    {.i64 = -1},      -1, 255,      SD}, | ||||||
|     { NULL }, |     { NULL }, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ | |||||||
| 
 | 
 | ||||||
| #define LIBAVCODEC_VERSION_MAJOR  57 | #define LIBAVCODEC_VERSION_MAJOR  57 | ||||||
| #define LIBAVCODEC_VERSION_MINOR  22 | #define LIBAVCODEC_VERSION_MINOR  22 | ||||||
| #define LIBAVCODEC_VERSION_MICRO 100 | #define LIBAVCODEC_VERSION_MICRO 101 | ||||||
| 
 | 
 | ||||||
| #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | ||||||
|                                                LIBAVCODEC_VERSION_MINOR, \ |                                                LIBAVCODEC_VERSION_MINOR, \ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user