From patchwork Sat Apr 4 21:57:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 3404 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0589E629B9 for ; Sat, 4 Apr 2020 23:57:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="oaApGnRP"; dkim-atps=neutral Received: by mail-lj1-x22d.google.com with SMTP id 19so10616284ljj.7 for ; Sat, 04 Apr 2020 14:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f4teGIoxrxlepDd6QY3IJoftLa3OQtPOasoCKLGxePk=; b=oaApGnRPLH9h5+MRkD1UnvUj3NUs7TnJ4lWoDtKUAm3zNaUAooRmg5QdUw/LpyriG2 ECaWI5TmdyljKdSomITsFb/fADr3WpNYsK8IlVjY7bYtzHiqs4xWjZZaS4HA59h7Dq// 1LxAk7gfm875eBQVTJMZXGaTAiGEPoDnZTjMH83kbu0hMfdRHfBx3m8WggKMRGIitmx6 1BacuAhpn9aTDvAIlEwr4sPBYnZ3BAuCwl1gYAR8+7lM8xFQFQZHXLDqho/rUeL4bKEj U25weMsi/pvTYFr67JVW0Qa+yZz1mXW9XHSF8ZxLJK1vpydbWZK8MChL8Md+SUHTG9+I k8Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=f4teGIoxrxlepDd6QY3IJoftLa3OQtPOasoCKLGxePk=; b=tGgQ9Cqy6uW7oz7urJ+Tg6SDwAM+37EOJCGWE9iX8gMxp50ZORU//gUvk6NrCLo4NU CTjCjJCJJC+v5o8LaKDTubymZdx6Qja4YNkgA1sG7BQTVS9THzpYd6bLeKri64vXdFDw HLCcTqmTY461V6EIgAJi+GJHZRE3t+uqc9tpweaqXD/981nRPmKs1EU9W66U38h+iY1o AS7xUNk/g0+P6ne6eU93pYNL9pM0e3N1tuN4VFCjqMdH8Og7R+7C81WKW4zsd/vRnyz0 /J/WIhzMlhxKi5myUtLccte8jacjkvynBWfucznUpRPIkG3HTfAbZvyXhqCOD+uTmISI pJJg== X-Gm-Message-State: AGi0PubnmzdUhxRDBW1xzIo+Bw/XSPXQFOh97Z35pcWwQI79EA0sMOpc mpBparz6AceDMQCYtUuFH+Zdt4J7ydM= X-Google-Smtp-Source: APiQypKae6NjDPtX01rVixQ0kmnSioW71ZupSlbVhYY5Ms0CGvJV1ilciZkevj7MdERsxwaIgrBp2A== X-Received: by 2002:a2e:b896:: with SMTP id r22mr8003783ljp.43.1586037465028; Sat, 04 Apr 2020 14:57:45 -0700 (PDT) Received: from localhost.localdomain (37-144-159-139.broadband.corbina.ru. [37.144.159.139]) by smtp.googlemail.com with ESMTPSA id h16sm7299627ljl.73.2020.04.04.14.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 14:57:44 -0700 (PDT) From: Andrey Konovalov To: libcamera-devel@lists.libcamera.org Date: Sun, 5 Apr 2020 00:57:30 +0300 Message-Id: <20200404215730.16194-2-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404215730.16194-1-andrey.konovalov@linaro.org> References: <20200404215730.16194-1-andrey.konovalov@linaro.org> Subject: [libcamera-devel] [RFC 1/1] libcamera: V4L2VideoDevice::to[V4L2]PixelFormat(): add Bayer 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: , X-List-Received-Date: Sat, 04 Apr 2020 21:57:46 -0000 Add support for 8-bit, 10-bit, and 10-bit packed raw Bayer formats in toPixelFormat() and toV4L2PixelFormat() methods of V4L2VideoDevice class. Signed-off-by: Andrey Konovalov --- src/libcamera/v4l2_videodevice.cpp | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index eb33a68..2e3aafc 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1687,6 +1687,36 @@ PixelFormat V4L2VideoDevice::toPixelFormat(V4L2PixelFormat v4l2Fourcc) case V4L2_PIX_FMT_MJPEG: return PixelFormat(DRM_FORMAT_MJPEG); + /* 8-bit Bayer formats. */ + case V4L2_PIX_FMT_SRGGB8: + return PixelFormat(DRM_FORMAT_SRGGB8); + case V4L2_PIX_FMT_SGRBG8: + return PixelFormat(DRM_FORMAT_SGRBG8); + case V4L2_PIX_FMT_SGBRG8: + return PixelFormat(DRM_FORMAT_SGBRG8); + case V4L2_PIX_FMT_SBGGR8: + return PixelFormat(DRM_FORMAT_SBGGR8); + + /* 10-bit Bayer formats. */ + case V4L2_PIX_FMT_SRGGB10: + return PixelFormat(DRM_FORMAT_SRGGB10); + case V4L2_PIX_FMT_SGRBG10: + return PixelFormat(DRM_FORMAT_SGRBG10); + case V4L2_PIX_FMT_SGBRG10: + return PixelFormat(DRM_FORMAT_SGBRG10); + case V4L2_PIX_FMT_SBGGR10: + return PixelFormat(DRM_FORMAT_SBGGR10); + + /* 10-bit Bayer packed formats. */ + case V4L2_PIX_FMT_SRGGB10P: + return PixelFormat(DRM_FORMAT_SRGGB10, MIPI_FORMAT_MOD_CSI2_PACKED); + case V4L2_PIX_FMT_SGRBG10P: + return PixelFormat(DRM_FORMAT_SGRBG10, MIPI_FORMAT_MOD_CSI2_PACKED); + case V4L2_PIX_FMT_SGBRG10P: + return PixelFormat(DRM_FORMAT_SGBRG10, MIPI_FORMAT_MOD_CSI2_PACKED); + case V4L2_PIX_FMT_SBGGR10P: + return PixelFormat(DRM_FORMAT_SBGGR10, MIPI_FORMAT_MOD_CSI2_PACKED); + /* V4L2 formats not yet supported by DRM. */ case V4L2_PIX_FMT_GREY: default: @@ -1734,6 +1764,8 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelForma V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelFormat, bool multiplanar) { + bool csi2Packed = pixelFormat.modifier() == MIPI_FORMAT_MOD_CSI2_PACKED; + switch (pixelFormat) { /* RGB formats. */ case DRM_FORMAT_BGR888: @@ -1777,6 +1809,30 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelForma /* Compressed formats. */ case DRM_FORMAT_MJPEG: return V4L2PixelFormat(V4L2_PIX_FMT_MJPEG); + + /* 8-bit Bayer formats. */ + case DRM_FORMAT_SRGGB8: + return V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8); + case DRM_FORMAT_SGRBG8: + return V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8); + case DRM_FORMAT_SGBRG8: + return V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8); + case DRM_FORMAT_SBGGR8: + return V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8); + + /* 10-bit Bayer formats, the packed ones included. */ + case DRM_FORMAT_SRGGB10: + return (csi2Packed) ? V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P) + : V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10); + case DRM_FORMAT_SGRBG10: + return (csi2Packed) ? V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P) + : V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10); + case DRM_FORMAT_SGBRG10: + return (csi2Packed) ? V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P) + : V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10); + case DRM_FORMAT_SBGGR10: + return (csi2Packed) ? V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P) + : V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10); } /*