From patchwork Mon Apr 6 17:52:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18731 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 C5852449AC5 for ; Mon, 6 Apr 2020 20:59:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF3BC68B4F5; Mon, 6 Apr 2020 20:59:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9344568A466 for ; Mon, 6 Apr 2020 20:59:16 +0300 (EEST) Received: from creator.alpe-d-promontory.fun (192.168.13.165) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Mon, 6 Apr 2020 10:59:15 -0700 From: John Stebbins To: Date: Mon, 6 Apr 2020 11:52:13 -0600 Message-ID: <20200406175218.1299994-19-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200406175218.1299994-1-jstebbins@jetheaddev.com> References: <20200406175218.1299994-1-jstebbins@jetheaddev.com> MIME-Version: 1.0 X-Originating-IP: [192.168.13.165] Subject: [FFmpeg-devel] [PATCH 18/23] lavc/movtextenc: add alpha tag handling 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/movtextenc.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 090536b887..e82393dde7 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -351,6 +351,26 @@ static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color */ } +static void mov_text_alpha_set(MovTextContext *s, uint8_t alpha) +{ + if (!s->style_attributes_temp || + (s->style_attributes_temp->style_color & 0xff) == alpha) { + // color hasn't changed + return; + } + if (mov_text_style_start(s)) + s->style_attributes_temp->style_color = + (s->style_attributes_temp->style_color & 0xffffff00) | alpha; +} + +static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id) +{ + MovTextContext *s = priv; + + if (alpha_id == 1) // primary alpha changes + mov_text_alpha_set(s, 255 - alpha); +} + static void mov_text_end_cb(void *priv) { // End of text, close any open style record @@ -360,7 +380,7 @@ static void mov_text_end_cb(void *priv) static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) { ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); - uint8_t style_flags; + uint8_t style_flags, alpha; uint32_t color; if (style) { @@ -370,6 +390,8 @@ static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) mov_text_style_set(s, style_flags); color = BGR_TO_RGB(style->primary_color & 0xffffff) << 8; mov_text_color_set(s, color); + alpha = 255 - ((uint32_t)style->primary_color >> 24); + mov_text_alpha_set(s, alpha); } } @@ -416,6 +438,7 @@ static const ASSCodesCallbacks mov_text_callbacks = { .new_line = mov_text_new_line_cb, .style = mov_text_style_cb, .color = mov_text_color_cb, + .alpha = mov_text_alpha_cb, .end = mov_text_end_cb, };