From patchwork Thu Oct 28 08:46:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14377 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0D71FBF415 for ; Thu, 28 Oct 2021 08:46:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4B6F7600C3; Thu, 28 Oct 2021 10:46:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="G9yC9F+F"; dkim-atps=neutral Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 13C16600B5 for ; Thu, 28 Oct 2021 10:46:54 +0200 (CEST) Received: by mail-wm1-x32c.google.com with SMTP id b2-20020a1c8002000000b0032fb900951eso504586wmd.4 for ; Thu, 28 Oct 2021 01:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DFVfDgiJ51NAaHuOgz8wXkOeYUYNO2/wkqOjzQm0aj8=; b=G9yC9F+F9fTddmBmr8fwRW3rEgIvkQ6MDjVAbBkENHeP+MR5+MbxTI27H4zqVE6tjy Fukber4giyxI4Rx6u5DsurtNpj5QtGDE2iQPJG11G/pQ+1dXfeVOOkArieMZsb7LE7yB ZLAJIxdpfUhwXa5gsXmC9OrkKPRu2o8W+A10HSIhzyCKnUTLZbRfd1Nmcc2hiRtYq6dy vftVrFnIkqLUvmTucifl3l5u2gzYDGaNvjMeWz+AxlPue6QC554sRaOlJHf3Lj0QDRKK /z6zOd6iWANVtuc7AuCbo/ZPJyHGB2O1GKen5TIjb18pOvfNFRcldqjbgDsNL3bH/Qr8 SF0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DFVfDgiJ51NAaHuOgz8wXkOeYUYNO2/wkqOjzQm0aj8=; b=IBnmE6OCt7YU6gPETpUm2Wme2vyQe7xnPDavgOWEh2B+OyJa5FZmWGrPWdCTDwHVIV n3+GI0L63Z5NXXznlugEO1zwKO8USdXvTqhfej6zb8JT4ytlE2pRcS+PF7Lw6rFkyB6e V4JhCe3RTc4vOoI+l38QhmcuwaO7QAW3asD2eaNiKsBTB9M9kgnvjFET/PqqshnxeE8g VrEu8IkBuzADynDDqGpcMCAR8blo8JmVYNelQ2QwRZqG6tvFK2w9SAzxLhaJZbdg94er ZfeM4NiF5DaJqBb0RjZCRgbe9m9Yji7YFBFlATm4+K20rbBwLasrg2okWinrxXCPmzUM N8Zw== X-Gm-Message-State: AOAM530Ginqb1YnjOUkAghF/+6IgQechbwSew9AF1DNssiHdSdA5vtyp LK9Knn/Y+EZaj4/ViaGtyKL92zVPlCBqaH4l X-Google-Smtp-Source: ABdhPJxmnLLJj4nvEYJiQ/fNfgK12FX7xHvocvZoa+fFfnR+dxHuqxgqep5n7VpEFoXA2InGpabOxw== X-Received: by 2002:a05:600c:35d0:: with SMTP id r16mr11038366wmq.97.1635410813577; Thu, 28 Oct 2021 01:46:53 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:53 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:37 +0100 Message-Id: <20211028084646.453775-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 01/10] include: drm_fourcc: Add R10 and R12 FourCC X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Laurent Pinchart Add FourCCs for 10- and 12-bit red format with padding to 16 bits. This is a temporary addition until the formats gets merged in the upstream kernel. Signed-off-by: Laurent Pinchart Signed-off-by: Naushir Patuck Reviewed-by: Naushir Patuck Acked-by: Kieran Bingham --- include/linux/drm_fourcc.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h index 05d697ff30ce..28ea3a167ecb 100644 --- a/include/linux/drm_fourcc.h +++ b/include/linux/drm_fourcc.h @@ -104,6 +104,12 @@ extern "C" { /* 8 bpp Red */ #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */ +/* 10 bpp Red */ +#define DRM_FORMAT_R10 fourcc_code('R', '1', '0', ' ') /* [15:0] x:R 6:10 little endian */ + +/* 12 bpp Red */ +#define DRM_FORMAT_R12 fourcc_code('R', '1', '2', ' ') /* [15:0] x:R 4:12 little endian */ + /* 16 bpp Red */ #define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ') /* [15:0] R little endian */ From patchwork Thu Oct 28 08:46:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14378 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E74A6BF415 for ; Thu, 28 Oct 2021 08:46:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 99958600F9; Thu, 28 Oct 2021 10:46:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="GzskVOnR"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B02EC600B7 for ; Thu, 28 Oct 2021 10:46:54 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id a20-20020a1c7f14000000b003231d13ee3cso8623084wmd.3 for ; Thu, 28 Oct 2021 01:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RG3zcG/cyCZQubLgG1F5CIX3ibyjzBGfN4/E1yy8ruU=; b=GzskVOnROpR2033pDx5/vpT4XDF2F14uiM2vPtup7IovgmlnUtZFYXJVlshB1TgjPK tFo5Y2F+p83/yo9j2LK8OFezJrs8wUOyv2qVlo50cokDJ1eA/llH5pmNlZd0dj7O7AB2 7YYNUTf3vZyc3CCONq81wa2aGZnzQ+njh58wal6xRLtzriNinMF6g5J4zANkJEtuZ5RH cpGMC2qeoiXhhWv8yqUxoecYazWrW9jRFxKaUDaRT/P6IwITDmcEokGbtHO+nem9dzli 8wLlfT+Dnrp5vxBe8HIN8ZX1ft/fFoDdp7lptmmJjswxGTDyva1ZDLI1Xgynsel/YKWJ iWow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RG3zcG/cyCZQubLgG1F5CIX3ibyjzBGfN4/E1yy8ruU=; b=aE80l1/NGXN/WAjlsJWehcL2dnReqkhwPzBBdmZCynhApXSsfM+O+TevOZ1g8aMeI3 9u4PrlySDPcXLEdxOPjlhVlRv1N82FaatE1xfF4NioH4BkpAVhoJeUZhACIPchX/Fhf9 4spdHSw7owDIwRTHUtmkKfb2Br25B8h89ACjRucuPaYOMlgaUsa0WFCE95etqkhDmIjP /VUoKNjkUUg73ZZIOJKbV2v+PYoaDhe6cE5/rmqU0uTc6Z8TF88f7ssuH1+kAvPhOV81 7zHtN/z63N7vX3jMPrFGUIprW6+oPbMt0xyLjza1/MDhXL9cRuz3D1+3DPsyEdHnCv63 O5DA== X-Gm-Message-State: AOAM533Q2M+T74PpH693u6iN8Rk0UpBfYcRhuujvnEcTP3uJsT/4eFPZ EFMa2OBZNkhm0w0uXtVg1XQb6HHlyESMNTn2 X-Google-Smtp-Source: ABdhPJzijmtEskSjN7q4DsvdcreD6a8LS4FAxg0yy/AdixbSih2QDNqkF1RU685O7//wAR+FEs5UyQ== X-Received: by 2002:a7b:c049:: with SMTP id u9mr3088638wmc.102.1635410814197; Thu, 28 Oct 2021 01:46:54 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:53 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:38 +0100 Message-Id: <20211028084646.453775-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 02/10] libcamera: formats: Add R10 and R12 formats X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Laurent Pinchart These new formats corresponds to the V4L2 V4L2_PIX_FMT_Y10 and V4L2_PIX_FMT_Y12 formats, and are the little-endian version of the DRM_FORMAT_R10 and DRM_FORMAT_R12 formats. Signed-off-by: Laurent Pinchart Signed-off-by: Naushir Patuck Reviewed-by: Naushir Patuck Reviewed-by: Kieran Bingham --- src/libcamera/formats.cpp | 26 ++++++++++++++++++++++++++ src/libcamera/formats.yaml | 4 ++++ src/libcamera/v4l2_pixelformat.cpp | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 1c29e1f2c5ab..d4781dfb3874 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -484,6 +484,32 @@ const std::map pixelFormatInfo{ .pixelsPerGroup = 1, .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }}, } }, + { formats::R10, { + .name = "R10", + .format = formats::R10, + .v4l2Formats = { + .single = V4L2PixelFormat(V4L2_PIX_FMT_Y10), + .multi = V4L2PixelFormat(), + }, + .bitsPerPixel = 10, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }}, + } }, + { formats::R12, { + .name = "R12", + .format = formats::R12, + .v4l2Formats = { + .single = V4L2PixelFormat(V4L2_PIX_FMT_Y12), + .multi = V4L2PixelFormat(), + }, + .bitsPerPixel = 12, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }}, + } }, /* Bayer formats. */ { formats::SBGGR8, { diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml index 43b5877e08f2..22a8e473a183 100644 --- a/src/libcamera/formats.yaml +++ b/src/libcamera/formats.yaml @@ -7,6 +7,10 @@ formats: - R8: fourcc: DRM_FORMAT_R8 + - R10: + fourcc: DRM_FORMAT_R10 + - R12: + fourcc: DRM_FORMAT_R12 - RGB565: fourcc: DRM_FORMAT_RGB565 diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp index 3649c6002620..0e0da3f0df07 100644 --- a/src/libcamera/v4l2_pixelformat.cpp +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -117,6 +117,10 @@ const std::map vpf2pf{ /* Greyscale formats. */ { V4L2PixelFormat(V4L2_PIX_FMT_GREY), { formats::R8, "8-bit Greyscale" } }, + { V4L2PixelFormat(V4L2_PIX_FMT_Y10), + { formats::R10, "10-bit Greyscale" } }, + { V4L2PixelFormat(V4L2_PIX_FMT_Y12), + { formats::R12, "12-bit Greyscale" } }, /* Bayer formats. */ { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8), From patchwork Thu Oct 28 08:46:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14379 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id CEE44C324E for ; Thu, 28 Oct 2021 08:47:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E02860103; Thu, 28 Oct 2021 10:47:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="k5WurwBq"; dkim-atps=neutral Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6967C600C1 for ; Thu, 28 Oct 2021 10:46:55 +0200 (CEST) Received: by mail-wm1-x32c.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so400029wme.4 for ; Thu, 28 Oct 2021 01:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4gQklNV8u9ONgLGzJ6qWEeraVIm9dy+r6zmPAgc0niU=; b=k5WurwBqIzupnYPozqQGhulwXvwMuRmkD3Y6RQbOFGcnRSwlFD+eHDr7ZnvW9TKNnD E2BFmJFtSqmtxw5W2lENeKj9l120wLtkW9LHsY/iZiVRVefIMY8mdMnVGkaQI5E5O9VI npw34zvSvKpxNMcq1BaNgQzv9cEmA+rNK2gC1RnKlSddxCirjD96/AVxk5O/KbGIaxXx 8ZWO8orwKfkoNVOMwOz/ppIOvE8jObXW19S7Zdbck+mod3PIHrFYFMGUwgvFCN4cOALi QNGaBe0B4x/9j158X6HIcUwnZG7XV7Px0atoCmTKu11cPROPFDGmgomE86ybv9qITeS7 wIug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4gQklNV8u9ONgLGzJ6qWEeraVIm9dy+r6zmPAgc0niU=; b=DoJH+cJUp4wnSzYehPtQT5oC1hTMlWQSY8c2GCt68Zgj1TlkneNU4ruxg28T5wO0xT TdJsLqMlqPbPxOAZNVKLv8LZBmKl0rAEAT2OiVA7Pa0jM17Pk73XhgKEs+8O2k5MJBHs lhgcp8jw7UQIANrUTfTqos6EQ/xT9+SBjG0ux851SMcWI0rOLZ+LK9xl0UE04qm8gKh1 9Xgy1vyGOJfGk8cLfcPEDHxJhBj6SDgONBTOoOQDZPRm3eqs3HvKQVidRrwaVAp6twDu gXtLQz6QTWj1R9dryTC25Lcuc7Kv3UI3y/bAiG7qZhPRaygNf9XjE2ExIVFM9VE8XcjX C5jQ== X-Gm-Message-State: AOAM530Hl8qRt0h6ocwtDNIgZd1ikZAUuS6EUO7Gnrm/E5eub8R/h/rp GxqJVixmn2tuqE7sdCheRVlMwio1bfvdtmsQ X-Google-Smtp-Source: ABdhPJzyM/BdTZQuOxYuHA+s52esfbJsueFZhUASvSE4M/HT6CFhNallhrm/wPi+UdW0G8bWWOir0Q== X-Received: by 2002:a05:600c:1d05:: with SMTP id l5mr3019192wms.97.1635410814889; Thu, 28 Oct 2021 01:46:54 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:54 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:39 +0100 Message-Id: <20211028084646.453775-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 03/10] libcamera: formats: Add R10_CSI2P format X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This new formats corresponds to the V4L2 V4L2_PIX_FMT_Y10P format, and is a CSI2-packed version of the DRM_FORMAT_R10 format. Signed-off-by: Naushir Patuck --- src/libcamera/formats.cpp | 13 +++++++++++++ src/libcamera/formats.yaml | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index d4781dfb3874..9b6ccdca0663 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -510,6 +510,19 @@ const std::map pixelFormatInfo{ .pixelsPerGroup = 1, .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }}, } }, + { formats::R10_CSI2P, { + .name = "R10_CSI2P", + .format = formats::R10, + .v4l2Formats = { + .single = V4L2PixelFormat(V4L2_PIX_FMT_Y10P), + .multi = V4L2PixelFormat(), + }, + .bitsPerPixel = 10, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = true, + .pixelsPerGroup = 1, + .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }}, + } }, /* Bayer formats. */ { formats::SBGGR8, { diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml index 22a8e473a183..1f3f043302c3 100644 --- a/src/libcamera/formats.yaml +++ b/src/libcamera/formats.yaml @@ -109,6 +109,10 @@ formats: - SBGGR16: fourcc: DRM_FORMAT_SBGGR16 + - R10_CSI2P: + fourcc: DRM_FORMAT_R10 + mod: MIPI_FORMAT_MOD_CSI2_PACKED + - SRGGB10_CSI2P: fourcc: DRM_FORMAT_SRGGB10 mod: MIPI_FORMAT_MOD_CSI2_PACKED From patchwork Thu Oct 28 08:46:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14380 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 81FAFBF415 for ; Thu, 28 Oct 2021 08:47:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3AC736032A; Thu, 28 Oct 2021 10:47:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="sRDZGtvD"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3DD26600BC for ; Thu, 28 Oct 2021 10:46:56 +0200 (CEST) Received: by mail-wr1-x434.google.com with SMTP id m22so8882630wrb.0 for ; Thu, 28 Oct 2021 01:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E+T1sqoCBrKwmoWpdxQHkpnxUQbwOn0Nnp6oELzP6YA=; b=sRDZGtvD4gO1B5AVOVdkhDao6YEn+A+kGV0LKVe0/r6dAWjDkgMmmAHrm7RTS4JRTt VQEOn8zQT+BOJ6ehoE72nBJsSN1mrx6MdUHydEtZ3OyYrFovDURRbP4M6aElPd5GEvdg zNXG+UyKhbSiRnJHkc2RF53vxPOY7gzLY+tfrZQZLmQrSCwvUPu5VeOlzvj2imdD175p VYVDNPBzn3LRymUz+UaIWK5zPDQZp/lzmRXm3Asg7RXNjCpB5QqEiNxtrtPYkrpv5cda qKM5J/n/ZXKv+P/mxoAMz1aIHE88a9OwJwAQPFhJ2iwO7UnALIA9OI7OUL7eNfvcceMc UgNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E+T1sqoCBrKwmoWpdxQHkpnxUQbwOn0Nnp6oELzP6YA=; b=09/xrSU0NSYKsRHZKuy12q1E3ec2s782Jn0Qlayg8wojKbdBV/wFQjRMDTEddKd5XJ 8RojgR2UZzXy6ZDIjnad/em4Ju0kQoC00ptExizvHSRFIQbKAKROV4D/spj4iMYhUIHF ONGjkMF1FeqqN7mXbd93d1gCexr0YXQUDtOM6gJ+630IBKW0XoMJeWqgCSLCkyyFwPpK kR7lQayGHp/HG2jdoLG+7m521mnXNBklnnIsqE6nbOjVsUZXX/PscNfrYFYMU+oEngPW JYtA+bsikFvCDdonkz8iaNg+6ovfLAIudy/QQopSqp8zaPnJGBuOu2eYVQc/2gWA/ffh w4DQ== X-Gm-Message-State: AOAM531ZH4EhQHoPEBZx8YbEb1/ulM1sR3XRbKDpb2VDuBR92mLUhbj0 rgYy60tLewSEhp8aryXGb3Jpb3Y4KPHQ4zy+ X-Google-Smtp-Source: ABdhPJzUWCLf0kbgXmltBm5jfNhdRe/SObJ4hr7OtcrUi6dM3Pwgft64+7vGvieLQgkySYI7WTCUKA== X-Received: by 2002:a5d:4882:: with SMTP id g2mr3738069wrq.399.1635410815507; Thu, 28 Oct 2021 01:46:55 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:55 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:40 +0100 Message-Id: <20211028084646.453775-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 04/10] libcamera: bayer_format: Turn BayerFormat::Packing into scoped enum X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Laurent Pinchart The unscoped enum BayerFormat::Packing leads to usage of the ambiguous BayerFormat::None enumerator. Turn the enumeration into a scoped enum to force usage of BayerFormat::Packing::None, and drop the now redundant "Packed" suffix for the CSI2 and IPU3 packing. Signed-off-by: Laurent Pinchart Signed-off-by: Naushir Patuck Reviewed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham --- include/libcamera/internal/bayer_format.h | 6 +- src/libcamera/bayer_format.cpp | 138 +++++++++++----------- test/bayer-format.cpp | 28 ++--- 3 files changed, 86 insertions(+), 86 deletions(-) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 723382d4168d..d9a56d744a25 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -27,10 +27,10 @@ public: MONO = 4 }; - enum Packing : uint16_t { + enum class Packing : uint16_t { None = 0, - CSI2Packed = 1, - IPU3Packed = 2, + CSI2 = 1, + IPU3 = 2, }; constexpr BayerFormat() diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 11355f144f66..1c1e849a7e31 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -53,11 +53,11 @@ namespace libcamera { * \enum BayerFormat::Packing * \brief Different types of packing that can be applied to a BayerFormat * - * \var BayerFormat::None + * \var BayerFormat::Packing::None * \brief No packing - * \var BayerFormat::CSI2Packed + * \var BayerFormat::Packing::CSI2 * \brief Format uses MIPI CSI-2 style packing - * \var BayerFormat::IPU3Packed + * \var BayerFormat::Packing::IPU3 * \brief Format uses IPU3 style packing */ @@ -85,73 +85,73 @@ struct BayerFormatComparator { }; const std::map bayerToV4l2{ - { { BayerFormat::BGGR, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) }, - { { BayerFormat::GBRG, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) }, - { { BayerFormat::GRBG, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) }, - { { BayerFormat::RGGB, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) }, - { { BayerFormat::BGGR, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) }, - { { BayerFormat::GBRG, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) }, - { { BayerFormat::GRBG, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) }, - { { BayerFormat::RGGB, 10, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) }, - { { BayerFormat::BGGR, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) }, - { { BayerFormat::GBRG, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) }, - { { BayerFormat::GRBG, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) }, - { { BayerFormat::RGGB, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) }, - { { BayerFormat::BGGR, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) }, - { { BayerFormat::GBRG, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) }, - { { BayerFormat::GRBG, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) }, - { { BayerFormat::RGGB, 10, BayerFormat::IPU3Packed }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) }, - { { BayerFormat::BGGR, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) }, - { { BayerFormat::GBRG, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) }, - { { BayerFormat::GRBG, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) }, - { { BayerFormat::RGGB, 12, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) }, - { { BayerFormat::BGGR, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) }, - { { BayerFormat::GBRG, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) }, - { { BayerFormat::GRBG, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) }, - { { BayerFormat::RGGB, 12, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) }, - { { BayerFormat::BGGR, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) }, - { { BayerFormat::GBRG, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) }, - { { BayerFormat::GRBG, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) }, - { { BayerFormat::RGGB, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) }, - { { BayerFormat::MONO, 8, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_GREY) }, - { { BayerFormat::MONO, 10, BayerFormat::CSI2Packed }, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) }, + { { BayerFormat::BGGR, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) }, + { { BayerFormat::GBRG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) }, + { { BayerFormat::GRBG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) }, + { { BayerFormat::RGGB, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) }, + { { BayerFormat::BGGR, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) }, + { { BayerFormat::GBRG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) }, + { { BayerFormat::GRBG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) }, + { { BayerFormat::RGGB, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) }, + { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) }, + { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) }, + { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) }, + { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) }, + { { BayerFormat::BGGR, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) }, + { { BayerFormat::GBRG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) }, + { { BayerFormat::GRBG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) }, + { { BayerFormat::RGGB, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) }, + { { BayerFormat::MONO, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_GREY) }, + { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) }, }; const std::unordered_map mbusCodeToBayer{ - { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10, BayerFormat::None } }, - { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12, BayerFormat::None } }, - { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14, BayerFormat::None } }, - { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14, BayerFormat::None } }, - { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16, BayerFormat::None } }, - { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16, BayerFormat::None } }, - { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16, BayerFormat::None } }, - { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8, BayerFormat::None } }, - { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10, BayerFormat::None } }, + { MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_Y8_1X8, { BayerFormat::MONO, 8, BayerFormat::Packing::None } }, + { MEDIA_BUS_FMT_Y10_1X10, { BayerFormat::MONO, 10, BayerFormat::Packing::None } }, }; } /* namespace */ @@ -214,9 +214,9 @@ std::string BayerFormat::toString() const result += "-" + std::to_string(bitDepth); - if (packing == CSI2Packed) + if (packing == Packing::CSI2) result += "-CSI2P"; - else if (packing == IPU3Packed) + else if (packing == Packing::IPU3) result += "-IPU3P"; return result; diff --git a/test/bayer-format.cpp b/test/bayer-format.cpp index e396ee83ca91..135bcb5214c8 100644 --- a/test/bayer-format.cpp +++ b/test/bayer-format.cpp @@ -30,7 +30,7 @@ protected: } /* A correct Bayer format has to be valid. */ - bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None); if (!bayerFmt.isValid()) { cerr << "A correct BayerFormat has to be valid." << endl; @@ -41,9 +41,9 @@ protected: * Two bayer formats created with the same order and bit depth * have to be equal. */ - bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None); BayerFormat bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8, - BayerFormat::None); + BayerFormat::Packing::None); if (bayerFmt != bayerFmtExpect) { cerr << "Comparison of identical formats failed." << endl; @@ -54,9 +54,9 @@ protected: * Two Bayer formats created with the same order but with a * different bitDepth are not equal. */ - bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None); bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 12, - BayerFormat::None); + BayerFormat::Packing::None); if (bayerFmt == bayerFmtExpect) { cerr << "Comparison of different formats failed." << endl; @@ -96,7 +96,7 @@ protected: * to a Bayer format. */ bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8, - BayerFormat::None); + BayerFormat::Packing::None); v4l2Fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8); bayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2Fmt); if (bayerFmt != bayerFmtExpect) { @@ -123,7 +123,7 @@ protected: * Test if a valid Bayer format can be converted to a * string representation. */ - bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None); if (bayerFmt.toString() != "BGGR-8") { cerr << "String representation != 'BGGR-8' (got: '" << bayerFmt.toString() << "' ) " << endl; @@ -145,9 +145,9 @@ protected: * Perform a horizontal Flip and make sure that the * order is adjusted accordingly. */ - bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None); bayerFmtExpect = BayerFormat(BayerFormat::GBRG, 8, - BayerFormat::None); + BayerFormat::Packing::None); BayerFormat hFlipFmt = bayerFmt.transform(Transform::HFlip); if (hFlipFmt != bayerFmtExpect) { cerr << "Horizontal flip of 'BGGR-8' should result in '" @@ -160,9 +160,9 @@ protected: * Perform a vertical Flip and make sure that * the order is adjusted accordingly. */ - bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None); bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8, - BayerFormat::None); + BayerFormat::Packing::None); BayerFormat vFlipFmt = bayerFmt.transform(Transform::VFlip); if (vFlipFmt != bayerFmtExpect) { cerr << "Vertical flip of 'BGGR-8' should result in '" @@ -176,7 +176,7 @@ protected: * pixels on the bottom left to top right diagonal and make * sure, that it doesn't change. */ - bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + bayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::Packing::None); BayerFormat transposeFmt = bayerFmt.transform( Transform::Transpose); if (transposeFmt != bayerFmt) { @@ -192,9 +192,9 @@ protected: * on the bottom left to top right diagonal and make sure * that their positions are switched. */ - bayerFmt = BayerFormat(BayerFormat::GBRG, 8, BayerFormat::None); + bayerFmt = BayerFormat(BayerFormat::GBRG, 8, BayerFormat::Packing::None); bayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8, - BayerFormat::None); + BayerFormat::Packing::None); transposeFmt = bayerFmt.transform(Transform::Transpose); if (transposeFmt != bayerFmtExpect) { cerr << "Transpose with the red & blue pixels on the " From patchwork Thu Oct 28 08:46:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14381 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id F0F05C324E for ; Thu, 28 Oct 2021 08:47:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B1D6A60157; Thu, 28 Oct 2021 10:47:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="jZtakmNQ"; dkim-atps=neutral Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D23E600C5 for ; Thu, 28 Oct 2021 10:46:56 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id b12so4351330wrh.4 for ; Thu, 28 Oct 2021 01:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AQhsv8etWZt5rB647X08XTKP+f4z+ciJxLxbIs36LKg=; b=jZtakmNQmmcpsc8dBGVBtmVK7RADULtSkVMmmIrRFNYzwY7ZBqrQnX+AY7/V2eYtAR 7lzmn3e09HAPyFnwjyMOq2nTv8qjIUt76KNyTVYcvqdEG/1qSzytxuORuSDfExcfW7a3 SqZY6/PtL9x1qGlXTCLulNsGAX9wQKlB2fGe0+n6xT0FHmBCVtFtBuufyh9ZBMA5IstH oQp6jlik+Uh2DjJFMj4k7FRpz/IXFnihy2PqyFl2p49X6ShlCkTsegPBqxMvRfrXFGGP aGDJi9eMT1TXtcJqnnfQ6bljpDvOr3fKhf8XU/xXNEWcqkaLi1nMX61z3yakkspUWxaQ 9oYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AQhsv8etWZt5rB647X08XTKP+f4z+ciJxLxbIs36LKg=; b=d/NLc/JftL5iyKAlTkwYJrf+B0JZEOsriYtr7jsbvETxbg2oz4H/hC7eWbGCSawxJq SCiuXi4kNFGdMzaUo+avUIAa5ImFIwj/ggkvigdg5XKfajIEiBp1M7bzxRcn4Uh42Y9p FH3vBHqjJYxje5LB5uY6NItC7NZGHDa5H3QX53HbgUZTLp8/UG89iLD8qJXtLqyA/iHw llCScWAQ6sY5rJodz65guiSZk0S6arI5wuKDxtET/qSLykfuQfh+KEqjVXRgm1Ckm2+W gRUqp2GQl8k3Ao4wugBaqKH/FKELDtuzbo1SyXGbNGj04l7otie8hUPPoMB8CPPz/Tc7 111w== X-Gm-Message-State: AOAM5326o2mDa1Grmryvx0QvDkxK7aEtcU4BMqEvwT63p7IwmrqvP028 v13MxwKOb/2mXMFEex59hGvXOzYSFhDQze6g X-Google-Smtp-Source: ABdhPJz6Jod+p07Wl9A8i9OckdPHs+fqoN05SVe2PKzcAAi9wzBkQRvPl0ECG4LkTFvQowXL4ctlbw== X-Received: by 2002:adf:c183:: with SMTP id x3mr3993052wre.90.1635410816019; Thu, 28 Oct 2021 01:46:56 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:55 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:41 +0100 Message-Id: <20211028084646.453775-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 05/10] libcamera: bayer_format: Rework BayerFormat conversion table X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Rename the bayerToV4l2 conversion table to bayerToFormat. Update the table to hold both the PixelFormat and V4L2PixelFormat conversions for a given BayerFormat. This will allow converting between BayerFormat and PixelFormat types in a subsequent change. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham --- src/libcamera/bayer_format.cpp | 112 ++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 37 deletions(-) diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 1c1e849a7e31..8665a025f7e0 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -13,6 +13,7 @@ #include +#include #include /** @@ -84,37 +85,74 @@ struct BayerFormatComparator { } }; -const std::map bayerToV4l2{ - { { BayerFormat::BGGR, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) }, - { { BayerFormat::GBRG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) }, - { { BayerFormat::GRBG, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) }, - { { BayerFormat::RGGB, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) }, - { { BayerFormat::BGGR, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) }, - { { BayerFormat::GBRG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) }, - { { BayerFormat::GRBG, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) }, - { { BayerFormat::RGGB, 10, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) }, - { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) }, - { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) }, - { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) }, - { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) }, - { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) }, - { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) }, - { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) }, - { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 }, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) }, - { { BayerFormat::BGGR, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) }, - { { BayerFormat::GBRG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) }, - { { BayerFormat::GRBG, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) }, - { { BayerFormat::RGGB, 12, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) }, - { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) }, - { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) }, - { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) }, - { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) }, - { { BayerFormat::BGGR, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) }, - { { BayerFormat::GBRG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) }, - { { BayerFormat::GRBG, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) }, - { { BayerFormat::RGGB, 16, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) }, - { { BayerFormat::MONO, 8, BayerFormat::Packing::None }, V4L2PixelFormat(V4L2_PIX_FMT_GREY) }, - { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 }, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) }, +struct Formats { + PixelFormat pixelFormat; + V4L2PixelFormat v4l2Format; +}; + +const std::map bayerToFormat{ + { { BayerFormat::BGGR, 8, BayerFormat::Packing::None }, + { formats::SBGGR8, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8) } }, + { { BayerFormat::GBRG, 8, BayerFormat::Packing::None }, + { formats::SGBRG8, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8) } }, + { { BayerFormat::GRBG, 8, BayerFormat::Packing::None }, + { formats::SGRBG8, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8) } }, + { { BayerFormat::RGGB, 8, BayerFormat::Packing::None }, + { formats::SRGGB8, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8) } }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::None }, + { formats::SBGGR10, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10) } }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::None }, + { formats::SGBRG10, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10) } }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::None }, + { formats::SGRBG10, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10) } }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::None }, + { formats::SRGGB10, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10) } }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::CSI2 }, + { formats::SBGGR10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) } }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::CSI2 }, + { formats::SGBRG10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) } }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::CSI2 }, + { formats::SGRBG10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) } }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::CSI2 }, + { formats::SRGGB10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) } }, + { { BayerFormat::BGGR, 10, BayerFormat::Packing::IPU3 }, + { formats::SBGGR10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10) } }, + { { BayerFormat::GBRG, 10, BayerFormat::Packing::IPU3 }, + { formats::SGBRG10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10) } }, + { { BayerFormat::GRBG, 10, BayerFormat::Packing::IPU3 }, + { formats::SGRBG10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10) } }, + { { BayerFormat::RGGB, 10, BayerFormat::Packing::IPU3 }, + { formats::SRGGB10_IPU3, V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10) } }, + { { BayerFormat::BGGR, 12, BayerFormat::Packing::None }, + { formats::SBGGR12, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12) } }, + { { BayerFormat::GBRG, 12, BayerFormat::Packing::None }, + { formats::SGBRG12, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12) } }, + { { BayerFormat::GRBG, 12, BayerFormat::Packing::None }, + { formats::SGRBG12, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12) } }, + { { BayerFormat::RGGB, 12, BayerFormat::Packing::None }, + { formats::SRGGB12, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12) } }, + { { BayerFormat::BGGR, 12, BayerFormat::Packing::CSI2 }, + { formats::SBGGR12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P) } }, + { { BayerFormat::GBRG, 12, BayerFormat::Packing::CSI2 }, + { formats::SGBRG12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P) } }, + { { BayerFormat::GRBG, 12, BayerFormat::Packing::CSI2 }, + { formats::SGRBG12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P) } }, + { { BayerFormat::RGGB, 12, BayerFormat::Packing::CSI2 }, + { formats::SRGGB12_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P) } }, + { { BayerFormat::BGGR, 16, BayerFormat::Packing::None }, + { formats::SBGGR16, V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16) } }, + { { BayerFormat::GBRG, 16, BayerFormat::Packing::None }, + { formats::SGBRG16, V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16) } }, + { { BayerFormat::GRBG, 16, BayerFormat::Packing::None }, + { formats::SGRBG16, V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16) } }, + { { BayerFormat::RGGB, 16, BayerFormat::Packing::None }, + { formats::SRGGB16, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) } }, + { { BayerFormat::MONO, 8, BayerFormat::Packing::None }, + { formats::R8, V4L2PixelFormat(V4L2_PIX_FMT_GREY) } }, + { { BayerFormat::MONO, 10, BayerFormat::Packing::None }, + { formats::R10, V4L2PixelFormat(V4L2_PIX_FMT_Y10) } }, + { { BayerFormat::MONO, 10, BayerFormat::Packing::CSI2 }, + { formats::R10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) } }, }; const std::unordered_map mbusCodeToBayer{ @@ -245,9 +283,9 @@ bool operator==(const BayerFormat &lhs, const BayerFormat &rhs) */ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const { - const auto it = bayerToV4l2.find(*this); - if (it != bayerToV4l2.end()) - return it->second; + const auto it = bayerToFormat.find(*this); + if (it != bayerToFormat.end()) + return it->second.v4l2Format; return V4L2PixelFormat(); } @@ -259,11 +297,11 @@ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const */ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) { - auto it = std::find_if(bayerToV4l2.begin(), bayerToV4l2.end(), + auto it = std::find_if(bayerToFormat.begin(), bayerToFormat.end(), [v4l2Format](const auto &i) { - return i.second == v4l2Format; + return i.second.v4l2Format == v4l2Format; }); - if (it != bayerToV4l2.end()) + if (it != bayerToFormat.end()) return it->first; return BayerFormat(); From patchwork Thu Oct 28 08:46:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14382 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9FE51BF415 for ; Thu, 28 Oct 2021 08:47:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 43A3260158; Thu, 28 Oct 2021 10:47:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="RuTlLia2"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 61212600B6 for ; Thu, 28 Oct 2021 10:46:57 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 192so3458055wme.3 for ; Thu, 28 Oct 2021 01:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YPq00NOuoRgq46bBhppDBKpNY7cAdhvldaSzvXvOLbo=; b=RuTlLia2DBcIksf1GDNyjNuQUhVW1x2Xp/FE4BTPeWs4wwQjtrZzLmloxgX37RtSRR Bp1q4IJc6o33Tru6yrmOPmRxR/4MFxFYBjto4xwINc1nwZrOuQCnBlMmTVuNwHgBG8i1 vI75rlfqjEA4TnRe61gwXVjJcKZMmiJnZ+/Kw5j9IN+7ARyM1GI3Hj0SnNm9G3xhYF/i Ur6Pp++nY/EKEXw2CAqgZpfvHNYYLfw+rKUWt15CdVJIxW0cMLpTAOhbU6DXBuOH7jke AXsGfg1uP6sKW4lKdDjbudEQhfycY/jt+mPakUS53oU9LHtBfiRnHfUt4/p7ynm4kPR2 ZEOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YPq00NOuoRgq46bBhppDBKpNY7cAdhvldaSzvXvOLbo=; b=3ZNuxzxXzPvfQeu6hwsfTeI4szzYbnfi8zeJxX6o6j9l7QyEEiKUSKyLt9xzQf9EVb Veifo5x8ETAhvdTrmKo9YqBTS/dh/MQc5ZC8Cw2KJzvvJjQtNFJlS5UEqYUq5Aw8yPvD 0CeE+Ow95xFuKffuiXt3YOQbbxTrfanFIzc9v7q9cxyFZdcvILqUsuVq6ZJG8j7d2VoS D3eGYiAU6XjstOs0y9gExp+PPUmpIJP4+bB6+NTgiO+0lZCo1oKYWVtoERxJDTTTJ1Hy WKXyNsqWdzCU++5SVfY8kzjYBptCvQjitgavyTkECbHTZVj0/T2niNNN1UKOV79t/0pB NGsw== X-Gm-Message-State: AOAM531bmEC6y53dYaDq0q+2UaedyquSDCeJLKnT8o3HuSIaeChmTYEO n6ubri91H20XWlX1Xu1/kDfMW3BPb9wZJMZQ X-Google-Smtp-Source: ABdhPJzSkUjhXmqMP+MI9FvkWilAEB5Mmv6MIjdfVOxFjynnQyST7Hg9SPsLLScv61Xt08bD5pmAmQ== X-Received: by 2002:a1c:2541:: with SMTP id l62mr11048667wml.11.1635410816905; Thu, 28 Oct 2021 01:46:56 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:56 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:42 +0100 Message-Id: <20211028084646.453775-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 06/10] libcamera: bayer_format: Add PixelFormat conversion helpers to BayerFormat class X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add BayerFormat::toPixelFormat() and BayerFormat::fromPixelFormat() helper functions to convert between BayerFormat and PixelFormat types. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/bayer_format.h | 4 ++++ src/libcamera/bayer_format.cpp | 29 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index d9a56d744a25..79a25b52582d 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -10,6 +10,8 @@ #include #include +#include + #include "libcamera/internal/v4l2_pixelformat.h" namespace libcamera { @@ -50,6 +52,8 @@ public: V4L2PixelFormat toV4L2PixelFormat() const; static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format); + PixelFormat toPixelFormat() const; + static BayerFormat fromPixelFormat(PixelFormat format); BayerFormat transform(Transform t) const; Order order; diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 8665a025f7e0..1805d6fbbab9 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -307,6 +307,35 @@ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) return BayerFormat(); } +/** + * \brief Convert a BayerFormat into the corresponding PixelFormat + * \return The PixelFormat corresponding to this BayerFormat + */ +PixelFormat BayerFormat::toPixelFormat() const +{ + const auto it = bayerToFormat.find(*this); + if (it != bayerToFormat.end()) + return it->second.pixelFormat; + + return PixelFormat(); +} + +/** + * \brief Convert a PixelFormat into the corresponding BayerFormat + * \return The BayerFormat corresponding to this PixelFormat + */ +BayerFormat BayerFormat::fromPixelFormat(PixelFormat format) +{ + const auto it = std::find_if(bayerToFormat.begin(), bayerToFormat.end(), + [format](const auto &i) { + return i.second.pixelFormat == format; + }); + if (it != bayerToFormat.end()) + return it->first; + + return BayerFormat(); +} + /** * \brief Apply a transform to this BayerFormat * \param[in] t The transform to apply From patchwork Thu Oct 28 08:46:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14383 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 39AE0C324F for ; Thu, 28 Oct 2021 08:47:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E3772600C9; Thu, 28 Oct 2021 10:47:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="H4oPzJA4"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5103F600C8 for ; Thu, 28 Oct 2021 10:46:58 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id b82-20020a1c8055000000b0032ccc728d63so4445294wmd.1 for ; Thu, 28 Oct 2021 01:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MDGjX4NwGmjiRyxQlWwLzmvPyGow8IaUSTGp2CloHE0=; b=H4oPzJA4al6m7a3gdf4qFKx7KIgcRE/MAD5bXaiIyErXerMUomjkyBUhBfrXFkXOZM F4pq05fFj9tpWnvEIzZdGu/+wOy12VODmeC81Gy58gnVMne8NzMoP6wYbz9DVw3pnD88 E0Nj98+WNArzcayA7/56Nr2Ki5YjQvEO3Gtw1yRCjvXeewJrpLWL+X4/D/Aj7dv3xIlb PhzsPFM1+BYYACKD4SAqOzocXCEtfbjPSTHbW7Zqq1cMP2gIkkJN5WabVUwg8tbzBHGa VjXrpxUPlAvBUEv02S2trbqLtwisWhm+XsJcneCUtaOt6khFjOVFZpF/KT5Bd0euPK6+ XhAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MDGjX4NwGmjiRyxQlWwLzmvPyGow8IaUSTGp2CloHE0=; b=je4Bq6M0bhPoU0bsARDnWBWVjIHrHaKGG1swSyKNkPo5wyKvcLaUVfsZ6KKV3uuiMe yN/Nag3CEa81tP/q+wJstP8EMX75i1RKCRgrbqYMCNnsfFgiMIr4WIKpxidJlbERmoEm +qysFEY/zOdH0TBnabNyT56TUORWfRGGlFn7cdUSNEREQmXsp8XmIFZB7hLcBWPy/TiT VbgnmFVtjusZbd58Ed2nxFdYwXPtBZ/jBKMrYXOpHg79Co7wAj7PQicJXBFE4d1Afafo cJplcuNjq5xWvKBto5ieYpx9ZNNCz6rvst0essP62c4eC0xPavV2zTyyIJhCUozzG4uG HhtA== X-Gm-Message-State: AOAM530RRjzazQA4ziEC0PISHsX3kMGAV97XD9I15tkgRPoxUWT1jB6x DW79jGCbj1BN5GJN/Mn6W8YKI7KehhpRCA6z X-Google-Smtp-Source: ABdhPJwnTaWauGrhNFByVmTZKfh0CFlDoyfaG0GbguenngzgVaNzpFrT0PIgfiuhpA9NidpuLvWF7A== X-Received: by 2002:a1c:f601:: with SMTP id w1mr10940512wmc.112.1635410817753; Thu, 28 Oct 2021 01:46:57 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:57 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:43 +0100 Message-Id: <20211028084646.453775-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 07/10] pipeline: raspberrypi: Apply sensor flips at the start of configure() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Sensor flips might change the Bayer order of the requested format. The existing code would set a sensor format along with the appropriate Unicam and ISP input formats, but reset the latter two on start() once the flips had been requested. We can now set the sensor flips just before we set the sensor mode in configure(), thereby not needing the second pair of format sets in start(). Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 51 ++++++------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 1634ca98f481..e078b8b9a811 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -598,14 +598,26 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) } } + /* + * Configure the H/V flip controls based on the combination of + * the sensor and user transform. + */ + if (data->supportsFlips_) { + const RPiCameraConfiguration *rpiConfig = + static_cast(config); + ControlList controls; + + controls.set(V4L2_CID_HFLIP, + static_cast(!!(rpiConfig->combinedTransform_ & Transform::HFlip))); + controls.set(V4L2_CID_VFLIP, + static_cast(!!(rpiConfig->combinedTransform_ & Transform::VFlip))); + data->setSensorControls(controls); + } + /* First calculate the best sensor mode we can use based on the user request. */ V4L2VideoDevice::Formats fmts = data->unicam_[Unicam::Image].dev()->formats(); V4L2DeviceFormat sensorFormat = findBestMode(fmts, rawStream ? sensorSize : maxSize); - /* - * Unicam image output format. The ISP input format gets set at start, - * just in case we have swapped bayer orders due to flips. - */ ret = data->unicam_[Unicam::Image].dev()->setFormat(&sensorFormat); if (ret) return ret; @@ -620,10 +632,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) LOG(RPI, Info) << "Sensor: " << camera->id() << " - Selected mode: " << sensorFormat.toString(); - /* - * This format may be reset on start() if the bayer order has changed - * because of flips in the sensor. - */ ret = data->isp_[Isp::Input].dev()->setFormat(&sensorFormat); if (ret) return ret; @@ -843,18 +851,6 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) return ret; } - /* - * IPA configure may have changed the sensor flips - hence the bayer - * order. Get the sensor format and set the ISP input now. - */ - V4L2DeviceFormat sensorFormat; - data->unicam_[Unicam::Image].dev()->getFormat(&sensorFormat); - ret = data->isp_[Isp::Input].dev()->setFormat(&sensorFormat); - if (ret) { - stop(camera); - return ret; - } - /* Enable SOF event generation. */ data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true); @@ -1253,10 +1249,6 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig) int RPiCameraData::configureIPA(const CameraConfiguration *config) { - /* We know config must be an RPiCameraConfiguration. */ - const RPiCameraConfiguration *rpiConfig = - static_cast(config); - std::map streamConfig; std::map entityControls; ipa::RPi::IPAConfig ipaConfig; @@ -1307,17 +1299,6 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) return -EPIPE; } - /* - * Configure the H/V flip controls based on the combination of - * the sensor and user transform. - */ - if (supportsFlips_) { - controls.set(V4L2_CID_HFLIP, - static_cast(!!(rpiConfig->combinedTransform_ & Transform::HFlip))); - controls.set(V4L2_CID_VFLIP, - static_cast(!!(rpiConfig->combinedTransform_ & Transform::VFlip))); - } - if (!controls.empty()) setSensorControls(controls); From patchwork Thu Oct 28 08:46:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14384 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DC50DC324E for ; Thu, 28 Oct 2021 08:47:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9FC09600B5; Thu, 28 Oct 2021 10:47:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lS3SCK96"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 52B22600C1 for ; Thu, 28 Oct 2021 10:46:59 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id m42so5011897wms.2 for ; Thu, 28 Oct 2021 01:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B0fl895moHkYilukOGROsqowWz/xVSGcgn2bqLUP+4c=; b=lS3SCK967SGhKNXDxJbyqmJqQuJIbTKoaeDSkeTLl9maM7ylvkTpC73D4EO/QUdDP+ uIpCT3baZol2DV0b6nQkQS3mMN+b2n79JraH8cLJs9ERcc/kcyUpNbaKEY8AXKxC6nua uAuk3BaktU7sJRchLsHzMvbZq+mYnfQUyhiay/TYxO56pRssZbOx0tcTsHtRdy6IL1JA U2apLVgQVTdkvAm+qigV4+2rwEvG7DrEUMdP+zNnDk1HyalSEg0mI6WPk05CiFJpKmnb ej4z6crJrUTHA5o3T8oiyZhnOCYyS3+1ZMhybKu7gQjYiyOKhodSofO3lx5XjmQQVy8y +W6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B0fl895moHkYilukOGROsqowWz/xVSGcgn2bqLUP+4c=; b=a++gqmlZSipZQSIlYoKOZgzJN8pj3qfC3IsgXInf3eutsI++RRfe0KxJwYLILJg80O DoAcSqmIRPL+ScKHFAhlaNhkYTGykP/qFngPsJ7+XVyrRPBPbhwWzFbO6/WmMY7Ox6zN Efotzfg9ttu99vOvt5TWFtgm3oT28vQWWjNygfRDA+HvFvi9owBBSutD9A7tCTP874VS lTmrRIkZ64Unxa69rDF7zM66vtbAPKly84YJpPRRFXIhbTf8G6pxlZBAo93xWhczY7M5 ctcmht5ZpZ7bxGHKQH0pV8wQ/PH1i30vUCwo51peuWgOHF2GJYCHDiFPAnVMA5IZL8mE lg/w== X-Gm-Message-State: AOAM53122PvGeaMH2sUuVtp7pO/HQlGqN1eQpf5oRXn5ufodNXiqdlsc erRfn2goRm6WMyfWZt4KBoGMVxYKxFdqM9VJ X-Google-Smtp-Source: ABdhPJxCZx5YaHlwEZKrcF7Idn124pXlSBsPFqMGwr+MUpBu4VpYBNA5ZZyfCF1zQN5c+z8tFwvXRQ== X-Received: by 2002:a05:600c:441a:: with SMTP id u26mr8391951wmn.180.1635410818480; Thu, 28 Oct 2021 01:46:58 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:57 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:44 +0100 Message-Id: <20211028084646.453775-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 08/10] pipeline: raspberrypi: Convert the pipeline handler to use media controller X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Switch the pipeline handler to use the new Unicam media controller based driver. With this change, we directly talk to the sensor device driver to set controls and set/get formats in the pipeline handler. This change requires the accompanying Raspberry Pi linux kernel change at https://github.com/raspberrypi/linux/pull/4645. If this kernel change is not present, the pipeline handler will fail to run with an error message informing the user to update the kernel build. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- .../pipeline/raspberrypi/raspberrypi.cpp | 167 ++++++++++++------ 1 file changed, 112 insertions(+), 55 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index e078b8b9a811..8e3e96a4359f 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include "libcamera/internal/bayer_format.h" @@ -48,6 +49,53 @@ LOG_DEFINE_CATEGORY(RPI) namespace { +/* Map of mbus codes to supported sizes reported by the sensor. */ +using SensorFormats = std::map>; + +SensorFormats populateSensorFormats(std::unique_ptr &sensor) +{ + SensorFormats formats; + + for (auto const mbusCode : sensor->mbusCodes()) + formats.emplace(mbusCode, sensor->sizes(mbusCode)); + + return formats; +} + +PixelFormat mbusCodeToPixelFormat(unsigned int mbus_code, + BayerFormat::Packing packingReq) +{ + BayerFormat bayer = BayerFormat::fromMbusCode(mbus_code); + + ASSERT(bayer.isValid()); + + bayer.packing = packingReq; + PixelFormat pix = bayer.toPixelFormat(); + + /* + * Not all formats (e.g. 8-bit or 16-bit Bayer formats) can have packed + * variants. So if the PixelFormat returns as invalid, use the non-packed + * conversion instead. + */ + if (!pix.isValid()) { + bayer.packing = BayerFormat::Packing::None; + pix = bayer.toPixelFormat(); + } + + return pix; +} + +V4L2DeviceFormat toV4L2DeviceFormat(const V4L2SubdeviceFormat &format, + BayerFormat::Packing packingReq) +{ + const PixelFormat pix = mbusCodeToPixelFormat(format.mbus_code, packingReq); + V4L2DeviceFormat deviceFormat; + + deviceFormat.fourcc = V4L2PixelFormat::fromPixelFormat(pix); + deviceFormat.size = format.size; + return deviceFormat; +} + bool isRaw(PixelFormat &pixFmt) { /* @@ -74,11 +122,10 @@ double scoreFormat(double desired, double actual) return score; } -V4L2DeviceFormat findBestMode(V4L2VideoDevice::Formats &formatsMap, - const Size &req) +V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &req) { double bestScore = std::numeric_limits::max(), score; - V4L2DeviceFormat bestMode; + V4L2SubdeviceFormat bestFormat; #define PENALTY_AR 1500.0 #define PENALTY_8BIT 2000.0 @@ -88,19 +135,19 @@ V4L2DeviceFormat findBestMode(V4L2VideoDevice::Formats &formatsMap, /* Calculate the closest/best mode from the user requested size. */ for (const auto &iter : formatsMap) { - V4L2PixelFormat v4l2Format = iter.first; - const PixelFormatInfo &info = PixelFormatInfo::info(v4l2Format); + const unsigned int mbusCode = iter.first; + const PixelFormat format = mbusCodeToPixelFormat(mbusCode, + BayerFormat::Packing::None); + const PixelFormatInfo &info = PixelFormatInfo::info(format); - for (const SizeRange &sz : iter.second) { - double modeWidth = sz.contains(req) ? req.width : sz.max.width; - double modeHeight = sz.contains(req) ? req.height : sz.max.height; + for (const Size &size : iter.second) { double reqAr = static_cast(req.width) / req.height; - double modeAr = modeWidth / modeHeight; + double fmtAr = size.width / size.height; /* Score the dimensions for closeness. */ - score = scoreFormat(req.width, modeWidth); - score += scoreFormat(req.height, modeHeight); - score += PENALTY_AR * scoreFormat(reqAr, modeAr); + score = scoreFormat(req.width, size.width); + score += scoreFormat(req.height, size.height); + score += PENALTY_AR * scoreFormat(reqAr, fmtAr); /* Add any penalties... this is not an exact science! */ if (!info.packed) @@ -115,18 +162,18 @@ V4L2DeviceFormat findBestMode(V4L2VideoDevice::Formats &formatsMap, if (score <= bestScore) { bestScore = score; - bestMode.fourcc = v4l2Format; - bestMode.size = Size(modeWidth, modeHeight); + bestFormat.mbus_code = mbusCode; + bestFormat.size = size; } - LOG(RPI, Info) << "Mode: " << modeWidth << "x" << modeHeight - << " fmt " << v4l2Format.toString() + LOG(RPI, Info) << "Format: " << size.toString() + << " fmt " << format.toString() << " Score: " << score << " (best " << bestScore << ")"; } } - return bestMode; + return bestFormat; } enum class Unicam : unsigned int { Image, Embedded }; @@ -170,6 +217,7 @@ public: std::unique_ptr ipa_; std::unique_ptr sensor_; + SensorFormats sensorFormats_; /* Array of Unicam and ISP device streams and associated buffers/streams. */ RPi::Device unicam_; RPi::Device isp_; @@ -352,9 +400,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * Calculate the best sensor mode we can use based on * the user request. */ - V4L2VideoDevice::Formats fmts = data_->unicam_[Unicam::Image].dev()->formats(); - V4L2DeviceFormat sensorFormat = findBestMode(fmts, cfg.size); - int ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&sensorFormat); + V4L2SubdeviceFormat sensorFormat = findBestFormat(data_->sensorFormats_, cfg.size); + V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorFormat, + BayerFormat::Packing::CSI2); + int ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&unicamFormat); if (ret) return Invalid; @@ -366,7 +415,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * fetch the "native" (i.e. untransformed) Bayer order, * because the sensor may currently be flipped! */ - V4L2PixelFormat fourcc = sensorFormat.fourcc; + V4L2PixelFormat fourcc = unicamFormat.fourcc; if (data_->flipsAlterBayerOrder_) { BayerFormat bayer = BayerFormat::fromV4L2PixelFormat(fourcc); bayer.order = data_->nativeBayerOrder_; @@ -375,15 +424,15 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() } PixelFormat sensorPixFormat = fourcc.toPixelFormat(); - if (cfg.size != sensorFormat.size || + if (cfg.size != unicamFormat.size || cfg.pixelFormat != sensorPixFormat) { - cfg.size = sensorFormat.size; + cfg.size = unicamFormat.size; cfg.pixelFormat = sensorPixFormat; status = Adjusted; } - cfg.stride = sensorFormat.planes[0].bpl; - cfg.frameSize = sensorFormat.planes[0].size; + cfg.stride = unicamFormat.planes[0].bpl; + cfg.frameSize = unicamFormat.planes[0].size; rawCount++; } else { @@ -472,7 +521,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, { RPiCameraData *data = cameraData(camera); CameraConfiguration *config = new RPiCameraConfiguration(data); - V4L2DeviceFormat sensorFormat; + V4L2SubdeviceFormat sensorFormat; unsigned int bufferCount; PixelFormat pixelFormat; V4L2VideoDevice::Formats fmts; @@ -487,9 +536,9 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, switch (role) { case StreamRole::Raw: size = data->sensor_->resolution(); - fmts = data->unicam_[Unicam::Image].dev()->formats(); - sensorFormat = findBestMode(fmts, size); - pixelFormat = sensorFormat.fourcc.toPixelFormat(); + sensorFormat = findBestFormat(data->sensorFormats_, size); + pixelFormat = mbusCodeToPixelFormat(sensorFormat.mbus_code, + BayerFormat::Packing::CSI2); ASSERT(pixelFormat.isValid()); bufferCount = 2; rawCount++; @@ -572,6 +621,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) for (auto const stream : data->streams_) stream->reset(); + BayerFormat::Packing packing = BayerFormat::Packing::CSI2; Size maxSize, sensorSize; unsigned int maxIndex = 0; bool rawStream = false; @@ -590,6 +640,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) */ sensorSize = cfg.size; rawStream = true; + /* Check if the user has explicitly set an unpacked format. */ + packing = BayerFormat::fromPixelFormat(cfg.pixelFormat).packing; } else { if (cfg.size > maxSize) { maxSize = config->at(i).size; @@ -615,24 +667,21 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) } /* First calculate the best sensor mode we can use based on the user request. */ - V4L2VideoDevice::Formats fmts = data->unicam_[Unicam::Image].dev()->formats(); - V4L2DeviceFormat sensorFormat = findBestMode(fmts, rawStream ? sensorSize : maxSize); - - ret = data->unicam_[Unicam::Image].dev()->setFormat(&sensorFormat); + V4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize); + ret = data->sensor_->setFormat(&sensorFormat); if (ret) return ret; - /* - * The control ranges associated with the sensor may need updating - * after a format change. - * \todo Use the CameraSensor::setFormat API instead. - */ - data->sensor_->updateControlInfo(); + V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorFormat, packing); + ret = data->unicam_[Unicam::Image].dev()->setFormat(&unicamFormat); + if (ret) + return ret; LOG(RPI, Info) << "Sensor: " << camera->id() - << " - Selected mode: " << sensorFormat.toString(); + << " - Selected sensor format: " << sensorFormat.toString() + << " - Selected unicam format: " << unicamFormat.toString(); - ret = data->isp_[Isp::Input].dev()->setFormat(&sensorFormat); + ret = data->isp_[Isp::Input].dev()->setFormat(&unicamFormat); if (ret) return ret; @@ -754,8 +803,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) data->ispMinCropSize_ = testCrop.size(); /* Adjust aspect ratio by providing crops on the input image. */ - Size size = sensorFormat.size.boundedToAspectRatio(maxSize); - Rectangle crop = size.centeredTo(Rectangle(sensorFormat.size).center()); + Size size = unicamFormat.size.boundedToAspectRatio(maxSize); + Rectangle crop = size.centeredTo(Rectangle(unicamFormat.size).center()); data->ispCrop_ = crop; data->isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &crop); @@ -769,8 +818,11 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) * supports it. */ if (data->sensorMetadata_) { - format = {}; + V4L2SubdeviceFormat embeddedFormat; + + data->sensor_->device()->getFormat(1, &embeddedFormat); format.fourcc = V4L2PixelFormat(V4L2_META_FMT_SENSOR_DATA); + format.planes[0].size = embeddedFormat.size.width * embeddedFormat.size.height; LOG(RPI, Debug) << "Setting embedded data format."; ret = data->unicam_[Unicam::Embedded].dev()->setFormat(&format); @@ -1000,6 +1052,8 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) if (data->sensor_->init()) return false; + data->sensorFormats_ = populateSensorFormats(data->sensor_); + ipa::RPi::SensorConfig sensorConfig; if (data->loadIPA(&sensorConfig)) { LOG(RPI, Error) << "Failed to load a suitable IPA library"; @@ -1026,6 +1080,11 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) return false; } + if (!data->unicam_[Unicam::Image].dev()->caps().hasMediaController()) { + LOG(RPI, Error) << "Unicam driver does not use the MediaController, please update your kernel!"; + return false; + } + /* * Setup our delayed control writer with the sensor default * gain and exposure delays. Mark VBLANK for priority write. @@ -1035,7 +1094,7 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) { V4L2_CID_EXPOSURE, { sensorConfig.exposureDelay, false } }, { V4L2_CID_VBLANK, { sensorConfig.vblankDelay, true } } }; - data->delayedCtrls_ = std::make_unique(data->unicam_[Unicam::Image].dev(), params); + data->delayedCtrls_ = std::make_unique(data->sensor_->device(), params); data->sensorMetadata_ = sensorConfig.sensorMetadata; /* Register the controls that the Raspberry Pi IPA can handle. */ @@ -1062,15 +1121,14 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) * As part of answering the final question, we reset the camera to * no transform at all. */ - - V4L2VideoDevice *dev = data->unicam_[Unicam::Image].dev(); - const struct v4l2_query_ext_ctrl *hflipCtrl = dev->controlInfo(V4L2_CID_HFLIP); + const V4L2Subdevice *sensor = data->sensor_->device(); + const struct v4l2_query_ext_ctrl *hflipCtrl = sensor->controlInfo(V4L2_CID_HFLIP); if (hflipCtrl) { /* We assume it will support vflips too... */ data->supportsFlips_ = true; data->flipsAlterBayerOrder_ = hflipCtrl->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT; - ControlList ctrls(dev->controls()); + ControlList ctrls(data->sensor_->controls()); ctrls.set(V4L2_CID_HFLIP, 0); ctrls.set(V4L2_CID_VFLIP, 0); data->setSensorControls(ctrls); @@ -1078,9 +1136,8 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) /* Look for a valid Bayer format. */ BayerFormat bayerFormat; - for (const auto &iter : dev->formats()) { - V4L2PixelFormat v4l2Format = iter.first; - bayerFormat = BayerFormat::fromV4L2PixelFormat(v4l2Format); + for (const auto &iter : data->sensorFormats_) { + bayerFormat = BayerFormat::fromMbusCode(iter.first); if (bayerFormat.isValid()) break; } @@ -1263,7 +1320,7 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) } } - entityControls.emplace(0, unicam_[Unicam::Image].dev()->controls()); + entityControls.emplace(0, sensor_->controls()); entityControls.emplace(1, isp_[Isp::Input].dev()->controls()); /* Always send the user transform to the IPA. */ @@ -1387,10 +1444,10 @@ void RPiCameraData::setSensorControls(ControlList &controls) ControlList vblank_ctrl; vblank_ctrl.set(V4L2_CID_VBLANK, controls.get(V4L2_CID_VBLANK)); - unicam_[Unicam::Image].dev()->setControls(&vblank_ctrl); + sensor_->setControls(&vblank_ctrl); } - unicam_[Unicam::Image].dev()->setControls(&controls); + sensor_->setControls(&controls); } void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) From patchwork Thu Oct 28 08:46:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14385 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8EBC4BF415 for ; Thu, 28 Oct 2021 08:47:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 49BB2600BA; Thu, 28 Oct 2021 10:47:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="nXSYDrQC"; dkim-atps=neutral Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 883E1600C6 for ; Thu, 28 Oct 2021 10:46:59 +0200 (CEST) Received: by mail-wr1-x431.google.com with SMTP id z14so8796751wrg.6 for ; Thu, 28 Oct 2021 01:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l2aBYZ7AsH1FcO9lnVpab/qb2Bw69co6fVhKXhX3xcg=; b=nXSYDrQCFrE/sQzE2TLPZ/4F9y6GU33SkXuh1EV0ilpWQzw/iA4Wv9PbLTve07G+9Y iSlg6Wj/5CaN1yO9yha/UR56je7gk7aWYzTS4/HmpKckXfW69PDl7GENW0lqvx1wAjOm NXHspmInoiJFUr7Ezs8SAG+LFgizcuItN/ZuNXFuOLvLPNayWJl70yiXtQTvx2ndIe/Y ZbWA9/4tDaMcr++xvecvgpvVgs4ozmGqVo4WoHKeVwcNdX/wa46+Xv+VMOYs9rEnBvSE 17hoirmdjHhVBfoDdGHThZeBlgvQtA8/DEjSIOXTiTSHGVD1AUy0eVQELDYM1xHahULD yIeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l2aBYZ7AsH1FcO9lnVpab/qb2Bw69co6fVhKXhX3xcg=; b=dOQlP4uhQtZnRKXCGi2gRWJ6HOUTnkKx43Xc3eqJYDaQkcJjfwT+NRuucAJOdZSgyI +4NiZ+ZejzCf0IUgope3DbRZQWT4T06uBaRROC9Pmk91+KOZdn9ZCq9OBPBGRbgtfVPm pwMi1mS/x3Q6XDtlMWHjuPgzcauUkio27TD+0J/Wib01cLXqrfxlVqmSYkaSKG4AVVB9 GyOqkE1HRZqL2ie1QV94vKAfvuVacO3dTYOSpPd1N7QrOT302lmSyO+214kqhKuXtAAs o5Amu4hl43V8yRr/mPnhVdl8BY5Ki2p5l20ESpFvFUz8j+VgboIXRVBGEhhGCfnGaQnj uqFg== X-Gm-Message-State: AOAM5323LEMa7JJVXEAnOlOATFeIJIU/pqOtHS/TNAk52PguphJcvwzC +aD0Iv0VkMQRPZWtOyamIC9/uudaqwr7MnwG X-Google-Smtp-Source: ABdhPJwW8P6mhAmCXBE/xppFPez1UWZ79uQaFJQv9/IvzHGosWmYWl36ybxgqPKfzpP9vtApouZRQQ== X-Received: by 2002:a05:6000:15c8:: with SMTP id y8mr3917625wry.377.1635410819059; Thu, 28 Oct 2021 01:46:59 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:58 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:45 +0100 Message-Id: <20211028084646.453775-10-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 09/10] pipeline: raspberrypi: Remove "unpacked" format penalty in mode selection X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" With the recent change to switch to programming the sensor device directly, the notion of packed vs unpacked modes are not relevent, since that is a Unicam format construct. Remove any scoring based on packed/unpacked modes. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 8e3e96a4359f..b405e2d55d57 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -131,7 +131,6 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size & #define PENALTY_8BIT 2000.0 #define PENALTY_10BIT 1000.0 #define PENALTY_12BIT 0.0 -#define PENALTY_UNPACKED 500.0 /* Calculate the closest/best mode from the user requested size. */ for (const auto &iter : formatsMap) { @@ -150,9 +149,6 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size & score += PENALTY_AR * scoreFormat(reqAr, fmtAr); /* Add any penalties... this is not an exact science! */ - if (!info.packed) - score += PENALTY_UNPACKED; - if (info.bitsPerPixel == 12) score += PENALTY_12BIT; else if (info.bitsPerPixel == 10) From patchwork Thu Oct 28 08:46:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14386 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 22814C3250 for ; Thu, 28 Oct 2021 08:47:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BDE4E60326; Thu, 28 Oct 2021 10:47:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="od0a5EV5"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 52776600BE for ; Thu, 28 Oct 2021 10:47:00 +0200 (CEST) Received: by mail-wr1-x434.google.com with SMTP id p14so8746909wrd.10 for ; Thu, 28 Oct 2021 01:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ueF6YVs7qys6bUFyj/crs11+E3JnkIbKFR1VrLXwuto=; b=od0a5EV5ddg/Wsa+jGrztrjFD7knJbvSV5le+kKuEzkG1sYT+pCCZonEgdxYiMJDct HwIxnHH3ax9n2+O/R7nGxVG3pATWqAkxlEOTgP3wkInOU41qnpZQup8jw09Y2zZ8iFpR 0fXe541A/T1L69dLp/168mTjs6MXwYtXMxSJQX+TDsqlXefrT8K5letfBgB67mE+aD3C +nR0GQSRxNC3fotPSxQo0XyMmbZPVKW5Ov1Esi3oCaoHDLzbFePXpQwbF3s9poiNGk3h 0tE6kP9velcj0LLIz8jI/Vhg5mbdMrhWGfYUGJKrE0T+Sng1lWkQfebKSE3QRJBsERP3 lTJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ueF6YVs7qys6bUFyj/crs11+E3JnkIbKFR1VrLXwuto=; b=g8dSatzEn0B6JolsuaavVkHLoZD7QDmL0cWaN0dY+e41Fo6qXFG7bGECl2IoFP08kl APIvnt/mLHfMq3EtHly5xhZFOVfaqptncUPv//KSX3C/sNt+jNuxtmUGfN0lo/ftyFZB Q1X4vw19yujKEJMIH29Pbh/0ae88/2L3UFZbQzKam0N7Qj58fdBA6cHDK8GaoZE24e07 yElWJpA/1sNb5KzXNfELg6wd0BgfttgGUyLzvuzr0FdZyjT4YXaV3MbbJT8aNDW6lRj9 V19dnrjtoZcxcXg7MsUoTmdaigoSpfzGBC/za5KAf8igAWTc+T+KIoQTPXewehKsS8EM 4yqw== X-Gm-Message-State: AOAM531hA2wHNFZ3kBPVwUgyXGey5eNGdfssSGBl7mp3fUun9x8inKB/ mXJRjqhCM9E4PL8MhTwQ7pnI0u+dwrn4Sagd X-Google-Smtp-Source: ABdhPJzXXfSZqR/BbtEF+Zsi06IQryjqvG8+TW9KJykiY7KErgjC6aB91vp5yNMePOc1IcZsCcQBxA== X-Received: by 2002:adf:d1ee:: with SMTP id g14mr3916366wrd.165.1635410819825; Thu, 28 Oct 2021 01:46:59 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:b894:feb0:b828:13b]) by smtp.gmail.com with ESMTPSA id z2sm1955281wmk.19.2021.10.28.01.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 01:46:59 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 09:46:46 +0100 Message-Id: <20211028084646.453775-11-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028084646.453775-1-naush@raspberrypi.com> References: <20211028084646.453775-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 10/10] pipeline: raspberrypi: Account for a missing Unicam embedded data node X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The unicam driver no longer registers an embedded data node if the sensor does not provide this stream. Account for this in the pipeline handler match routine by not assuming it is always present. Add a warning if Unicam and the CamHelper do not agree on the presense of sensor embedded data, and disable its usage in these cases. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- .../pipeline/raspberrypi/raspberrypi.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index b405e2d55d57..36f648804878 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -995,7 +995,6 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) DeviceMatch unicam("unicam"); DeviceMatch isp("bcm2835-isp"); - unicam.add("unicam-embedded"); unicam.add("unicam-image"); isp.add("bcm2835-isp0-output0"); /* Input */ @@ -1016,9 +1015,16 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) return false; /* Locate and open the unicam video streams. */ - data->unicam_[Unicam::Embedded] = RPi::Stream("Unicam Embedded", unicam_->getEntityByName("unicam-embedded")); data->unicam_[Unicam::Image] = RPi::Stream("Unicam Image", unicam_->getEntityByName("unicam-image")); + /* An embedded data node will not be present if the sensor does not support it. */ + MediaEntity *embeddedEntity = unicam_->getEntityByName("unicam-embedded"); + if (embeddedEntity) { + data->unicam_[Unicam::Embedded] = RPi::Stream("Unicam Embedded", embeddedEntity); + data->unicam_[Unicam::Embedded].dev()->bufferReady.connect(data.get(), + &RPiCameraData::unicamBufferDequeue); + } + /* Tag the ISP input stream as an import stream. */ data->isp_[Isp::Input] = RPi::Stream("ISP Input", isp_->getEntityByName("bcm2835-isp0-output0"), true); data->isp_[Isp::Output0] = RPi::Stream("ISP Output0", isp_->getEntityByName("bcm2835-isp0-capture1")); @@ -1028,7 +1034,6 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) /* Wire up all the buffer connections. */ data->unicam_[Unicam::Image].dev()->frameStart.connect(data.get(), &RPiCameraData::frameStarted); data->unicam_[Unicam::Image].dev()->bufferReady.connect(data.get(), &RPiCameraData::unicamBufferDequeue); - data->unicam_[Unicam::Embedded].dev()->bufferReady.connect(data.get(), &RPiCameraData::unicamBufferDequeue); data->isp_[Isp::Input].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispInputDequeue); data->isp_[Isp::Output0].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispOutputDequeue); data->isp_[Isp::Output1].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispOutputDequeue); @@ -1056,6 +1061,13 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) return false; } + if (sensorConfig.sensorMetadata ^ !!embeddedEntity) { + LOG(RPI, Warning) << "Mismatch between Unicam and CamHelper for embedded data usage!"; + sensorConfig.sensorMetadata = false; + if (embeddedEntity) + data->unicam_[Unicam::Embedded].dev()->bufferReady.disconnect(); + } + /* * Open all Unicam and ISP streams. The exception is the embedded data * stream, which only gets opened below if the IPA reports that the sensor