[{"id":28835,"web_url":"https://patchwork.libcamera.org/comment/28835/","msgid":"<87jzmhao3t.fsf@redhat.com>","date":"2024-03-04T17:44:22","subject":"Re: [PATCH v4 15/18] libcamera: debayer_cpu: Add BGR888 output\n\tsupport","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> BGR888 is RGB888 with the red and blue pixels swapped, adjust\n> the debayering to swap the red and blue pixels in the bayer pattern\n> to add support for writing formats::BGR888.\n>\n> Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s\n> Tested-by: Pavel Machek <pavel@ucw.cz>\n> Signed-off-by: Hans de Goede <hdegoede@redhat.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  src/libcamera/software_isp/debayer_cpu.cpp | 42 +++++++++++++++++++---\n>  src/libcamera/software_isp/debayer_cpu.h   |  1 +\n>  2 files changed, 38 insertions(+), 5 deletions(-)\n>\n> diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\n> index 22ae99cd..215ca615 100644\n> --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> @@ -261,7 +261,7 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\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\tconfig.outputFormats = std::vector<PixelFormat>({ formats::RGB888, formats::BGR888 });\n>  \t\treturn 0;\n>  \t}\n>  \n> @@ -271,7 +271,7 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\n>  \t\tconfig.bpp = 10;\n>  \t\tconfig.patternSize.width = 4; /* 5 bytes per *4* pixels */\n>  \t\tconfig.patternSize.height = 2;\n> -\t\tconfig.outputFormats = std::vector<PixelFormat>({ formats::RGB888 });\n> +\t\tconfig.outputFormats = std::vector<PixelFormat>({ formats::RGB888, formats::BGR888 });\n>  \t\treturn 0;\n>  \t}\n>  \n> @@ -282,7 +282,7 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\n>  \n>  int DebayerCpu::getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config)\n>  {\n> -\tif (outputFormat == formats::RGB888) {\n> +\tif (outputFormat == formats::RGB888 || outputFormat == formats::BGR888) {\n>  \t\tconfig.bpp = 24;\n>  \t\treturn 0;\n>  \t}\n> @@ -318,13 +318,41 @@ int DebayerCpu::setupStandardBayerOrder(BayerFormat::Order order)\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> +int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, PixelFormat outputFormat)\n>  {\n>  \tBayerFormat bayerFormat =\n>  \t\tBayerFormat::fromPixelFormat(inputFormat);\n>  \n>  \txShift_ = 0;\n> +\tswapRedBlueGains_ = false;\n> +\n> +\tswitch (outputFormat) {\n> +\tcase formats::RGB888:\n> +\t\tbreak;\n> +\tcase formats::BGR888:\n> +\t\t/* Swap R and B in bayer order to generate BGR888 instead of RGB888 */\n> +\t\tswapRedBlueGains_ = true;\n> +\n> +\t\tswitch (bayerFormat.order) {\n> +\t\tcase BayerFormat::BGGR:\n> +\t\t\tbayerFormat.order = BayerFormat::RGGB;\n> +\t\t\tbreak;\n> +\t\tcase BayerFormat::GBRG:\n> +\t\t\tbayerFormat.order = BayerFormat::GRBG;\n> +\t\t\tbreak;\n> +\t\tcase BayerFormat::GRBG:\n> +\t\t\tbayerFormat.order = BayerFormat::GBRG;\n> +\t\t\tbreak;\n> +\t\tcase BayerFormat::RGGB:\n> +\t\t\tbayerFormat.order = BayerFormat::BGGR;\n> +\t\t\tbreak;\n> +\t\tdefault:\n> +\t\t\tgoto invalid_fmt;\n> +\t\t}\n> +\t\tbreak;\n> +\tdefault:\n> +\t\tgoto invalid_fmt;\n> +\t}\n>  \n>  \tif ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10 || bayerFormat.bitDepth == 12) &&\n>  \t    bayerFormat.packing == BayerFormat::Packing::None &&\n> @@ -371,6 +399,7 @@ int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, [[maybe_unused]] Pi\n>  \t\t}\n>  \t}\n>  \n> +invalid_fmt:\n>  \tLOG(Debayer, Error) << \"Unsupported input output format combination\";\n>  \treturn -EINVAL;\n>  }\n> @@ -654,6 +683,9 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams\n>  \t\tgamma_correction_ = params.gamma;\n>  \t}\n>  \n> +\tif (swapRedBlueGains_)\n> +\t\tstd::swap(params.gainR, params.gainB);\n> +\n>  \tfor (unsigned int i = 0; i < kRGBLookupSize; i++) {\n>  \t\tconstexpr unsigned int div =\n>  \t\t\tkRGBLookupSize * DebayerParams::kGain10 / kGammaLookupSize;\n> diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\n> index 73ca41f1..b9e5f3fd 100644\n> --- a/src/libcamera/software_isp/debayer_cpu.h\n> +++ b/src/libcamera/software_isp/debayer_cpu.h\n> @@ -145,6 +145,7 @@ private:\n>  \tunsigned int lineBufferIndex_;\n>  \tunsigned int xShift_; /* Offset of 0/1 applied to window_.x */\n>  \tbool enableInputMemcpy_;\n> +\tbool swapRedBlueGains_;\n>  \tfloat gamma_correction_;\n>  \tunsigned int measuredFrames_;\n>  \tint64_t frameProcessTime_;","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 C7D6ABD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  4 Mar 2024 17:44:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 71EFD62871;\n\tMon,  4 Mar 2024 18:44:30 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 81B4B62867\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  4 Mar 2024 18:44:28 +0100 (CET)","from mail-wr1-f70.google.com (mail-wr1-f70.google.com\n\t[209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-160-xWw2vlQyNwWmJoworC9IwA-1; Mon, 04 Mar 2024 12:44:26 -0500","by mail-wr1-f70.google.com with SMTP id\n\tffacd0b85a97d-33e4397540bso593044f8f.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 04 Mar 2024 09:44:26 -0800 (PST)","from nuthatch (nat-pool-brq-t.redhat.com. [213.175.37.10])\n\tby smtp.gmail.com with ESMTPSA id\n\tm6-20020a5d4a06000000b0033dbeb2eb4dsm12697592wrq.110.2024.03.04.09.44.22\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 04 Mar 2024 09:44:22 -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=\"DUI4wvaE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1709574267;\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=eldiZjpdiddAql4yrbHyHQ3tox3V4faZoDMNMwLPlnc=;\n\tb=DUI4wvaEElkFeK3EpmhtiNcsGH97cLH1+kCIo8D8nzXm2LkuaDiwPJclMZsIqkwV0CtP5q\n\tt7/15VvLoIkx118iyIamHFRXo1eWCxFda9GZBYM72yeelIhU95Zh8ndFfEMKW+iSc6rq+b\n\telEUtG9ipzGP0Xq63AJSmH/1Te8F3Xk=","X-MC-Unique":"xWw2vlQyNwWmJoworC9IwA-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1709574263; x=1710179063;\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=eldiZjpdiddAql4yrbHyHQ3tox3V4faZoDMNMwLPlnc=;\n\tb=i6kg4U9gUKUJ+5Q6hOPQMiCI5IeMfoHW8a0pzr4VXzBuBGTzGbfwx2OjblOBJ4mP4a\n\tpoLOQz34UvQisUUc/qk5b48SW2MgSSp3BdEY2v0Ji+LSNXOvV/mvKZbn9z5n+RJ4Ass8\n\tY/gAoS1yxGZ+0bf3FNBQ3RkSOcv2H08eagkDzi3K+Pfo+QhpIv2+cML1s5TU9U8pgcMv\n\tb7N2Np4s5Z2dAYLfF2ogOEfUX4o4OGxYcVjsKJ8d1BPUpx0AUk2So0w1XNALrqav7VoD\n\tEZJ+s5yjYNrDGBkvyFg+CFJNZdn6zqtl077wV/Khsh4BvbUu1FvcwrlODPVR2jmNIxG/\n\tVcvg==","X-Gm-Message-State":"AOJu0YzGpr1hVv3PBoyiBCdx2bqxqC5RlRBj3wZoHqVevPMnXLTw/8gE\n\tGqP6LKmOLZgzvwbA7OZFUJrpj6ZcZH6wsJYKSP7pVE34dB+BaOP0RN8pMBc2YwfCGWIwNfKfao1\n\t5w+xEaB/f9j22OwzpHbMjWqcBktgfmB5sLBrVXV/FPiNVetN6/cLB9gFkiApOhoL5clLnJCl9O7\n\tTtCV4=","X-Received":["by 2002:a05:6000:12c2:b0:33e:1629:6523 with SMTP id\n\tl2-20020a05600012c200b0033e16296523mr7099427wrx.42.1709574263493; \n\tMon, 04 Mar 2024 09:44:23 -0800 (PST)","by 2002:a05:6000:12c2:b0:33e:1629:6523 with SMTP id\n\tl2-20020a05600012c200b0033e16296523mr7099414wrx.42.1709574263120; \n\tMon, 04 Mar 2024 09:44:23 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IEyb+VQtxdd588f1883+9c5TyIugMS2m0ntuZ1B2Z7q+bqmiTmZbRTlSfhQgGpY/kL5glA3sQ==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Hans de Goede <hdegoede@redhat.com>","Subject":"Re: [PATCH v4 15/18] libcamera: debayer_cpu: Add BGR888 output\n\tsupport","In-Reply-To":"<20240229183654.7206-16-hdegoede@redhat.com> (Hans de Goede's\n\tmessage of \"Thu, 29 Feb 2024 19:36:26 +0100\")","References":"<20240229183654.7206-1-hdegoede@redhat.com>\n\t<20240229183654.7206-16-hdegoede@redhat.com>","Date":"Mon, 04 Mar 2024 18:44:22 +0100","Message-ID":"<87jzmhao3t.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":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>,\n\tlibcamera-devel@lists.libcamera.org, Maxime Ripard <mripard@redhat.com>, \n\tPavel Machek <pavel@ucw.cz>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]