From patchwork Mon Mar 27 12:20:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18475 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 92F86C329D for ; Mon, 27 Mar 2023 12:20:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2D30162754; Mon, 27 Mar 2023 14:20:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679919652; bh=XJZ+b37RC6DAoNkN9LySXWzskZlFzHIPkUne8vcW67I=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lD+PI0F6CZZ0LG6+dCzDlZnoTumBlN+PWjnHUN2z59Bkqglgd2iSha2J93FOxTu7v UkLes9+uEaNAt62v9jeDFCIhIdqiuGYflh36T9wWy1VzCCNgz+nL1Cd2surSDDQaFe atN1ZEZWGzqIFNW/NSIFJbP/2GOHvJ6LmPWNXGvM1BMtP0VaPgwJ9NThop9dS7cByt B1eD51htCoCNqztDWNJZDitOMC2QLiPP/nqRHqC4LEUKXF6kK3jf16fyzLV2jLBCgH uBo2emCUG899bUwdF8N72Te5V72iUW2jiXa1xje+mw8QguthHKcYI5UgPz/0a/1bcN rtnNy0enBWbGQ== Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A2AC562720 for ; Mon, 27 Mar 2023 14:20:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="V43C2Lus"; dkim-atps=neutral Received: by mail-il1-x12a.google.com with SMTP id h11so4512733ild.11 for ; Mon, 27 Mar 2023 05:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1679919647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FKREP6jJa308Taqx9N+sEobA15WmVJReEHkapGWA6lw=; b=V43C2LusEWI/Ci8v5eK6nkNsOWY/tnnwnl0wWIJ7XJne/uQibdIQG74uAmOE1DFF4+ 0IhZimiO2eF6tHsca8BcYjVj29437wykbr2MxcFAhyfoDgdFz/xp9aEAmKHDlbIGbaav EapabiebyTGxmj1X/PvnsyYp2iINppPUgei98x1yuERApBrT3ohoA8J49qBlsMV0vaBa eQpnK/SLtbr9AoJCdQtK6cl3zkTCWoKXn5DtfkIMZVuol++veg7gyWNEqpU8QJlPrlyL IytfJ73mjcW2L4Q2fuemPfN0T06X8AvNEHybzktdrTqeX+K6PXnNXVQ/Ae21OPX7dLNo JAiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679919647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FKREP6jJa308Taqx9N+sEobA15WmVJReEHkapGWA6lw=; b=P612gSLouQJiQAPQ/8vnaGzMgpKvI+aXPXoOi6JOYbJ+CeFOrCgxWOgJvy/PQ1efX6 zEgyRqxNzm7tk7WmX+ln3CWX0cyVMz91+yANnCHEe6A1vJAdy7rYvBcRhBetiCHKLQA0 yGMuB4jLyivtc838nX+Jn22+h60DHJUBxF/m8yum+mmXYbcjxsVxg7dCoz18PVQRdRyX W3IlCoE8ce6gIj5QtmZRqEa6mhDnk/l9611zahZmTt8KH1znNFpGPneg9fAyMKl//1KT nD6Ty0JnGi84nT2a9BlrHwjd2Q40l9G7ENBeDQVoLh8FggSEf+s0e7ObrDVniip0SaDW DTsQ== X-Gm-Message-State: AAQBX9cuyqXXz67/qeCPzM4zzGFzIc/h0deVQUOf6kUCm02RXAz+exYC MfmqIaO+2yagMONuXUnbA3xgEh2Z5Keh8yZfJNjHMg== X-Google-Smtp-Source: AKy350YvtuZSR5nTWWQFOvLSKWdSSZ7lWa3+cNOMUNy15Bh0uqjAVjiAFS1fYBBVqxFrAz8OAH2lxw== X-Received: by 2002:a92:da11:0:b0:325:b002:89b4 with SMTP id z17-20020a92da11000000b00325b00289b4mr9008042ilm.25.1679919646985; Mon, 27 Mar 2023 05:20:46 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id r7-20020a5edb47000000b00758ff97aaedsm3239026iop.16.2023.03.27.05.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 05:20:46 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Mar 2023 13:20:26 +0100 Message-Id: <20230327122030.11756-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327122030.11756-1-naush@raspberrypi.com> References: <20230327122030.11756-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 06/10] ipa: raspberrypi: Generalise the contrast algorithm 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Generalise the contrast algorithm code by removing any hard-coded assumptions about the target hardware platform. Instead, the algorithm code creates a generic Pwl that gets returned to the IPA, where it gets converted to the bcm2835 hardware specific lookup table. As a drive-by, remove an unused mutex. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- .../raspberrypi/controller/contrast_status.h | 11 ++----- .../raspberrypi/controller/rpi/contrast.cpp | 30 ++++--------------- src/ipa/raspberrypi/controller/rpi/contrast.h | 1 - src/ipa/raspberrypi/raspberrypi.cpp | 15 +++++++--- 4 files changed, 20 insertions(+), 37 deletions(-) diff --git a/src/ipa/raspberrypi/controller/contrast_status.h b/src/ipa/raspberrypi/controller/contrast_status.h index ef2a7c680fc2..fb9fe4bace71 100644 --- a/src/ipa/raspberrypi/controller/contrast_status.h +++ b/src/ipa/raspberrypi/controller/contrast_status.h @@ -6,20 +6,15 @@ */ #pragma once +#include "pwl.h" + /* * The "contrast" algorithm creates a gamma curve, optionally doing a little bit * of contrast stretching based on the AGC histogram. */ -constexpr unsigned int ContrastNumPoints = 33; - -struct ContrastPoint { - uint16_t x; - uint16_t y; -}; - struct ContrastStatus { - struct ContrastPoint points[ContrastNumPoints]; + RPiController::Pwl gammaCurve; double brightness; double contrast; }; diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp index a4f8c4f04fc4..bee1eadd3657 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp @@ -65,34 +65,19 @@ void Contrast::setContrast(double contrast) contrast_ = contrast; } -static void fillInStatus(ContrastStatus &status, double brightness, - double contrast, Pwl &gammaCurve) -{ - status.brightness = brightness; - status.contrast = contrast; - for (unsigned int i = 0; i < ContrastNumPoints - 1; i++) { - int x = i < 16 ? i * 1024 - : (i < 24 ? (i - 16) * 2048 + 16384 - : (i - 24) * 4096 + 32768); - status.points[i].x = x; - status.points[i].y = std::min(65535.0, gammaCurve.eval(x)); - } - status.points[ContrastNumPoints - 1].x = 65535; - status.points[ContrastNumPoints - 1].y = 65535; -} - void Contrast::initialise() { /* * Fill in some default values as Prepare will run before Process gets * called. */ - fillInStatus(status_, brightness_, contrast_, config_.gammaCurve); + status_.brightness = brightness_; + status_.contrast = contrast_; + status_.gammaCurve = config_.gammaCurve; } void Contrast::prepare(Metadata *imageMetadata) { - std::unique_lock lock(mutex_); imageMetadata->set("contrast.status", status_); } @@ -183,12 +168,9 @@ void Contrast::process(StatisticsPtr &stats, * And fill in the status for output. Use more points towards the bottom * of the curve. */ - ContrastStatus status; - fillInStatus(status, brightness_, contrast_, gammaCurve); - { - std::unique_lock lock(mutex_); - status_ = status; - } + status_.brightness = brightness_; + status_.contrast = contrast_; + status_.gammaCurve = std::move(gammaCurve); } /* Register algorithm with the system. */ diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.h b/src/ipa/raspberrypi/controller/rpi/contrast.h index c68adbc9e463..9c81277a0450 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.h +++ b/src/ipa/raspberrypi/controller/rpi/contrast.h @@ -46,7 +46,6 @@ private: double brightness_; double contrast_; ContrastStatus status_; - std::mutex mutex_; }; } /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 257d862e07b6..d813b1b7ca61 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1592,14 +1592,21 @@ void IPARPi::applyCCM(const struct CcmStatus *ccmStatus, ControlList &ctrls) void IPARPi::applyGamma(const struct ContrastStatus *contrastStatus, ControlList &ctrls) { + const unsigned int numGammaPoints = controller_.getHardwareConfig().numGammaPoints; struct bcm2835_isp_gamma gamma; - gamma.enabled = 1; - for (unsigned int i = 0; i < ContrastNumPoints; i++) { - gamma.x[i] = contrastStatus->points[i].x; - gamma.y[i] = contrastStatus->points[i].y; + for (unsigned int i = 0; i < numGammaPoints - 1; i++) { + int x = i < 16 ? i * 1024 + : (i < 24 ? (i - 16) * 2048 + 16384 + : (i - 24) * 4096 + 32768); + gamma.x[i] = x; + gamma.y[i] = std::min(65535, contrastStatus->gammaCurve.eval(x)); } + gamma.x[numGammaPoints - 1] = 65535; + gamma.y[numGammaPoints - 1] = 65535; + gamma.enabled = 1; + ControlValue c(Span{ reinterpret_cast(&gamma), sizeof(gamma) }); ctrls.set(V4L2_CID_USER_BCM2835_ISP_GAMMA, c);