From patchwork Fri Mar 31 07:23:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18502 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 2582FC329D for ; Fri, 31 Mar 2023 07:40:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B3BA46279A; Fri, 31 Mar 2023 09:40:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680248458; bh=+GFENiSMhQ3HqhhlTZZ9jxVl3H1/G1XEnMd7DpUDotY=; 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=hTZpMMZyqG9cz7cNeVpCyNWKQZi8jceeWEUNPtlS0S4NmAsQw/3Ie6xPH+H11n4Sv +kO0Hfnx8ZZtSPVsWtHueswrPpx85I4UjjvEW3rOjtPXSPtA3FolVv2QF6VzvfJ1oc CfYXHQewSrs1IDfU+sngdUpMHV5S7SK7VpxGxcFIVAQibzPv/U2P4w6O+JnGM+jKsm yHVEJA5JhryQTAccqDVreJ/1c/scj6FlRF7qXs6YGH//WByWDYQ9KfhsFTNownnOek 97ZpdxUEPNle0xDY/ZCvlK8oWTmdM5B0T6OVnotMkvaWdrXHbBIJdhF3mgVSkpFDBn NdJm9yZXxbHUQ== Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 504206277E for ; Fri, 31 Mar 2023 09:40:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qIEZ7HLr"; dkim-atps=neutral Received: by mail-io1-xd2e.google.com with SMTP id bl9so9384549iob.8 for ; Fri, 31 Mar 2023 00:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1680248454; 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=CBhJt0BIC9Lqwq4l4PQJqQPOKidr71Zuik9quGaeQXo=; b=qIEZ7HLrdACAYDmlLPtVpqIWy7Rea+VFIgZYUwgZGF8H0ZbEOR9dsjuHoZcO7tM3Zp mGMUca72yl+xnq0Q9P6r0RegBC2LEtEh3Bg6C0od99ibUgV/ePCkWdpICnYuOKeGfdxW EdLsRy5qMZ6vuOvkQEn18S7oTa8y1Iqsc4TmZjnvQ4wvSBaLMKSs8GyJEJN9TKnN+U7F 0v1UbCAXz0g31NSdofsLf+fpW3uHMybFYM5upRlrZJNh4e60YBjh4yKuVho2WQGtKhn2 /pHEBmjfD/gc2nGZkSZABOnnV+QBOgPXAlRAeutRH6pk6yUE3aikoDOqc6z5iYVrhqUc x5mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680248454; 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=CBhJt0BIC9Lqwq4l4PQJqQPOKidr71Zuik9quGaeQXo=; b=dbmqGMi14J7E0LSqRcRtF4mfKPc/cvej4Lsz4VfKkCYdAZnHRdJzR6EbsRa5hyTa55 AMubmvkH3/we0WqYlxLZes0JjSuf+ufZvhnHuSCdmkINMzvcUWN23dhFhbCQwuXydBC8 NgoxU63wJMfhrcqoDAwAnALjM+HzBcwdwNt9GCpYQucoj9t7pY4cc31ldkKErVVyde2n zE0o2fCEYqoENh23IFGql4sm+Gat9wSKRH3fSrlTr3ZHXdmz6BBzTwYKjqZWAiBfONXX pevw8AEwcynnwYi+fQq6841toN8AmvwdU55ZzpI2zX4ubJGlO4X0jS3QCsWopvII8Y5N FNzQ== X-Gm-Message-State: AO0yUKWbklBHWgoQ0hOQ1fL6Kw9yNto2ojir1ziNG93DmDutoWUEM1k/ /kfwYHs6SWadQI21HVQkWjM5b75uMqVtcKD8tJI/gw== X-Google-Smtp-Source: AK7set+at/3/A6n30NpBjD8Y5w9jFiWISNNVPjiHpLBFcTBUJO5gNRwaLwu684OJYw2GMqyu3+FQOQ== X-Received: by 2002:a5e:8b49:0:b0:758:1db1:ca99 with SMTP id z9-20020a5e8b49000000b007581db1ca99mr18057445iom.19.1680248453684; Fri, 31 Mar 2023 00:40:53 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id i17-20020a6bf411000000b0074555814e73sm421943iog.32.2023.03.31.00.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 00:40:53 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 08:23:37 +0100 Message-Id: <20230331072341.24851-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230331072341.24851-1-naush@raspberrypi.com> References: <20230331072341.24851-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 c74558f1dc0c..e2662938c9d3 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1593,14 +1593,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);