[{"id":28834,"web_url":"https://patchwork.libcamera.org/comment/28834/","msgid":"<87o7btao67.fsf@redhat.com>","date":"2024-03-04T17:42:56","subject":"Re: [PATCH v4 14/18] libcamera: debayer_cpu: Add support for 8, 10\n\tand 12 bpp unpacked bayer input","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hans de Goede <hdegoede@redhat.com> writes:\n\n> Add support for 8, 10 and 12 bpp unpacked bayer input for all 4 standard\n> bayer orders.\n>\n> Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s\n> Tested-by: Pavel Machek <pavel@ucw.cz>\n> Reviewed-by: Pavel Machek <pavel@ucw.cz>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Signed-off-by: Hans de Goede <hdegoede@redhat.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n(My e-mail client displays smileys in this patch so it must be right.)\n\n> ---\n> Changes in v3:\n> - Also add support for 12bpp (by Kieran Bingham)\n> ---\n>  src/libcamera/software_isp/debayer_cpu.cpp | 128 +++++++++++++++++++++\n>  src/libcamera/software_isp/debayer_cpu.h   |  13 +++\n>  2 files changed, 141 insertions(+)\n>\n> diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\n> index 53e90776..22ae99cd 100644\n> --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> @@ -56,6 +56,11 @@ DebayerCpu::~DebayerCpu()\n>  \t\tfree(lineBuffers_[i]);\n>  }\n>  \n> +#define DECLARE_SRC_POINTERS(pixel_t)                            \\\n> +\tconst pixel_t *prev = (const pixel_t *)src[0] + xShift_; \\\n> +\tconst pixel_t *curr = (const pixel_t *)src[1] + xShift_; \\\n> +\tconst pixel_t *next = (const pixel_t *)src[2] + xShift_;\n> +\n>  // RGR\n>  // GBG\n>  // RGR\n> @@ -92,6 +97,70 @@ DebayerCpu::~DebayerCpu()\n>  \t*dst++ = red_[curr[x] / (div)];                                                        \\\n>  \tx++;\n>  \n> +void DebayerCpu::debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src[])\n> +{\n> +\tDECLARE_SRC_POINTERS(uint8_t)\n> +\n> +\tfor (int x = 0; x < (int)window_.width;) {\n> +\t\tBGGR_BGR888(1, 1, 1)\n> +\t\tGBRG_BGR888(1, 1, 1)\n> +\t}\n> +}\n> +\n> +void DebayerCpu::debayer8_GRGR_BGR888(uint8_t *dst, const uint8_t *src[])\n> +{\n> +\tDECLARE_SRC_POINTERS(uint8_t)\n> +\n> +\tfor (int x = 0; x < (int)window_.width;) {\n> +\t\tGRBG_BGR888(1, 1, 1)\n> +\t\tRGGB_BGR888(1, 1, 1)\n> +\t}\n> +}\n> +\n> +void DebayerCpu::debayer10_BGBG_BGR888(uint8_t *dst, const uint8_t *src[])\n> +{\n> +\tDECLARE_SRC_POINTERS(uint16_t)\n> +\n> +\tfor (int x = 0; x < (int)window_.width;) {\n> +\t\t/* divide values by 4 for 10 -> 8 bpp value */\n> +\t\tBGGR_BGR888(1, 1, 4)\n> +\t\tGBRG_BGR888(1, 1, 4)\n> +\t}\n> +}\n> +\n> +void DebayerCpu::debayer10_GRGR_BGR888(uint8_t *dst, const uint8_t *src[])\n> +{\n> +\tDECLARE_SRC_POINTERS(uint16_t)\n> +\n> +\tfor (int x = 0; x < (int)window_.width;) {\n> +\t\t/* divide values by 4 for 10 -> 8 bpp value */\n> +\t\tGRBG_BGR888(1, 1, 4)\n> +\t\tRGGB_BGR888(1, 1, 4)\n> +\t}\n> +}\n> +\n> +void DebayerCpu::debayer12_BGBG_BGR888(uint8_t *dst, const uint8_t *src[])\n> +{\n> +\tDECLARE_SRC_POINTERS(uint16_t)\n> +\n> +\tfor (int x = 0; x < (int)window_.width;) {\n> +\t\t/* divide values by 16 for 12 -> 8 bpp value */\n> +\t\tBGGR_BGR888(1, 1, 16)\n> +\t\tGBRG_BGR888(1, 1, 16)\n> +\t}\n> +}\n> +\n> +void DebayerCpu::debayer12_GRGR_BGR888(uint8_t *dst, const uint8_t *src[])\n> +{\n> +\tDECLARE_SRC_POINTERS(uint16_t)\n> +\n> +\tfor (int x = 0; x < (int)window_.width;) {\n> +\t\t/* divide values by 16 for 12 -> 8 bpp value */\n> +\t\tGRBG_BGR888(1, 1, 16)\n> +\t\tRGGB_BGR888(1, 1, 16)\n> +\t}\n> +}\n> +\n>  void DebayerCpu::debayer10P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[])\n>  {\n>  \tconst int width_in_bytes = window_.width * 5 / 4;\n> @@ -186,6 +255,16 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\n>  \tBayerFormat bayerFormat =\n>  \t\tBayerFormat::fromPixelFormat(inputFormat);\n>  \n> +\tif ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10 || bayerFormat.bitDepth == 12) &&\n> +\t    bayerFormat.packing == BayerFormat::Packing::None &&\n> +\t    isStandardBayerOrder(bayerFormat.order)) {\n> +\t\tconfig.bpp = (bayerFormat.bitDepth + 7) & ~7;\n> +\t\tconfig.patternSize.width = 2;\n> +\t\tconfig.patternSize.height = 2;\n> +\t\tconfig.outputFormats = std::vector<PixelFormat>({ formats::RGB888 });\n> +\t\treturn 0;\n> +\t}\n> +\n>  \tif (bayerFormat.bitDepth == 10 &&\n>  \t    bayerFormat.packing == BayerFormat::Packing::CSI2 &&\n>  \t    isStandardBayerOrder(bayerFormat.order)) {\n> @@ -213,12 +292,61 @@ int DebayerCpu::getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &c\n>  \treturn -EINVAL;\n>  }\n>  \n> +/*\n> + * Check for standard Bayer orders and set xShift_ and swap debayer0/1, so that\n> + * a single pair of BGGR debayer functions can be used for all 4 standard orders.\n> + */\n> +int DebayerCpu::setupStandardBayerOrder(BayerFormat::Order order)\n> +{\n> +\tswitch (order) {\n> +\tcase BayerFormat::BGGR:\n> +\t\tbreak;\n> +\tcase BayerFormat::GBRG:\n> +\t\txShift_ = 1; /* BGGR -> GBRG */\n> +\t\tbreak;\n> +\tcase BayerFormat::GRBG:\n> +\t\tstd::swap(debayer0_, debayer1_); /* BGGR -> GRBG */\n> +\t\tbreak;\n> +\tcase BayerFormat::RGGB:\n> +\t\txShift_ = 1; /* BGGR -> GBRG */\n> +\t\tstd::swap(debayer0_, debayer1_); /* GBRG -> RGGB */\n> +\t\tbreak;\n> +\tdefault:\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\treturn 0;\n> +}\n> +\n>  /* TODO: this ignores outputFormat since there is only 1 supported outputFormat for now */\n>  int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, [[maybe_unused]] PixelFormat outputFormat)\n>  {\n>  \tBayerFormat bayerFormat =\n>  \t\tBayerFormat::fromPixelFormat(inputFormat);\n>  \n> +\txShift_ = 0;\n> +\n> +\tif ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10 || bayerFormat.bitDepth == 12) &&\n> +\t    bayerFormat.packing == BayerFormat::Packing::None &&\n> +\t    isStandardBayerOrder(bayerFormat.order)) {\n> +\t\tswitch (bayerFormat.bitDepth) {\n> +\t\tcase 8:\n> +\t\t\tdebayer0_ = &DebayerCpu::debayer8_BGBG_BGR888;\n> +\t\t\tdebayer1_ = &DebayerCpu::debayer8_GRGR_BGR888;\n> +\t\t\tbreak;\n> +\t\tcase 10:\n> +\t\t\tdebayer0_ = &DebayerCpu::debayer10_BGBG_BGR888;\n> +\t\t\tdebayer1_ = &DebayerCpu::debayer10_GRGR_BGR888;\n> +\t\t\tbreak;\n> +\t\tcase 12:\n> +\t\t\tdebayer0_ = &DebayerCpu::debayer12_BGBG_BGR888;\n> +\t\t\tdebayer1_ = &DebayerCpu::debayer12_GRGR_BGR888;\n> +\t\t\tbreak;\n> +\t\t}\n> +\t\tsetupStandardBayerOrder(bayerFormat.order);\n> +\t\treturn 0;\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/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\n> index 98782838..73ca41f1 100644\n> --- a/src/libcamera/software_isp/debayer_cpu.h\n> +++ b/src/libcamera/software_isp/debayer_cpu.h\n> @@ -17,6 +17,8 @@\n>  \n>  #include <libcamera/base/object.h>\n>  \n> +#include \"libcamera/internal/bayer_format.h\"\n> +\n>  #include \"debayer.h\"\n>  #include \"swstats_cpu.h\"\n>  \n> @@ -82,6 +84,15 @@ private:\n>  \t */\n>  \tusing debayerFn = void (DebayerCpu::*)(uint8_t *dst, const uint8_t *src[]);\n>  \n> +\t/* 8-bit raw bayer format */\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> +\t/* unpacked 10-bit raw bayer format */\n> +\tvoid debayer10_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);\n> +\tvoid debayer10_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);\n> +\t/* unpacked 12-bit raw bayer format */\n> +\tvoid debayer12_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);\n> +\tvoid debayer12_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);\n>  \t/* CSI-2 packed 10-bit raw bayer format (all the 4 orders) */\n>  \tvoid debayer10P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);\n>  \tvoid debayer10P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);\n> @@ -103,6 +114,7 @@ private:\n>  \n>  \tint getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);\n>  \tint getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);\n> +\tint setupStandardBayerOrder(BayerFormat::Order order);\n>  \tint setDebayerFunctions(PixelFormat inputFormat, PixelFormat outputFormat);\n>  \tvoid setupInputMemcpy(const uint8_t *linePointers[]);\n>  \tvoid shiftLinePointers(const uint8_t *linePointers[], const uint8_t *src);\n> @@ -131,6 +143,7 @@ private:\n>  \tunsigned int lineBufferLength_;\n>  \tunsigned int lineBufferPadding_;\n>  \tunsigned int lineBufferIndex_;\n> +\tunsigned int xShift_; /* Offset of 0/1 applied to window_.x */\n>  \tbool enableInputMemcpy_;\n>  \tfloat gamma_correction_;\n>  \tunsigned int measuredFrames_;","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 6BC0ABD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  4 Mar 2024 17:43:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C443D6286F;\n\tMon,  4 Mar 2024 18:43:04 +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 3E0446286C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  4 Mar 2024 18:43:02 +0100 (CET)","from mail-wm1-f72.google.com (mail-wm1-f72.google.com\n\t[209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-677-szqiwbKvN8OAuTjryrMKsQ-1; Mon, 04 Mar 2024 12:42:59 -0500","by mail-wm1-f72.google.com with SMTP id\n\t5b1f17b1804b1-412e79148d8so4346285e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 04 Mar 2024 09:42:59 -0800 (PST)","from nuthatch (nat-pool-brq-t.redhat.com. [213.175.37.10])\n\tby smtp.gmail.com with ESMTPSA id\n\tl21-20020a05600c4f1500b004101543e843sm18422722wmq.10.2024.03.04.09.42.56\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 04 Mar 2024 09:42:57 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"LZATkvQ4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1709574181;\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=iO/jVxhEOzL21qB9am5U2PA8ZspehKfw+6yqvEFHWT0=;\n\tb=LZATkvQ4Z1+03CUeNxeJbrqOY60KEYu+ttrSbyjLeaFvGvRNCWb07WNtRaNTLZrsiQFDT2\n\tbBcFI6JnS0tQasrAtOOJMY0jpDQn9hzTeaJNJ7xoK/HcxoClAZzjS2ZoJ8Fqf+BExrJyuS\n\tcN4Rw06m1HzORRfYjbU9ccadHZiyuL8=","X-MC-Unique":"szqiwbKvN8OAuTjryrMKsQ-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1709574178; x=1710178978;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=iO/jVxhEOzL21qB9am5U2PA8ZspehKfw+6yqvEFHWT0=;\n\tb=BhIv42Qe0N7qgm9EFK6Z2TqjwNz317F42DE7YaDxj/X0eBtNRL6r3E1VU5MNXsIYA0\n\t9Ctf1zCcdAmRLH7QxOJ/Rbfs1sUJw5Mx1YhEtZo/l4dw4l7r/7G34O/VwT0aWV/A3V+q\n\t+6EHdiacu3yaBkw3ttlhffctmliA5Z2yIuFr1U+hZAeePp7wCBRMkHjbQJ+0OqfE5B84\n\t+YJrZ3GZo9cNxhoq/j2xsmyG2tbY6V5sAeyos3CsMuu7uxIWm6KtZZWfLCvSn9jTBdv/\n\t0wwg8JaAqtxRvfD6W3YNNkrIQ9cfSh3r3YIoDTgS1GK7+w11n8b9g20dlbLQmYs2IfpC\n\ttWqQ==","X-Gm-Message-State":"AOJu0Yxsx4YaeJ5896/SSCujbTScfXJJe+szDGd3xgZ3UQpaTOi9FRXG\n\tHj8LsNiCLVQC2BxlCAWrhvitwqy1klT2Nqi43LMLhng7zTbLIrNAPqURABk7swcO+m/MTDHNsAg\n\tAVRR/HMi/XGgiYlfZyaMEPmgDdvGAYoqftU4iNgwYvkMjSFwqzktivsVCSWDLL3+RdkQYebydSH\n\twGUH4=","X-Received":["by 2002:a05:600c:a55:b0:412:ca5a:4bd1 with SMTP id\n\tc21-20020a05600c0a5500b00412ca5a4bd1mr7063940wmq.39.1709574177979; \n\tMon, 04 Mar 2024 09:42:57 -0800 (PST)","by 2002:a05:600c:a55:b0:412:ca5a:4bd1 with SMTP id\n\tc21-20020a05600c0a5500b00412ca5a4bd1mr7063921wmq.39.1709574177648; \n\tMon, 04 Mar 2024 09:42:57 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IHGJYmD4QuKLc7t+IRf+JAspatmB2PM6EbYO3MeHD5QB1udbAkqQ2W7ziDYZg6/rHLzgC7+FA==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Hans de Goede <hdegoede@redhat.com>","Subject":"Re: [PATCH v4 14/18] libcamera: debayer_cpu: Add support for 8, 10\n\tand 12 bpp unpacked bayer input","In-Reply-To":"<20240229183654.7206-15-hdegoede@redhat.com> (Hans de Goede's\n\tmessage of \"Thu, 29 Feb 2024 19:36:25 +0100\")","References":"<20240229183654.7206-1-hdegoede@redhat.com>\n\t<20240229183654.7206-15-hdegoede@redhat.com>","Date":"Mon, 04 Mar 2024 18:42:56 +0100","Message-ID":"<87o7btao67.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>","Cc":"Maxime Ripard <mripard@redhat.com>, libcamera-devel@lists.libcamera.org, \n\tPavel Machek <pavel@ucw.cz>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]