{"id":18433,"url":"https://patchwork.libcamera.org/api/1.1/patches/18433/?format=json","web_url":"https://patchwork.libcamera.org/patch/18433/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20230322130612.5208-7-naush@raspberrypi.com>","date":"2023-03-22T13:06:08","name":"[libcamera-devel,v1,06/10] ipa: raspberrypi: Generalise the contrast algorithm","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"232cacec53bcb2219f1ceaf771ad6b8083fdf80a","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18433/mbox/","series":[{"id":3810,"url":"https://patchwork.libcamera.org/api/1.1/series/3810/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3810","date":"2023-03-22T13:06:02","name":"Raspberry Pi: Generalised algorithms","version":1,"mbox":"https://patchwork.libcamera.org/series/3810/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18433/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18433/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5B29DC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Mar 2023 13:06:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BA2E762724;\n\tWed, 22 Mar 2023 14:06:28 +0100 (CET)","from mail-il1-x132.google.com (mail-il1-x132.google.com\n\t[IPv6:2607:f8b0:4864:20::132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7040E62716\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Mar 2023 14:06:25 +0100 (CET)","by mail-il1-x132.google.com with SMTP id j6so9804706ilr.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Mar 2023 06:06:25 -0700 (PDT)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tl6-20020a026646000000b003c488204c6fsm4927960jaf.76.2023.03.22.06.06.23\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 22 Mar 2023 06:06:23 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679490389;\n\tbh=9A/rwptP+p9jk3E0TaYU1mMV8Yim4LEVhI7SIMYQAvA=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=Q3iLK/oLXkjQ2e8AVm8dEq7at38NzgnzFAYSsCOAnE3epxGzvPW6ZWaZIn26TX1NC\n\ttUiZKXThZpjEhpL+SxVVT3Po9M4/bxWmf+0y+CL4CXkhAg6/1udi2lDEU7+vFsiyT5\n\t9hnRKiCLY9LWrEWV61ZCQ791HHute5/CUm+ACtKbJP5VkWbHJnfNP6v+iYVlVSp9hb\n\tHY17XyxMHNZlLqYvAE0lBarm5ntcpUyEtzDIHmaZJoCx06oAIAXsM6ZRpunjyhXhug\n\txxdom8Fgg7rpnRXxcaEO+OLXVlXcOXJ3IZhgKvVjRE04/NeBaAYO/QbTLVJ9ZcQeWC\n\tKSz0Q3Ub+lzBw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1679490384;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=yoxd2YPF+mGleci8HMNu54DMJ+86Zo6lhHkuT0jgQAk=;\n\tb=JYsPqXNIpAGYp99P9jBi9Vnf1yKSII4hZyJ4yedHgFFCVk9Wn9soVCXdZafSxgNhIQ\n\tOaPGaBmpKlt6bmL9qLpGCRhtOOO7rSPqv4ycaksAgWTvY3cESUzTLy3H8KRgIyi3GAQk\n\tA0yHL2eUUAILOQdczfWtnrOoAQYZwVk385jJpb2wTo+3ix2310e0//9Z/opq+btCOBRQ\n\tvz6hJ1NBp41/CmfoMTVNqYgNc/py1wtiplyauQjIiZbg1pn/dlSe9nSJbOiZ6qq3YAGc\n\tNQM2FncyiukrqpKSetwfTsrKoS7Zi6HWIUXRRJIOUHwaj2HcWD08h4GweaQfo4rVekis\n\tILnA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"JYsPqXNI\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1679490384;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=yoxd2YPF+mGleci8HMNu54DMJ+86Zo6lhHkuT0jgQAk=;\n\tb=hOPm51RIehbSGVcjwyL1EzIQ3SuqoZcpxIDW1eTMaSJV16PXChvXQiu2fesTYgIq9C\n\tkzhGz3FfnB8ByQVquOF1BNFOSq6rheZDw7CFmPSGrPvurVCvonlQUgQgyMn4EHM97x1G\n\t0ULpPUy19ykexe/EMe/QseLPm5hbzLzo3huROpAclywvR804PaZE1fcoBZZnUCUN4h5Y\n\tJAz4UzJXLakIufXsyHZfIyz2YCCmxPmfTDqt7VD+q9FmAgRpkbbYE2G3/mR3RkUnbnPo\n\tASwogL6rWzOAXCnUMT4gYDL3W3uCUE9MzP5yvbpSJwGFizBUmswehsilsNiNwLFhOmNY\n\t8+QA==","X-Gm-Message-State":"AO0yUKXR/WHAwVgnY7pegHSPgTw80mqgLZKBxSQSTvT9UNJ/6ZB77VSQ\n\tHmb5JuW7qtzesd7g6RIamG8QlYbK/ZFA/RkPe+TtRQ==","X-Google-Smtp-Source":"AK7set/oen4OaDsZ/oc9QFKjKAFDFYcSXXjiDCiYv7GOMSZenutodUrV1V6g43K9bGdewMWha4sduw==","X-Received":"by 2002:a92:dac9:0:b0:325:bc3f:f757 with SMTP id\n\to9-20020a92dac9000000b00325bc3ff757mr1588557ilq.0.1679490383992; \n\tWed, 22 Mar 2023 06:06:23 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 22 Mar 2023 13:06:08 +0000","Message-Id":"<20230322130612.5208-7-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20230322130612.5208-1-naush@raspberrypi.com>","References":"<20230322130612.5208-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1 06/10] ipa: raspberrypi: Generalise the\n\tcontrast algorithm","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Generalise the contrast algorithm code by removing any hard-coded\nassumptions about the target hardware platform. Instead, the algorithm\ncode creates a generic Pwl that gets returned to the IPA, where it gets\nconverted to the bcm2835 hardware specific lookup table.\n\nAs a drive-by, remove an unused mutex.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../raspberrypi/controller/contrast_status.h  | 11 ++-----\n .../raspberrypi/controller/rpi/contrast.cpp   | 30 ++++---------------\n src/ipa/raspberrypi/controller/rpi/contrast.h |  1 -\n src/ipa/raspberrypi/raspberrypi.cpp           | 15 +++++++---\n 4 files changed, 20 insertions(+), 37 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/controller/contrast_status.h b/src/ipa/raspberrypi/controller/contrast_status.h\nindex ef2a7c680fc2..fb9fe4bace71 100644\n--- a/src/ipa/raspberrypi/controller/contrast_status.h\n+++ b/src/ipa/raspberrypi/controller/contrast_status.h\n@@ -6,20 +6,15 @@\n  */\n #pragma once\n \n+#include \"pwl.h\"\n+\n /*\n  * The \"contrast\" algorithm creates a gamma curve, optionally doing a little bit\n  * of contrast stretching based on the AGC histogram.\n  */\n \n-constexpr unsigned int ContrastNumPoints = 33;\n-\n-struct ContrastPoint {\n-\tuint16_t x;\n-\tuint16_t y;\n-};\n-\n struct ContrastStatus {\n-\tstruct ContrastPoint points[ContrastNumPoints];\n+\tRPiController::Pwl gammaCurve;\n \tdouble brightness;\n \tdouble contrast;\n };\ndiff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp\nindex a4f8c4f04fc4..bee1eadd3657 100644\n--- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp\n@@ -65,34 +65,19 @@ void Contrast::setContrast(double contrast)\n \tcontrast_ = contrast;\n }\n \n-static void fillInStatus(ContrastStatus &status, double brightness,\n-\t\t\t double contrast, Pwl &gammaCurve)\n-{\n-\tstatus.brightness = brightness;\n-\tstatus.contrast = contrast;\n-\tfor (unsigned int i = 0; i < ContrastNumPoints - 1; i++) {\n-\t\tint x = i < 16 ? i * 1024\n-\t\t\t       : (i < 24 ? (i - 16) * 2048 + 16384\n-\t\t\t\t\t : (i - 24) * 4096 + 32768);\n-\t\tstatus.points[i].x = x;\n-\t\tstatus.points[i].y = std::min(65535.0, gammaCurve.eval(x));\n-\t}\n-\tstatus.points[ContrastNumPoints - 1].x = 65535;\n-\tstatus.points[ContrastNumPoints - 1].y = 65535;\n-}\n-\n void Contrast::initialise()\n {\n \t/*\n \t * Fill in some default values as Prepare will run before Process gets\n \t * called.\n \t */\n-\tfillInStatus(status_, brightness_, contrast_, config_.gammaCurve);\n+\tstatus_.brightness = brightness_;\n+\tstatus_.contrast = contrast_;\n+\tstatus_.gammaCurve = config_.gammaCurve;\n }\n \n void Contrast::prepare(Metadata *imageMetadata)\n {\n-\tstd::unique_lock<std::mutex> lock(mutex_);\n \timageMetadata->set(\"contrast.status\", status_);\n }\n \n@@ -183,12 +168,9 @@ void Contrast::process(StatisticsPtr &stats,\n \t * And fill in the status for output. Use more points towards the bottom\n \t * of the curve.\n \t */\n-\tContrastStatus status;\n-\tfillInStatus(status, brightness_, contrast_, gammaCurve);\n-\t{\n-\t\tstd::unique_lock<std::mutex> lock(mutex_);\n-\t\tstatus_ = status;\n-\t}\n+\tstatus_.brightness = brightness_;\n+\tstatus_.contrast = contrast_;\n+\tstatus_.gammaCurve = std::move(gammaCurve);\n }\n \n /* Register algorithm with the system. */\ndiff --git a/src/ipa/raspberrypi/controller/rpi/contrast.h b/src/ipa/raspberrypi/controller/rpi/contrast.h\nindex c68adbc9e463..9c81277a0450 100644\n--- a/src/ipa/raspberrypi/controller/rpi/contrast.h\n+++ b/src/ipa/raspberrypi/controller/rpi/contrast.h\n@@ -46,7 +46,6 @@ private:\n \tdouble brightness_;\n \tdouble contrast_;\n \tContrastStatus status_;\n-\tstd::mutex mutex_;\n };\n \n } /* namespace RPiController */\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 0fa79bb4af41..b6e5465ca32a 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -1592,14 +1592,21 @@ void IPARPi::applyCCM(const struct CcmStatus *ccmStatus, ControlList &ctrls)\n \n void IPARPi::applyGamma(const struct ContrastStatus *contrastStatus, ControlList &ctrls)\n {\n+\tconst unsigned int numGammaPoints = controller_.getHardwareConfig().numGammaPoints;\n \tstruct bcm2835_isp_gamma gamma;\n \n-\tgamma.enabled = 1;\n-\tfor (unsigned int i = 0; i < ContrastNumPoints; i++) {\n-\t\tgamma.x[i] = contrastStatus->points[i].x;\n-\t\tgamma.y[i] = contrastStatus->points[i].y;\n+\tfor (unsigned int i = 0; i < numGammaPoints - 1; i++) {\n+\t\tint x = i < 16 ? i * 1024\n+\t\t\t       : (i < 24 ? (i - 16) * 2048 + 16384\n+\t\t\t\t\t : (i - 24) * 4096 + 32768);\n+\t\tgamma.x[i] = x;\n+\t\tgamma.y[i] = std::min<uint16_t>(65535, contrastStatus->gammaCurve.eval(x));\n \t}\n \n+\tgamma.x[numGammaPoints - 1] = 65535;\n+\tgamma.y[numGammaPoints - 1] = 65535;\n+\tgamma.enabled = 1;\n+\n \tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&gamma),\n \t\t\t\t\t    sizeof(gamma) });\n \tctrls.set(V4L2_CID_USER_BCM2835_ISP_GAMMA, c);\n","prefixes":["libcamera-devel","v1","06/10"]}