From patchwork Mon Feb 8 15:07:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11190 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 23D83BD160 for ; Mon, 8 Feb 2021 15:07:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E82E260D26; Mon, 8 Feb 2021 16:07:56 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="J6TpuUT8"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 413AC60D18 for ; Mon, 8 Feb 2021 16:07:54 +0100 (CET) Received: by mail-wm1-x32d.google.com with SMTP id j21so10820404wmj.0 for ; Mon, 08 Feb 2021 07:07:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2fyJrzrB4k8ujzQt1Ep5Gso6AESqBPahpZVRJorJDsA=; b=J6TpuUT8650KCIjaIz3YXDxzvf5absJBMrLpP9Y+IaXHljQ6i2ZbhKTEnM2Al5kj0u eGbnWvFN18EfWgdPO0o7Cf28QuV99/CR2Yv2M/7j6cxuO7nK+QozUZSfBiyHmR2LlALr O+iQSCmNVyP9C59J5+vgowUf40YoQLnmh4+1tIa2VUgqxPJ6oWCzCE86BAqRQ+ZMhixv YiHzhIBxmFMQaq5AMQoCb7jE4s5z0ROgGHd2Y0XvsDcTZ4LYe4j4E51PwTpvuyG3Uuc6 KsP7LK4B0fJ3lwdSCgVE5yIyTMmUg2e4NPfNOeLCyMCvzRqOXmnxi/JnkD+ZEXUBlhzw gLkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2fyJrzrB4k8ujzQt1Ep5Gso6AESqBPahpZVRJorJDsA=; b=SZI1iS1zSbh+zj70yddNOIruDgZ+qfVJZfHrABYquLoSwjKdipn9AARKck3BpKOY8b sxjCbOUFnfSVW/lDG62jpRmHksD9i/AiQE147Z/BDMfhfDVqmJrYN1V10CMQAqukVph2 g4cd4ZeROMreQOaiQBppZW88VogNGBNWXAK6OO3oz9hiuAHIR9doAPDA9coV5tyJyAjT LEdoyTAa745MqzCTweWcV0sXsFjk+BYX8iIW+NJV3GcFHKHNA77xPYTUnBxKa34jl47+ YVn9SUvQEycmQVfC1dLSYmB8U2Tdub+KOSA98QVgsrH/YhYwTQJ/A9XnLpDKHbrhYd5v GV8A== X-Gm-Message-State: AOAM533cAVhT3VB4Zmv7+4hTx4uYvD/ZaJ9ZW1iurCGUGaNz36pBfg57 YAwlyt48abIcacDoYTNinNJAj7LSpUHRuUX8 X-Google-Smtp-Source: ABdhPJySqkdbkBD6NxXrZblI4uBUHBWyTO4IruQuh+53ysyFifIabn+Mzddn5+CnLzr6bo0s7y6/rQ== X-Received: by 2002:a05:600c:4f93:: with SMTP id n19mr14910253wmq.163.1612796864869; Mon, 08 Feb 2021 07:07:44 -0800 (PST) Received: from naush-laptop.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id a17sm31261389wrx.63.2021.02.08.07.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 07:07:44 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 8 Feb 2021 15:07:33 +0000 Message-Id: <20210208150738.2293520-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210208150738.2293520-1-naush@raspberrypi.com> References: <20210208150738.2293520-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 1/6] pipeline: raspberrypi: Refactor stream configuration routine 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Refactor the high/low resolution stream format and output selection routine. This change is in preparation of adding 1/4 resolution output for fast colour denoise. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 57 ++++++------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 0804a4393c19..183a690dbca1 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -623,52 +623,27 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) continue; } - if (i == maxIndex) { - /* ISP main output format. */ - V4L2VideoDevice *dev = data->isp_[Isp::Output0].dev(); - V4L2PixelFormat fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat); - format.size = cfg.size; - format.fourcc = fourcc; - - ret = dev->setFormat(&format); - if (ret) - return -EINVAL; - - if (format.size != cfg.size || format.fourcc != fourcc) { - LOG(RPI, Error) - << "Failed to set format on ISP capture0 device: " - << format.toString(); - return -EINVAL; - } - - cfg.setStream(&data->isp_[Isp::Output0]); - data->isp_[Isp::Output0].setExternal(true); - } + /* The largest resolution gets routed to the ISP Output 0 node. */ + RPi::Stream *stream = i == maxIndex ? &data->isp_[Isp::Output0] + : &data->isp_[Isp::Output1]; - /* - * ISP second output format. This fallthrough means that if a - * second output stream has not been configured, we simply use - * the Output0 configuration. - */ - V4L2VideoDevice *dev = data->isp_[Isp::Output1].dev(); - format.fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat); + V4L2PixelFormat fourcc = stream->dev()->toV4L2PixelFormat(cfg.pixelFormat); format.size = cfg.size; + format.fourcc = fourcc; - ret = dev->setFormat(&format); - if (ret) { + ret = stream->dev()->setFormat(&format); + if (ret) + return -EINVAL; + + if (format.size != cfg.size || format.fourcc != fourcc) { LOG(RPI, Error) - << "Failed to set format on ISP capture1 device: " - << format.toString(); - return ret; - } - /* - * If we have not yet provided a stream for this config, it - * means this is to be routed from Output1. - */ - if (!cfg.stream()) { - cfg.setStream(&data->isp_[Isp::Output1]); - data->isp_[Isp::Output1].setExternal(true); + << "Failed to set requested format on " << stream->name() + << ", returned " << format.toString(); + return -EINVAL; } + + cfg.setStream(stream); + stream->setExternal(true); } /* ISP statistics output format. */ From patchwork Mon Feb 8 15:07:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11192 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 CEBC9BD160 for ; Mon, 8 Feb 2021 15:07:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9DCA860D2D; Mon, 8 Feb 2021 16:07:58 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="BkQsrYjE"; dkim-atps=neutral Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C7EA760D18 for ; Mon, 8 Feb 2021 16:07:56 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id n6so4707359wrv.8 for ; Mon, 08 Feb 2021 07:07:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ryNStR4waILijeEpS9cXHD4lYAxZzMUYzfSprSf3nS0=; b=BkQsrYjE5ZtzOYWQdJqvDSYgHhp8cxRaugY5P/+4+zCLuJMrzr1k9CQPiR7TLk1KeT F1YlMpWTBMn9s1zlyXl4oeR7E7t81oGpDe4hAAtiY1JbZzbtVd3Yo/tjyVJx4P33sMLb CFbSeac0p36JNMSQ5NVb8gKNwDjdH+Fs0mLpO3mhfa+DstU8itqcoaSngWaZIMrKEUJw ldwcu99/J5fLXlT3yrzJ0aNMjQh+TADy8ezbq73rM5hhfxzJZMv+EIUtiKOHDABAly47 PcJUeMOfqTiYKWWJnvsF/OEW73ZLUiLD410V4Vq2jEhsiZLFfhnPvU6/ICE3cg2yLs/w 4mQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ryNStR4waILijeEpS9cXHD4lYAxZzMUYzfSprSf3nS0=; b=i6kBR927EZtEhowE8sp0XF9S7BvESUsigMLVq7p5PqOSfiHC5wwDxHjSXQ394O/9RX GXuYqpzpPuLVQJOirwlzRU2jOM/a915rSYLuEEd1JzQxf4NqOmopyITX+VcMU6tBdeav XdX6cBg48m75xMPuTjViO7OYzbZHb48SK33aiE/m/4d9HJEg2Tf4NwGZNncWPbLtKWsF CEO2fasP5WHL11CCodKv7lOqv3A8KEfiiDpjbXITlX8/jsQSMHkdt7ahlqa4woMu09BF cSpU0JVnBRWp4L+rVXONp9QLgn+HV5du0t+UDVyp9z3Xaa+aEQ8jUDSmLJfqz8MwZD9S usMg== X-Gm-Message-State: AOAM530GnJBp6UBxHPcpzD47F6IJQ8TSor+qanghyZ4GkWRoj2Am/ClS JGd7M4PfGIZiRf+W7/p5tRhCvDdIEwkdagU9 X-Google-Smtp-Source: ABdhPJwyEaWzfsa+PvS4FLqnrzPtZq9iJB/WYez6RQDZ1he6LsnZSI/EYoHEOUiCRf/cYJAcB6u/GQ== X-Received: by 2002:adf:ed45:: with SMTP id u5mr20235183wro.358.1612796874100; Mon, 08 Feb 2021 07:07:54 -0800 (PST) Received: from naush-laptop.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id a17sm31261389wrx.63.2021.02.08.07.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 07:07:53 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 8 Feb 2021 15:07:34 +0000 Message-Id: <20210208150738.2293520-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210208150738.2293520-1-naush@raspberrypi.com> References: <20210208150738.2293520-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 2/6] pipeline: raspberrypi: Set the ISP Output1 to 1/4 resolution if unused 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In preparation for fast colour denoise, set the low resolution ISP output stream (Output1) to a 1/4 resolution of the application requested stream (Output0). This only happens if the application has not requested an additional YUV or RGB stream. We also constrain this 1/4 resolution to at most 1200 pixels in the largest dimension to avoid being too taxing on memory usage and system bandwidth. Also switch the default StreamRole::VideoRecording to YUV420 to allow fast colour denoise to run. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 183a690dbca1..7ecb080f62d3 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -494,8 +494,16 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, break; case StreamRole::VideoRecording: + /* + * The colour denoise algorithm require the analysis + * image, produced by the second ISP output, to be in + * YUV420 format. Select this format as the default, to + * maximize chances that it will be picked by + * applications and enable usage of the colour denoise + * algorithm. + */ fmts = data->isp_[Isp::Output0].dev()->formats(); - pixelFormat = formats::NV12; + pixelFormat = formats::YUV420; size = { 1920, 1080 }; bufferCount = 4; outCount++; @@ -607,6 +615,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) * StreamConfiguration appropriately. */ V4L2DeviceFormat format; + bool output1Set = false; for (unsigned i = 0; i < config->size(); i++) { StreamConfiguration &cfg = config->at(i); @@ -631,6 +640,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) format.size = cfg.size; format.fourcc = fourcc; + LOG(RPI, Debug) << "Setting " << stream->name() << " to " + << format.toString(); + ret = stream->dev()->setFormat(&format); if (ret) return -EINVAL; @@ -644,6 +656,38 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) cfg.setStream(stream); stream->setExternal(true); + + if (i != maxIndex) + output1Set = true; + } + + /* + * If ISP::Output1 stream has not been requested by the application, we + * set it up for internal use now. This second stream will be used for + * fast colour denoise, and must be a quarter resolution of the ISP::Output0 + * stream. However, also limit the maximum size to 1200 pixels in the + * larger dimension, just to avoid being wasteful with buffer allocations + * and memory bandwidth. + * + * \todo If Output 1 format is not YUV420, Output 1 ought to be disabled as + * colour denoise will not run. + */ + if (!output1Set) { + V4L2DeviceFormat output1Format = format; + constexpr Size maxDimensions(1200, 1200); + const Size limit = maxDimensions.boundedToAspectRatio(format.size); + + output1Format.size = (format.size / 2).boundedTo(limit).alignedDownTo(2, 2); + + LOG(RPI, Debug) << "Setting ISP Output1 (internal) to " + << output1Format.toString(); + + ret = data->isp_[Isp::Output1].dev()->setFormat(&output1Format); + if (ret) { + LOG(RPI, Error) << "Failed to set format on ISP Output1: " + << ret; + return -EINVAL; + } } /* ISP statistics output format. */ From patchwork Mon Feb 8 15:07:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11191 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 A1136BD160 for ; Mon, 8 Feb 2021 15:07:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3DC6760D2B; Mon, 8 Feb 2021 16:07:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="WX5HpsC4"; dkim-atps=neutral Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B05E60D20 for ; Mon, 8 Feb 2021 16:07:56 +0100 (CET) Received: by mail-wr1-x42d.google.com with SMTP id b3so17526386wrj.5 for ; Mon, 08 Feb 2021 07:07:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3HH8/GUJORTvoTeFuBrsV0XIkD1kOM1ZRQFK0DdpmdE=; b=WX5HpsC4/GZSwASifETmCXTctAMT4OE/VBHxloymOfHhBzcot1fD1LypIGIpHS78cR vz8fZFTtsxszsIBIB+mdZAy7I2CstzEYvYoqM3W7OPCw7+elm7BeMdXh18jEwAhi43IV DNKvyereKQml9URcJ7+tltrSr2NZAE5YMi33BSKm71E5zrGhN1TvahUGugtYp4Wtx96V SNILbvAPgcgQTRVID94OcK51hvshTLqTKd35dix3SzYZ4As/LlNMW0mxMZP9iZPaOTSk CYTWu48ERe29I/V5OMs3IiogHvCms8hlrlI4kZPAN61OIZwkIIA1zLf6KQP4D+NYFemA Pn8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3HH8/GUJORTvoTeFuBrsV0XIkD1kOM1ZRQFK0DdpmdE=; b=lbFj3UzXJJFsfIOMJ9FfbYhHb1WmhxdntalQrwsNSwVg313xjt419snTwZxybxJ5LH cSeAeUFBYuW/SxEn3U6y8NpjRwLlILnokWFLcBlrkqd9+x+7mbUB6M3v3MEUnDjqnrjQ pFfJyGgSfDHahz4hSlICuAndV3bIQ4LeCCt82qsy+aNlCeKB6L+r0f9xwpK6YwdLIKTM pCsBIWlQ5imxTkBioVBEOuFPhM81iYTP3c5kJTmPF+UdnHnaRhTiCoSIuvZrrpTrNQoN Ehot2jC4BZ/sb3T+Ym+2UJtDGnEQ0mYYRTfaf8qRvO0P9IEH+xkiMdwnRr6oEonPNGsB NMoQ== X-Gm-Message-State: AOAM530G7qQQ9F8ZJK6dbdNtwiyYIyz4mZeCqcpKxkuHK4Y20KAwcwWM AiBUKWiUbm2S4fQ6D8qk9LTuclTM90q3eqKY X-Google-Smtp-Source: ABdhPJyMLgoiiB/1KZKLvjR2R5xZlstWDx1IzHoj4tzmvqARWYoF6IE+gd91jsqwc6YGPCavRt5W6A== X-Received: by 2002:a5d:5049:: with SMTP id h9mr20942064wrt.404.1612796875466; Mon, 08 Feb 2021 07:07:55 -0800 (PST) Received: from naush-laptop.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id a17sm31261389wrx.63.2021.02.08.07.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 07:07:54 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 8 Feb 2021 15:07:35 +0000 Message-Id: <20210208150738.2293520-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210208150738.2293520-1-naush@raspberrypi.com> References: <20210208150738.2293520-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 3/6] uapi: raspberrypi: Update the bcm2835-isp header definition 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Update the bcm2835-isp.h file with the latest version available in the downstream Raspberry Pi linux repo at commit: 68878170d8a98afd6d519a3a2c909080c19de4ce This change adds support for colour denoise processing, and the following downstream kernel changes must be available: https://github.com/raspberrypi/linux/pull/4069 https://github.com/raspberrypi/linux/pull/4083 The Raspberry Pi image must also be running the latest firmware, obtained by running rpi-update. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Acked-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/linux/bcm2835-isp.h | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/include/linux/bcm2835-isp.h b/include/linux/bcm2835-isp.h index 45abb681517e..94c3af947883 100644 --- a/include/linux/bcm2835-isp.h +++ b/include/linux/bcm2835-isp.h @@ -31,7 +31,8 @@ (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0007) #define V4L2_CID_USER_BCM2835_ISP_DPC \ (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0008) - +#define V4L2_CID_USER_BCM2835_ISP_CDN \ + (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0009) /* * All structs below are directly mapped onto the equivalent structs in * drivers/staging/vc04_services/vchiq-mmal/mmal-parameters.h @@ -46,7 +47,7 @@ */ struct bcm2835_isp_rational { __s32 num; - __s32 den; + __u32 den; }; /** @@ -140,7 +141,7 @@ struct bcm2835_isp_black_level { __u16 black_level_r; __u16 black_level_g; __u16 black_level_b; - __u8 pad_[2]; /* Unused */ + __u8 padding[2]; /* Unused */ }; /** @@ -175,6 +176,31 @@ struct bcm2835_isp_gamma { __u16 y[BCM2835_NUM_GAMMA_PTS]; }; +/** + * enum bcm2835_isp_cdn_mode - Mode of operation for colour denoise. + * + * @CDN_MODE_FAST: Fast (but lower quality) colour denoise + * algorithm, typically used for video recording. + * @CDN_HIGH_QUALITY: High quality (but slower) colour denoise + * algorithm, typically used for stills capture. + */ +enum bcm2835_isp_cdn_mode { + CDN_MODE_FAST = 0, + CDN_MODE_HIGH_QUALITY = 1, +}; + +/** + * struct bcm2835_isp_cdn - Colour denoise parameters set with the + * V4L2_CID_USER_BCM2835_ISP_CDN ctrl. + * + * @enabled: Enable colour denoise. + * @cdn_mode: Colour denoise operating mode (see enum &bcm2835_isp_cdn_mode) + */ +struct bcm2835_isp_cdn { + __u32 enabled; + __u32 mode; +}; + /** * struct bcm2835_isp_denoise - Denoise parameters set with the * V4L2_CID_USER_BCM2835_ISP_DENOISE ctrl. From patchwork Mon Feb 8 15:07:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11195 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 56660BD162 for ; Mon, 8 Feb 2021 15:08:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2560660D26; Mon, 8 Feb 2021 16:08:35 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="fHnWd8Ba"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 50B0C60D21 for ; Mon, 8 Feb 2021 16:08:33 +0100 (CET) Received: by mail-wr1-x435.google.com with SMTP id u14so17572495wri.3 for ; Mon, 08 Feb 2021 07:08:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MeSSeQisOMZr1VtdPoWYea3+nhKVhtFXVS0jLnW5PYM=; b=fHnWd8Ba3I9vbcqjtsLpUzTgu1gd+cbe8qUT5/kEZKv1cQGHiZLjsWbMyE25GqT5kY LRXCPaTMZfFGZMU7KRCuThOPVMWeBMOlqJKgerA6AkspB7U3GpK0kVNcxmP4tH8og4um FXEou5BG4cJsWxi6Ad0ao2jjIsgKaPKK6AmS7hPm2NQUyVPk3Z7GB6qQBEQE7LO1oSeU KYP+ENOMn+DbV7twaAhoiYpKnZVbeleFxTW4BMhns4dkB9gibgrbIJjDgaprAG5XqP+S QPpPOGZcad264F5dPyYGz9WTviIyAMr+69ahD2sjGX2nl0ZvgZBLtJ6GDi7uZY6CUy1H FOCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MeSSeQisOMZr1VtdPoWYea3+nhKVhtFXVS0jLnW5PYM=; b=J51h7Rb2roRLCstY29UCFvUhGjEA52P0kwnPQ+8gNBXZ8OIXL6YA5muhxeL7wjM3fQ 9VQeoq7kfbXxXc8SoU4aeJe5jlT4XJf3Lh0KnnSpL50hvc2a3mQPmxZDBXlh9nESFImC dEv2hYEPlaDo9rxcT4HzRS0TjPxhRSZQNULWA+ysMg9ggkhQW839oaD6zg0EzWis5mS2 Sl4DyEGaLz/vG6KJs+18OZzX3f/YeGyUvqsNViKcbiNJpLl2tx5wm7LrXYA76VDnAQsu GSE1o4PwUXHChWQIEujMCrwRK/wtkMtRne5Uu9dyp1szXOn8SPoDuCr8yg7nAVA9cydy iXOA== X-Gm-Message-State: AOAM531GGtMn9RQQKFc6KmbuWAxLwqA12cvnIpLRaKsDPNfdE/smRRpH 7CBbsdPsvDWh5NI1/FsiOGL5q2FZL/eYcbIA X-Google-Smtp-Source: ABdhPJxthSXt+jz2Q3HLqhY8c3kyVEdmu++TITUImB1iuc305Pxr1Gn51/keTfUi+vciXa0RyvtwlA== X-Received: by 2002:a5d:47ae:: with SMTP id 14mr20271703wrb.378.1612796881599; Mon, 08 Feb 2021 07:08:01 -0800 (PST) Received: from naush-laptop.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id a17sm31261389wrx.63.2021.02.08.07.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 07:07:56 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 8 Feb 2021 15:07:36 +0000 Message-Id: <20210208150738.2293520-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210208150738.2293520-1-naush@raspberrypi.com> References: <20210208150738.2293520-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 4/6] ipa: raspberrypi: Rename SdnStatus to DenoiseStatus 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This change is in anticipation of the addition of a DenoiseAlgorithm base class which the SDN class will derive from. We want to match the metadata object name with the base class algorithm name. This renames: - SdnStatus metadata object to DenoiseStatus - "sdn.status" metadata string key to "denoise.status" - sdn_status.h header file to denoise_status.h Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- .../controller/{sdn_status.h => denoise_status.h} | 8 ++++---- src/ipa/raspberrypi/controller/rpi/sdn.cpp | 4 ++-- src/ipa/raspberrypi/raspberrypi.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) rename src/ipa/raspberrypi/controller/{sdn_status.h => denoise_status.h} (50%) diff --git a/src/ipa/raspberrypi/controller/sdn_status.h b/src/ipa/raspberrypi/controller/denoise_status.h similarity index 50% rename from src/ipa/raspberrypi/controller/sdn_status.h rename to src/ipa/raspberrypi/controller/denoise_status.h index 871e0b62af1f..94f5df200ffd 100644 --- a/src/ipa/raspberrypi/controller/sdn_status.h +++ b/src/ipa/raspberrypi/controller/denoise_status.h @@ -1,18 +1,18 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * Copyright (C) 2019-2021, Raspberry Pi (Trading) Limited * - * sdn_status.h - SDN (spatial denoise) control algorithm status + * denoise_status.h - Denoise control algorithm status */ #pragma once -// This stores the parameters required for Spatial Denoise (SDN). +// This stores the parameters required for Denoise (SDN). #ifdef __cplusplus extern "C" { #endif -struct SdnStatus { +struct DenoiseStatus { double noise_constant; double noise_slope; double strength; diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.cpp b/src/ipa/raspberrypi/controller/rpi/sdn.cpp index 0fad25504345..ef84a2dcbf86 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.cpp @@ -7,8 +7,8 @@ #include "libcamera/internal/log.h" +#include "../denoise_status.h" #include "../noise_status.h" -#include "../sdn_status.h" #include "sdn.hpp" @@ -49,7 +49,7 @@ void Sdn::Prepare(Metadata *image_metadata) LOG(RPiSdn, Debug) << "Noise profile: constant " << noise_status.noise_constant << " slope " << noise_status.noise_slope; - struct SdnStatus status; + struct DenoiseStatus status; status.noise_constant = noise_status.noise_constant * deviation_; status.noise_slope = noise_status.noise_slope * deviation_; status.strength = strength_; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index ff14cfc4b706..e76688a7b323 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -43,13 +43,13 @@ #include "contrast_algorithm.hpp" #include "contrast_status.h" #include "controller.hpp" +#include "denoise_status.h" #include "dpc_status.h" #include "focus_status.h" #include "geq_status.h" #include "lux_status.h" #include "metadata.hpp" #include "noise_status.h" -#include "sdn_status.h" #include "sharpen_algorithm.hpp" #include "sharpen_status.h" @@ -110,7 +110,7 @@ private: void applyBlackLevel(const struct BlackLevelStatus *blackLevelStatus, ControlList &ctrls); void applyGamma(const struct ContrastStatus *contrastStatus, ControlList &ctrls); void applyGEQ(const struct GeqStatus *geqStatus, ControlList &ctrls); - void applyDenoise(const struct SdnStatus *denoiseStatus, ControlList &ctrls); + void applyDenoise(const struct DenoiseStatus *denoiseStatus, ControlList &ctrls); void applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls); void applyDPC(const struct DpcStatus *dpcStatus, ControlList &ctrls); void applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls); @@ -952,7 +952,7 @@ void IPARPi::prepareISP(unsigned int bufferId) if (geqStatus) applyGEQ(geqStatus, ctrls); - SdnStatus *denoiseStatus = rpiMetadata_.GetLocked("sdn.status"); + DenoiseStatus *denoiseStatus = rpiMetadata_.GetLocked("denoise.status"); if (denoiseStatus) applyDenoise(denoiseStatus, ctrls); @@ -1171,7 +1171,7 @@ void IPARPi::applyGEQ(const struct GeqStatus *geqStatus, ControlList &ctrls) ctrls.set(V4L2_CID_USER_BCM2835_ISP_GEQ, c); } -void IPARPi::applyDenoise(const struct SdnStatus *denoiseStatus, ControlList &ctrls) +void IPARPi::applyDenoise(const struct DenoiseStatus *denoiseStatus, ControlList &ctrls) { bcm2835_isp_denoise denoise; From patchwork Mon Feb 8 15:07:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11193 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 396D2BD160 for ; Mon, 8 Feb 2021 15:08:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0607760D2A; Mon, 8 Feb 2021 16:08:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="oynFR6Wy"; dkim-atps=neutral Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EC57160D21 for ; Mon, 8 Feb 2021 16:08:10 +0100 (CET) Received: by mail-wr1-x433.google.com with SMTP id u14so17570041wri.3 for ; Mon, 08 Feb 2021 07:08:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7Eib4zDANaA6JZXba1QgQGfirur2ZBzw8jt8Oj+tjQE=; b=oynFR6WyE3i9iD9IZoL3/6ltKptPrDd7O2jAjXKjMTLLRKc/wenZWisPhtueVR7PKS nkfAgWqwfR9nUbPcada5baf5wzpp0lVupUVV3JA1+AXtJ3CTXXsrLoqtAUoScOOOTeJM i21McJanX2srNt7S3mR8qNKExs6G3gHQBex0DVIzYblUPy5xGLMAT3JDHS3THw0cSbjn GfWrXCPrasFFk70qlk8P3VriBbPZeecQR9IJgZDlNLVtwfWb6CVGmHQVUiXuX3FviHsE 669ar94OfrVulpcPKzCysvl/7AFZ14okM3MQhykZyD+nbKdkYUxd2VX31QDRvz/WpOD3 YnHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Eib4zDANaA6JZXba1QgQGfirur2ZBzw8jt8Oj+tjQE=; b=lB9QPeA0zGXxgtQtyBMSOwkpIeUPYoY3RcTsAOLGgHmjr6oyMVu9WuzmtPPo5ra0bT nN6EmTzkNCpVsGOOfI68RUozQ9I7oKMrPb2jZzRcihr1X1S+DF/d7lTIuXf7soUrLxpZ qTIBSFTr2udLT0DE2wu2YrJGFBw8mb5UX4/jsmAuqq2vq9zMn/Ym/Rg5rQfKWc8CX25O C4mS2pdlwTvaHWb5r/tjvrwzurlpP+WgjLXn8FjJpmF4UXTQeNsmIcQQ9EZfEglo/Tma IxTKdQqEaHhmqASFy1TfP/OEOtX2xTo1yOwKVvRhhTSo3/qGrQ+W+W10/VQdVZRmvdFK UYSA== X-Gm-Message-State: AOAM532YLzorIsVg2T+45X3U121uSGSv5bT54W8JOelivDbcnYgVlxnM +ikHn2ctKANjNk8/y8g83Ktc02sjt7ZwpkUQ X-Google-Smtp-Source: ABdhPJzecF1i7owsGGUyogsWJGt3OhT0zON6NmQok6WaByx8096mcv/fWS6whK1UPDcrcUFpU+GDzw== X-Received: by 2002:adf:d852:: with SMTP id k18mr20688998wrl.262.1612796890416; Mon, 08 Feb 2021 07:08:10 -0800 (PST) Received: from naush-laptop.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id a17sm31261389wrx.63.2021.02.08.07.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 07:08:09 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 8 Feb 2021 15:07:37 +0000 Message-Id: <20210208150738.2293520-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210208150738.2293520-1-naush@raspberrypi.com> References: <20210208150738.2293520-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 5/6] ipa: raspberrypi: Add a DenoiseAlgorithm class to the Controller 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This denoise algorithm class will be used to pass in the user requested denoise operating mode to the controller. The existing Denoise controller will derive from this new DenoiseAlgorithm class. Add a denoise mode field in the denoise status metadata object for the IPA to use when configuring the ISP. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- .../controller/denoise_algorithm.hpp | 23 +++++++++++++++++++ .../raspberrypi/controller/denoise_status.h | 1 + src/ipa/raspberrypi/controller/rpi/sdn.cpp | 11 +++++++-- src/ipa/raspberrypi/controller/rpi/sdn.hpp | 5 +++- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/ipa/raspberrypi/controller/denoise_algorithm.hpp diff --git a/src/ipa/raspberrypi/controller/denoise_algorithm.hpp b/src/ipa/raspberrypi/controller/denoise_algorithm.hpp new file mode 100644 index 000000000000..39fcd7e94df2 --- /dev/null +++ b/src/ipa/raspberrypi/controller/denoise_algorithm.hpp @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2021, Raspberry Pi (Trading) Limited + * + * denoise.hpp - Denoise control algorithm interface + */ +#pragma once + +#include "algorithm.hpp" + +namespace RPiController { + +enum class DenoiseMode { Off, ColourOff, ColourFast, ColourHighQuality }; + +class DenoiseAlgorithm : public Algorithm +{ +public: + DenoiseAlgorithm(Controller *controller) : Algorithm(controller) {} + // A Denoise algorithm must provide the following: + virtual void SetMode(DenoiseMode mode) = 0; +}; + +} // namespace RPiController diff --git a/src/ipa/raspberrypi/controller/denoise_status.h b/src/ipa/raspberrypi/controller/denoise_status.h index 94f5df200ffd..4f1ca71e5f5a 100644 --- a/src/ipa/raspberrypi/controller/denoise_status.h +++ b/src/ipa/raspberrypi/controller/denoise_status.h @@ -16,6 +16,7 @@ struct DenoiseStatus { double noise_constant; double noise_slope; double strength; + unsigned int mode; }; #ifdef __cplusplus diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.cpp b/src/ipa/raspberrypi/controller/rpi/sdn.cpp index ef84a2dcbf86..899a38417695 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.cpp @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * Copyright (C) 2019-2021, Raspberry Pi (Trading) Limited * * sdn.cpp - SDN (spatial denoise) control algorithm */ @@ -23,7 +23,7 @@ LOG_DEFINE_CATEGORY(RPiSdn) #define NAME "rpi.sdn" Sdn::Sdn(Controller *controller) - : Algorithm(controller) + : DenoiseAlgorithm(controller), mode_(DenoiseMode::ColourOff) { } @@ -53,6 +53,7 @@ void Sdn::Prepare(Metadata *image_metadata) status.noise_constant = noise_status.noise_constant * deviation_; status.noise_slope = noise_status.noise_slope * deviation_; status.strength = strength_; + status.mode = static_cast>(mode_); image_metadata->Set("sdn.status", status); LOG(RPiSdn, Debug) << "programmed constant " << status.noise_constant @@ -60,6 +61,12 @@ void Sdn::Prepare(Metadata *image_metadata) << " strength " << status.strength; } +void Sdn::SetMode(DenoiseMode mode) +{ + // We only distinguish between off and all other modes. + mode_ = mode; +} + // Register algorithm with the system. static Algorithm *Create(Controller *controller) { diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.hpp b/src/ipa/raspberrypi/controller/rpi/sdn.hpp index 486c000d7b77..2371ce04163f 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.hpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.hpp @@ -7,12 +7,13 @@ #pragma once #include "../algorithm.hpp" +#include "../denoise_algorithm.hpp" namespace RPiController { // Algorithm to calculate correct spatial denoise (SDN) settings. -class Sdn : public Algorithm +class Sdn : public DenoiseAlgorithm { public: Sdn(Controller *controller = NULL); @@ -20,10 +21,12 @@ public: void Read(boost::property_tree::ptree const ¶ms) override; void Initialise() override; void Prepare(Metadata *image_metadata) override; + void SetMode(DenoiseMode mode) override; private: double deviation_; double strength_; + DenoiseMode mode_; }; } // namespace RPiController From patchwork Mon Feb 8 15:07:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11194 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 E1211BD160 for ; Mon, 8 Feb 2021 15:08:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AFD3F60D2D; Mon, 8 Feb 2021 16:08:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="g70WEax7"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5AE8860D2D for ; Mon, 8 Feb 2021 16:08:12 +0100 (CET) Received: by mail-wm1-x334.google.com with SMTP id o24so5816737wmh.5 for ; Mon, 08 Feb 2021 07:08:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KHB2EKmGz+hGJNbn8Yl7NuwoNezMZZa7kmvh9ntqrA0=; b=g70WEax7RWFeh8eOumjUKGhZJVzWxqenlLMQk6lzTJqK3H/xaRlvAq1ntltQaZ9U5x Z0SzFa8OZ0+A58aEvdVlpQtB+bBxJn9UfBfPcqkaO5SBcJpIP17AgIJW1A0vjznKsnyJ zr+4coTTERkBgnFxr9Dc0L4vNTN+vcbgu3AtR2TVjNGC3vYFCzusrRoqO8Qs92phxpnd ybxunRdn1VJT658IubxXrA83JzEQSZqVYqmbsebGytYqgfoftNSx43CCla9Tiwk6D/YF oz/enBR2FIhqpLifIRQeNiA1Thsiu3/9fUJ2Zil7hxgUMGnzK/y1ncYChoF5GOYuaQhM aLvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KHB2EKmGz+hGJNbn8Yl7NuwoNezMZZa7kmvh9ntqrA0=; b=DFd6qqEkInDEHgkzM8N2LZBxZk002bgMptR3F36E1uvfdp9g95jc73RK1L+gl2IuJH mtRzkfRqbNi3JV3O8DtXEh11ocp5uwW6g1E/Q0CwRx4/imi57zoQE0q0ub3c9szQhLdD lI/+ww1093FN+yWBDhkTN3m7TfFpbwoSPDtpjO8s9rMnTzDAOlxJmFdTRbqTOxWKfpah B6AG9E8RlirPOCxRKJT2IJOhaAdo65PVSRCDBS3h1jhaz8mBTwdJKsgAQtGJ4UlhtOBk TQOJxEzM+Uzk87KceAKphdc2V66Dmd3R5G5MyKf1JamvDmDBquJg7ZixCtfHNXKlH0Xj n26w== X-Gm-Message-State: AOAM533t7EI8uh/Rj+tyO7W7Vr33gYDoYpj4cmAlC2f4b7pHNx6HOnW4 OHnmOvT3q4qPqwYEAWp2PUKZzWzhZvERgvYG X-Google-Smtp-Source: ABdhPJw7HxlbPGXkDZr3Aj35UM/MVV5iZZA0NGzJf5ZGEW164FdG1LELaWyKOxy/hLkiqkUiWjnw8g== X-Received: by 2002:a1c:e90d:: with SMTP id q13mr14919707wmc.136.1612796891643; Mon, 08 Feb 2021 07:08:11 -0800 (PST) Received: from naush-laptop.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id a17sm31261389wrx.63.2021.02.08.07.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 07:08:10 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 8 Feb 2021 15:07:38 +0000 Message-Id: <20210208150738.2293520-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210208150738.2293520-1-naush@raspberrypi.com> References: <20210208150738.2293520-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 6/6] ipa: raspberrypi: Handle control::NoiseReductionMode in the controller 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The application provided noise reduction mode gets passed into the denoise controller. The denoise controller in turn returns the mode to the IPA which now sets up the colour denoise processing appropriately. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Naushir Patuck --- include/libcamera/ipa/raspberrypi.h | 1 + src/ipa/raspberrypi/raspberrypi.cpp | 57 ++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h index d333c2edfa53..ee673a4651a6 100644 --- a/include/libcamera/ipa/raspberrypi.h +++ b/include/libcamera/ipa/raspberrypi.h @@ -76,6 +76,7 @@ static const ControlInfoMap Controls = { { &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) }, { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, { &controls::FrameDurations, ControlInfo(INT64_C(1000), INT64_C(1000000000)) }, + { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }, }; } /* namespace RPi */ diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index e76688a7b323..ef8b19baa754 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -43,6 +43,7 @@ #include "contrast_algorithm.hpp" #include "contrast_status.h" #include "controller.hpp" +#include "denoise_algorithm.hpp" #include "denoise_status.h" #include "dpc_status.h" #include "focus_status.h" @@ -573,6 +574,7 @@ bool IPARPi::validateIspControls() V4L2_CID_USER_BCM2835_ISP_SHARPEN, V4L2_CID_USER_BCM2835_ISP_DPC, V4L2_CID_USER_BCM2835_ISP_LENS_SHADING, + V4L2_CID_USER_BCM2835_ISP_CDN, }; for (auto c : ctrls) { @@ -622,6 +624,14 @@ static const std::map AwbModeTable = { { controls::AwbCustom, "custom" }, }; +static const std::map DenoiseModeTable = { + { controls::draft::NoiseReductionModeOff, RPiController::DenoiseMode::Off }, + { controls::draft::NoiseReductionModeFast, RPiController::DenoiseMode::ColourFast }, + { controls::draft::NoiseReductionModeHighQuality, RPiController::DenoiseMode::ColourHighQuality }, + { controls::draft::NoiseReductionModeMinimal, RPiController::DenoiseMode::ColourOff }, + { controls::draft::NoiseReductionModeZSL, RPiController::DenoiseMode::ColourHighQuality }, +}; + void IPARPi::queueRequest(const ControlList &controls) { /* Clear the return metadata buffer. */ @@ -889,6 +899,29 @@ void IPARPi::queueRequest(const ControlList &controls) break; } + case controls::NOISE_REDUCTION_MODE: { + RPiController::DenoiseAlgorithm *sdn = dynamic_cast( + controller_.GetAlgorithm("SDN")); + ASSERT(sdn); + + int32_t idx = ctrl.second.get(); + auto mode = DenoiseModeTable.find(idx); + if (mode != DenoiseModeTable.end()) { + sdn->SetMode(mode->second); + + /* + * \todo If the colour denoise is not going to run due to an + * analysis image resolution or format mismatch, we should + * report the status correctly in the metadata. + */ + libcameraMetadata_.set(controls::draft::NoiseReductionMode, idx); + } else { + LOG(IPARPI, Error) << "Noise reduction mode " << idx + << " not recognised"; + } + break; + } + default: LOG(IPARPI, Warning) << "Ctrl " << controls::controls.at(ctrl.first)->name() @@ -1173,18 +1206,40 @@ void IPARPi::applyGEQ(const struct GeqStatus *geqStatus, ControlList &ctrls) void IPARPi::applyDenoise(const struct DenoiseStatus *denoiseStatus, ControlList &ctrls) { + using RPiController::DenoiseMode; + bcm2835_isp_denoise denoise; + DenoiseMode mode = static_cast(denoiseStatus->mode); - denoise.enabled = 1; + denoise.enabled = mode != DenoiseMode::Off; denoise.constant = denoiseStatus->noise_constant; denoise.slope.num = 1000 * denoiseStatus->noise_slope; denoise.slope.den = 1000; denoise.strength.num = 1000 * denoiseStatus->strength; denoise.strength.den = 1000; + /* Set the CDN mode to match the SDN operating mode. */ + bcm2835_isp_cdn cdn; + switch (mode) { + case DenoiseMode::ColourFast: + cdn.enabled = 1; + cdn.mode = CDN_MODE_FAST; + break; + case DenoiseMode::ColourHighQuality: + cdn.enabled = 1; + cdn.mode = CDN_MODE_HIGH_QUALITY; + break; + default: + cdn.enabled = 0; + } + ControlValue c(Span{ reinterpret_cast(&denoise), sizeof(denoise) }); ctrls.set(V4L2_CID_USER_BCM2835_ISP_DENOISE, c); + + c = ControlValue(Span{ reinterpret_cast(&cdn), + sizeof(cdn) }); + ctrls.set(V4L2_CID_USER_BCM2835_ISP_CDN, c); } void IPARPi::applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls)