[{"id":28307,"web_url":"https://patchwork.libcamera.org/comment/28307/","msgid":"<ZXib0mZlnKC0D3DP@duo.ucw.cz>","date":"2023-12-12T17:43:46","subject":"Re: [libcamera-devel] [RFC PATCH v2 0/7] libcamera: introduce\n\tSoftware ISP and Software IPA","submitter":{"id":49,"url":"https://patchwork.libcamera.org/api/people/49/","name":"Pavel Machek","email":"pavel@ucw.cz"},"content":"Hi!\n\n> Here is a draft implementation of Software ISP and Software IPA\n> which provide debayering and implementation of image processing\n> algorithms for systems without a hardware ISP, or in cases when\n> there are no public drivers for the hardware ISP present in the\n> system.\n\nAfter tweaks to support 8-bit it works for me and is quite useful on\nPinePhone.\n\nIMO something needs fixing in\nSimplePipelineHandler::generateConfiguration, otherwise code will\nsigsegv when suitable formats are not available.\n\nTested-by: Pavel Machek <pavel@ucw.cz>\n\nBest regards,\n\t\t\t\t\t\t\t\tPavel\n\ncommit a9966b193ebe4c9624e00a962ba17786a1aeaad5\nAuthor: Pavel Machek <pavel@ucw.cz>\nDate:   Tue Dec 5 13:01:54 2023 +0100\n\n    b8: Got 8-bit bayer to work.\n\ndiff --git a/include/libcamera/internal/software_isp/swisp_linaro.h b/include/libcamera/internal/software_isp/swisp_linaro.h\nindex c0df7863..f7fc7682 100644\n--- a/include/libcamera/internal/software_isp/swisp_linaro.h\n+++ b/include/libcamera/internal/software_isp/swisp_linaro.h\n@@ -89,6 +89,11 @@ private:\n \t\tint setDebayerInfo(PixelFormat format);\n \t\tdebayerInfo *debayerInfo_;\n \n+\t  \tvoid debayerRaw(uint8_t *dst, const uint8_t *src, bool is10p);\n+\t  \n+\t\t/* Bayer 8 */\n+\t\tvoid debayerRaw8(uint8_t *dst, const uint8_t *src);\n+\n \t\t/* CSI-2 packed 10-bit raw bayer format (all the 4 orders) */\n \t\tvoid debayerRaw10P(uint8_t *dst, const uint8_t *src);\n \t\tstatic SizeRange outSizesRaw10P(const Size &inSize);\ndiff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex b95d7689..4561961e 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -1137,6 +1137,14 @@ SimplePipelineHandler::generateConfiguration(Camera *camera, Span<const StreamRo\n \t */\n \tfor ([[maybe_unused]] StreamRole role : roles) {\n \t\tStreamConfiguration cfg{ StreamFormats{ formats } };\n+\t\tif (! formats.begin()->first) {\n+\t\t  LOG(SimplePipeline, Error)\n+\t\t\t<< \"No formats -- first?\";\n+\t\t  continue;\n+\t\t}\n+\t\t  LOG(SimplePipeline, Error)\n+\t\t\t<< \"Going through roles?\";\n+\n \t\tcfg.pixelFormat = formats.begin()->first;\n \t\tcfg.size = formats.begin()->second[0].max;\n \ndiff --git a/src/libcamera/software_isp/swisp_linaro.cpp b/src/libcamera/software_isp/swisp_linaro.cpp\nindex b7f36db1..0255ce85 100644\n--- a/src/libcamera/software_isp/swisp_linaro.cpp\n+++ b/src/libcamera/software_isp/swisp_linaro.cpp\n@@ -88,7 +88,7 @@ bool SwIspLinaro::isValid() const\n  * \\todo Split the stats calculations out of this function.\n  * \\todo Move the AWB algorithm into the IPA module.\n  */\n-void SwIspLinaro::IspWorker::debayerRaw10P(uint8_t *dst, const uint8_t *src)\n+void SwIspLinaro::IspWorker::debayerRaw(uint8_t *dst, const uint8_t *src, bool is10p)\n {\n \t/* for brightness values in the 0 to 255 range: */\n \tstatic const unsigned int BRIGHT_LVL = 200U << 8;\n@@ -118,9 +118,15 @@ void SwIspLinaro::IspWorker::debayerRaw10P(uint8_t *dst, const uint8_t *src)\n \t\t\tint phase = 2 * phase_y + phase_x;\n \n \t\t\t/* x part of the offset in the input buffer: */\n-\t\t\tint x_m1 = x + x / 4;\t\t/* offset for (x-1) */\n-\t\t\tint x_0 = x + 1 + (x + 1) / 4;\t/* offset for x */\n-\t\t\tint x_p1 = x + 2 + (x + 2) / 4;\t/* offset for (x+1) */\n+\t\t\tint x_m1 = x;\t\t/* offset for (x-1) */\n+\t\t\tint x_0 = x + 1;\t/* offset for x */\n+\t\t\tint x_p1 = x + 2;\t/* offset for (x+1) */\n+\n+\t\t\tif (is10p) {\n+\t\t\t\tx_m1 += x_m1 / 4;\t/* offset for (x-1) */\n+\t\t\t\tx_0 += x_0 / 4;\t/* offset for x */\n+\t\t\t\tx_p1 += x_p1 / 4;\t/* offset for (x+1) */\n+\t\t\t}\n \t\t\t/* the colour component value to write to the output */\n \t\t\tunsigned val;\n \t\t\t/* Y value times 256 */\n@@ -267,6 +273,16 @@ void SwIspLinaro::IspWorker::debayerRaw10P(uint8_t *dst, const uint8_t *src)\n \t\t<< \" (minDenom = \" << minDenom << \")\";\n }\n \n+void SwIspLinaro::IspWorker::debayerRaw10P(uint8_t *dst, const uint8_t *src)\n+{\n+\tdebayerRaw(dst, src, true);\n+}\n+\n+void SwIspLinaro::IspWorker::debayerRaw8(uint8_t *dst, const uint8_t *src)\n+{\n+\tdebayerRaw(dst, src, false);\n+}\n+\n SizeRange SwIspLinaro::IspWorker::outSizesRaw10P(const Size &inSize)\n {\n \tif (inSize.width < 2 || inSize.height < 2) {\n@@ -286,6 +302,10 @@ unsigned int SwIspLinaro::IspWorker::outStrideRaw10P(const Size &outSize)\n SwIspLinaro::IspWorker::IspWorker(SwIspLinaro *swIsp)\n \t: swIsp_(swIsp)\n {\n+\tdebayerInfos_[formats::SBGGR8] = { formats::RGB888,\n+\t\t\t\t\t\t  &SwIspLinaro::IspWorker::debayerRaw8,\n+\t\t\t\t\t\t  &SwIspLinaro::IspWorker::outSizesRaw10P,\n+\t\t\t\t\t\t  &SwIspLinaro::IspWorker::outStrideRaw10P };\n \tdebayerInfos_[formats::SBGGR10_CSI2P] = { formats::RGB888,\n \t\t\t\t\t\t  &SwIspLinaro::IspWorker::debayerRaw10P,\n \t\t\t\t\t\t  &SwIspLinaro::IspWorker::outSizesRaw10P,","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 BE9B3BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 12 Dec 2023 17:43:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1FF9662B2E;\n\tTue, 12 Dec 2023 18:43:49 +0100 (CET)","from jabberwock.ucw.cz (jabberwock.ucw.cz [46.255.230.98])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 77C6E629E1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Dec 2023 18:43:47 +0100 (CET)","by jabberwock.ucw.cz (Postfix, from userid 1017)\n\tid 197C21C006F; Tue, 12 Dec 2023 18:43:47 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1702403029;\n\tbh=WnoDsm+NWYaWO5dWEvcV8/V1+YXM/9Zhu56oAaFXvmA=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=t46iGhl2vYKtkE6xZw+ZNFJjP38JJK1ge6spVeSKsuzRrinV5aBlIMO0uJMqob0R8\n\tEHsyY+FBVNCHMEL9/0eJaBROQaRKOpm+bY2eYOE+3oGVBA4mMy5Uy6SWtuphrbmoqo\n\tGo1dauguiiPZ42yFytRyks1K+9/tr0p7v2W8s5CllEIyrtA7OOq/LokrMGfUaQDTji\n\taw2lq579mBFFdYFpeldMOFqKe/tApHDnJxMjaUSaYS7JlcKc+/U0jaI/LSdW659BS+\n\tT3ZxcskiET3OPkAXkojtZEvAUWky6fJsutuTZHYHv7JszeiWonbhl+tNxs/Egk1m8T\n\trKjN96rUoVloQ==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1;\n\tt=1702403027;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=DFowaOxFKjucERAe7D1qs2yq6DOhr/slXRiOrD+XbbQ=;\n\tb=HMunX5SLT0U6gunWUVEEcph+AFf+NIuFtdzDHyua4NyvMwyoVJK6v98mLyve40k17qTadP\n\tXTK8xHyBENyM//ixcl0wNAUCFE1gDmd194MOFFwA9zXsYomEbkH8Hzbmjf0azqb79xFes9\n\tZkYOGHdDgDzcb+MUfx15EP1Q68VTRsI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ucw.cz header.i=@ucw.cz\n\theader.b=\"HMunX5SL\"; dkim-atps=neutral","Date":"Tue, 12 Dec 2023 18:43:46 +0100","To":"Andrey Konovalov <andrey.konovalov@linaro.org>","Message-ID":"<ZXib0mZlnKC0D3DP@duo.ucw.cz>","References":"<20231212115046.102726-1-andrey.konovalov@linaro.org>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha1;\n\tprotocol=\"application/pgp-signature\"; boundary=\"HnC0RewH6PZv/ff+\"","Content-Disposition":"inline","In-Reply-To":"<20231212115046.102726-1-andrey.konovalov@linaro.org>","Subject":"Re: [libcamera-devel] [RFC PATCH v2 0/7] libcamera: introduce\n\tSoftware ISP and Software IPA","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":"Pavel Machek via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Pavel Machek <pavel@ucw.cz>","Cc":"mripard@redhat.com, g.martti@gmail.com, t.langendam@gmail.com,\n\tlibcamera-devel@lists.libcamera.org, srinivas.kandagatla@linaro.org, \n\tbryan.odonoghue@linaro.org, admin@dennisbonke.com","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]