{"id":18475,"url":"https://patchwork.libcamera.org/api/1.1/patches/18475/?format=json","web_url":"https://patchwork.libcamera.org/patch/18475/","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":"<20230327122030.11756-7-naush@raspberrypi.com>","date":"2023-03-27T12:20:26","name":"[libcamera-devel,v2,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/18475/mbox/","series":[{"id":3819,"url":"https://patchwork.libcamera.org/api/1.1/series/3819/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3819","date":"2023-03-27T12:20:20","name":"Raspberry Pi: Generalised algorithms","version":2,"mbox":"https://patchwork.libcamera.org/series/3819/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18475/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18475/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 92F86C329D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Mar 2023 12:20:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2D30162754;\n\tMon, 27 Mar 2023 14:20:52 +0200 (CEST)","from mail-il1-x12a.google.com (mail-il1-x12a.google.com\n\t[IPv6:2607:f8b0:4864:20::12a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A2AC562720\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Mar 2023 14:20:47 +0200 (CEST)","by mail-il1-x12a.google.com with SMTP id h11so4512733ild.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Mar 2023 05:20:47 -0700 (PDT)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tr7-20020a5edb47000000b00758ff97aaedsm3239026iop.16.2023.03.27.05.20.46\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 27 Mar 2023 05:20:46 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679919652;\n\tbh=XJZ+b37RC6DAoNkN9LySXWzskZlFzHIPkUne8vcW67I=;\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:Cc:\n\tFrom;\n\tb=lD+PI0F6CZZ0LG6+dCzDlZnoTumBlN+PWjnHUN2z59Bkqglgd2iSha2J93FOxTu7v\n\tUkLes9+uEaNAt62v9jeDFCIhIdqiuGYflh36T9wWy1VzCCNgz+nL1Cd2surSDDQaFe\n\tatN1ZEZWGzqIFNW/NSIFJbP/2GOHvJ6LmPWNXGvM1BMtP0VaPgwJ9NThop9dS7cByt\n\tB1eD51htCoCNqztDWNJZDitOMC2QLiPP/nqRHqC4LEUKXF6kK3jf16fyzLV2jLBCgH\n\tuBo2emCUG899bUwdF8N72Te5V72iUW2jiXa1xje+mw8QguthHKcYI5UgPz/0a/1bcN\n\trtnNy0enBWbGQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1679919647;\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=FKREP6jJa308Taqx9N+sEobA15WmVJReEHkapGWA6lw=;\n\tb=V43C2LusEWI/Ci8v5eK6nkNsOWY/tnnwnl0wWIJ7XJne/uQibdIQG74uAmOE1DFF4+\n\t0IhZimiO2eF6tHsca8BcYjVj29437wykbr2MxcFAhyfoDgdFz/xp9aEAmKHDlbIGbaav\n\tEapabiebyTGxmj1X/PvnsyYp2iINppPUgei98x1yuERApBrT3ohoA8J49qBlsMV0vaBa\n\teQpnK/SLtbr9AoJCdQtK6cl3zkTCWoKXn5DtfkIMZVuol++veg7gyWNEqpU8QJlPrlyL\n\tIytfJ73mjcW2L4Q2fuemPfN0T06X8AvNEHybzktdrTqeX+K6PXnNXVQ/Ae21OPX7dLNo\n\tJAiQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"V43C2Lus\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1679919647;\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=FKREP6jJa308Taqx9N+sEobA15WmVJReEHkapGWA6lw=;\n\tb=P612gSLouQJiQAPQ/8vnaGzMgpKvI+aXPXoOi6JOYbJ+CeFOrCgxWOgJvy/PQ1efX6\n\tzEgyRqxNzm7tk7WmX+ln3CWX0cyVMz91+yANnCHEe6A1vJAdy7rYvBcRhBetiCHKLQA0\n\tyGMuB4jLyivtc838nX+Jn22+h60DHJUBxF/m8yum+mmXYbcjxsVxg7dCoz18PVQRdRyX\n\tW3IlCoE8ce6gIj5QtmZRqEa6mhDnk/l9611zahZmTt8KH1znNFpGPneg9fAyMKl//1KT\n\tnD6Ty0JnGi84nT2a9BlrHwjd2Q40l9G7ENBeDQVoLh8FggSEf+s0e7ObrDVniip0SaDW\n\tDTsQ==","X-Gm-Message-State":"AAQBX9cuyqXXz67/qeCPzM4zzGFzIc/h0deVQUOf6kUCm02RXAz+exYC\n\tMfmqIaO+2yagMONuXUnbA3xgEh2Z5Keh8yZfJNjHMg==","X-Google-Smtp-Source":"AKy350YvtuZSR5nTWWQFOvLSKWdSSZ7lWa3+cNOMUNy15Bh0uqjAVjiAFS1fYBBVqxFrAz8OAH2lxw==","X-Received":"by 2002:a92:da11:0:b0:325:b002:89b4 with SMTP id\n\tz17-20020a92da11000000b00325b00289b4mr9008042ilm.25.1679919646985; \n\tMon, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.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>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.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 257d862e07b6..d813b1b7ca61 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","v2","06/10"]}