{"id":19408,"url":"https://patchwork.libcamera.org/api/patches/19408/?format=json","web_url":"https://patchwork.libcamera.org/patch/19408/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240113142218.28063-19-hdegoede@redhat.com>","date":"2024-01-13T14:22:18","name":"[libcamera-devel,v2,18/18] libcamera: debayer_cpu: Add BGR888 output support","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"ce9fb0322ce70f98cf74f9aeb7e876c180c77549","submitter":{"id":102,"url":"https://patchwork.libcamera.org/api/people/102/?format=json","name":"Hans de Goede","email":"hdegoede@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19408/mbox/","series":[{"id":4142,"url":"https://patchwork.libcamera.org/api/series/4142/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4142","date":"2024-01-13T14:22:00","name":"[libcamera-devel,v2,01/18] libcamera: pipeline: simple: fix size adjustment in validate()","version":2,"mbox":"https://patchwork.libcamera.org/series/4142/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19408/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19408/checks/","tags":{},"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 7AE02C32BD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 13 Jan 2024 14:23:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2354F62945;\n\tSat, 13 Jan 2024 15:23:19 +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 0203A628B1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Jan 2024 15:23:16 +0100 (CET)","from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-687-oaE6KQq3Mpytou6fgjIV_g-1;\n\tSat, 13 Jan 2024 09:23:09 -0500","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mimecast-mx02.redhat.com (Postfix) with ESMTPS id 71B0F29AA38D;\n\tSat, 13 Jan 2024 14:23:09 +0000 (UTC)","from localhost.localdomain (unknown [10.39.192.58])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 758AF3C25;\n\tSat, 13 Jan 2024 14:23:07 +0000 (UTC)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1705155799;\n\tbh=yKqOHb0PaVLFqvzK2FMtDNXbnF8zJTMer4bge0eZ5Ew=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=uT9ASNzeJ2Q+rEQY1V4JhaIjVgbPLZdBkd5AH9Gl4Esr05q2a9YEzTgjtL6Ywx1df\n\tXNFVbUzIBt8DrnNc2X6ReBkiA4CGkXj8qUlNF5A/npR5cUllWIxMEWQQ4StiApoW4n\n\t/ncnHi8srDqEyAd4L2+si/Yc4GQB3GjcZb64WL8EK+E+9JQ0Iedh39CnYp8OiFStSg\n\t7aKtsZJ9zBf6r6rbXUXBBiiUNr+M0nNTe0Z9fVxgL0r+2F7pewA4vJR+dQ5ecfV/zy\n\tS5mH4QpiSc8s/Tts70AKeQDAlyczb3pBKkp07T/vTTmEppdeVe0hIToOCkVDUVhy7y\n\tLx/KPf85JHa5A==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1705155796;\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\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=Pa0Fyd790cew1kOWIPhZ75+OEi+zOdG8ysc+f1wvhRY=;\n\tb=a+NXN8C04SU9q5WtItm7Z1ojwj33y080Xz6AQPWKiafuWpCQy4UXwDXenOiP+vt3oB5nvg\n\t+S8Ex4Jx7aK9/TnCwQ0fwsCaYIwpUDkuMUqxCQzvKUYWt4X8pxYJqQnrdtoCMsLQqXtT24\n\ttiB5CqQOMRfInbYkk62aYtB6R89ZcMM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"a+NXN8C0\"; \n\tdkim-atps=neutral","X-MC-Unique":"oaE6KQq3Mpytou6fgjIV_g-1","To":"libcamera-devel@lists.libcamera.org,\n\tAndrey Konovalov <andrey.konovalov.ynk@gmail.com>","Date":"Sat, 13 Jan 2024 15:22:18 +0100","Message-ID":"<20240113142218.28063-19-hdegoede@redhat.com>","In-Reply-To":"<20240113142218.28063-1-hdegoede@redhat.com>","References":"<20240113142218.28063-1-hdegoede@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.11.54.1","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain; charset=\"US-ASCII\"; x-default=true","Subject":"[libcamera-devel] [PATCH v2 18/18] libcamera: debayer_cpu: Add\n\tBGR888 output 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>","Cc":"Maxime Ripard <mripard@redhat.com>, g.martti@gmail.com,\n\tt.langendam@gmail.com, srinivas.kandagatla@linaro.org,\n\tPavel Machek <pavel@ucw.cz>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>, admin@dennisbonke.com","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"BGR888 is RGB888 with the red and blue pixels swapped, adjust\nthe debayering to swap the red and blue pixels in the bayer pattern\nto add support for writing formats::BGR888.\n\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\nTested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s\nTested-by: Pavel Machek <pavel@ucw.cz>\n---\n .../internal/software_isp/debayer_cpu.h       |  1 +\n src/libcamera/software_isp/debayer_cpu.cpp    | 43 ++++++++++++++++---\n 2 files changed, 39 insertions(+), 5 deletions(-)","diff":"diff --git a/include/libcamera/internal/software_isp/debayer_cpu.h b/include/libcamera/internal/software_isp/debayer_cpu.h\nindex 99914e2a..4ad4ba8f 100644\n--- a/include/libcamera/internal/software_isp/debayer_cpu.h\n+++ b/include/libcamera/internal/software_isp/debayer_cpu.h\n@@ -129,6 +129,7 @@ private:\n \tunsigned int lineBufferIndex_;\n \tunsigned int x_shift_; /* Offset of 0/1 applied to window_.x */\n \tbool enableInputMemcpy_;\n+\tbool swapRedBlueGains_;\n \tfloat gamma_correction_;\n \tint measuredFrames_;\n \tint64_t frameProcessTime_;\ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex d1f8fa15..6c794735 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -221,7 +221,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@@ -231,7 +231,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@@ -242,7 +242,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@@ -278,12 +278,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+\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 \tx_shift_ = 0;\n \n \tif ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10) &&\n@@ -327,6 +356,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@@ -566,6 +596,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 (int i = 0; i < 256; i++) {\n \t\tint idx;\n \n","prefixes":["libcamera-devel","v2","18/18"]}