From patchwork Tue Dec 7 23:21:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 32166 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a0c:cdc3:0:0:0:0:0 with SMTP id a3csp1131002qvn; Tue, 7 Dec 2021 15:22:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/pzWv3XeNietZ8VdozvH9IKZV8+X1gH3wY3zgFNQZf1INdkuLnXcXNzn1inyjnX7dYxJS X-Received: by 2002:a05:6402:d73:: with SMTP id ec51mr13570543edb.175.1638919354180; Tue, 07 Dec 2021 15:22:34 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t5si2262080edd.468.2021.12.07.15.22.16; Tue, 07 Dec 2021 15:22:34 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=H48ESGia; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6A60168AB67; Wed, 8 Dec 2021 01:22:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-oln040092072085.outbound.protection.outlook.com [40.92.72.85]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0627868996A for ; Wed, 8 Dec 2021 01:22:07 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UwPeZ44FmBz9j8Lv93h5Bw7XNeVZXzxzgAxbOUTIi10Aj+clY+u28cp8/C7EUQU1aAwtqyl8RywKdeciMovznIWL8aXMDL6+thgdxoNjaTUkTdVsci491M/d5r6GMEKlp8v2fkBeLMkjgnpCbQS5o8WJCM557CFMUiRhfIneZxLhksVfosI0lklwg0cGWWxJlpxwxfoBarZFQPgpBdRJ6gVqt83hiY8MijooZmnPq0vCCh5Avwe90Gjy5LYcEXYokzTc0PjRv3+KAhqCGSXsHmbjrUg9uIMek0ZxYot3lc3WuIGVsSJj2aPmBJa/E69c+V2WP+aXRS6XCZpPWELRjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZsJOxBxZsT7VTPYKY7PcfySZ3t88bTMIYBJEF2m7a7k=; b=Ol5pGxIvRcrcH97h4QnL4AWd2jA2Gxxk7H9tj4jHCSxBliXK3Knk31/YnTWezgEFzMSzmopS/Fha2A3wY6EGp5ruEK67qttNz2WnYJmq1QS929UKW2C3ZIkaSa7bJCkOrN3Y3vl+SONVx/hfOFV40OJD9AaerNKs7PRYEY67mZnKqBW39fMCt3YHog4haUFVen3PuQiprcms+CU0pAhtIzV2/gTwxsQi+7DkYiHItovFqLj30Bb6A+rQiTLzMM+Od0061Kz4bQ0UDJETEAKbNL37wjjssWSh8PkeebjVKnIQpKIGl5cB0aQ6vI9lFyysD4/67AzSaZjvy4FWDVOeEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZsJOxBxZsT7VTPYKY7PcfySZ3t88bTMIYBJEF2m7a7k=; b=H48ESGiaa2McwY8mvzXrlQXzqN7sKvZB+2k3JCRrpPXcYejEXEOEzDUi1Leyqf579s10FZ5OFoaRBHxVcht+hA24lPsM9Sl1qEvzUZCgb4/j2aeuFqSoXhoa9Ov+xEWZavdXflIhYzEayfsPmKc9eHWyl5iAxhuGYRgyYSq08dafySyQ0pR0qxXz/CpmvM9pzaPPxZwuLxcBuLAuHvWov7HVHOm6fXgtDBQrCefdE78s6tbXGy/uy+tUPWUClOUlKk12lw81hwyjS73ale7LY7xXPRRLmxj75b3vBXjhmBfd4fTfkI7upPRvRhqQq7mA7CHoZSObRcVY7ULemH5AMA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR0302MB3480.eurprd03.prod.outlook.com (2603:10a6:209:19::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Tue, 7 Dec 2021 23:22:05 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.024; Tue, 7 Dec 2021 23:22:05 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Dec 2021 00:21:53 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 X-TMN: [jsZT1P33roWUSFnn2v25enAsXaJ3iT8T] X-ClientProxiedBy: AM0PR10CA0049.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::29) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211207232156.483811-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM0PR10CA0049.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.17 via Frontend Transport; Tue, 7 Dec 2021 23:22:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 769537bd-fe9e-4bcb-1e7f-08d9b9d86115 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSZafVhYkhL3hNKBaHIpDWhq+VWCVHAamM1c7W8bk73401n33CoAIDmZjLi84jJ+UqxqzqEm066K3PeBK4fxzM2xOSadn2cB6+v6ae6SSBNNBRiqlfEy4cnqkBYtzVyaA+ygZa/Bd4aJz5PgazLtm07s9aKdz1SpSTusF9djoFoHFDCYmJU7LV09roSZ6/WkTZxjTQzBVau0iibwSe53NWH1fOYMH4gcj2ril9akyHFJqbvKNZ+0EnzqsD+nkrrK8IEn5+/s0QJ9Jd+FSxK3+n9ZuZh6R3qs1sUBOHPHrVnr7gDo1+k1UKIpP0UWM518TbtMVLGF3esS6GzWi8ZH66ebMHjVbcgBZvDHk9P2grshrr1jT/AJmKRT4EI5Pr8gNKIJ/zho8NIdqMuZ3PxQ/xNX3DxTxM9KswAgltiWymx/i3Duw3yljYxb3hDg4zt/Dpbl3EYE0ndHwmYgR/NaO3xiLUd8oE+8Ni/5pDmvZ+Ounm01YsPwqLZI7i1Kz0zq//b8kH50BPs/hJZ0phGAkpCrufYzgYEiykBUm2jGJAEzQ70dCY4H/VwbF0awTZq8UbRIEiXESsFPwx56gzjzqG1I72xKMcHY+njyNV36MfA5KIkG/Yfhdk/dj81bNKmYMPqlDjEj2NDvCPSlsFwQJB++hz8GdrLWwQPJJPNvQCphlxMDol6roL7XQ/h5HPDT7SpxS7HdzSI/kJQAnslZcjNKbxp57g4c0wlDrNUd2DQtsUjepkO9MkeoidM6pS4y9I= X-MS-TrafficTypeDiagnostic: AM6PR0302MB3480:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X9OwWgGzta59VYgIxe1A7m+ooQ8mFD0ekCp+JbfkiwIQ3MQnx6dfdx+6q7GqUijcvj/ckL4aPa/xXDHXhaRNwnM6gDpLRpFWUL3fbSMLRWutqamUDJIBp0edOLdra1S2Z5prSTrAZPRXeVxe/sti3fQFpaDHd7VkdCmkh+o67bFJ1fmuEnBfavCvv5LjFhz1kEdikoBQlbdCLRlgitw8GDvmu8+2sol2+I7dMmlsfFi7bwNNsCmWaUpjT3877trAcMsSVP5kS7IthPWMiW5pP/Ozj52rGBb9hbf1X5vOYIXI3eGfYJ3AsZCHXkPvxwkvckAvPnoK3vNvR67QBjXd0Tn8icVcaWvgaZLql7nSuQE0QkmYKNTmJOaUsJRrNL2A0Dl6nvBURvB2LUEyHj53RJSvNJJys/YJFHz9cT+7PiBGFySIJ5c12beyhaqG0VDfmNz+6VaMNmcdcMQ6hk0tpxDJgFoaV2+RnODljTaQGcdygkVEYNu+enz9GaBaXcZnUrY/OQfpDE3vq9UpH6VknV+oQ6OsN0CmArLAdE7MCY82/V8a9VjN/r5XYtoRtpkjjQE1txaLVg8L/wT2YGf7WA== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yxd91h027NRPNPWMuUMpOXsn46VfIP2gnHVNGDetRQ7swOYya0yu7O1Vsb4yz/dWG1jS4hJfmjFMWX0NV5D9yXCEUdwmsFnrcqzoh0YP9kmw8RSdK/cICZpEkwumNMS8QEK3P7E9UIa8jkf0g2O7Vj6nJ7RS9nrvfNgoSQLyQEZ+66Fj03BBFud/BY1+eD/T/DaMUjk+GcGANfP3tKw06LLR0MHcb0EVrbNb3Ppk/ZxgP5NvH0jH4bUaNIavDgj5/EdYVNAQmc9A6fnft39wzu2qS0TAntFGY7cmGnCrjlfQdvIxvbD/1ryaXYALius8VcW53eMg5ely+89hJDFcBqlXBMwVo3XSNrqpubSa+q2iT9QcJF0C+T6Kax1cHrPg6EpnAXNHk8DeZJC8sPTJpPdMQcipS9BVbS44Joi6FUY4GLRFvgPmyfZasceZLLWu0eUVhdBe0Hz/a/sV2cFB91t02gBeanWzvTWreGdEp1lDzHupeZ1gDIqUzZ4zDJDL1LdHntXfe+giI+u1/IdH+rakuk9yd37kbf/AZgSRggEj12OjQrozBLmzu4+rAfM+7By9lEAX/lZHFbHd+YPqxcYVqIrnnbSvu+UbdhmI1/FEoAQ1IYcAxEyaduozItb7d1bFIUQRTcY3CIrLPST7/eLCDbVEtt0ZsEMzwGUf+fwaSnghAwJvgdtlsF5RL3mCPGng8r4GwJAnvW6JTeCgpj445VKsZ0dVNGwpetWOa6JzHjLfWnrPkbrtDEsQbLhTFWPyeEnwP1EIrVbhAU/1bKNuwmj1hDJvX4n6TognVdmswROG0vZhMjUTlL/41HWzv1AnCY5E8W4QQrNmpVwkm5fCE4dUPb6TzTidKagSrZJRb875QrUzdTEod1hjglWL4e4sLFJa5rvQi2u2y6BkippCgzZqasPyQJ3NZEfEMAcQfYuf92QKXjJWcJO61r7a58ojYjbtzru2tKi9cAZdTg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 769537bd-fe9e-4bcb-1e7f-08d9b9d86115 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2021 23:22:05.0307 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0302MB3480 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/movtextdec: Rename several structure elements X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: X9H69IM6UlmD Content-Length: 6263 Giving elements of a structure called StyleBox names like "style_start" or "style_end" is redundant, especially given that the relevant variables are also called style. Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextdec.c | 54 ++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index 4e14ae5900..7021ad9e24 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -54,7 +54,7 @@ #define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff)) typedef struct { - uint16_t fontID; + uint16_t font_id; const char *font; uint8_t fontsize; int color; @@ -68,21 +68,21 @@ typedef struct { } MovTextDefault; typedef struct { - uint16_t fontID; + uint16_t font_id; char *font; } FontRecord; typedef struct { - uint16_t style_start; - uint16_t style_end; - uint8_t style_flag; + uint16_t start; + uint16_t end; + uint8_t flags; uint8_t bold; uint8_t italic; uint8_t underline; int color; uint8_t alpha; uint8_t fontsize; - uint16_t style_fontID; + uint16_t font_id; } StyleBox; typedef struct { @@ -186,12 +186,12 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) // StyleRecord tx3g_ptr += 4; // fontID - m->d.fontID = bytestream_get_be16(&tx3g_ptr); + m->d.font_id = bytestream_get_be16(&tx3g_ptr); // face-style-flags - s_default.style_flag = bytestream_get_byte(&tx3g_ptr); - m->d.bold = !!(s_default.style_flag & STYLE_FLAG_BOLD); - m->d.italic = !!(s_default.style_flag & STYLE_FLAG_ITALIC); - m->d.underline = !!(s_default.style_flag & STYLE_FLAG_UNDERLINE); + s_default.flags = bytestream_get_byte(&tx3g_ptr); + m->d.bold = !!(s_default.flags & STYLE_FLAG_BOLD); + m->d.italic = !!(s_default.flags & STYLE_FLAG_ITALIC); + m->d.underline = !!(s_default.flags & STYLE_FLAG_UNDERLINE); // fontsize m->d.fontsize = bytestream_get_byte(&tx3g_ptr); // Primary color @@ -218,8 +218,8 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) m->ftab_entries = ftab_entries; for (i = 0; i < m->ftab_entries; i++) { - m->ftab[i].fontID = bytestream_get_be16(&tx3g_ptr); - if (m->ftab[i].fontID == m->d.fontID) + m->ftab[i].font_id = bytestream_get_be16(&tx3g_ptr); + if (m->ftab[i].font_id == m->d.font_id) j = i; font_length = bytestream_get_byte(&tx3g_ptr); @@ -283,14 +283,14 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *a for(i = 0; i < m->style_entries; i++) { StyleBox *style = &m->s[i]; - style->style_start = bytestream_get_be16(&tsmb); - style->style_end = bytestream_get_be16(&tsmb); - if ( style->style_end < style->style_start - || (i && style->style_start < m->s[i - 1].style_end)) { + style->start = bytestream_get_be16(&tsmb); + style->end = bytestream_get_be16(&tsmb); + if (style->end < style->start || + (i && style->start < m->s[i - 1].end)) { mov_text_cleanup(m); return AVERROR(ENOMEM); } - if (style->style_start == style->style_end) { + if (style->start == style->end) { /* Skip this style as it applies to no character */ tsmb += 8; m->style_entries--; @@ -298,11 +298,11 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *a continue; } - style->style_fontID = bytestream_get_be16(&tsmb); - style->style_flag = bytestream_get_byte(&tsmb); - style->bold = !!(style->style_flag & STYLE_FLAG_BOLD); - style->italic = !!(style->style_flag & STYLE_FLAG_ITALIC); - style->underline = !!(style->style_flag & STYLE_FLAG_UNDERLINE); + style->font_id = bytestream_get_be16(&tsmb); + style->flags = bytestream_get_byte(&tsmb); + style->bold = !!(style->flags & STYLE_FLAG_BOLD); + style->italic = !!(style->flags & STYLE_FLAG_ITALIC); + style->underline = !!(style->flags & STYLE_FLAG_UNDERLINE); style->fontsize = bytestream_get_byte(&tsmb); style->color = bytestream_get_be24(&tsmb); style->alpha = bytestream_get_byte(&tsmb); @@ -355,13 +355,13 @@ 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_end) { + if (text_pos == style->end) { av_bprintf(buf, "{\\r}"); color = m->d.color; entry++; style++; } - if (entry < m->style_entries && text_pos == style->style_start) { + if (entry < m->style_entries && text_pos == style->start) { if (style->bold ^ m->d.bold) av_bprintf(buf, "{\\b%d}", style->bold); if (style->italic ^ m->d.italic) @@ -370,9 +370,9 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, av_bprintf(buf, "{\\u%d}", style->underline); if (style->fontsize != m->d.fontsize) av_bprintf(buf, "{\\fs%d}", style->fontsize); - if (style->style_fontID != m->d.fontID) + if (style->font_id != m->d.font_id) for (i = 0; i < m->ftab_entries; i++) { - if (style->style_fontID == m->ftab[i].fontID) + if (style->font_id == m->ftab[i].font_id) av_bprintf(buf, "{\\fn%s}", m->ftab[i].font); } if (m->d.color != style->color) { From patchwork Tue Dec 7 23:24:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 32117 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp6946527iog; Tue, 7 Dec 2021 15:25:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJza3UCpqbMqiQytmdYbilMtd85kkyrVMWC6SZKJGjKpmcvglk2nmRmqJznFwVtXLkurUIaW X-Received: by 2002:a17:907:7210:: with SMTP id dr16mr2975724ejc.267.1638919517497; Tue, 07 Dec 2021 15:25:17 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x14si1941523edd.374.2021.12.07.15.25.16; Tue, 07 Dec 2021 15:25:17 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=jsoar6wf; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E11B568AB2E; Wed, 8 Dec 2021 01:25:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (unknown [40.92.89.38]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D0DF56880FC for ; Wed, 8 Dec 2021 01:25:07 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eQxoXyVahwyYTm2L0muHdmQFkjxQwEDm8jEV+XmJhpGp/VDu+/Q2nDfYXSApiuDSSLLUxtxHMpNXurZ7GTmlEXT0Q1tv+h0zRu7kx+7BRgb+uJcOtFlq0GLm9g7NgUhjkh/7zSxidt3d5lbhe/ALfhWoriK2DzaFbD1e4qywUJ1/HUR4Zg5mdmgETykcAwCqP+0I1P6Gn5K505UKqcC9X9nxMMNNIxBVcTxfilGu4QkRvOW1XVN/V3IwzbPnGz6VUzbWh24sz98rRSEDWCy5wWqXiSFh28v5vfh41gzZga/EbTEjdkiwr15b1o6MktH5XHaxu2KK5ZVdc4HsIFK7ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4CJyk9G9Gsz+LNRCBJCczAGPFBJKLx8Hr5nCKuoU+Y8=; b=fZHqeE+nNMOTq/LkDcdxZsSLfx5+nkIxt7kDtcrPJ1CJe35yQUPKD7CZ2sD2xXwyCZg+5pBmTQB/3EkNxasJx7+7eHo9wLo4yNiWW2+35V84o1oYOql3gJPLtA9fIvL+8iJr3vqn33scnMTEkeW40nTJZpfP+wFtG8B3qCr2BOZrYPdEGoMzdVv0RDASLan19tj4UYJl3iVD15gNiDjcG1exQG0U37Vaqm7e76UgEvcKyTQbHowNeHoa/HYi3A6QzsQr+MO7KbKhcvcU33pN5CJn9kKSifVSqflCyV6EH4yeRJPRoWmxCPhq32UF1QimMJKmbkKO7Vydy7B3gS8oLA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4CJyk9G9Gsz+LNRCBJCczAGPFBJKLx8Hr5nCKuoU+Y8=; b=jsoar6wfTO376qNeRc24XYhi+MQVR+JRC5B//592mt6SXoQb+/hNJl7sThfuKm27Wq9DMwSQyihzhHrivJJ/Vesx/tKfzGagfVNH+5VhdwETD/T8wMYj7zK69mEYjfYOZ+WhEIj2aRRHgJvSubAks7kvuVdP/fhkDOwHg63i19kSrUJ4Ub8ex8+4Mlm44ThQfx1xlh91t2NodEt/OQgBRbil9xTWyzda7aiB7IENeuBWbjvWbOSRczYaRoKCTGUcgSSTay2ySfiektZZkCvJGb1lrpSc/8Lp+Io4qOXb0Fphaembp2wrt1ddoxl5yR4ZbOmFOTpjn8XulrY8pnPHQw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR0302MB3480.eurprd03.prod.outlook.com (2603:10a6:209:19::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Tue, 7 Dec 2021 23:25:06 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.024; Tue, 7 Dec 2021 23:25:06 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Dec 2021 00:24:57 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [/4SSl7rZZKkmrXGMjWUUgV5KcY33QHW/] X-ClientProxiedBy: AM6P192CA0034.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::47) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211207232459.483893-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM6P192CA0034.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11 via Frontend Transport; Tue, 7 Dec 2021 23:25:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a7fcd122-95fc-479a-1578-08d9b9d8cd79 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXOjPmV/Ff/siVXexYT0WFzwlbFaG+vXipNWAJZpmO2CLo3jIGiKp+HX4H6pBZyuzC/f/Jr7scEEpf/luCrwIIAhGTHualubYLUCQ3NPklog+eBxtiVS1fNXV1FpssgbSTQDdAxspDGbbi4huD2gtlVhTLbyquJ2bfshTUSqvJ89zr5oDhOnqfdrMsQ6w0agap52ZD6qKCqjA/MevHFy6fVzfP4Xg5vCRbLpZ1h1fpc8gEwtNX0zZDahJS0yAyJGFq3C6MdZMKkU0rF1phZpzaHeIV3eC5rfeYOEp623KYF9ZRwwUceA/6FywTEoUTYRzt0qt7YfuwlFtYvfvETfAk/fpxxhVg2DDkDztspub0CzSlUhZ9t9E3BqxFwAp46a2mFEBd7l+97E4RqynOO3xckjQQKXF/ganX1q0D7vLuMNlKjOZbVFc7ePgopaNahehCh02dufezWUGibTakeGtd5jHbMaJqtrX35r5uaszDb8n0mE0hxhPVsSj8Zci/54RCbPSEOD8KVRr0WlPj0EgdGzehWvsHH0kUm8O6Vxlswu1VuPiboBatU9OkncuAXfMRFMyg+BOwIPcIhMvJUveLGzR/NjJEoOO+E9MNIK3AiEv++cwP5x8Xq1rrt+vy+wWXAqqNFhXDDIW/g1rTHh2lC59Gik2FVCxZkJdHXDIu3RMpKL1Peerg/7FUcze04K/uoTYdchhFColtCq02agoCp8Sa5IqLXOFM= X-MS-TrafficTypeDiagnostic: AM6PR0302MB3480:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kFcfsxr1zdHFRWrEM6X/soC0YB5wj8Ig2wcAEMue5DJMt71L6xFRrGvscQFvWHmD8QvT37MdWHbL0qunutco3UwEilR+BP15LekthvoclNZX7MBGTAhy9Pfp8QEvlqcEIPlHaO7ekAvQKpkEIyff+fxdykmJh1RV3wVgS4V+Z90HByVM1eItliPkbz0ae2FnUQW8ULmD5WuN4yeLfoN1IxlgH98VEtEm11IQex3zEuLj3ldPlYITnlTSM8wLfSx0XfN5ik4A6XQG07vzt7sOvzHclqDT+sjscoSbEVQLzXo3oHp/MdahiWv/i/6KEhUryIHpz2bstt1+I6BM7bnq2Cdu2iqoA5+lqf7kqL/pQ6rbHCKZQXKOyTR0RPsekky4Oy1GMFYySARMxwnef9EEi76PYBpTf4WrnBdBrwgOfZPRS89efB1x3iJ113uCqpFztq5i9kP/RsLWTLL/T0Q11/JEYK/1eOV9/XqgbDzY+5vNzZSgfFBOxsqi83ICWsM/eQVHZtkzDBusZ1wjQqNxWDqFf4bWB3cFjkDy4uPumHtp9N2NXQWEh2HGRLeju6oqLsbKhuTv345F0XBKEDsqzA== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c8o+l8vONUNmFW4aRu9zP4OblluyuqIKGJtyYnI7ZjmPe6SWobiiLTjAXY/CUsH8XpcS8NO0Y5lxJxTFHsZYdoF1HjdojhWdy3Kgw5I48ZjdjTSVrbRPoYfHQiN1KBUMEvXeyEnZH4F157h7m58zDkmuk+iL7xguKUXDZiZxYi6DrCfHv6aUyn7HHY8nfx9d4BibM5gmjAbv2/mrkWpi/Z7ptYdAo7m6fSV0qEW0cw/gV0YE084NkqVzNBItHKYJ2g6rYriFfThaUCdYDraWeDKeSK8k2idSIlLEsa7FlrhSFGt2Nk44EBDpedn5Te2B/Het8B2i9dJggNW+0n/DRuYpdxVlYx8feZT7z4qUDjehJjEzh9jmMOifew+gVhP1wbZl8NngBXIbXjfsHTUmFszoeJyiAZs+Lf23zZZQGcwrc852Vcqc8mEXVV66dNpHbuTarfD+kWOeihR0HJh5cTIU/r1TogQE9BZOKC9H/toMh3N9QpgIo927wDgkMa6AulkapLEFFOZPqJGpt7smZKQ6/dtBZwAZj+lbatXmobeeV4TSd6QrN79SN4VKfBRjUcZTCkGIuJ59PQzo85CblVVx/380SUcIUfjEgfcUjEZ73QtxNMt+uBJ79MsaDIwMiXy6MoxM2Y3Rum3jNq4hyzliczm3R1EAuOkS4QxJkLSSy4UxIGXx2pIvYVIg00AU13+2O5wu9vk7IL9pIelZGIj2ZR3aP14+l62GPd3dn4X90d59Yy4wZ24ZJ4WnYcBeJsY6eiMSsie992n0eqcbAVrM48OHAJdy4cKVh4/YgHwm2knvUd841LzHP17oIuGeTPN6aLrTd5GSwmmcKICupQBtl1wNrcxsKIYaKmAXQUm1BLiche6lfTj5VnkrEvzEA1ARIkjEWQCAEtmM/G+iqKpVR3CglF9UfRBWEnIsbD8eQ4lfUAXcDQEr3npzf+LXnzlEblhxpp4+liwpMGOq1A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7fcd122-95fc-479a-1578-08d9b9d8cd79 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2021 23:25:06.3620 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0302MB3480 Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/movtextdec: Deduplicate parsing of StyleRecords X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: zeTxqQ9Y18N1 Both TextSampleEntry and TextSample can contain StyleRecords; yet both the code as well as the structures for them were duplicated. This commit changes this. Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextdec.c | 95 +++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 51 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index 7021ad9e24..d3b15d07f8 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -53,20 +53,6 @@ #define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff)) -typedef struct { - uint16_t font_id; - const char *font; - uint8_t fontsize; - int color; - uint8_t alpha; - int back_color; - uint8_t back_alpha; - uint8_t bold; - uint8_t italic; - uint8_t underline; - int alignment; -} MovTextDefault; - typedef struct { uint16_t font_id; char *font; @@ -85,6 +71,14 @@ typedef struct { uint16_t font_id; } StyleBox; +typedef struct { + StyleBox style; + const char *font; + int back_color; + uint8_t back_alpha; + int alignment; +} MovTextDefault; + typedef struct { uint16_t hlit_start; uint16_t hlit_end; @@ -137,13 +131,28 @@ static void mov_text_cleanup_ftab(MovTextContext *m) m->ftab_entries = 0; } +static void mov_text_parse_style_record(StyleBox *style, const uint8_t **ptr) +{ + // fontID + style->font_id = bytestream_get_be16(ptr); + // face-style-flags + style->flags = bytestream_get_byte(ptr); + style->bold = !!(style->flags & STYLE_FLAG_BOLD); + style->italic = !!(style->flags & STYLE_FLAG_ITALIC); + style->underline = !!(style->flags & STYLE_FLAG_UNDERLINE); + // fontsize + style->fontsize = bytestream_get_byte(ptr); + // Primary color + style->color = bytestream_get_be24(ptr); + style->alpha = bytestream_get_byte(ptr); +} + static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) { const uint8_t *tx3g_ptr = avctx->extradata; int i, j = -1, font_length, remaining = avctx->extradata_size - BOX_SIZE_INITIAL; int8_t v_align, h_align; unsigned ftab_entries; - StyleBox s_default; m->ftab_entries = 0; if (remaining < 0) @@ -185,18 +194,7 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) tx3g_ptr += 8; // StyleRecord tx3g_ptr += 4; - // fontID - m->d.font_id = bytestream_get_be16(&tx3g_ptr); - // face-style-flags - s_default.flags = bytestream_get_byte(&tx3g_ptr); - m->d.bold = !!(s_default.flags & STYLE_FLAG_BOLD); - m->d.italic = !!(s_default.flags & STYLE_FLAG_ITALIC); - m->d.underline = !!(s_default.flags & STYLE_FLAG_UNDERLINE); - // fontsize - m->d.fontsize = bytestream_get_byte(&tx3g_ptr); - // Primary color - m->d.color = bytestream_get_be24(&tx3g_ptr); - m->d.alpha = bytestream_get_byte(&tx3g_ptr); + mov_text_parse_style_record(&m->d.style, &tx3g_ptr); // FontRecord // FontRecord Size tx3g_ptr += 4; @@ -219,7 +217,7 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) for (i = 0; i < m->ftab_entries; i++) { m->ftab[i].font_id = bytestream_get_be16(&tx3g_ptr); - if (m->ftab[i].font_id == m->d.font_id) + if (m->ftab[i].font_id == m->d.style.font_id) j = i; font_length = bytestream_get_byte(&tx3g_ptr); @@ -298,14 +296,7 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *a continue; } - style->font_id = bytestream_get_be16(&tsmb); - style->flags = bytestream_get_byte(&tsmb); - style->bold = !!(style->flags & STYLE_FLAG_BOLD); - style->italic = !!(style->flags & STYLE_FLAG_ITALIC); - style->underline = !!(style->flags & STYLE_FLAG_UNDERLINE); - style->fontsize = bytestream_get_byte(&tsmb); - style->color = bytestream_get_be24(&tsmb); - style->alpha = bytestream_get_byte(&tsmb); + mov_text_parse_style_record(style, &tsmb); } return 0; } @@ -337,10 +328,11 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, AVCodecContext *avctx) { MovTextContext *m = avctx->priv_data; + const StyleBox *const default_style = &m->d.style; int i = 0; int text_pos = 0; int entry = 0; - int color = m->d.color; + int color = default_style->color; if (text < text_end && m->box_flags & TWRP_BOX) { if (m->w.wrap_flag == 1) { @@ -357,29 +349,29 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, const StyleBox *style = &m->s[entry]; if (text_pos == style->end) { av_bprintf(buf, "{\\r}"); - color = m->d.color; + color = default_style->color; entry++; style++; } if (entry < m->style_entries && text_pos == style->start) { - if (style->bold ^ m->d.bold) + if (style->bold ^ default_style->bold) av_bprintf(buf, "{\\b%d}", style->bold); - if (style->italic ^ m->d.italic) + if (style->italic ^ default_style->italic) av_bprintf(buf, "{\\i%d}", style->italic); - if (style->underline ^ m->d.underline) + if (style->underline ^ default_style->underline) av_bprintf(buf, "{\\u%d}", style->underline); - if (style->fontsize != m->d.fontsize) + if (style->fontsize != default_style->fontsize) av_bprintf(buf, "{\\fs%d}", style->fontsize); - if (style->font_id != m->d.font_id) + if (style->font_id != default_style->font_id) for (i = 0; i < m->ftab_entries; i++) { if (style->font_id == m->ftab[i].font_id) av_bprintf(buf, "{\\fn%s}", m->ftab[i].font); } - if (m->d.color != style->color) { + if (default_style->color != style->color) { color = style->color; av_bprintf(buf, "{\\1c&H%X&}", RGB_TO_BGR(color)); } - if (m->d.alpha != style->alpha) + if (default_style->alpha != style->alpha) av_bprintf(buf, "{\\1a&H%02X&}", 255 - style->alpha); } } @@ -400,10 +392,10 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, } if (text_pos == m->h.hlit_end) { if (m->box_flags & HCLR_BOX) { - av_bprintf(buf, "{\\2c&H%X&}", RGB_TO_BGR(m->d.color)); + av_bprintf(buf, "{\\2c&H%X&}", RGB_TO_BGR(default_style->color)); } else { av_bprintf(buf, "{\\1c&H%X&}{\\2c&H%X&}", - RGB_TO_BGR(color), RGB_TO_BGR(m->d.color)); + RGB_TO_BGR(color), RGB_TO_BGR(default_style->color)); } } } @@ -441,18 +433,19 @@ static int mov_text_init(AVCodecContext *avctx) { MovTextContext *m = avctx->priv_data; ret = mov_text_tx3g(avctx, m); if (ret == 0) { + const StyleBox *const default_style = &m->d.style; if (!m->frame_width || !m->frame_height) { m->frame_width = ASS_DEFAULT_PLAYRESX; m->frame_height = ASS_DEFAULT_PLAYRESY; } return ff_ass_subtitle_header_full(avctx, m->frame_width, m->frame_height, - m->d.font, m->d.fontsize, - (255U - m->d.alpha) << 24 | RGB_TO_BGR(m->d.color), - (255U - m->d.alpha) << 24 | RGB_TO_BGR(m->d.color), + m->d.font, default_style->fontsize, + (255U - default_style->alpha) << 24 | RGB_TO_BGR(default_style->color), + (255U - default_style->alpha) << 24 | RGB_TO_BGR(default_style->color), (255U - m->d.back_alpha) << 24 | RGB_TO_BGR(m->d.back_color), (255U - m->d.back_alpha) << 24 | RGB_TO_BGR(m->d.back_color), - m->d.bold, m->d.italic, m->d.underline, + default_style->bold, default_style->italic, default_style->underline, ASS_DEFAULT_BORDERSTYLE, m->d.alignment); } else return ff_ass_subtitle_header_default(avctx); From patchwork Tue Dec 7 23:24:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 32116 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp6946679iog; Tue, 7 Dec 2021 15:25:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyjjCGi7z0Z4Ob6Vq08N8bxq9eAXNcjPPQ2W7wQcwM1LeEoXCSGoQuNJuryqEg+Cwh7MdY0 X-Received: by 2002:a17:906:2590:: with SMTP id m16mr3035289ejb.38.1638919526865; Tue, 07 Dec 2021 15:25:26 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id yd6si1448783ejb.108.2021.12.07.15.25.26; Tue, 07 Dec 2021 15:25:26 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=Y5qP5Rgq; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E47A068ACC3; Wed, 8 Dec 2021 01:25:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (unknown [40.92.89.38]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0B35C68921B for ; Wed, 8 Dec 2021 01:25:13 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AyNg5BWmEzqOgFju6PoOh+8q6a9NhJ7kW0TwfPeFAQKGgvrCl9nbf6N2enmI4ZcQYgd6iD5ZjBvTheTlWZP5nNUmGlJpY5Y3e5fFLDYBKIkqRBBgikDnswXn/vgIbAz+6ATfdQpPfPzvdaL2YMMSwHhniRdVuX9kwAgwVZUN58qj2mr7/j6zMCblViSbT0IWDquDmUz+RXIk8aMe3Ofh9jzALdEI06b8pyd5p8hgsAZ9WzFUr77UpOZBhIk+uJCzw/tNGCAjClos+SQjPzuJwsYVrHumcSEoajrNMzUGeEUPzU+RVlV7wKHcnWqYbcc97zvQN7D5oO09m9gNE8OUAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MXEBh4iZ0uGmrUzCsmgPDB7c5WX2DjbD3s7GK371OUw=; b=KfRfkpmgQFNWvvPgvK/3E8xnUAY4NMfOj21teJzeZBtn/Ssfk/z8hcEcAISNDmVs0BxNlFtVhQE0whOEkFnyRa8XTI5rgays7lU1pGEFbjlK2HyjHaWBK2p8AEElQSR16oSAYG05DChNvnaCexhlGWAJfSavBYM1MtiDBeMbNA2oVn0QuRUln3Rlb7tDS+DCSHTZJcx30tJluo97Grt73Uc3B0ZvEp/EoU5E5uHTyxoEadXb+knrp9YYK7Zzz4xOHUJBJ6j5shd+YCWABR5xspncAFeeSzfjmHyIK7LegqCHoSoyGKO1LmIaSFH9OqbxrX/O0/heG6vS+Rj234k5Bw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MXEBh4iZ0uGmrUzCsmgPDB7c5WX2DjbD3s7GK371OUw=; b=Y5qP5RgqEtc0szC+MhQdUFKMEqS8qwD8dpE4GVMMDmFl/4Y42geiEyjLFG8j4k6GtPBT9n/0d8YibiLTYdWJDtgXVskEJSyFG3uxSsQrKOx4i/mddMCeKNM25rgO3Ntan29ETBSJZYHwM4ShPS9NRBMci3L2w9qaJZDZnDqadvpdKBMPCxJDVG2C64xiLeVukASIyJq2Ah+kBqHlyC+IME4EdEgQMzIqp7XgbNUlXJ5PqHo2kYAx8mOIYnwBkPnWiBGcUm0GlMP6DgwrnpKJy7etKFAL1mX5rne76l/UJGHXxNkm5ioMDjJzG4L8R8Z02QTz6XsOX0/5ZmzLj1waGA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR0302MB3480.eurprd03.prod.outlook.com (2603:10a6:209:19::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Tue, 7 Dec 2021 23:25:12 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.024; Tue, 7 Dec 2021 23:25:12 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Dec 2021 00:24:58 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [7aYQ/ekVuf2dK5nghzWqM46k5M6P2Ok4] X-ClientProxiedBy: AM6P192CA0034.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::47) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211207232459.483893-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM6P192CA0034.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11 via Frontend Transport; Tue, 7 Dec 2021 23:25:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d8983cb-2547-40ba-649d-08d9b9d8d141 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSZafVhYkhL3hNKBaHIpDWhgr/P8CPQmxQ8kpo736YRihTKi9RQh4g/HUUW5kSqtCE2wXcVDzhNf+zxiWTI1sZpYTP7Yj0wMkyyNvzVb/woHZXbXJWU/O+d9tyG1QMHu+8Cep5VW0FofQjGuu1T2TzntJzV3BDJ4tOVWIKap8zxFdrirAvnBnQL6hylHr+nKFCkMb88dLiEnXpsnEVzuptj3qkFJWl42DHkfPR1BnmxWd3ZKA22uf9XGZFPQxzyq480ccFGIeB+ozTucakDuKBoSSQAvOGj+YWlU6e/wELZFccJHkPIb0kXvzKfSSvgDgC5y0woTrKSTlWCQs++3YHy+b5hBOM2mt7/ZPJvlfXTtXu64rxXrAmkFlHWVmTdlVy/EVkizgcll0NfER5CcHMgQvy3KBOdn8sKqxZQikD+xLpxMkfTcdnAUAslRlnGhDsgMSm5eQo9H4Uukp4PqnPfxyeCSiroNQhGa+4tMbqb3hoKNg76cAb8B79/rDi8A0DrG9uuq2C/QnHmhn9SdRKL82nH3jfD+K7KkyF/4MqQNW/9Ot6C5x15cXLfWUP51OTz+3WiaJjx4HbqVpRS8097ajOXPksnShIjBxEFT+7Inxk2xut6fwOzW7ADo2M30v+sBmvZyqVc5oBe89PJUR8A6Irji476JvHKHKtr+0F+z+3OReJYLHlWZLAlltxsWq3xbsfs5bZ35bH6WeoG1KflXr/+V4us/IZ9i9BuDXgpYm7oj1oF0jqyJIZV/zxA4YU= X-MS-TrafficTypeDiagnostic: AM6PR0302MB3480:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qQ+AWnVWPZ3bulzDwimRLRIC3yuXPlogCqeTJibyWyRj0UX79lqoREfhmnHaQ9DVEZUByJ4Pj1ufXJuUMviVigC5paVOtTOgiK1nwMwL5++O2C36cFGfkKTYfsTHXQO8y0ESDCqqyc1gKQqXipFt87yYxmR99PXIXxvO5MEhkZlZUbsG00vBLY9ic/HzlLMpAfnIb3fB+ExoKqFTxSNeuhjayj3lQcoXPg9JhwHgu5X2oKpj7xix9BPnTSXHW3fGjXB6Lr2O80+BjO5D78/LmuUse8r+dfeqtvLK/Mk7xT42lAD8l1u6MzeKjtqGvsY++84O9mOqG8tTvfOo7RTQjHVQB2gQXLwFlwW/FDMXck4VpnkZBU1Zg5vnJQG4ZQZw7Fr6qCa1sCfEYp9OtmpnD/BZY+4d2RgOWCNmSun/srL1wnAfT2CaJxZm0j3FlLBtJFP/H00JPtF6b1oo6FkA884YqA4QB7Aauc084+b69zFZN5Zx4XdJpguF5mHv3J5YiPtZUSu2Bg5yGooUKqUifkLikWGsTslDkhi2abpqi5oUIlUgcqGuBQ9XOVnG0FADYhndK5wKiUuoFXD/U+IJcQ== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WbYtkoyRyCNmSB70bnhZDf2GE14YZDQafuF3DndWJiwReVL2oVTZH9kiZrunJnaWE3yhq0u+DxOany3SkzcmLAK23/txUmZTuK1jfY+7DOgJcu/84zB1f4IjuE2uPDAhhw9a30HJPIMkWQ3WAyLY8/g1Btxu48HVzVVsayBh3mlKQl9PRhQE1WWBoqKa/SjdJZ7JPZpa3b0yqm6mdjc5ibzrTgREGOjOTEDtdpV/INlII0LdKA79VW9aj7MV/mh1MIpWKYr0S1Q6L16xcv5f++5Lhgz+qSwQivWSBR3cPiy13/4neIm4M782RbJ+hLzpyI7I8yrzjv3IvVwdCKy4d2qPAz0esfeVvm5+fbkeYo9MjLGpFCQqQo1Cpk3mmCH1b9lLD+STiJCuXlpg+43oaVIBD5KHTTsLH8fSjVfz37ID6nb7u5OeY0BqPp2t8tzb8BlPPdbjDVADzwgCjyWmEyigSyKJ/UIiHU6vX/0vp8d8TQYIODgRbyAxbj+vaHJt5TJyuCa//h/iOvKZeQGLgzXbd2T2nKfnjIt8Dd9HdpxorHe5qzvHQSgeV4HZQIULHX/C82dJ+AmlPPzL94bp1GiWyW+mG9lCKTYIhY/e4P3rZ0KTbSMmrsU/qEF92wZRmjJY/hEAWok+p712MdEQQZD9qi/oVEWLZYmekiANPqYLNMZp3+BlDYEd5KtOBTZm7k+deQ866Hmv6vC8D0ahKIy/7NrhsEvpd54l3k6upnGWes+i2vNSZ6mDA8tE2BcUfKF6jdLsrgo/ACYTa71WNb7fI0KdUu4zXeCox/KrOGEAVMJJkCrd0m4i6z3voAYCVlKSFuig3ln5atX/UYWHgNtSGC49WhKyGZx/6GTiBMggwIFnxZtyIVIuoDBhx6hw6wOiAifDwOm9UEbm3ktInkjZZKaDJxA7VoqVeKe+aE8KrhdbHtkCa5GoVaUP9On4gPh/gF1efpB2WSwKO5V66A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d8983cb-2547-40ba-649d-08d9b9d8d141 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2021 23:25:12.6152 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0302MB3480 Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/movtextdec: Perform RGB->BGR color conversion early X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: c5yLG6yf3nTq Reduces the amount of conversions. Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextdec.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index d3b15d07f8..c50626c0b5 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -144,6 +144,7 @@ static void mov_text_parse_style_record(StyleBox *style, const uint8_t **ptr) style->fontsize = bytestream_get_byte(ptr); // Primary color style->color = bytestream_get_be24(ptr); + style->color = RGB_TO_BGR(style->color); style->alpha = bytestream_get_byte(ptr); } @@ -189,6 +190,7 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) } // Background Color m->d.back_color = bytestream_get_be24(&tx3g_ptr); + m->d.back_color = RGB_TO_BGR(m->d.back_color); m->d.back_alpha = bytestream_get_byte(&tx3g_ptr); // BoxRecord tx3g_ptr += 8; @@ -369,7 +371,7 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, } if (default_style->color != style->color) { color = style->color; - av_bprintf(buf, "{\\1c&H%X&}", RGB_TO_BGR(color)); + av_bprintf(buf, "{\\1c&H%X&}", color); } if (default_style->alpha != style->alpha) av_bprintf(buf, "{\\1a&H%02X&}", 255 - style->alpha); @@ -392,10 +394,10 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, } if (text_pos == m->h.hlit_end) { if (m->box_flags & HCLR_BOX) { - av_bprintf(buf, "{\\2c&H%X&}", RGB_TO_BGR(default_style->color)); + av_bprintf(buf, "{\\2c&H%X&}", default_style->color); } else { av_bprintf(buf, "{\\1c&H%X&}{\\2c&H%X&}", - RGB_TO_BGR(color), RGB_TO_BGR(default_style->color)); + color, default_style->color); } } } @@ -441,10 +443,10 @@ static int mov_text_init(AVCodecContext *avctx) { return ff_ass_subtitle_header_full(avctx, m->frame_width, m->frame_height, m->d.font, default_style->fontsize, - (255U - default_style->alpha) << 24 | RGB_TO_BGR(default_style->color), - (255U - default_style->alpha) << 24 | RGB_TO_BGR(default_style->color), - (255U - m->d.back_alpha) << 24 | RGB_TO_BGR(m->d.back_color), - (255U - m->d.back_alpha) << 24 | RGB_TO_BGR(m->d.back_color), + (255U - default_style->alpha) << 24 | default_style->color, + (255U - default_style->alpha) << 24 | default_style->color, + (255U - m->d.back_alpha) << 24 | m->d.back_color, + (255U - m->d.back_alpha) << 24 | m->d.back_color, default_style->bold, default_style->italic, default_style->underline, ASS_DEFAULT_BORDERSTYLE, m->d.alignment); } else From patchwork Tue Dec 7 23:24:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 32115 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp6946847iog; Tue, 7 Dec 2021 15:25:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2hKhi/uhIvZeXFOKQK5NTyJhAYnMJ1aH7BNLVDg3qQ05XTexRF868P9VkZufaFDmMUtSp X-Received: by 2002:a05:6402:3da:: with SMTP id t26mr14016612edw.232.1638919536388; Tue, 07 Dec 2021 15:25:36 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m17si1767813edj.224.2021.12.07.15.25.36; Tue, 07 Dec 2021 15:25:36 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=KAlQIGVW; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0550768ADE7; Wed, 8 Dec 2021 01:25:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (unknown [40.92.89.38]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D68268921B for ; Wed, 8 Dec 2021 01:25:18 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ghvBV2JbgoFEUfs5dXvz9dFVU0/BonbITE/yfk09IS1VzK+ODsmmvdMb35ITVkQyndygsbPuoyJZVRterTbeiRM2ynj8JxP+eMW93d00hO4SL9tDFTo5Edvvek1BzAfbtExFIUe6BxEvakOLHIf+uRglnGvCFVKkl39wiuhL/EbLjs/9qp3MdBSczUqLZAuibaxQU+So8HSyvSrWr4mJFgc8hO4VvaVwp8cKBv1AOhec0tslvwd9j6AGDuTFgdEGsSZLeTZHSEPanEzhMQHUCPZz4fw5YtZ9LgD+W4leo18WfU8vOvkF+fcl72eGOckLet0p+nJ0QmRuPzjMOEnGew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ISg0kpsgwaGJjdZlBcdUmZmKlBc/tq4wuy7XnRgB8Jk=; b=j63Ixtme9QOrt4DwGJ2wgZotvVbg7XI90zYgvwnPU6jgYgh8MExYTY1ofQe162wJlH5zsQkcEmn3bGB1g6HWoDemdgiJ7VdOrgOuMxoIk2OGaC63DMZss2FJ3kbqELrFJut47kvCg1zh2dFrBTBTuLNFVeHHoiyhQUAB57H0hrrpfZg0KjhtdxU+7j+kJ3PHbURpnQJ2U+sJsUgk+WkhVtgQlXEom0vNUIxAYjJUMcn1B7w2OJk+HWpXKCUplDNbHyV4Qt2Zjd8+a5Qo2shCydmkRvYcee3Uyw/qsnyp5K+jHEGaRGdsxYZMAIxE8TlaOCgHO9dFymrkl/++HmeVeA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ISg0kpsgwaGJjdZlBcdUmZmKlBc/tq4wuy7XnRgB8Jk=; b=KAlQIGVWXN3SVq+GgP90+pVBq7lkXbhhG9vm12242RmRVYGxY+dsNqmp8CMeDdv9Cx5qtPthb0tbNcZuqcFUDtBY2FlkgfppTMrZLDFiHV1efYlKV4OwAE+sKz7Wg3xbwFAyi4mZT1uU8VgBtYUeeRvkDoFPraUKmxC8WZanzO5sfGTnHhV1QWgEBx1AjxOIO1aj81bJOBKIijiWzE7jAxsfHUkMlGIOtP8xg1jYSVeBodlWyizeiw6a8F3vEDUtwugyKkjVwddw/tH4DaP6tZ+mx0GnCh7SEb2aTgVdWrlGGcVC+u/8Wr8swRrgpmUtM9+s+25kRyRxt0ErrgCjrg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR0302MB3480.eurprd03.prod.outlook.com (2603:10a6:209:19::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Tue, 7 Dec 2021 23:25:14 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.024; Tue, 7 Dec 2021 23:25:14 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Dec 2021 00:24:59 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [EA4rKOXOru4n1scKR+1GaVTFmSBZCIiT] X-ClientProxiedBy: AM6P192CA0034.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::47) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211207232459.483893-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM6P192CA0034.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11 via Frontend Transport; Tue, 7 Dec 2021 23:25:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d6368e85-c01d-45ed-46cc-08d9b9d8d21f X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UL+8t5iTwQUa9bnNW0N/TvNnHDaZ78mrC5XY1Jn6sOWBNsyZU1Wu6GmCJk8c+3E+cso1x8nasEiqCScZZ/yl+jUOoTfsYBafTul/S5DVVBTPPMo3h736irPI4hnhjpmIgmtULmB8EeT0Q9WSPSc3f2aHrxZfTYsCmvpU5j3VtXJbM8g99nrnucTjBYunGUTlIfxb37uvQ7kRIIRLS/fAIwzJo9vbkltUAq2++gzVSm2tEc8YUvIMkeiO7w5ibfRXQ6HS/RVe8+tlICWVDtN2xQIITv5xJIywoYkBwXqx3nS//zjbG0AMWV7SFtFOU+V3rTdHE/fQadpyqr5IcIBBPfcT+a0hRElSgHaFCWeGtu/nGdEtxLbfFC+JNQ+01PbD6DCcXWISKqaAxjK3dmCy7e8zortKNMDTbdi+eYWG26Naxj69/5mS5Tzy0nYJGhgAb93Zkab/pi41BUO5LoS/lB4KmCwoJ7PpqX60ktMsDSqHRTuqv46hrAtAKLlQJRjD3gNEEIgTxFJ+Wod7zwAJ6smSJGkVJen9xXa61wQBNl0zCzSVtzK5M9bjPg3WitL6RbIsyiWWZ23cokBs1K1GtxLVKPxfbhx8f4/mGXPrsVM4zAfhGtI0uy42FWK99OhB+e7Xp4T1h0S2ZTuWDjmdj/OL0tO3rrQjCL30lJgzAYabBibt6IDwFWWSeG5AoK8EVWrZrbj4IB0yg== X-MS-TrafficTypeDiagnostic: AM6PR0302MB3480:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5jiQ4R3URMB6StwJ0zs1BQZI3BvqJsD+06NthI62rj3pjif74N4+wyJV9vfaSIfK9EzhQOJs7EOLGYWSWofODJya2twOStXDfUm8Auj/T6IkN/xD2oo3af2WMWn1QGNFwQVJByWqzQvTAlDDFBf72EUbHczZGQSqAM9SxIX9NBaA9WiUu5HiO3ekfyBvtrcXsUKUpJCtF2UMvGBt0W/1Uzv5ycHzLW0rbRuW6rrU2F5iCnEl/TrvVN+JmBWwhIkmCr3S8mrSGhMp11340JXgLUY4EV9k2n9qZisG8exZY4ROA40xSqJzBKBr3z0oLGSxbd7U+mJsrpffWf5Jqv65n2fXCQlXHM0jjt2whLFGzJqABja2QGaw23yJNgVJf/ZgXOoF9fWGcadtl8Bbz+Qo3bsx4BxJ+uecGH7BdRigKY8N8u3Q8Ln/u8UDGAI+Ssbp1eX68MjYyVc/13kJ+iUsXfxUEqNXclV8YYiD32r9dsUlAJR9KqLSfzeKvBKaL4jTQC7hcUNJBzc9f/hYgiaozC0biLgRnmDUbVYo1VYe1SaTVGvmE8N9ui8RHBvOqgnxaTap//yBDWzIug/lRPOEQQ== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5imfjNrAXIP7gr6ybEQVBaoq11dySKD32Z+hbAAmEzBXPHb18bwLhVb8XZ8bRBwN1pjiDGx585mbWmRkKEVDLq0YxOMlJdJ7DnLZ1IhJwoq8Vj1I6ZJWvU0jXSwf9+2BqSCHJU10znYm+GjFVZ0mBko9y0lDc9Okykc8v1k7cy7dlVsEtElw9qzNB9XbVssqyZTrchoMifLTHfM+JA6L+hWHFJi/2SQVSBEzLff+6O4pB87LC1Ft+AZRQYhfhZNpigLB987yzUPMU5o8ZWJ2C+2J6gS9ew2hbbW6nf0Kesp4EUchXNJpIk7vvF8Ckp+8CLaM/dY5REoHopiiQMy9UJYW/UlxHbhPPF7jloIWpGwK0IdtFDsKiCZrGjd0TTjNyvfzPF6n13vJmPzBunNYqnsGpbu5HDqt1//V6Gd7TjFvqwhvR7qlX6G+op/Zqa/IivkJGXwrATS+AwgQjeIm4hvIFD/Vn5UCwBXt3vDfH2YEhJIYM4hQ+hzhS0vOhOIVJrr6BFwApJpfmyI3bpcPG3i/z0B0Fe0Jq0ADjXDcNZcrwoUc27ZaAhAP4zg3eXz1cQARy2W3I7mJGUOxBX4hqUFXglplpvYbe8u4jhadtvnSCdgsQL4zEwbOcf+eO/KJxr27WzP2PYSleD1kXTm3zjuxJqCXvYtykV9omTnqymgK7ZbIbNf7ozhnUe6yLKzSfOthQL/4Va3kqQ04GO3ygfpKWeJjl/wCbtT7MIESSAWdHE3v7y504/A89Um7giUfJRFNr8VoL/jRZo9oKhOCx3GanLK7aEMOnYcZVROh2nDpJ3iTwFjNVo7IOfYLt2owowJfsKJ23OAt0DKdKy0dTonbbeWi9fUaOq3lQ1O7hiVaJVoPugP9ZwBk3/CJnuTVYUQ6CkSsBk/dkgaUwEAZsp6BDJPCfOF6MKqTfq39bw67qOCQP4BtSxR5iUOhQtq3J7XIZq5t35L4llKnWg3AZw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6368e85-c01d-45ed-46cc-08d9b9d8d21f X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2021 23:25:14.0850 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0302MB3480 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/movtextdec: Sanitize style entries X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: VQ8aCCRXaXGV There are three types of style entries which are redundant: a) Entries with length zero. They are already discarded. b) Entries that are equivalent to the default style: They can be safely discarded. c) Entries that are equivalent to the immediately preceding style if the start of the current style coincides with the end of the preceding style. In this case the styles can be merged. This commit implements discarding/merging in cases b) and c). This fixes ticket #9548. In said ticket each packet contained exactly one style entry that covered the complete packet with the exception of the last character (probably created by a tool that didn't know that the style's end is exclusive). Said style coincided with the default style, leading to a superfluous reset, which is now gone. Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextdec.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index c50626c0b5..b0c54bf1d0 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -263,6 +263,14 @@ static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, const AVPacket *a return 0; } +static int styles_equivalent(const StyleBox *a, const StyleBox *b) +{ +#define CMP(field) a->field == b->field + return CMP(bold) && CMP(italic) && CMP(underline) && CMP(color) && + CMP(alpha) && CMP(fontsize) && CMP(font_id); +#undef CMP +} + static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt) { int i; @@ -299,6 +307,19 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *a } mov_text_parse_style_record(style, &tsmb); + if (styles_equivalent(style, &m->d.style)) { + /* Skip this style as it is equivalent to the default style */ + m->style_entries--; + i--; + continue; + } else if (i && style->start == style[-1].end && + styles_equivalent(style, &style[-1])) { + /* Merge the two adjacent styles */ + style[-1].end = style->end; + m->style_entries--; + i--; + continue; + } } return 0; }