From patchwork Mon Nov 1 09:15:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14436 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 C8308BDB1C for ; Mon, 1 Nov 2021 09:15:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 977F8600C9; Mon, 1 Nov 2021 10:15:16 +0100 (CET) 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="ZhqkPIBy"; 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 8299F600BD for ; Mon, 1 Nov 2021 10:15:14 +0100 (CET) Received: by mail-wr1-x42b.google.com with SMTP id b12so22728220wrh.4 for ; Mon, 01 Nov 2021 02:15:14 -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=ZhqkPIByu5gZ3pPu4Nc7C1KzB0m7YQHoqjpwsT7P2L9daINh+oWG4NraMGywaW/5KX B72Y4IwdHNKh7MAoIaBGsYRN9QaLTRIwDhpf5SiUlLbQ6yuU9Pa8R9tYN8p8KqI6pcHm aZsEJxIVUxuNub7eAG5G4hBnO4dsgXQWBVeUmbFIlaPqwoZJXE0eYtOsZOTcVnZgcsfU i4eL+IzHSBBvLM7LTRhwhUQNsKKOBS7EJdDEGgzUNY2ks0Ra7OEyeN3vTS4qbBlrjow7 HnbmZu7PGdj0WRO0N+5v0Z/DpjCFKffWF8cXbsW20kfiewd0rIt5PGU7QW9vru/o2XeR dZXA== 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=c45JEpR5roxqIxemeeRf4DOmrn4mkIfuERvtwHOsOwlYHo3x67Ak9J4H8lC1yBt5f1 qJj2uBl/+LjLzUZfqjNoZvyHibpzQXQJpu/Kzet+HHrl8m/+LbRB18uJKuOy5E1W0eub BVSf5+EJpOcCTK8P2C3+8WAhGO5IJx/ylzj0YZw7Tk79c8l9OlXWx0tn5NSh0pVZ23Dw ksHVRRDbBIzfUqA/Tgn86K79nbSHIvObm0GiQ4geDT51+Aohyyb6VtxfDW5eO+N3xCSz y3IMv+dt8jxAwtUbntxuZy2Rn8+SzuYIVzFGGMBCv+RDI/NSlfCy5vSuO4T4Ql+hoOxs aK6g== X-Gm-Message-State: AOAM531LqkMqco2u9NPiA116G2W4HeglMN4LDxBAMA6c4RQAJj4AAie2 +WdbI46GK2/ksEmwLjXa7IRsFg/8IdY19H/6 X-Google-Smtp-Source: ABdhPJzmkRLSAK6wAaf2srdLeK3YMQ9Lc+EXNaf7HxN0dCrM3yAVF98lpqdWzm29qITRvVHODduovQ== X-Received: by 2002:a5d:69c5:: with SMTP id s5mr33074229wrw.283.1635758113920; Mon, 01 Nov 2021 02:15:13 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:13 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:00 +0000 Message-Id: <20211101091510.23204-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 01/11] 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 Mon Nov 1 09:15:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14437 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 04367BDB1C for ; Mon, 1 Nov 2021 09:15:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 18A2760125; Mon, 1 Nov 2021 10:15:17 +0100 (CET) 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="jLGi/aCm"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1022F600BF for ; Mon, 1 Nov 2021 10:15:15 +0100 (CET) Received: by mail-wr1-x436.google.com with SMTP id r8so14352900wra.7 for ; Mon, 01 Nov 2021 02:15:15 -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=jLGi/aCmhSCQk8/fgy9+QcXhjWeYj+jclttvdJz0BvsZAhrnID08trusMCpgLgeBdi TLR/G5LWKZn+0X2U13lUSYH+MnPRCQDqjXHFw5cqNgJwwIwn24ISl6taXNreJBmHvWEB PFu9Sg1Plm5pBlK33Y5PzPKBEFzA8OXsNmJT3Z0c15luNvYxuJFBQqZ43ubG3RHKde9J SjVVvQZhO8DwqwhuAKPMEmCLVwutoBie8ejyzo5Lf0vp5ow8xHjUYGlFrZVzAQcIcm4O Ik925Nf/bY6E4t0PIGrctpS+0YgYANYnyS7/fxeAak1oDqflRiBPHoxM0r/M/Jpb7Rv0 Y6yA== 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=e/myiRDJNCQ5WZOU3FIvETS3VBIkGoPpqfmetIXCQJyk5UUOluHqMaVabLNfUek53z yKlNNEemC9Si5c5irwBo0ZgAJjcCjKsYfVrtIBgB51XHyd695105mkZL9NYQYHliQGXb BAICb2hNj8X4OhKQaeO8tE3lS3ctFjwBgtnOD3R/f34nfVvX8zb1ny4sYReb9T8RRB9b fgUdiOGo4ZehcFn252IL3eIlD31vPydELsUcWOyPy7RfJXS5WhjG4MZa+b+kCgXqfIVf NIRD7a1frYhefMPRXGqyZ4U5STzRYbED+XSDREfYJxj3pEV5/Jwkz58fjSRBjvxsc6za XfnA== X-Gm-Message-State: AOAM531UL46vruTpy0aXFcY9lUHB1X4GqwYJIKv+7nIzJa3EPNVio19m +zm2WgEoebgHH+Vp/JPNCpWvxEU9xqiCl/ej X-Google-Smtp-Source: ABdhPJx/V4+SKPprUDTKMDsHvAjwq1+SyZeAehJmUyLcGtk6h+stj4BPZU47ByZRnUUdLoH7Lr53kg== X-Received: by 2002:a05:6000:1a86:: with SMTP id f6mr36444997wry.343.1635758114621; Mon, 01 Nov 2021 02:15:14 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:14 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:01 +0000 Message-Id: <20211101091510.23204-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 02/11] 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 Mon Nov 1 09:15:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14438 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 985E0C324E for ; Mon, 1 Nov 2021 09:15:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 92139600F9; Mon, 1 Nov 2021 10:15:17 +0100 (CET) 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="oCEtz6RQ"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A6F4E600BF for ; Mon, 1 Nov 2021 10:15:15 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id r8so14352939wra.7 for ; Mon, 01 Nov 2021 02:15:15 -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=euyjLCE+1e2oMFePuUF4DYfqmMu3lRUlmwKChksNLN0=; b=oCEtz6RQNyynQ6OqQPd4GJ+ri10P4QAhqeDNj6jCg1LvjKCauohzX1AGrGtB37N2Zd ZgRcamtZbgJmdZuUT3Z1Pj1hEOWO4D+V3SurB853GqjqazuluOTMNR+3DbnGpzgDuV2u nivHbC4KC4llojj/VwHsi+dvckg0I+nM1+6TAcHz9OmeeiPD6jstqA5sfWJ5QKA3iqrb HKQCpW2xaIqsTmq++qcbGEJ59xG4lIHucsJCNCZuSZe7c7DHQhzTTBK022Z2BFLUU5Y6 f+jmA1wGVnnnl/vTmJX6hB3IrnbuUGpV/ZfFGuK+VRW9q49lMhzO32YEr/XkFINq3ezc XW7Q== 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=euyjLCE+1e2oMFePuUF4DYfqmMu3lRUlmwKChksNLN0=; b=ZAWOAvuANbNKtVWcRjHUnD9Ux05wB6zjx1hEaU5YWrC4tl1rG/AMcU5SDTOubDmZLR paFiZs8WrU64viNnR40K40WsEvMlyhMPo2kzt3hG5IfcKTOzlCJRITn9MyeQ5vEHbfHh rYInFsFEG5dYf9G9TxYKg1Gmvizmw4W/IR6arjRbSinSk/znBucumys7D3dxgmaAf7Mi aa+uB60sMwiawMHXgI9qSs/LX44P8evKZ4OI0nNNoRKLi//RLBZm9SjeAYwMaSEAcyJz Lim/MT6UKacNTLOymqfixelelDH0BxONNm8Pfd9FOmET9EzASQ9SoASpJrG+4QSdOJIf xHPg== X-Gm-Message-State: AOAM533SUdMOx7CWbbmQBjRa9Bn9eQ3XibJiOJh94cvFDcq/Zw74u6mk deWThtnhE6Kb9IACQ8o/Nz4h9XJoOSFVlc6r X-Google-Smtp-Source: ABdhPJx+UGqo0hJy+97SvLRC31s5f+Y6jFusS7BcSZekFH0NY9tmPqXLaEClFEmycRfqOetVPQIWsg== X-Received: by 2002:a5d:44d1:: with SMTP id z17mr24994211wrr.143.1635758115226; Mon, 01 Nov 2021 02:15:15 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:14 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:02 +0000 Message-Id: <20211101091510.23204-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 03/11] 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 Reviewed-by: Kieran Bingham --- 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..afcaabc519f7 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 = 4, + .planes = {{ { 5, 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 Mon Nov 1 09:15:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14439 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 3E2D9BDB1C for ; Mon, 1 Nov 2021 09:15:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8648F60128; Mon, 1 Nov 2021 10:15:20 +0100 (CET) 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="I1oLSZxr"; dkim-atps=neutral Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A4AED60103 for ; Mon, 1 Nov 2021 10:15:16 +0100 (CET) Received: by mail-wr1-x42f.google.com with SMTP id b12so22728372wrh.4 for ; Mon, 01 Nov 2021 02:15:16 -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=wPwP+7gLyC1NYrW5yRF6O6abO9wP5U7Ay5h40dfr6kc=; b=I1oLSZxrFpsdrYEGplp3dFLYqS3RcBsPSGZP+UoQxOwHIWyqamHawbNSOFg7f3yYmC JSRmAd4VG7Few41zMxUH83NTu8E64uaZUP8JGULx//gXhBITu9qN5CG+Hh0gpyRDa8Hs FrpfLFoGdhMN50NwBUD4pZAtOqwFtrA07gK1NL5Sf1pVsYCuLy6Pb56HlKyoG2v5JHgb v3mzU5jnoqOD+81p7tupkTmU7tu2GJ3v4Mua+tbmKnJ7T1gYSmFGPrwSYCSrPsWHlPyi uL9PMArVcTpiaGXQBV4MnfKi3+9dSd7kiF/g6NMEV6z+jO8Cw3Aa/lMgcM2VPATXTe8k k3iw== 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=wPwP+7gLyC1NYrW5yRF6O6abO9wP5U7Ay5h40dfr6kc=; b=g1McqV9G81EjTX96CKwLsyDcPG6Vy8fA+jKlFgozpUS1AwfrQXRsKtu3iQ+clZFbsz NILca5k8Oo6GN1zxUmjltdMrMiUu+Ot6Lt9QIlx2Q8YCUzulNKBKdfE5hAplzhkhJz2+ /sipbTcSFiuLzFFuA5CWLWK+ySU/6ckVhvqNaE2jARhWXJCz32hXpDXyyl/cstcFZy5i nEiMlh3dGYpivRMdqTwznEIadHdVqUVVyEy/lIhGcCPey+Dc2RYXvmvYy/4XdM+OMn2i zPxSJjoqKetprr1r0C0E1/5T1c9GrCDJApcxaJh98hoZohN7bUcoloqLVP3F2OZimlcd cDSw== X-Gm-Message-State: AOAM5322c5w8YSi1/Hw/I62Q5RAvwGXTjdU/clvqLX01zELNm177IzHB 03AbQ2fGc5XFYZ1ClWYo3yN79nwF0M8RV3sO X-Google-Smtp-Source: ABdhPJw9l8l/+Ul+/1YFgAa9YVxymyjKgek7Yf1QyO8e4+ohOP64/GcX3GRWzn6KHKM7UL/FuMF+zw== X-Received: by 2002:adf:a152:: with SMTP id r18mr37053570wrr.317.1635758115881; Mon, 01 Nov 2021 02:15:15 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:15 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:03 +0000 Message-Id: <20211101091510.23204-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 04/11] 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-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 Mon Nov 1 09:15:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14440 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 9C77CC324F for ; Mon, 1 Nov 2021 09:15:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 30AFA60329; Mon, 1 Nov 2021 10:15:21 +0100 (CET) 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="W6Nf2gX5"; 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 0D14C60123 for ; Mon, 1 Nov 2021 10:15:17 +0100 (CET) Received: by mail-wm1-x32c.google.com with SMTP id v127so12816751wme.5 for ; Mon, 01 Nov 2021 02:15:17 -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=4h+Hq4Z7h1kX/XifGZPKWYh0O2oL6hH6gJ4EJSh8gwU=; b=W6Nf2gX5QmXPlUV8hdaZujjALynBXnx7iaeYLrjiXeiLL9ZTDWkk5Y7W1RB8GV7lz7 Q0K48guCqkkK6oxVV+eNQQ7rMhHk+xTvv37ycXZuVBB+z2cpxsaVOgd0iP6j/K0/L+rT bvr8yke3Dddxod+hJ8uJDKg+ZHbF9jozLebKeQi9iVHPYbAQz8nrDRVvBkT4OHLSDOYW 6j78ffEXIFSw2cma4lzQ9+RF/WCE7pgV5HrkjJVV4a6lfsT2WJjG8awCH8aGA0Ak0TF1 NuR7ITRBeOyEQSFGXIXFQEHwgApN1xqe8pD8Gxrgn29BTrjvk4qur/B7aomA4O9u34TL 80pA== 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=4h+Hq4Z7h1kX/XifGZPKWYh0O2oL6hH6gJ4EJSh8gwU=; b=ivlfA9A+XF/zECdXf/CyOARQaZjNffFClpmqQ03b7SGOM1sBW6l1HZpxw0BIlaM0p5 vp2LGX7Kvvs9weZEGkQUk4qQugVC63OjMzLTm65rM7Nw6/itLgjdpPoIajZYwuhvcmML L/eCCMrISjSWRKbez5gLDn/jLwBQrPv6CW2cXcHYa07Csmx7PdE/WumkhO2TMLCbSbr3 sGDXZN3c2oFXnOW7YpgbSXQNcV1SSK67Qgoj/9/HzT19Ow1j/PgCpF7Eo4nWaBcqglps RD8aTo0772MPmT6vtcIyi6mvdKP9A9H+1d82HM8xE83ZBhuF3XYubecW6T0pUsUPCLc4 zadQ== X-Gm-Message-State: AOAM53249oOCFiuKnfb7K9RHy/NPkLaZU59lPBQCO+GJYbVOT9ajS28G w0ztnDIpEAwNNuWattgnXzGKt9Lxuk9bn5Tn X-Google-Smtp-Source: ABdhPJzZ0FODq536f1KvQlM7wKlj4K/pXksuN498qj61E3y3VlW3XSNowc0ZtnKOnhfbCkaQgsN/yg== X-Received: by 2002:a05:600c:253:: with SMTP id 19mr6986662wmj.179.1635758116454; Mon, 01 Nov 2021 02:15:16 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:16 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:04 +0000 Message-Id: <20211101091510.23204-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 05/11] 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 | 110 ++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 37 deletions(-) diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 1c1e849a7e31..120115ce8f62 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -13,6 +13,7 @@ #include +#include #include /** @@ -84,37 +85,72 @@ 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::CSI2 }, + { formats::R10_CSI2P, V4L2PixelFormat(V4L2_PIX_FMT_Y10P) } }, }; const std::unordered_map mbusCodeToBayer{ @@ -245,9 +281,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 +295,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 Mon Nov 1 09:15:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14441 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 232D5C3250 for ; Mon, 1 Nov 2021 09:15:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CEB94600C4; Mon, 1 Nov 2021 10:15:21 +0100 (CET) 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="eBaNO+bE"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AF35860128 for ; Mon, 1 Nov 2021 10:15:17 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id u18so27199766wrg.5 for ; Mon, 01 Nov 2021 02:15:17 -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=YesGHpRAyZMpmSPOBCJXtfRxd1p/hEyqkx/brSyO1nk=; b=eBaNO+bEQtD517HXixD2GGZL4sXzIBu+LQIm06cQV94yaRRh+YxevHLgjl3ieWFkpv xGIY1Ops6pRZm11ktne+ETs2DcnsCpQqKNEglAFsrHB1U2EtdgRb/LEhilDwOkPOchpV F7v5hMJtgROlF9qwRIOPtP46x35iCthd5F6AdGWalb+EbU9ghIQ1KE/3fGKvctNHZ2nE akAwuTo1leDI18jvC7Rw+qKWftjjXgeJHaYYEI/dUrpRAP7cWzqgEZq4WHFDKjERArZA 0qOYnX2oUylpUXgm/inUzh0pOrUJFroS7RuQZN7JFi42My73BTWPkFqNlxrJwE9s8feu MaiQ== 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=YesGHpRAyZMpmSPOBCJXtfRxd1p/hEyqkx/brSyO1nk=; b=GrWqCws1Ovlh94yRSmVqGvIZ8FugXfPYVRBRt3a7eGJrDavEL9RqOEwGGPoie2K54p 1F11DvFeVCWmmhFMmNgctZl/m8LrwW5CCvPFOxIM6MoKwwki4XDrpXxaBbfGR/lNpvYc f4/OooWHvALJZeGMjCMdR/dR51oYkrI2XryYsXPDKVxc1wDbY2mJGcz7QhFojouOj//0 JRFCFM4Q4nFpZ4CWYJDRjoWsutSzdnkY3WTLEmOH7mWIjZ0XthiI0wpihPLpj4lhSkVL z8/HkITI8KuoEuVrho1d3PqDGlVAmNawP2nW+E90tMGZUS6vVS710Y0my3Ov9JeNXRIp NrWg== X-Gm-Message-State: AOAM532N90KUGmFoJbdlyj07IF+NlFEtoJiiCNuZNAN/BCGEXuIHrSv7 eEuPcSxm2D0V+TmvMA7u0lhJU/n8M9WgnwZm X-Google-Smtp-Source: ABdhPJz6ziOs1ZkzP85nUYGBHr6RBxOlJqRKkMOqxc38InzmdWkI/YsGHY1xZssuObNqp3Oy/3yaGg== X-Received: by 2002:a5d:648b:: with SMTP id o11mr37081766wri.56.1635758117262; Mon, 01 Nov 2021 02:15:17 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:16 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:05 +0000 Message-Id: <20211101091510.23204-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 06/11] libcamera: bayer_format: Add unpacked mono 10-bit format to the 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" Add BayerFormat conversions for formats::R10 (10-bit unpacked) format. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham --- src/libcamera/bayer_format.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 120115ce8f62..8665a025f7e0 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -149,6 +149,8 @@ const std::map bayerToFormat{ { 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) } }, }; From patchwork Mon Nov 1 09:15:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14442 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 82A9BC324E for ; Mon, 1 Nov 2021 09:15:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 374AA60326; Mon, 1 Nov 2021 10:15:22 +0100 (CET) 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="CC54aEAQ"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5700B600C8 for ; Mon, 1 Nov 2021 10:15:18 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id j128-20020a1c2386000000b003301a98dd62so8282498wmj.5 for ; Mon, 01 Nov 2021 02:15:18 -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=CC54aEAQgdstehTc4vf/gb45MzoUJImCC5bBe/aCpHbkY33409EL3gxNUHfGwsxn7U oDaz+urJ98BgxMZdszkwDCK3uAE6RklCGxwwCLk5uvpSGhR/fvUfcr0ejCKivQSHEbwx Czl2SB8Uyp1ed/1B5nTL1+qrbT+UjephMfIf8FEgvJe8oZqrJEsht9mJf+MJ3nK6so7h nmf3/V0TnPUTPdKo1aOYlRKdXEOKfrcrqJ1smzYZLKHUK4R5KkbxbIhXXwB5zbFbFVCm Lw5anrtqOut5L/qSCxbvmrXJw1I5g1s2VdDDWh9E8PHseAA3dQVAFkye1dTh3Zp2H1xt dsRA== 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=vO6JUGiEiWESJE28akCAzcZGli1sqfUrI1BGUQkifZr1jg0bXicT/MjVDpv7M6KZCy bP5kBsbepUZfSKyNcvRZI8gKT1Udm8vpRAPdaMDz/ngCt3SDb2w/ZPZBDrf1sGlmZ2/+ CQ2bofuSS0+IK6TWRMCMpqb1ZZkSi0FCqf9epFqli8NRt3LabCcZ9LYuEcpl3qncTmEZ +FikpZOE/k6NV+mnmX+NJfv49eM5GLEaIVXxuFdUEGydVa39GgREyT8R29PKDRwH7bXL GYLncLT6e640ih4601E/xHM4+onq+ulm6yRiFydmSGb+Rd9jJMyq0A0Xm7eJzi4MXP0i GF7A== X-Gm-Message-State: AOAM533hJq6trqXAlUz/6gaH9vl+TDVTAbr0+CLgS32HLjkvuMICeoRz 06WRzhRLj9CkSl2QL7Pl61/DpmmtISoRIyQG X-Google-Smtp-Source: ABdhPJxKOdXT/TzHVMjPROpVPMncNJCfvVUj236lj7KOreA4P/HOK1Q+L8HbVJxO/mdrdf0F6Vp9aw== X-Received: by 2002:a05:600c:202:: with SMTP id 2mr11958755wmi.134.1635758117905; Mon, 01 Nov 2021 02:15:17 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:17 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:06 +0000 Message-Id: <20211101091510.23204-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 07/11] 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 Mon Nov 1 09:15:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14443 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 5ABDEBDB1C for ; Mon, 1 Nov 2021 09:15:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 077F7600BB; Mon, 1 Nov 2021 10:15:25 +0100 (CET) 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="R3R/MAqB"; 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 439C860158 for ; Mon, 1 Nov 2021 10:15:19 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id m22so27267312wrb.0 for ; Mon, 01 Nov 2021 02:15:19 -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=R3R/MAqBJYUw1avowwmBHeDPgrDFnj1Z+yGz4FH9OotnQM63gnH9GdRz1PaiMIC1Kr LoTV0Jg4kiUjLqDdPSs4jbet+rI1r2bP+d7+beOFDLo1JDVxsGYo3B3s0p2kl5Dqw6RE UyFoD38FX/7XO4tP+Pt+10PVTCrV4N89q4sXD/U0FrpV0ijm4ABEp5SCMiLKEmJEZJrZ eea+ymZHpMIyfK5hw+B/LZDGsmDAqfF9Kv0CRD/8EhfVdLjnBj4V6dTZmJhnXD7f0W4/ 7FHsJmNZqQkKLf85cSU2iWMN/s8GrUtA3Yhd9T6OmDWNeJKo1ESy/HbSYrrkCTRNl2pj C1Xg== 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=JiJ51Usnl5fM2YeiV6cTKkWMBjcQ17gmyHuqctGACkmLJgSYaZ86qdcRBcTqRU+ca0 MWT5vNoOB3EI/Z1aHZUfGfUIeaYzyDHEVRiLlRP6pZzLm/+RXmIiTQ8MWDK3hTRGgelk 9fa/45qFisYNk7CEhADjzZQWhYNEh1r36AFju9OQXlvp2vJBqJT4j7GbXoWWQ50C4Sr6 dhPrPLfEA5K8KM0fI8BY1pUxaI6qR604F8wPa07F/q/s+Jm/RDSkeE2+XS5uuz1KrjV6 2CzoI1KdgzFhH45gpfS2M4icoCaOMZTeS/2HZsK0kKR46XIfZ0lWOm558ZSLPZ6wp1oK JJFA== X-Gm-Message-State: AOAM530fXCxBVgFNpQvwgM7YQWahpWBk68kvp/Q0o7Ol0rBNzezWJ0ya CIKHXtI5Kfi4YGUysIQ0df2holRLaw0PCucR X-Google-Smtp-Source: ABdhPJzvYu78jYotIPu8SNbi7roCNoNHk4POQK1wl4553eWXzp07nLjSjXVQpJUBQJAXtc75EskYcQ== X-Received: by 2002:adf:c514:: with SMTP id q20mr17722258wrf.420.1635758118617; Mon, 01 Nov 2021 02:15:18 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:18 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:07 +0000 Message-Id: <20211101091510.23204-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 08/11] 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 Mon Nov 1 09:15:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14444 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 F3BB4C324F for ; Mon, 1 Nov 2021 09:15:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A5869600C6; Mon, 1 Nov 2021 10:15:25 +0100 (CET) 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="QenvjKUe"; dkim-atps=neutral Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7D66E60123 for ; Mon, 1 Nov 2021 10:15:20 +0100 (CET) Received: by mail-wr1-x433.google.com with SMTP id d3so27149903wrh.8 for ; Mon, 01 Nov 2021 02:15:20 -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=sSAE2t0TfGnGNvu/KiRxxESSKtU+KguqXz4CdJXHZrQ=; b=QenvjKUejvfLpQo8F5kHeptnDYhlXHAkW9CH5SatITc+erBZUzocJGKxDT6mZLEL+l u0lhDY7+fr3Tj0LFMFR/spX3cPLeXjsImo42EK00VdbUL8bZc6Jd9Y48ZJGixrEl85z3 IqviMKqqVxtV3trtUI3GVt+U/SYmb8E89GtmiR9PGSBRqVsKlACiL2wp70InNl8ikQE4 Ebu0TnRDfwsbMdNGX12a7MP9FvC4fs23M3dVmwxHTPaL+Vv/FwoUSFTrVOQbEp6GIn5D D6fGpQ7tGKg6WezTgW24uvOLB+OoUn93QWKFStGZc29Dussj/EVSs/QYLS+xQjTDF16B OSjQ== 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=sSAE2t0TfGnGNvu/KiRxxESSKtU+KguqXz4CdJXHZrQ=; b=veLmy5hueb4VUvus+PcVkrDb6r03J5X1FPKWkrYjGoL4Y8an7hsYneTFukS36bAh3M GGXrV3lsvG1SQ75h7w653FkvPphRZz+dCXwXdH4fTmIiK6Zi0OlraSsD9RxSB0/iE6Tc 1N/8c6xrT46sQxndNRzxu1iEEczGbRLHz9jTvaW5vPyPPD4pxzkVl0WDBSXFv61GlJIi XB59MHSjVReU+8y5jWfjQWj2OUCmQUKUReEFqvwWEDPDyc44knQi6SgJRXjYbXveClTz p2EqkqU6UpnDvfVhElP1ef+n/SwI33XrY+4eqCI+iH0YQu0ZxLMcV+mhVh9vWzqSTMNQ E2Eg== X-Gm-Message-State: AOAM531+2gLdirThZepr7nIWYFuRpgMpVEIMEskfQKmuq21sUrraPMGn eMdETK638sp5vAaxJYE3s6YGan+aP/Icwh8C X-Google-Smtp-Source: ABdhPJx10KfZwRK0OC42vJ1Asz7qlFM0iIrK+EucX6kC7CtAb9DiwtQBZI9FPZsDxVyDFjKGvHmqNQ== X-Received: by 2002:adf:a2d4:: with SMTP id t20mr36156991wra.229.1635758119596; Mon, 01 Nov 2021 02:15:19 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:18 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:08 +0000 Message-Id: <20211101091510.23204-10-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 09/11] 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 | 173 ++++++++++++------ 1 file changed, 115 insertions(+), 58 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index e078b8b9a811..863516b997b2 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_; @@ -374,16 +423,16 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() fourcc = bayer.toV4L2PixelFormat(); } - PixelFormat sensorPixFormat = fourcc.toPixelFormat(); - if (cfg.size != sensorFormat.size || - cfg.pixelFormat != sensorPixFormat) { - cfg.size = sensorFormat.size; - cfg.pixelFormat = sensorPixFormat; + PixelFormat unicamPixFormat = fourcc.toPixelFormat(); + if (cfg.size != unicamFormat.size || + cfg.pixelFormat != unicamPixFormat) { + cfg.size = unicamFormat.size; + cfg.pixelFormat = unicamPixFormat; 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 Mon Nov 1 09:15:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14445 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 5FEC6C3250 for ; Mon, 1 Nov 2021 09:15:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 185A360253; Mon, 1 Nov 2021 10:15:26 +0100 (CET) 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="nTvif4Eq"; dkim-atps=neutral Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AF4B2600C3 for ; Mon, 1 Nov 2021 10:15:20 +0100 (CET) Received: by mail-wr1-x42e.google.com with SMTP id k7so27090266wrd.13 for ; Mon, 01 Nov 2021 02:15:20 -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=pNLu50p/bpoSwik19pLTW1p9L6Hq5BR0d1Kqq9L4id8=; b=nTvif4EqM9rGa+sartidXDNBQGwx0DR+dJTIysNxh7iRSfL2/22XQHzsIy4RjhZiE7 3ZVnF1ZEqXnrvKcs06oEQe8vibmuWKQQ84uwp1nHcrNVu8oLCqSAhr78GMaRCuFwgowv 4MnGFhqIPH2Vrb6eUhdHFPtvYiS3uEpg0ul+Xwx7KHvy91Lezz8tHhd/tRpC0L5kPtUJ mdlm5O9rAPwAiQHiHOkscVK+FeJmV4tjAPOrb7Sb/uHfVzzQTUMHcrYwbn1+Vj8frVkc SV4WyPT9XSaSINxWucitrGty+05lCI7acpxMRuSwOM5Tbz+0x7LTyLmwlB4rfpNziAY5 tW7Q== 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=pNLu50p/bpoSwik19pLTW1p9L6Hq5BR0d1Kqq9L4id8=; b=3S1ojf/u576l1vRrV5QAiOURXyWMpo2eIsnMzLc4k7S8CT2U+0VndzS7s5YLC8d2k8 dycYT2WDuyCxDQN8QXvBHG8z9HVgq1v/mVNUb+Eae7nGTMG2408GQhXEBZwRhc1g2yec DLRezbF0pk8y42Emga4ZMtmHs16Tia/5U3pOUUTpgPdUSoWT24c5mGeluOWkRbhYKbFd eY6nwr1mheW0hDNuwmYgrwkeI52agmqMj2vZ0XgHTMRjTxmpeezLJkKSioIJ41AkRaSi 2igKAnVH2t2ehcCLO1oSP/Co145zbLWC7CO4dExuM5zlwuv7bZyPsOCddRNgVV+fUB6C +P9g== X-Gm-Message-State: AOAM530v64jANHlRs24u5z8PAwTk1oP4YLrUbdsxeptwYFjFpYpPeWZE NrzF4GwiYCNb0emoWB/BkqxBsB12IzZ0/O1b X-Google-Smtp-Source: ABdhPJzuDArb94LDBeoC77LY9mvs83IDRVZaBQWLyCJTHCn83KQap8VZrs05eqLTslIQlWIN/5xa7A== X-Received: by 2002:adf:a2d7:: with SMTP id t23mr37582496wra.156.1635758120200; Mon, 01 Nov 2021 02:15:20 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:19 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:09 +0000 Message-Id: <20211101091510.23204-11-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 10/11] 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 863516b997b2..996743cf48ef 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 Mon Nov 1 09:15:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14446 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 BB872C3251 for ; Mon, 1 Nov 2021 09:15:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 76FC9600C8; Mon, 1 Nov 2021 10:15:26 +0100 (CET) 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="oyRw+diQ"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 62EEC6032D for ; Mon, 1 Nov 2021 10:15:21 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id d5so11876486wrc.1 for ; Mon, 01 Nov 2021 02:15:21 -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=3PIdxG9cdt0Y7XN4FXtc4NokkaMhwWrDugoWY42qyGY=; b=oyRw+diQOzvtWIHI+OIvYBxfEBug1YYOLmoFv6W6EXza/qc2cqL+KWgYiDONNDKypd UfaE1ZmJzO1HjVw8oKRM3tGJy9vrxmpTgrfGmS3weYEZfElDkikDgItiK8ktz09syVyo tdP1936BIO8ubLvgBeIYVvP72q1eu+V70AZod32Ed8xQvYhpVR3xIi4KnDQM5rEFKZsV Ws8De6VoqKq1klogyDxqmZfqTSFHpN2ypZP6cYor5FbZ0RnYfj91IuWvefEF+2vlbZPU mS/xHF/eVpi4iGXfaOVEgraVCM06O/zMwdiVvYQIpuQ8ayw5pebCulX9Zbk1NMKN9Qdn zTgQ== 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=3PIdxG9cdt0Y7XN4FXtc4NokkaMhwWrDugoWY42qyGY=; b=yGVKV7tVtJIpcUJRPKkpp9OHVwVqwNNIAjLbaPXj5nOTXaESG9ne0STG5sGxJJFfk3 A56pkZUReziynPZ5GtIZWpMB2KZ9WhiOj+CjPpWJnVrHLVTCIyjkXAUDiBhd6p9aJ/KC R6BNwqs6G5GGZkpeo43ogE5ZKcYgJAMNOE3Y5dPi1W3ABmnV0oCVNtqUHM1Jzot1esO2 zS4BgbVws4UinAmfak3K4fcqKHQT9pETBCM1wY3iv4F1uDA8L5dU/5XIxE2wGQxPCa8J uikFJBcmUruooOvsWP29SoSY5dKv47XpJNskmEthwSltnyAod6jq+1LI9ZGD1afxSW4O X2cQ== X-Gm-Message-State: AOAM532kgm0IfoUZwLCJzDBk3ZM47qM7WaSc3ZhNnIntJOWeFv53Ye4b iI2UtXQ8I28c6h24usAcqnN7gIsaS54GHJjZ X-Google-Smtp-Source: ABdhPJyBNvaO5VGrxE9bfIdhcfmLbPZd0K1rfUItdQl8+lZ6zLL+ozGHMlMGHL28QLcSN/nIWnp9pg== X-Received: by 2002:a5d:4a46:: with SMTP id v6mr35426304wrs.262.1635758120902; Mon, 01 Nov 2021 02:15:20 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:3a2b:9d8c:92b9:ece6]) by smtp.gmail.com with ESMTPSA id w10sm13168849wrq.88.2021.11.01.02.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 02:15:20 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Nov 2021 09:15:10 +0000 Message-Id: <20211101091510.23204-12-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211101091510.23204-1-naush@raspberrypi.com> References: <20211101091510.23204-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 11/11] 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 996743cf48ef..44760093f7ab 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