From patchwork Tue Dec 27 23:17:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 39780 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp3761732pzb; Tue, 27 Dec 2022 15:20:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXsQex9SaHRVc6EmxzhZsNAzZfEts5D8cLYpMuD/ONxm7I6Ka6+kMst50wXCZplTA1MFwJbA X-Received: by 2002:a17:906:374e:b0:7c1:f64:61f1 with SMTP id e14-20020a170906374e00b007c10f6461f1mr24223830ejc.45.1672183223345; Tue, 27 Dec 2022 15:20:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672183223; cv=none; d=google.com; s=arc-20160816; b=Hexnpq4btEbANTIZlhzcnQqoPUCK8cGrJ6sSW/ZYUmYbS8GGXD8MFB3InlyYPBtRaV UgKHDdZ/gZU7pqexMValVc18XlTKeUJiTGOUJyDEkvHZq+ki1f9A9dOcCkuiNkFTWsHG hpleOz6zXS1rhUH+BlOPAx9d3s7bUdwonhTFKR5v47scSahKv2ajWnjWrYAH896Fk89/ GzZ9G+nPjVc/O/Gn9jU8iGAVvU3Ar9/oIv0ltta9c/eF+xVvjpAP4iDscedrHWI+PUud AOIujYgCTHi6GDzejrNjUu88WOzXQ+I5iVhtZmq3cJEeoQQPIapxDoZCXsXg1jmEkhLB WUDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=m/PaDYYi+W9HX6WvGWCh7YcOmyWqSBEB9yfLkT5UMz4=; b=tstygglx9jLUkTcd/mf/ruayfz0nEnX4+nNtKL/wj6XuClpia1lbmgMCH8nAUM8g1i an30RDgD7Yxyd5yVa5a4nX6FvR1r1s4vDc894I3VtgtqT+mXs9noGZWJ1UBLOT2h1FP7 8DklI2z8tiUeC4tB8RhG8+kRmkORbEjsMyPI5wkBM68leTFxvxXfktC73FVN86ovkYEB RqoCtbWVdQ2sELacetP0iqw37to3N1yM3kk7l/rzRZ5sb8oB3JDAgIOSoppsDOcTJP+H uKndPAcWgxOmZ+Jns9g6aC5EwK0/FUk0YApyGd3f3Kl8OQuV9UXkCMzhascwxYoiXYpm Mkxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=hWFtBdOj; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ji20-20020a170907981400b007adfe2889efsi12276044ejc.607.2022.12.27.15.20.23; Tue, 27 Dec 2022 15:20:23 -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=@pkh.me header.s=selector1 header.b=hWFtBdOj; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9A4BD68BCDA; Wed, 28 Dec 2022 01:18:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CD69568BCBE for ; Wed, 28 Dec 2022 01:18:33 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1672183098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C9dR0R/CH1U22B4W3i+Me/usr2Lt/Vp9sPq3ldzy8Og=; b=hWFtBdOjzAKuQUizD+5fylY0qRPSIFZB0bUTdL7epJJBo7c4s5Bcy0xRuFtdMF7zMLTWrB n93Gb58nQYx6dMtAPy3KbLY74V5Jki6oHa8PFZyiZoxW3kfNfBkT9mErTEZ7fLxfCUnkmb uf0LKXL9w9QT7/Hg+ZhNLU0/I8mbc/w= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 37f47f9a; Tue, 27 Dec 2022 23:18:18 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Dec 2022 00:17:58 +0100 Message-Id: <20221227231814.2520181-17-u@pkh.me> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221227231814.2520181-1-u@pkh.me> References: <20221105152617.1809282-1-u@pkh.me> <20221227231814.2520181-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 16/32] avfilter/palettegen: compute average color within compute_box_stats() 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3ydRnv7nHMLH --- libavfilter/vf_palettegen.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c index 00b5f88c49..36f0a976d9 100644 --- a/libavfilter/vf_palettegen.c +++ b/libavfilter/vf_palettegen.c @@ -153,6 +153,7 @@ static void compute_box_stats(PaletteGenContext *s, struct range_box *box) avg[0] = sr / box->weight; avg[1] = sg / box->weight; avg[2] = sb / box->weight; + box->color = 0xffU<<24 | avg[0]<<16 | avg[1]<<8 | avg[2]; /* Compute squared error of each color channel */ for (int i = box->start; i < box->start + box->len; i++) { @@ -196,32 +197,6 @@ static int get_next_box_id_to_split(PaletteGenContext *s) return best_box_id; } -/** - * Get the 32-bit average color for the range of RGB colors enclosed in the - * specified box. Takes into account the weight of each color. - */ -static uint32_t get_avg_color(struct color_ref * const *refs, - const struct range_box *box) -{ - int i; - const int n = box->len; - uint64_t r = 0, g = 0, b = 0, div = 0; - - for (i = 0; i < n; i++) { - const struct color_ref *ref = refs[box->start + i]; - r += (ref->color >> 16 & 0xff) * ref->count; - g += (ref->color >> 8 & 0xff) * ref->count; - b += (ref->color & 0xff) * ref->count; - div += ref->count; - } - - r = r / div; - g = g / div; - b = b / div; - - return 0xffU<<24 | r<<16 | g<<8 | b; -} - /** * Split given box in two at position n. The original box becomes the left part * of the split, and the new index box is the right part. @@ -237,8 +212,6 @@ static void split_box(PaletteGenContext *s, struct range_box *box, int n) av_assert0(box->len >= 1); av_assert0(new_box->len >= 1); - box->color = get_avg_color(s->refs, box); - new_box->color = get_avg_color(s->refs, new_box); compute_box_stats(s, box); compute_box_stats(s, new_box); } @@ -336,7 +309,6 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx) box = &s->boxes[box_id]; box->len = s->nb_refs; box->sorted_by = -1; - box->color = get_avg_color(s->refs, box); compute_box_stats(s, box); s->nb_boxes = 1;