From patchwork Tue Apr 7 15:00:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18748 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 172A244B0E5 for ; Tue, 7 Apr 2020 18:00:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E1FE068B636; Tue, 7 Apr 2020 18:00:57 +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 D9A4968AE86 for ; Tue, 7 Apr 2020 18:00:50 +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; Tue, 7 Apr 2020 08:00:48 -0700 From: John Stebbins To: Date: Tue, 7 Apr 2020 09:00:34 -0600 Message-ID: <20200407150034.9916-1-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.2 MIME-Version: 1.0 X-Originating-IP: [192.168.13.165] Subject: [FFmpeg-devel] [PATCH 20/23] lavc/movtextenc: handle cancel overrides callback 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 | 43 ++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 9e657c9635..2d3c416407 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -69,6 +69,7 @@ typedef struct { AVCodecContext *avctx; ASSSplitContext *ass_ctx; + ASSStyle *ass_dialog_style; AVBPrint buffer; StyleBox **style_attributes; StyleBox *style_attributes_temp; @@ -396,9 +397,8 @@ static void mov_text_end_cb(void *priv) mov_text_style_start((MovTextContext*)priv); } -static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) +static void mov_text_ass_style_set(MovTextContext *s, ASSStyle *style) { - ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); uint8_t style_flags, alpha; uint32_t color; @@ -412,9 +412,33 @@ static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) alpha = 255 - ((uint32_t)style->primary_color >> 24); mov_text_alpha_set(s, alpha); mov_text_font_size_set(s, style->font_size); + } else { + // End current style record, go back to defaults + mov_text_style_start(s); } } +static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog) +{ + ASSStyle * style = ff_ass_style_get(s->ass_ctx, dialog->style); + + s->ass_dialog_style = style; + mov_text_ass_style_set(s, style); +} + +static void mov_text_cancel_overrides_cb(void *priv, const char * style_name) +{ + MovTextContext *s = priv; + ASSStyle * style; + + if (!style_name || !*style_name) + style = s->ass_dialog_style; + else + style= ff_ass_style_get(s->ass_ctx, style_name); + + mov_text_ass_style_set(s, style); +} + static uint16_t utf8_strlen(const char *text, int len) { uint16_t i = 0, ret = 0; @@ -454,13 +478,14 @@ static void mov_text_new_line_cb(void *priv, int forced) } static const ASSCodesCallbacks mov_text_callbacks = { - .text = mov_text_text_cb, - .new_line = mov_text_new_line_cb, - .style = mov_text_style_cb, - .color = mov_text_color_cb, - .alpha = mov_text_alpha_cb, - .font_size = mov_text_font_size_cb, - .end = mov_text_end_cb, + .text = mov_text_text_cb, + .new_line = mov_text_new_line_cb, + .style = mov_text_style_cb, + .color = mov_text_color_cb, + .alpha = mov_text_alpha_cb, + .font_size = mov_text_font_size_cb, + .cancel_overrides = mov_text_cancel_overrides_cb, + .end = mov_text_end_cb, }; static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,