[{"id":28332,"web_url":"https://patchwork.libcamera.org/comment/28332/","msgid":"<93837e31-9f9b-4dff-83fd-e929cb1e3841@redhat.com>","date":"2023-12-15T14:17:44","subject":"Re: [libcamera-devel] [RFC] Add 8-bit bayer support.","submitter":{"id":102,"url":"https://patchwork.libcamera.org/api/people/102/","name":"Hans de Goede","email":"hdegoede@redhat.com"},"content":"Hi Pavel,\n\nOn 12/14/23 22:37, Pavel Machek wrote:\n> ---\n> \n> Did I get it mostly right? I can't test other formats but providing\n> them should not be too hard. Does it make sense to add this to your\n> series or is it better to just wait for v1 to be merged?\n\nYes this looks about right. Yesterday I finished about a 10\nday libcamera sprint so for now I'm not going to touch\nlibcamera for a few days.\n\nI plan to get back to libcamera again on Wednesday.\nI'll add a commit adding 8bpp bayer, all 4 orders,\nto my personal libcamera softisp branch then and when\nthat is in place I'll send you an email asking to test it.\n\nRegards,\n\nHans\n\n\n> \n> \n> diff --git a/include/libcamera/internal/software_isp/debayer_cpu.h b/include/libcamera/internal/software_isp/debayer_cpu.h\n> index 7fb5be77..f3bb4321 100644\n> --- a/include/libcamera/internal/software_isp/debayer_cpu.h\n> +++ b/include/libcamera/internal/software_isp/debayer_cpu.h\n> @@ -67,6 +67,9 @@ private:\n>  \tvoid debayer10P_GBGB_BGR888(uint8_t *dst, const uint8_t *src);\n>  \tvoid debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src);\n>  \n> +\tvoid debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src);\n> +\tvoid debayer8_GRGR_BGR888(uint8_t *dst, const uint8_t *src);\n> +\n>  \ttypedef void (DebayerCpu::*debayerFn)(uint8_t *dst, const uint8_t *src);\n>  \n>  \tstruct DebayerInputConfig {\n> diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\n> index 0ceb995f..3c43e146 100644\n> --- a/include/libcamera/internal/software_isp/swstats_cpu.h\n> +++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n> @@ -29,6 +29,8 @@ public:\n>  \t/* FIXME this should be dropped once AWB has moved to the IPA */\n>  \tSwIspStats getStats() { return *sharedStats_; }\n>  private:\n> +\tvoid statsBGGR8Line0(const uint8_t *src, unsigned int stride);\n> +\n>  \tvoid statsBGGR10PLine0(const uint8_t *src, unsigned int stride);\n>  \tvoid statsGBRG10PLine0(const uint8_t *src, unsigned int stride);\n>  \tvoid statsGRBG10PLine0(const uint8_t *src, unsigned int stride);\n> diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\n> index 3eacdd5d..52910a03 100644\n> --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> @@ -111,6 +111,36 @@ void DebayerCpu::debayer10P_GRGR_BGR888(uint8_t *dst, const uint8_t *src)\n>  \t}\n>  }\n>  \n> +void DebayerCpu::debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src)\n> +{\n> +\tconst int width_in_bytes = window_.width;\n> +\tstruct ctxt_8bit_src c = {\n> +\t\tsrc - inputConfig_.stride, src, src + inputConfig_.stride,\n> +\t\tred_, green_, blue_ };\n> +\n> +\tfor (int x = 0; x < width_in_bytes; ) {\n> +\t\t/* Even pixel */\n> +\t\tbggr8_bgr888(c, dst, x++, 1, 1);\n> +\t\t/* Odd pixel BGGR -> GBRG */\n> +\t\tgbrg8_bgr888(c, dst, x++, 1, 1);\n> +\t}\n> +}\n> +\n> +void DebayerCpu::debayer8_GRGR_BGR888(uint8_t *dst, const uint8_t *src)\n> +{\n> +\tconst int width_in_bytes = window_.width;\n> +\tstruct ctxt_8bit_src c = {\n> +\t\tsrc - inputConfig_.stride, src, src + inputConfig_.stride,\n> +\t\tred_, green_, blue_ };\n> +\n> +\tfor (int x = 0; x < width_in_bytes; ) {\n> +\t\t/* Even pixel */\n> +\t\tgrbg8_bgr888(c, dst, x++, 1, 1);\n> +\t\t/* Odd pixel GRBG -> RGGB */\n> +\t\trggb8_bgr888(c, dst, x++, 1, 1);\n> +\t}\n> +}\n> +\n>  void DebayerCpu::debayer10P_GBGB_BGR888(uint8_t *dst, const uint8_t *src)\n>  {\n>  \tconst int width_in_bytes = window_.width * 5 / 4;\n> @@ -152,6 +182,22 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\n>  \tBayerFormat bayerFormat =\n>  \t\tBayerFormat::fromPixelFormat(inputFormat);\n>  \n> +\tif (bayerFormat.bitDepth == 8) {\n> +\t    \tconfig.bpp = 8;\n> +\t\tconfig.patternSize.height = 2;\n> +\t\tconfig.patternSize.width = 4;\n> +\t\tconfig.x_shift = 0;\n> +\t\tconfig.outputFormats = std::vector<PixelFormat>({ formats::RGB888 });\n> +\n> +\t\tswitch (bayerFormat.order) {\n> +\t\tcase BayerFormat::BGGR:\n> +\t\t\treturn 0;\n> +\t\tdefault:\n> +\t\t\tbreak;\n> +\t\t}\n> +\t/* } else if (future supported fmts) { ... */\n> +\t}\n> +\n>  \tif (bayerFormat.bitDepth == 10 &&\n>  \t    bayerFormat.packing == BayerFormat::Packing::CSI2) {\n>  \t    \tconfig.bpp = 10;\n> @@ -195,6 +241,17 @@ int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, [[maybe_unused]] Pi\n>  \tBayerFormat bayerFormat =\n>  \t\tBayerFormat::fromPixelFormat(inputFormat);\n>  \n> +\tif (bayerFormat.bitDepth == 8) {\n> +\t\tswitch (bayerFormat.order) {\n> +\t\tcase BayerFormat::BGGR:\n> +\t\t\tdebayer0_ = &DebayerCpu::debayer8_BGBG_BGR888;\n> +\t\t\tdebayer1_ = &DebayerCpu::debayer8_GRGR_BGR888;\n> +\t\t\treturn 0;\n> +\t\tdefault:\n> +\t\t\tbreak;\n> +\t\t}\n> +\t}\n> +\n>  \tif (bayerFormat.bitDepth == 10 &&\n>  \t    bayerFormat.packing == BayerFormat::Packing::CSI2) {\n>  \t\tswitch (bayerFormat.order) {\n> diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\n> index 15f23953..e65b1b65 100644\n> --- a/src/libcamera/software_isp/swstats_cpu.cpp\n> +++ b/src/libcamera/software_isp/swstats_cpu.cpp\n> @@ -37,9 +37,9 @@ static const unsigned int GREEN_Y_MUL = 150;\t\t/* 0.59 * 256 */\n>  static const unsigned int BLUE_Y_MUL = 29;\t\t/* 0.11 * 256 */\n>  \n>  static inline __attribute__((always_inline)) void\n> -statsBayer10P(const int width, const uint8_t *src0, const uint8_t *src1, bool bggr, unsigned int &bright_sum_, unsigned int &too_bright_sum_, SwIspStats &stats_)\n> +statsBayer10P(const int width, const uint8_t *src0, const uint8_t *src1, bool bggr, unsigned int &bright_sum_, unsigned int &too_bright_sum_, SwIspStats &stats_, bool is10p)\n>  {\n> -\tconst int width_in_bytes = width * 5 / 4;\n> +\tconst int width_in_bytes = width * (4 + is10p) / 4;\n>  \tuint8_t r, g, b, g2;\n>  \tunsigned int y_val;\n>  \tunsigned int sumR = 0;\n> @@ -49,7 +49,7 @@ statsBayer10P(const int width, const uint8_t *src0, const uint8_t *src1, bool bg\n>  \tunsigned int bright_sum = 0;\n>  \tunsigned int too_bright_sum = 0;\n>  \n> -\tfor (int x = 0; x < width_in_bytes; x += 5) {\n> +\tfor (int x = 0; x < width_in_bytes; x += (4 + is10p)) {\n>  \t\tif (bggr) {\n>  \t\t\t/* BGGR */\n>  \t\t\tb  = src0[x];\n> @@ -84,26 +84,31 @@ statsBayer10P(const int width, const uint8_t *src0, const uint8_t *src1, bool bg\n>  \ttoo_bright_sum_ += too_bright_sum;\n>  }\n>  \n> +void SwStatsCpu::statsBGGR8Line0(const uint8_t *src, unsigned int stride)\n> +{\n> +\tstatsBayer10P(window_.width, src, src + stride, true, bright_sum_, too_bright_sum_, stats_, false);\n> +}\n> +\n>  void SwStatsCpu::statsBGGR10PLine0(const uint8_t *src, unsigned int stride)\n>  {\n> -\tstatsBayer10P(window_.width, src, src + stride, true, bright_sum_, too_bright_sum_, stats_);\n> +\tstatsBayer10P(window_.width, src, src + stride, true, bright_sum_, too_bright_sum_, stats_, true);\n>  }\n>  \n>  void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src, unsigned int stride)\n>  {\n> -\tstatsBayer10P(window_.width, src, src + stride, false, bright_sum_, too_bright_sum_, stats_);\n> +\tstatsBayer10P(window_.width, src, src + stride, false, bright_sum_, too_bright_sum_, stats_, true);\n>  }\n>  \n>  void SwStatsCpu::statsGRBG10PLine0(const uint8_t *src, unsigned int stride)\n>  {\n>  \t/* GRBG is BGGR with the lines swapped */\n> -\tstatsBayer10P(window_.width, src + stride, src, true, bright_sum_, too_bright_sum_, stats_);\n> +\tstatsBayer10P(window_.width, src + stride, src, true, bright_sum_, too_bright_sum_, stats_, true);\n>  }\n>  \n>  void SwStatsCpu::statsRGGB10PLine0(const uint8_t *src, unsigned int stride)\n>  {\n>  \t/* RGGB is GBRG with the lines swapped */\n> -\tstatsBayer10P(window_.width, src + stride, src, false, bright_sum_, too_bright_sum_, stats_);\n> +\tstatsBayer10P(window_.width, src + stride, src, false, bright_sum_, too_bright_sum_, stats_, true);\n>  }\n>  \n>  void SwStatsCpu::resetStats(void)\n> @@ -134,6 +139,24 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n>  \tstartFrame_ = (SwStats::statsVoidFn)&SwStatsCpu::resetStats;\n>  \tfinishFrame_ = (SwStats::statsVoidFn)&SwStatsCpu::finishStats;\n>  \n> +\tif (bayerFormat.bitDepth == 8) {\n> +\t\tbpp_ = 8;\n> +\t\tpatternSize_.height = 2;\n> +\t\tpatternSize_.width = 4;\n> +\t\ty_skip_mask_ = 0x0c; /* Skip every 3th and 4th line */\n> +\t\tx_shift_ = 0;\n> +\n> +\t\tswitch (bayerFormat.order) {\n> +\t\tcase BayerFormat::BGGR:\n> +\t\t\tstats0_ = (SwStats::statsProcessFn)&SwStatsCpu::statsBGGR8Line0;\n> +\t\t\treturn 0;\n> +\t\tdefault:\n> +\t\t\tbreak;\n> +\t\t}\n> +\t/* } else if (future supported fmts) { ... */\n> +\t}\n> +\n> +\n>  \tif (bayerFormat.bitDepth == 10 &&\n>  \t    bayerFormat.packing == BayerFormat::Packing::CSI2) {\n>  \t\tbpp_ = 10;\n>","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 698BCBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Dec 2023 14:17:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C198D62B32;\n\tFri, 15 Dec 2023 15:17:51 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7985161D96\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Dec 2023 15:17:50 +0100 (CET)","from mail-ed1-f70.google.com (mail-ed1-f70.google.com\n\t[209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-339-ebHaEFr1MzWfyteDCItvTg-1; Fri, 15 Dec 2023 09:17:47 -0500","by mail-ed1-f70.google.com with SMTP id\n\t4fb4d7f45d1cf-54c882dcb76so833638a12.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Dec 2023 06:17:47 -0800 (PST)","from ?IPV6:2001:1c00:c32:7800:5bfa:a036:83f0:f9ec?\n\t(2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl.\n\t[2001:1c00:c32:7800:5bfa:a036:83f0:f9ec])\n\tby smtp.gmail.com with ESMTPSA id\n\tdg12-20020a0564021d0c00b0054c9635b24esm7791591edb.21.2023.12.15.06.17.44\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tFri, 15 Dec 2023 06:17:45 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1702649871;\n\tbh=PZk+TMkxPU53IICAdO28+kiOCQh/PvCGkLwvOM2lo48=;\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:\n\tFrom;\n\tb=l1lIlDk6UCeuU2sV5+ixu7oO05jd2qMM1of675Nsg6ELZChHQc+6WOjlKyH+y2itx\n\tyVqjGooTfmnZ0q93vHMwaZOHizVbF+O5mmmr8zZ3xv3O1AupTL7Ul2GE/cMXSrrxhv\n\t9YNeOvKMRkNCcg+7SrruANgwwUll6qU2gfpXsAbhoSs3SxFAxsi9N7qJRsGVqhyrSV\n\tiyS8vbRUY+jJq9FOWml+WVg/bjpM2KG3x8jXlg2M478g9mD/TceLKIjOefo100tn+d\n\twtsyCzBFUfm7TKJHF2Of4yL4VtWf0afYarRCgjJ+4r1eJ1deC0gji3g+tCt2Gj3vIf\n\tPnA7eX3W1+hgQ==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1702649869;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=O19814tQcK39zl37E2aCUonw4kKF3NPf6Pw+hr1mXps=;\n\tb=LPM1mauK+IFN6FHAOvvMEDBAM5ZM4USx2TNTkaDWRnO5jG3oDlEGBmU0bVqO/BG+NVZGkY\n\tCd7GsZbnxpeock7nZw18Fvz/MJqtd70osjSgi0JNC8iNoe2/yFLNDhb264bogG3XNCrkp+\n\tjD9A2IBbb6en2vaZUjfKpLP0bjKx6Us="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"LPM1mauK\"; \n\tdkim-atps=neutral","X-MC-Unique":"ebHaEFr1MzWfyteDCItvTg-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1702649866; x=1703254666;\n\th=content-transfer-encoding:in-reply-to:from:references:to\n\t:content-language:subject:user-agent:mime-version:date:message-id\n\t:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;\n\tbh=O19814tQcK39zl37E2aCUonw4kKF3NPf6Pw+hr1mXps=;\n\tb=Qq9stC12e1JljjIPKfDsrnKpwSIJuGAHZyTW9Let+kwbs2wkJj0JsiZCSG/Q9RSDQI\n\tCQ6uu93oGWuLFfBU5JD+2j+cQyGOcOXki0C+8gcOwwmGH6DBuZ1kLRl5dAJyrN8qK5rT\n\tx9jJy+8F1iahsukaOAAEj/lSwInPMC+5t6i8eIH4ty52nlJN6FmLbb33TXSqBGhURvtG\n\tcfa6LGay3tjoivYeyAdFmHF5HQ4npeEijdHGptpQx1CeLEknQ96pX2gEHwkkVBjB64ac\n\tlBcuqCIvJUfesAPTMQrXOigo58aKEHQffAbwJ5Q8bOhJL1rdnN+z/TzkwXwXQ61a7mHr\n\tjVvw==","X-Gm-Message-State":"AOJu0Yxlzv6r+e1/fqEthBkiAvHFL/l8vaaHShgWEoW87/9TXY3yUMxA\n\tcGwRLKQ8va1KbIUeOJnDKqnyP6FW37kLrY79wxBvPSLGSylao+LulZia/sKsalAvSOWhnRC6XcN\n\thFLBGXFlhYbpRAvL/BjL76DJG5yVAKAMKrpT0Z9zONA==","X-Received":["by 2002:a50:9e81:0:b0:552:63bd:4326 with SMTP id\n\ta1-20020a509e81000000b0055263bd4326mr2915894edf.21.1702649866022; \n\tFri, 15 Dec 2023 06:17:46 -0800 (PST)","by 2002:a50:9e81:0:b0:552:63bd:4326 with SMTP id\n\ta1-20020a509e81000000b0055263bd4326mr2915884edf.21.1702649865706; \n\tFri, 15 Dec 2023 06:17:45 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IGr5d6pHG/Y2ri1AtY1Hrsu0czFO/Dokx8IgW1UZ5+tbOwuuGY83TCHxgcjmncrOoy9iVNSPQ==","Message-ID":"<93837e31-9f9b-4dff-83fd-e929cb1e3841@redhat.com>","Date":"Fri, 15 Dec 2023 15:17:44 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","To":"Pavel Machek <pavel@ucw.cz>, libcamera-devel@lists.libcamera.org","References":"<ZXt1mDW1SpMyLrbT@duo.ucw.cz>","In-Reply-To":"<ZXt1mDW1SpMyLrbT@duo.ucw.cz>","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US, nl","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [RFC] Add 8-bit bayer support.","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":"Hans de Goede via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Hans de Goede <hdegoede@redhat.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]