From b50968169df4c44d37cb46bce6d68fd3ae51c8fb Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 1 Dec 2013 13:10:24 +0100 Subject: [PATCH 1/4] libzvbi-teletextdec: cosmetics Signed-off-by: Marton Balint --- libavcodec/libzvbi-teletextdec.c | 36 ++++++++++---------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c index bf2dc063ab..e02bc0518a 100644 --- a/libavcodec/libzvbi-teletextdec.c +++ b/libavcodec/libzvbi-teletextdec.c @@ -43,7 +43,6 @@ typedef struct TeletextPage int64_t pts; } TeletextPage; -/* main data structure */ typedef struct TeletextContext { AVClass *class; @@ -67,14 +66,10 @@ typedef struct TeletextContext #ifdef DEBUG vbi_export * ex; #endif - /* Don't even _think_ about making sliced stack-local! */ vbi_sliced sliced[64]; } TeletextContext; -/************************************************************************/ - -static int -chop_spaces_utf8(const unsigned char* t, int len) +static int chop_spaces_utf8(const unsigned char* t, int len) { t += len; while (len > 0) { @@ -85,8 +80,7 @@ chop_spaces_utf8(const unsigned char* t, int len) return len; } -static void -subtitle_rect_free(AVSubtitleRect **sub_rect) +static void subtitle_rect_free(AVSubtitleRect **sub_rect) { av_freep(&(*sub_rect)->pict.data[0]); av_freep(&(*sub_rect)->pict.data[1]); @@ -94,8 +88,7 @@ subtitle_rect_free(AVSubtitleRect **sub_rect) av_freep(sub_rect); } -static int -create_ass_text(TeletextContext *ctx, const char *text, char **ass) +static int create_ass_text(TeletextContext *ctx, const char *text, char **ass) { int ret; AVBPrint buf, buf2; @@ -127,9 +120,8 @@ create_ass_text(TeletextContext *ctx, const char *text, char **ass) return 0; } -// draw a page as text -static int -gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top) +/* Draw a page as text */ +static int gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top) { const char *in; AVBPrint buf; @@ -195,8 +187,8 @@ gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int return 0; } -static void -fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top, uint8_t transparent_color, int resx, int resy) +static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, + int chop_top, uint8_t transparent_color, int resx, int resy) { int iy; @@ -226,9 +218,8 @@ fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, } } -// draw a page as bitmap -static int -gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top) +/* Draw a page as bitmap */ +static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top) { int resx = page->columns * 12; int resy = (page->rows - chop_top) * 10; @@ -289,8 +280,7 @@ gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, i return 0; } -static void -handler(vbi_event *ev, void *user_data) +static void handler(vbi_event *ev, void *user_data) { TeletextContext *ctx = user_data; TeletextPage *new_pages; @@ -311,7 +301,6 @@ handler(vbi_event *ev, void *user_data) if (ctx->handler_ret < 0) return; - /* Fetch the page. */ res = vbi_fetch_vt_page(ctx->vbi, &page, ev->ev.ttx_page.pgno, ev->ev.ttx_page.subno, @@ -369,10 +358,7 @@ handler(vbi_event *ev, void *user_data) vbi_unref_page(&page); } -static int -teletext_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - AVPacket *pkt) +static int teletext_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt) { TeletextContext *ctx = avctx->priv_data; AVSubtitle *sub = data; From 249a435989d064833efac7f5bb319bb4cc4c58aa Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 7 Dec 2013 17:14:15 +0100 Subject: [PATCH 2/4] libzvbi-teletextdec: use defined constants for bitmap char width and height Signed-off-by: Marton Balint --- libavcodec/libzvbi-teletextdec.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c index e02bc0518a..1bdd5fa3ab 100644 --- a/libavcodec/libzvbi-teletextdec.c +++ b/libavcodec/libzvbi-teletextdec.c @@ -34,6 +34,8 @@ #define VBI_B(rgba) (((rgba) >> 16) & 0xFF) #define VBI_A(rgba) (((rgba) >> 24) & 0xFF) #define MAX_BUFFERED_PAGES 25 +#define BITMAP_CHAR_WIDTH 12 +#define BITMAP_CHAR_HEIGHT 10 typedef struct TeletextPage { @@ -195,13 +197,13 @@ static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi // Hack for transparency, inspired by VLC code... for (iy = 0; iy < resy; iy++) { uint8_t *pixel = sub_rect->pict.data[0] + iy * sub_rect->pict.linesize[0]; - vbi_char *vc = page->text + (iy / 10 + chop_top) * page->columns; + vbi_char *vc = page->text + (iy / BITMAP_CHAR_HEIGHT + chop_top) * page->columns; vbi_char *vcnext = vc + page->columns; for (; vc < vcnext; vc++) { - uint8_t *pixelnext = pixel + 12; + uint8_t *pixelnext = pixel + BITMAP_CHAR_WIDTH; switch (vc->opacity) { case VBI_TRANSPARENT_SPACE: - memset(pixel, transparent_color, 12); + memset(pixel, transparent_color, BITMAP_CHAR_WIDTH); break; case VBI_OPAQUE: case VBI_SEMI_TRANSPARENT: @@ -221,8 +223,8 @@ static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi /* Draw a page as bitmap */ static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top) { - int resx = page->columns * 12; - int resy = (page->rows - chop_top) * 10; + int resx = page->columns * BITMAP_CHAR_WIDTH; + int resy = (page->rows - chop_top) * BITMAP_CHAR_HEIGHT; uint8_t ci, cmax = 0; int ret; vbi_char *vc = page->text + (chop_top * page->columns); From c77e0c2130c314cf1456156fbdefee898a483216 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 7 Dec 2013 17:18:27 +0100 Subject: [PATCH 3/4] libzvbi-teletextdec: add chopped top row size to y offset Signed-off-by: Marton Balint --- libavcodec/libzvbi-teletextdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c index 1bdd5fa3ab..664906adc9 100644 --- a/libavcodec/libzvbi-teletextdec.c +++ b/libavcodec/libzvbi-teletextdec.c @@ -255,7 +255,7 @@ static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_pa fix_transparency(ctx, sub_rect, page, chop_top, cmax, resx, resy); sub_rect->x = ctx->x_offset; - sub_rect->y = ctx->y_offset; + sub_rect->y = ctx->y_offset + chop_top * BITMAP_CHAR_HEIGHT; sub_rect->w = resx; sub_rect->h = resy; sub_rect->nb_colors = (int)cmax + 1; From 97f880e7a9526465a966565598741f4cc25ecc47 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 7 Dec 2013 17:51:19 +0100 Subject: [PATCH 4/4] libzvbi-teletextdec: set bitmap teletext canvas dimensions Signed-off-by: Marton Balint --- libavcodec/libzvbi-teletextdec.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c index 664906adc9..abc24c37ea 100644 --- a/libavcodec/libzvbi-teletextdec.c +++ b/libavcodec/libzvbi-teletextdec.c @@ -474,6 +474,11 @@ static int teletext_init_decoder(AVCodecContext *avctx) return AVERROR_EXTERNAL; } + if (ctx->format_id == 0) { + avctx->width = 41 * BITMAP_CHAR_WIDTH; + avctx->height = 25 * BITMAP_CHAR_HEIGHT; + } + ctx->dx = NULL; ctx->vbi = NULL; ctx->pts = AV_NOPTS_VALUE;