From patchwork Sun Jun 14 10:42:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 20344 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5CE9644AD8E for ; Sun, 14 Jun 2020 13:49:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3082368B5C9; Sun, 14 Jun 2020 13:49:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F7FD68B072 for ; Sun, 14 Jun 2020 13:49:51 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id n24so14408535ejd.0 for ; Sun, 14 Jun 2020 03:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=KotsPtdOsYcvpr/5DSp4gevkI4n5OhHJa+hjzz82ulM=; b=ekk4KdKgGAYEyQEB7ruREjBl7AZfn5pdfL1w8DVvo0mwRydkSNdimt7qNYlJcCA9pK 9q6Ve8+OeMBhDt6N7+QRYyIFwdY1G0AnEq0scqE7Q57Yd2ynO9/KVxeb9Q9cibC/yqE9 xMJvaAMmG80SwMkzSydMs2PuGLkulNAVY7MyIUM7TIC3r21jrdXbSFV0jGjIfLQTg2bZ /ghfw/sEy8YP0apoaHK1kgWQG/qSyorgRH3Y8JrmWOYNmY6T5JV5ky2CdMMhaDzxWrxM k6nKm5Ih8c5VUIvSTcws7RvzuM2ibG57LAc1Z/vHk1wfUZX+F8V8XFew7Yz4yu8G5u2t AxGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=KotsPtdOsYcvpr/5DSp4gevkI4n5OhHJa+hjzz82ulM=; b=J9qEYOO9Z0owHQQPwOELU2QcEmloCF2QvX+Qh2nbnFnTM7/5KJ/zNv+3JJTuAX09G/ fz7xHL0k+WDhYqpuyDT02quC8bpxwkncVHRKqQxzjZJeTdKehKsG/yCZjvmIF3vrfeLP VYMrgfMl2/3G8Jwcc9dELo+DN+e8f8ccLgO8VUmo0SpCC9UA2EOtHuRG24h4nceXNcqh A2/cxHWDWs9rnQnpLc9SsKS5PnZmBIUfv+A0WPwBii+GDO5rckb28dEMNmqNSIB7N3JR nAb0vd/U/8KWBDf3pbBdPHQMcIm9Cs00YtUBHgyeDcxcVdkPf+T3TgPFR8bqFOJib2Ar 7ZRg== X-Gm-Message-State: AOAM533jsui4/mhZBfkxO0b9WUIUqYOREJ7G6292TWjAa5aDmM5fcopo tKX1fhudKtVnA9kQLdZQ58d22DVjte8= X-Google-Smtp-Source: ABdhPJxEOgNVo/KB/uzRBDWS41RbjiKxovSWdubxPfOVt6RL5f5fAqBODrhuWS5IsYsPdUZKzZrTIw== X-Received: by 2002:a17:906:af76:: with SMTP id os22mr20236530ejb.191.1592131386468; Sun, 14 Jun 2020 03:43:06 -0700 (PDT) Received: from localhost.localdomain ([37.244.249.74]) by smtp.gmail.com with ESMTPSA id j2sm6424334edn.30.2020.06.14.03.43.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 03:43:05 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sun, 14 Jun 2020 12:42:57 +0200 Message-Id: <20200614104257.1373-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avcodec/ccaption_dec: add support for colors X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavcodec/ccaption_dec.c | 43 +++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c index 936e2db27f..a953181e53 100644 --- a/libavcodec/ccaption_dec.c +++ b/libavcodec/ccaption_dec.c @@ -32,10 +32,6 @@ static const AVRational ms_tb = {1, 1000}; -/* - * TODO list - * 1) handle font and color completely - */ enum cc_mode { CCMODE_POPON, CCMODE_PAINTON, @@ -319,11 +315,13 @@ static void 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]; + char *color = screen->colors[ctx->cursor_row]; char *charset = screen->charsets[ctx->cursor_row]; if (col < SCREEN_COLUMNS) { row[col] = ch; font[col] = ctx->cursor_font; + color[col] = ctx->cursor_color; charset[col] = ctx->cursor_charset; ctx->cursor_charset = CCSET_BASIC_AMERICAN; if (ch) ctx->cursor_column++; @@ -437,6 +435,7 @@ static int capture_screen(CCaptionSubContext *ctx) int i, j, tab = 0; struct Screen *screen = ctx->screen + ctx->active_screen; enum cc_font prev_font = CCFONT_REGULAR; + enum cc_color_code prev_color = CCCOL_WHITE; av_bprint_clear(&ctx->buffer); for (i = 0; screen->row_used && i < SCREEN_ROWS; i++) @@ -457,6 +456,7 @@ static int capture_screen(CCaptionSubContext *ctx) if (CHECK_FLAG(screen->row_used, i)) { const char *row = screen->characters[i]; const char *font = screen->fonts[i]; + const char *color = screen->colors[i]; const char *charset = screen->charsets[i]; const char *override; int x, y, seen_char = 0; @@ -471,7 +471,7 @@ static int capture_screen(CCaptionSubContext *ctx) av_bprintf(&ctx->buffer, "{\\an7}{\\pos(%d,%d)}", x, y); for (; j < SCREEN_COLUMNS; j++) { - const char *e_tag = "", *s_tag = ""; + const char *e_tag = "", *s_tag = "", *c_tag = ""; if (row[j] == 0) break; @@ -500,15 +500,42 @@ static int capture_screen(CCaptionSubContext *ctx) break; } } + if (prev_color != color[j]) { + switch (color[j]) { + case CCCOL_WHITE: + c_tag = "{\\c&HFFFFFF&}"; + break; + case CCCOL_GREEN: + c_tag = "{\\c&H00FF00&}"; + break; + case CCCOL_BLUE: + c_tag = "{\\c&HFF0000&}"; + break; + case CCCOL_CYAN: + c_tag = "{\\c&HFFFF00&}"; + break; + case CCCOL_RED: + c_tag = "{\\c&H0000FF&}"; + break; + case CCCOL_YELLOW: + c_tag = "{\\c&H00FFFF&}"; + break; + case CCCOL_MAGENTA: + c_tag = "{\\c&HFF00FF&}"; + break; + } + } + prev_font = font[j]; + prev_color = color[j]; override = charset_overrides[(int)charset[j]][(int)row[j]]; if (override) { - av_bprintf(&ctx->buffer, "%s%s%s", e_tag, s_tag, override); + av_bprintf(&ctx->buffer, "%s%s%s%s", e_tag, s_tag, c_tag, override); seen_char = 1; } else if (row[j] == ' ' && !seen_char) { - av_bprintf(&ctx->buffer, "%s%s\\h", e_tag, s_tag); + av_bprintf(&ctx->buffer, "%s%s%s\\h", e_tag, s_tag, c_tag); } else { - av_bprintf(&ctx->buffer, "%s%s%c", e_tag, s_tag, row[j]); + av_bprintf(&ctx->buffer, "%s%s%s%c", e_tag, s_tag, c_tag, row[j]); seen_char = 1; }