From patchwork Tue Dec 27 23:18:01 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: 39767 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp3761939pzb; Tue, 27 Dec 2022 15:20:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXviI8StwO99HR8qsPyCavlVeE3sSlf4/bv/1jB52EBWzcZT9DVH7hZqbJgnPX7/v8d28YSV X-Received: by 2002:a17:907:a708:b0:82e:a59a:5c3e with SMTP id vw8-20020a170907a70800b0082ea59a5c3emr27893126ejc.10.1672183248617; Tue, 27 Dec 2022 15:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672183248; cv=none; d=google.com; s=arc-20160816; b=vl9rbL8G58tTFUEE0fhWSDGwMWBJnYNBKfTM5mZol2W1SBudOiV0JmeQttb7EOznPu XSn2rqfNHGGMiESySQPQJA6geY2kHNcvy5cAh7rbbOZAfdf09J5fclpTLrDwd75BxhBV GqzfvFH/d0sylz23iEiSU+hhDxEiD4l4TrAvVv60fgYi4HEjX12mP2ChpZIeBshDYEDl eWkuWqP4oBVJ0resSB0rHYtUTUOiKKUWniLgYBf6KajOCsjYR+cQ+Yj8slYaUhY/6Zlg KGLKTBeROAJQobQ95d312wG7OVVoCoTe8l1j/apdHCKhg42wx+Io9yjcn3x8gil0HbG3 f3Bw== 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=KHv1Dsw01L1q8Etp9hcKSvKL+wIIG1HsGT3POgAIHxw=; b=cNeaA7R0v2QG1jcLCobll4E2x3A7mHrHtABmw2LCOLKFt7K3xHsYTppCr2G1jF7kxk RoZDSmdAOIsvqChCuH/QiT5tcl2JIF1EILObNxW/pW2zz1Arejmqpj3zu8p6gLPQDGu8 Q+MGlYmvCE624C6/DCD0XREjhEE3lAqBj7vLvM3kyIOYI19DlhN4jQveMaU7PzSfO/SQ +MX2qn5EIxCj0DruIiVxge/Qhydb6ZBKpD/ooQWLIaqrmJojbixx72qRTmMreKIVZRuv iaR0KArpleCVaPGizbz0Q31O4F3t1U5MZzHI4mSkiPKjHtqJPC3UNbxamFmFd3QC6wsC w//g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=T7iiQuGP; 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 ne34-20020a1709077ba200b007c12fc0bd81si10900127ejc.362.2022.12.27.15.20.48; Tue, 27 Dec 2022 15:20:48 -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=T7iiQuGP; 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 43B2968BD38; Wed, 28 Dec 2022 01:18:44 +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 6A37A68BCAF for ; Wed, 28 Dec 2022 01:18:34 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1672183099; 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=wQ2XHgYCfowomGLd0GpmUXYVv+XX1Db/W0EOpR9BRW0=; b=T7iiQuGPpT86oOCtvH6pVPk9VqWDZSkCvYcB2+qVbINJm7b0zLEv7DAF6gUIiTwl1mcbt4 WBtOhZbOI6avR/ZsKLyUZmW3AejDCEy1A6az/rJffB/UuLbdCSo0DijSBeutMun+oXH9jo OT4yKbIololA9pThw36ragZQbvraBvs= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id e35ab9aa; Tue, 27 Dec 2022 23:18:19 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Dec 2022 00:18:01 +0100 Message-Id: <20221227231814.2520181-20-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 19/32] avfilter/palettegen: switch to signed arithmetic 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: Cu7uE+i2A3M4 This prevents mixed sign arithmetic (typically because we have signed color channel differences), which has nasty side effects in C. --- libavfilter/vf_palettegen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c index b8db234fef..99e4512e52 100644 --- a/libavfilter/vf_palettegen.c +++ b/libavfilter/vf_palettegen.c @@ -34,14 +34,14 @@ /* Reference a color and how much it's used */ struct color_ref { uint32_t color; - uint64_t count; + int64_t count; }; /* Store a range of colors */ struct range_box { uint32_t color; // average color int major_axis; // best axis candidate for cutting the box - uint64_t weight; // sum of all the weights of the colors + int64_t weight; // sum of all the weights of the colors int64_t cut_score; // how likely the box is to be cut down (higher implying more likely) int start; // index in PaletteGenContext->refs int len; // number of referenced colors @@ -141,7 +141,7 @@ static void compute_box_stats(PaletteGenContext *s, struct range_box *box) int64_t er2[3] = {0}; /* Compute average color */ - uint64_t sr = 0, sg = 0, sb = 0; + int64_t sr = 0, sg = 0, sb = 0; box->weight = 0; for (int i = box->start; i < box->start + box->len; i++) { const struct color_ref *ref = s->refs[i]; @@ -314,7 +314,7 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx) while (box && box->len > 1) { int i; - uint64_t median, weight; + int64_t median, weight; ff_dlog(ctx, "box #%02X [%6d..%-6d] (%6d) w:%-6"PRIu64" sort by %c (already sorted:%c) ", box_id, box->start, box->start + box->len - 1, box->len, box->weight,