[FFmpeg-cvslog] lavc/ccaption_dec: implement font styles

Aman Gupta git at videolan.org
Sat Jan 9 12:33:37 CET 2016


ffmpeg | branch: master | Aman Gupta <aman at tmm1.net> | Fri Jan  8 19:52:09 2016 -0800| [b7e64be8fbf48c6ded06130146209040c0b32919] | committer: Clément Bœsch

lavc/ccaption_dec: implement font styles

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b7e64be8fbf48c6ded06130146209040c0b32919
---

 libavcodec/ccaption_dec.c |   55 ++++++++++++++++++++++++++++++++++++++++-----
 tests/ref/fate/sub-cc     |    4 ++--
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 603b162..971561a 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -172,9 +172,11 @@ static int write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch)
 {
     uint8_t col = ctx->cursor_column;
     char *row = screen->characters[ctx->cursor_row];
+    char *font = screen->fonts[ctx->cursor_row];
 
     if (col < SCREEN_COLUMNS) {
         row[col] = ch;
+        font[col] = ctx->cursor_font;
         if (ch) ctx->cursor_column++;
         return 0;
     }
@@ -283,17 +285,60 @@ static int capture_screen(CCaptionSubContext *ctx)
     int i;
     int ret = 0;
     struct Screen *screen = ctx->screen + ctx->active_screen;
+    enum cc_font prev_font = CCFONT_REGULAR;
     av_bprint_clear(&ctx->buffer);
 
     for (i = 0; screen->row_used && i < SCREEN_ROWS; i++)
     {
         if (CHECK_FLAG(screen->row_used, i)) {
-            char *str = screen->characters[i];
-            /* skip space */
-            while (*str == ' ')
-                str++;
+            char *row = screen->characters[i];
+            char *font = screen->fonts[i];
+            int j = 0;
+
+            /* skip leading space */
+            while (row[j] == ' ')
+                j++;
+
+            for (; j < SCREEN_COLUMNS; j++) {
+                if (row[j] == 0)
+                    break;
+
+                const char *e_tag = "", *s_tag = "";
+                if (prev_font != font[j]) {
+                    switch (prev_font) {
+                    case CCFONT_ITALICS:
+                        e_tag = "{/i0}";
+                        break;
+                    case CCFONT_UNDERLINED:
+                        e_tag = "{/u0}";
+                        break;
+                    case CCFONT_UNDERLINED_ITALICS:
+                        e_tag = "{/u0}{/i0}";
+                        break;
+                    }
+                    switch (font[j]) {
+                    case CCFONT_ITALICS:
+                        s_tag = "{/i1}";
+                        break;
+                    case CCFONT_UNDERLINED:
+                        s_tag = "{/u1}";
+                        break;
+                    case CCFONT_UNDERLINED_ITALICS:
+                        s_tag = "{/u1}{/i1}";
+                        break;
+                    }
+                }
+                prev_font = font[j];
+
+                av_bprintf(&ctx->buffer, "%s%s%c", e_tag, s_tag, row[j]);
+                ret = av_bprint_is_complete(&ctx->buffer);
+                if (ret == 0) {
+                    ret = AVERROR(ENOMEM);
+                    break;
+                }
+            }
 
-            av_bprintf(&ctx->buffer, "%s\\N", str);
+            av_bprintf(&ctx->buffer, "\\N");
             ret = av_bprint_is_complete(&ctx->buffer);
             if (ret == 0) {
                 ret = AVERROR(ENOMEM);
diff --git a/tests/ref/fate/sub-cc b/tests/ref/fate/sub-cc
index 3d8c764..8583e18 100644
--- a/tests/ref/fate/sub-cc
+++ b/tests/ref/fate/sub-cc
@@ -10,5 +10,5 @@ Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10
 
 [Events]
 Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
-Dialogue: 0,0:00:12.36,0:00:40.83,Default,,0,0,0,,( inaudible radio chatter )
-Dialogue: 0,0:00:40.83,0:00:59.07,Default,,0,0,0,,( inaudible radio chatter )\N>> Safety remains our number one
+Dialogue: 0,0:00:12.36,0:00:40.83,Default,,0,0,0,,({/i1} inaudible radio chatter{/i0} )
+Dialogue: 0,0:00:40.83,0:00:59.07,Default,,0,0,0,,({/i1} inaudible radio chatter{/i0} )\N>> Safety remains our number one



More information about the ffmpeg-cvslog mailing list