From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 0D96C42D43 for ; Sat, 5 Nov 2022 15:27:45 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7C57D68B57A; Sat, 5 Nov 2022 17:26:43 +0200 (EET) 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 24EC768B3E0 for ; Sat, 5 Nov 2022 17:26:41 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1667661982; 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=1JLpbEYvTNppxpJXLXniUM699Kk7plGGItR7SCcxX60=; b=l66VAmlTEll3UXrlsrfQKuPax0NVVAvwDgcNCcauHz/cK6AAYVKMNok+knpf+y2jOQLOcL 5+CxwNrx1sjvf2APvIG5pzRudNqq53VLDUi5LOsqclh/CSERrSFI2l9ZquheinMvUgJUU8 TOTA4u0qqIaRCcmmG2cehQuKn6Do+j4= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 4e4ed742; Sat, 5 Nov 2022 15:26:22 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 5 Nov 2022 16:26:12 +0100 Message-Id: <20221105152617.1809282-11-u@pkh.me> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221105152617.1809282-1-u@pkh.me> References: <20221105152617.1809282-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/15] avfilter/palettegen: move box variance computation in a dedicated function 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?q?Cl=C3=A9ment=20B=C5=93sch?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavfilter/vf_palettegen.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c index 00bc323d17..2b412cdb55 100644 --- a/libavfilter/vf_palettegen.c +++ b/libavfilter/vf_palettegen.c @@ -144,12 +144,23 @@ static av_always_inline int diff(const uint32_t a, const uint32_t b) return dr*dr + dg*dg + db*db; } +static void compute_box_variance(PaletteGenContext *s, struct range_box *box) +{ + int64_t variance = 0; + + for (int i = 0; i < box->len; i++) { + const struct color_ref *ref = s->refs[box->start + i]; + variance += diff(ref->color, box->color) * ref->count; + } + box->variance = variance; +} + /** * Find the next box to split: pick the one with the highest variance */ static int get_next_box_id_to_split(PaletteGenContext *s) { - int box_id, i, best_box_id = -1; + int box_id, best_box_id = -1; int64_t max_variance = -1; if (s->nb_boxes == s->max_colors - s->reserve_transparent) @@ -159,16 +170,8 @@ static int get_next_box_id_to_split(PaletteGenContext *s) struct range_box *box = &s->boxes[box_id]; if (s->boxes[box_id].len >= 2) { - - if (box->variance == -1) { - int64_t variance = 0; - - for (i = 0; i < box->len; i++) { - const struct color_ref *ref = s->refs[box->start + i]; - variance += diff(ref->color, box->color) * ref->count; - } - box->variance = variance; - } + if (box->variance == -1) + compute_box_variance(s, box); if (box->variance > max_variance) { best_box_id = box_id; max_variance = box->variance; -- 2.38.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".