From patchwork Tue Dec 12 23:00:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Machek X-Patchwork-Id: 19314 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 81EDFC31E9 for ; Tue, 12 Dec 2023 23:00:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A8225629BD; Wed, 13 Dec 2023 00:00:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1702422016; bh=IqqYRfcxcU4Dm4kKzrpx9dL2E2y6m2tpuDvvyDpYB/c=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=IRVV1S/DqariCiLf5evNW/Jrell+wIzDyfcm/ijwfcLyFEGZs+jeugnNloTdRku83 kAFvBs8PUCS1KoWJX0GGXKjAHIAwtywDLFsiQXU/qReCBVMSaIaJllWLRzPkyeb14W jBHMKSLWgNuSIKns9EMTGzhMbIZGeTtqUmrNA6pPt/ixCdDpUgB6g3s8SnLVH2MorT P5wWCOcxUjOZ3S2EilkEUyRYYMy2tCQJH4LLVrSoofTIu6Ju2lS39swiMPgj/EyoL4 lGNwDYWWoIzdqunxVneWpVMZdDpQgKQEe3fTWcS2ueXtuPN6K0f46KsDv2E/Clgtzf iEt97diHly/TQ== Received: from jabberwock.ucw.cz (jabberwock.ucw.cz [46.255.230.98]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E045F629BD for ; Wed, 13 Dec 2023 00:00:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ucw.cz header.i=@ucw.cz header.b="hQuLTbK7"; dkim-atps=neutral Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 766001C0071; Wed, 13 Dec 2023 00:00:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1702422014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7w0xL6AB4mKl3Q24XSVREyQkLPmVtZgZelobhcJ8Sws=; b=hQuLTbK7xfVb4PNF3NDSUdZpcUF6aW5PM0IGf4ScZ2oUjyLkHj42/y+xpS+Hb9/FApJq+X 5eaCjuOPJnvin5L8w4Bou1ToFX/+0JSmP8Rkq9QM49TK6yV3lq/wtqT/HEinkIpsEBAZQx ROCqkNwXGSdNw/ND9wzTNoWmflhxmr0= Date: Wed, 13 Dec 2023 00:00:13 +0100 To: Hans de Goede Message-ID: References: <20231212115046.102726-1-andrey.konovalov@linaro.org> <20231212115046.102726-5-andrey.konovalov@linaro.org> <170239706778.3044059.6462285174630637754@ping.linuxembedded.co.uk> <170239891199.3044059.3154360492786632784@ping.linuxembedded.co.uk> <4dc8535c-53da-4c96-a2c0-1f786a8857f9@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4dc8535c-53da-4c96-a2c0-1f786a8857f9@redhat.com> Subject: [libcamera-devel] statistics cleanup was Re: ... libcamera: ipa: Soft IPA: add a Soft IPA implementation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pavel Machek via libcamera-devel From: Pavel Machek Reply-To: Pavel Machek Cc: mripard@redhat.com, g.martti@gmail.com, t.langendam@gmail.com, Pavel Machek via libcamera-devel , srinivas.kandagatla@linaro.org, bryan.odonoghue@linaro.org, admin@dennisbonke.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Hi! > ATM the statistics and debayer classes are mostly ready, > but I need to merge this with Andrey's v2 RFC and > then produce a clean new series from this > (assuming people like the approach). Could I get you to apply this? My camera is bayer8, so this is compile-tested only, but should give same performance with shorter and more readable source. (It will also allow me to add bayer8 statistics with little modifications). Thank you and best regards, Pavel Signed-off-by: Pavel Machek Signed-off-by: Pavel Machek Signed-off-by: Hans de Goede diff --git a/src/libcamera/software_isp/swstats_linaro.cpp b/src/libcamera/software_isp/swstats_linaro.cpp index 0323f45f..2f203b17 100644 --- a/src/libcamera/software_isp/swstats_linaro.cpp +++ b/src/libcamera/software_isp/swstats_linaro.cpp @@ -38,80 +38,55 @@ static const unsigned int RED_Y_MUL = 77; /* 0.30 * 256 */ static const unsigned int GREEN_Y_MUL = 150; /* 0.59 * 256 */ static const unsigned int BLUE_Y_MUL = 29; /* 0.11 * 256 */ -/* - * These need to be macros because it accesses a whole bunch of local - * variables (and copy and pasting this x times is undesirable) - */ -#define SWISP_LINARO_START_LINE_STATS() \ - uint8_t r, g, b; \ - unsigned int y_val; \ - \ - unsigned int sumR = 0; \ - unsigned int sumG = 0; \ - unsigned int sumB = 0; \ - \ - unsigned int bright_sum = 0; \ - unsigned int too_bright_sum = 0; - -#define SWISP_LINARO_ACCUMULATE_LINE_STATS() \ - sumR += r; \ - sumG += g; \ - sumB += b; \ - \ - y_val = r * RED_Y_MUL; \ - y_val += g * GREEN_Y_MUL; \ - y_val += b * BLUE_Y_MUL; \ - if (y_val > BRIGHT_LVL) ++bright_sum; \ - if (y_val > TOO_BRIGHT_LVL) ++too_bright_sum; - -#define SWISP_LINARO_FINISH_LINE_STATS() \ - stats_.sumR_ += sumR; \ - stats_.sumG_ += sumG; \ - stats_.sumB_ += sumB; \ - \ - bright_sum_ += bright_sum; \ - too_bright_sum_ += too_bright_sum; - -void SwStatsLinaro::statsBGGR10PLine(const uint8_t *src0, const uint8_t *src1) +static void inline statsBayer(const int width, const uint8_t *src0, const uint8_t *src1, bool bggr, unsigned int &bright_sum, unsigned int &too_bright_sum, StatsLinaro &stats) { - const int width_in_bytes = width_ * 5 / 4; - uint8_t g2; + const int width_in_bytes = width * 5 / 4; + uint8_t r, g, b, g2; + unsigned int y_val; - SWISP_LINARO_START_LINE_STATS() + stats.sumR_ = 0; + stats.sumG_ = 0; + stats.sumB_ = 0; - for (int x = 0; x < width_in_bytes; x += 5) { - /* BGGR */ - b = src0[x]; - g = src0[x + 1]; - g2 = src1[x]; - r = src1[x + 1]; + bright_sum = 0; + too_bright_sum = 0; + for (int x = 0; x < width_in_bytes; x += 5) { + if (bggr) { + /* BGGR */ + b = src0[x]; + g = src0[x + 1]; + g2 = src1[x]; + r = src1[x + 1]; + } else { + /* GBRG */ + g = src0[x]; + b = src0[x + 1]; + r = src1[x]; + g2 = src1[x + 1]; + } g = g + g2 / 2; - SWISP_LINARO_ACCUMULATE_LINE_STATS() + stats.sumR_ += r; + stats.sumG_ += g; + stats.sumB_ += b; + + y_val = r * RED_Y_MUL; + y_val += g * GREEN_Y_MUL; + y_val += b * BLUE_Y_MUL; + if (y_val > BRIGHT_LVL) ++bright_sum; + if (y_val > TOO_BRIGHT_LVL) ++too_bright_sum; } - SWISP_LINARO_FINISH_LINE_STATS() } -void SwStatsLinaro::statsGBRG10PLine(const uint8_t *src0, const uint8_t *src1) +void SwStatsLinaro::statsBGGR10PLine(const uint8_t *src0, const uint8_t *src1) { - const int width_in_bytes = width_ * 5 / 4; - uint8_t g2; - - SWISP_LINARO_START_LINE_STATS() - - for (int x = 0; x < width_in_bytes; x += 5) { - /* GBRG */ - g = src0[x]; - b = src0[x + 1]; - r = src1[x]; - g2 = src1[x + 1]; - - g = g + g2 / 2; + statsBayer(width_, src0, src1, true, bright_sum_, too_bright_sum_, stats_); +} - SWISP_LINARO_ACCUMULATE_LINE_STATS() - } - SWISP_LINARO_FINISH_LINE_STATS() +void SwStatsLinaro::statsGBRG10PLine(const uint8_t *src0, const uint8_t *src1) +{ + statsBayer(width_, src0, src1, false, bright_sum_, too_bright_sum_, stats_); } void SwStatsLinaro::statsBGGR10PLine0(const uint8_t *src, unsigned int stride)