From patchwork Fri Sep 2 20:42:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 402 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp1646978vsd; Fri, 2 Sep 2016 13:43:02 -0700 (PDT) X-Received: by 10.28.56.195 with SMTP id f186mr4773732wma.59.1472848982118; Fri, 02 Sep 2016 13:43:02 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h70si6082919wma.48.2016.09.02.13.43.01; Fri, 02 Sep 2016 13:43:02 -0700 (PDT) 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=@gmail.com; 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 dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 29533689C35; Fri, 2 Sep 2016 23:42:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CD821689C35 for ; Fri, 2 Sep 2016 23:42:44 +0300 (EEST) Received: by mail-wm0-f66.google.com with SMTP id v143so4250863wmv.1 for ; Fri, 02 Sep 2016 13:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=2mf2lpgseo9cFvrGfEe3DWfiIEHjv/4afdA4TD32a9w=; b=gjV9nUIOTQNKH8iqhkvoC2s1K/NsMAWkthlR+umffrn3LozdiAWPiydpQFBDe6Kloo 8SzR2Jp/2EFSEqHf15eXy7gFTOOroCT9Tw+TBWu61zJjQbokC6aZdaijzhviB5VE55Nh x348rOuIALaVqdDWZZUm1tAj9XfRQFzuc6uU1rSu6bfyWtidc/LFjfMi41Dxe/GSJueZ XWwuAseMTu4WamR4U9c1lZvtCTqrJzEoa/HPesM5n47siQqrqEjahn4OYpMbJBSVLvVZ anUKuZfMXDS9n1GqcGfQZhaYozkeo04riXPzmy+Pt6IXNwWDQSJ3Dmbj0g7ibLDfEvk4 Aufg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=2mf2lpgseo9cFvrGfEe3DWfiIEHjv/4afdA4TD32a9w=; b=FEEtA3YB3DVuafaTN8Gw+8jUBl4JX+twyGIMD9ZJdTskL381kjGJkaM5/ldW+1rbjN VmQf3MQPigIa97HhQvFtDkSYW/pF5E1Q1g4N7V72ujqAnByMgvNSt2rDtuSSfKnLjnGQ pGXsrTeXxTL4xccPvbaIHzegCK3sbKcvBIy760pGRX07H8bZQ6vn6D7Whc11mKRK0AAL 4JPiGQNJyIFGU6obUmxs7gxTspDE2d3GWJHtL3jILpX9S5QytjBao3eRK4Ja/Nr+G4il 7GOx9FlMXdWifXGcxqqOW20qdyUtUrs0f+iA/EJytalHKmKl+aeNgkMXGzqBH/qU/zvB oIDw== X-Gm-Message-State: AE9vXwOVBzXsXJPZ1BUQuaiXSP4oSc7Z2xvqX3ZuMJMBlQUhp/lhDBet5UZQ179dCqazuQ== X-Received: by 10.194.172.229 with SMTP id bf5mr12748588wjc.37.1472848972120; Fri, 02 Sep 2016 13:42:52 -0700 (PDT) Received: from computer.gigaset.lan (236-208.dsl.iskon.hr. [89.164.236.208]) by smtp.gmail.com with ESMTPSA id d80sm5254306wmd.14.2016.09.02.13.42.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Sep 2016 13:42:51 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Sep 2016 22:42:10 +0200 Message-Id: <1472848930-1985-2-git-send-email-onemda@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1472848930-1985-1-git-send-email-onemda@gmail.com> References: <1472848930-1985-1-git-send-email-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_paletteuse: add option to use new palette for each output frame 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavfilter/vf_paletteuse.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c index dece05a..ed51cfe 100644 --- a/libavfilter/vf_paletteuse.c +++ b/libavfilter/vf_paletteuse.c @@ -86,6 +86,7 @@ typedef struct PaletteUseContext { uint32_t palette[AVPALETTE_COUNT]; int palette_loaded; int dither; + int new; set_frame_func set_frame; int bayer_scale; int ordered_dither[8*8]; @@ -122,6 +123,7 @@ static const AVOption paletteuse_options[] = { { "bruteforce", "brute-force into the palette", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_SEARCH_BRUTEFORCE}, INT_MIN, INT_MAX, FLAGS, "search" }, { "mean_err", "compute and print mean error", OFFSET(calc_mean_err), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, { "debug_accuracy", "test color search accuracy", OFFSET(debug_accuracy), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, + { "new", "take new palette for each output frame", OFFSET(new), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, { NULL } }; @@ -928,8 +930,15 @@ static void load_palette(PaletteUseContext *s, const AVFrame *palette_frame) const uint32_t *p = (const uint32_t *)palette_frame->data[0]; const int p_linesize = palette_frame->linesize[0] >> 2; - i = 0; - for (y = 0; y < palette_frame->height; y++) { + if (s->new) { + memset(s->palette, 0, sizeof(s->palette)); + memset(s->map, 0, sizeof(s->map)); + for (i = 0; i < CACHE_SIZE; i++) + av_freep(&s->cache[i].entries); + memset(s->cache, 0, sizeof(s->cache)); + } + + for (i = 0, y = 0; y < palette_frame->height; y++) { for (x = 0; x < palette_frame->width; x++) s->palette[i++] = p[x]; p += p_linesize; @@ -937,7 +946,8 @@ static void load_palette(PaletteUseContext *s, const AVFrame *palette_frame) load_colormap(s); - s->palette_loaded = 1; + if (!s->new) + s->palette_loaded = 1; } static AVFrame *load_apply_palette(AVFilterContext *ctx, AVFrame *main,