From patchwork Sat Oct 17 18:22:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23047 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 9E92344B29E for ; Sat, 17 Oct 2020 21:23:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B5E368BB52; Sat, 17 Oct 2020 21:23:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF14868BB23 for ; Sat, 17 Oct 2020 21:23:20 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id 13so6518225wmf.0 for ; Sat, 17 Oct 2020 11:23:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JtjB52rY7QOXK8IO4eSI/EwTLBjeDiiIF41zA4RDWGg=; b=K7nTY6CpBYBcDu90wUJAYHilQ8qBqpGDTEyeHv9itcFHE45DwmLQ0tRrqCvh920E39 obI61c+O7DBRuymCfSBCxX9Nxyy5e/AgvXSu/BFgAJu1Yz2gTOdBMLxAxCcclLTSQNnd GlIM/w9wccCHz5yrMs3DFntNdAxpH0U20hvC5iVkiHGP2vmR1dVYzTy1uvH3NA0K3Ypc Zq/yvGWZ2wj+sVpBISTKgf3aDKCh1eRkLg1kUNgF88MmogkPLR0qiDvcSBmpCmGg4JLz fNhZCa2r2qorZbF66gxBIagCWnCyif6dzk3VxDqDXqvcJ/SQVEkZxFz7++YfY3DnK8jF Cmhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JtjB52rY7QOXK8IO4eSI/EwTLBjeDiiIF41zA4RDWGg=; b=aGWLsz8Ghr0zbrGrBKBTdmQGKGBeID1IQxbVuQolF6mZURPg3NHvCuddENZV9QUyyl Aka5XwojxkFzH4iwKR5CwvF2CT0BeKAbIyy7gI+4jpXZSVqNx7/Qxe1HQ1PqPNhav5kJ pOBx0+Eb6sl6UPkTDdGPuWKyEjbBUqG7fC+tp2pSjnG5ZDpNi9JWVPChwDtb2QZYTGpQ Hi8bbNfKvporrA82Kk2uOI8vw0eAewu9TChYdNeTdGalkHboi537GQFYyOtQvU5LifzG OEghdoMVCGLmk33T2cfOElQ2XfCett/99zozQPUgFrBhLp5Z9+z801vwivp/cdzzzpwb 9uYw== X-Gm-Message-State: AOAM533q90ve26pm9aCls3fWxWsPn8tS4Rfy0abQi6g0CRy+C6o34DNE mMz/kgfSDHQge2u7DxHHfCN/LNomylE= X-Google-Smtp-Source: ABdhPJyU+fOnAn09f7jsLkM3WfE85B6yytEZ/yHrUoHtxRibPo7itEvZMZSl4i2N8pNy7BNi9y2HIg== X-Received: by 2002:a1c:7707:: with SMTP id t7mr10077558wmi.54.1602959000106; Sat, 17 Oct 2020 11:23:20 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id d20sm10440688wra.38.2020.10.17.11.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:23:19 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Oct 2020 20:22:44 +0200 Message-Id: <20201017182248.577108-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201017182248.577108-1-andreas.rheinhardt@gmail.com> References: <20201017182248.577108-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/11] avcodec/movtextdec: Fix immediately adjacent styles 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The checks for whether a style should be opened/closed at the current character position are as follows: A variable entry contained the index of the currently active or potentially next active style. If the current character position coincided with the start of style[entry], the style was activated; this was followed by a check whether the current character position coincided with the end of style[entry]; if so, the style was deactivated and entry incremented. Afterwards the char was processed. The order of the checks leads to problems in case the endChar of style A coincides with the startChar of the next style (say B): Style B was never opened. When we are at said common position, the currently active style is A and so the start pos check does not succeed; but the end pos check does and it closes the currently active style A and increments entry. At the next iteration of the loop, the current character position is bigger than the start position of style B (which is style[entry]) and therefore the style is not activated. The solution is of course to first check for whether a style needs to be closed (and increment entry if it does) before checking whether the next style needs to be opened. Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextdec.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index d167eddea5..d46d64b6f2 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -373,7 +373,16 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, if ((m->box_flags & STYL_BOX) && entry < m->style_entries) { const StyleBox *style = &m->s[entry]; - if (text_pos == style->style_start) { + if (text_pos == style->style_end) { + if (style_active) { + av_bprintf(buf, "{\\r}"); + style_active = 0; + color = m->d.color; + } + entry++; + style++; + } + if (entry < m->style_entries && text_pos == style->style_start) { style_active = 1; if (style->bold ^ m->d.bold) av_bprintf(buf, "{\\b%d}", style->bold); @@ -395,14 +404,6 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, if (m->d.alpha != style->alpha) av_bprintf(buf, "{\\1a&H%02X&}", 255 - style->alpha); } - if (text_pos == style->style_end) { - if (style_active) { - av_bprintf(buf, "{\\r}"); - style_active = 0; - color = m->d.color; - } - entry++; - } } if (m->box_flags & HLIT_BOX) { if (text_pos == m->h.hlit_start) {