From patchwork Fri Jan 24 17:57:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kuron X-Patchwork-Id: 17520 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 06462449AB7 for ; Fri, 24 Jan 2020 20:26:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CBFBE68AE86; Fri, 24 Jan 2020 20:26:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2B6D068AE86 for ; Fri, 24 Jan 2020 20:25:57 +0200 (EET) Received: by mail-ed1-f53.google.com with SMTP id r21so3450093edq.0 for ; Fri, 24 Jan 2020 10:25:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yhqXTVBVbBPsorcJSHLlP1glVmbZ6AOCkVuNS2Rq5uc=; b=bkgXVmXMNNILCotyoMjkAwm9kOF9f+6tqed5Zq9D7cJV/9SOHggQJ58CLE15v+4Osp klPi6NvyllAX15Qbbju7OKgYU1pRDnphKHqQw+cfz3/KCEO4UycI0Q2ZH8+eO9eoiK7e YlUnRT+YOOULaAZqILlIUNhikKk8vvyzl2Z9D44adsA+yP38maq5RWGsxtdFy3kD+HfQ 3eUS2TJl1ymMSBzds5q8Mwl19Ce5kb3jKU37bjC9EABCMET620cL+4pBnNFdQCMrlVev +ksz+M+MeJdOIb+BzaDdC8cWoLM4gxmcr1SnyBl4skPDvWtXIjyGZqOL4aQhlGvYW2et bhuw== 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:mime-version :content-transfer-encoding; bh=yhqXTVBVbBPsorcJSHLlP1glVmbZ6AOCkVuNS2Rq5uc=; b=BqCrqLFyMOdU0Q0jB4lTxDmCPJCbrrN9gmYWHk3RDgLJGYxj/+r+rzF/O/i3IBXr3r NultIwULv0AilL6htYniSN3xSXiAC4kdY8UnqVg8dk4QU6jBG24NJciM5qIpvq0AZ7Ny JRd0VCqz8p01ZlN5AHiFq0W8YHKIz7GFWPdQ8qSYaBo7dUvZhmEQxK+wv4AlrFXimauR C3kxGh/0PuIchWrxSPxb9a32bMt13tyHc3iLIfJbCyjb0VgZs9Xan9LURazTC4M5zyQO 1hFjq9L3JyX3j5opwHZJiidpLztr585cOvE4NUt8vzcVf7bYCTSIudE1OFMsrIQfZI4G QUEw== X-Gm-Message-State: APjAAAUEuyoSXzLu6ylztjrJMCpS4HuiSGod2JlezT1vXWC8CzsfAxnO M645/qTla1PCkYqiorBT6pqFn4I3 X-Google-Smtp-Source: APXvYqxi8m8LKzxBMC0am69oDT/ajueUJq6w3lBW1oTaz3017ixkTvbLfDiJWwj15D0PvBFN/5oe0g== X-Received: by 2002:adf:f3cc:: with SMTP id g12mr5496428wrp.236.1579888662081; Fri, 24 Jan 2020 09:57:42 -0800 (PST) Received: from mkuron-mbp-icp.home.kuron-germany.de (i5DB5319B.pool.tripleplugandplay.com. [93.181.49.155]) by smtp.gmail.com with ESMTPSA id u14sm7812710wrm.51.2020.01.24.09.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 09:57:41 -0800 (PST) From: Michael Kuron To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Jan 2020 18:57:37 +0100 Message-Id: <20200124175737.30631-1-michael.kuron@gmail.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/dvdsubenc: accept palette from options 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: Michael Kuron Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Previously, the default palette would always be used. Now, we can accept a custom palette, just like dvdsubdec does. Signed-off-by: Michael Kuron --- doc/encoders.texi | 9 +++++++++ libavcodec/dvdsubenc.c | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index eefd124751..f8d5ecb5f9 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3115,6 +3115,15 @@ and they can also be used in Matroska files. @subsection Options +@table @option +@item palette +Specify the global palette used by the bitmaps. + +The format for this option is a string containing 16 24-bits hexadecimal +numbers (without 0x prefix) separated by comas, for example @code{0d00ee, +ee450d, 101010, eaeaea, 0ce60b, ec14ed, ebff0b, 0d617a, 7b7b7b, d1d1d1, +7b2a0e, 0d950c, 0f007b, cf0dec, cfa80c, 7c127b}. + @table @option @item even_rows_fix When set to 1, enable a work-around that makes the number of pixel rows diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c index ff95ed2002..674d97ab9b 100644 --- a/libavcodec/dvdsubenc.c +++ b/libavcodec/dvdsubenc.c @@ -29,6 +29,7 @@ typedef struct { AVClass *class; uint32_t global_palette[16]; + char *palette_str; int even_rows_fix; } DVDSubtitleContext; @@ -423,6 +424,17 @@ fail: return ret; } +static void parse_palette(DVDSubtitleContext *ctx, char *p) +{ + int i; + + for (i=0; i<16; i++) { + ctx->global_palette[i] = strtoul(p, &p, 16); + while (*p == ',' || av_isspace(*p)) + p++; + } +} + static int dvdsub_init(AVCodecContext *avctx) { DVDSubtitleContext *dvdc = avctx->priv_data; @@ -436,7 +448,11 @@ static int dvdsub_init(AVCodecContext *avctx) int i, ret; av_assert0(sizeof(dvdc->global_palette) == sizeof(default_palette)); - memcpy(dvdc->global_palette, default_palette, sizeof(dvdc->global_palette)); + if (dvdc->palette_str) { + parse_palette(dvdc, dvdc->palette_str); + } else { + memcpy(dvdc->global_palette, default_palette, sizeof(dvdc->global_palette)); + } av_bprint_init(&extradata, 0, AV_BPRINT_SIZE_AUTOMATIC); if (avctx->width && avctx->height) @@ -467,6 +483,7 @@ static int dvdsub_encode(AVCodecContext *avctx, #define OFFSET(x) offsetof(DVDSubtitleContext, x) #define SE AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { + {"palette", "set the global palette", OFFSET(palette_str), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, SE }, {"even_rows_fix", "Make number of rows even (workaround for some players)", OFFSET(even_rows_fix), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, SE}, { NULL }, };