From patchwork Mon Jun 22 04:38:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 4105 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3CA19603BC for ; Mon, 22 Jun 2020 06:38:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="LaKdDRJf"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ACD5A30D; Mon, 22 Jun 2020 06:38:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1592800720; bh=ZcBHorP7XCD8/kiPNjRmi7ioc5TAlfBf9l4HH+OC8vE=; h=From:To:Cc:Subject:Date:From; b=LaKdDRJf+RtCglUiUeja2+vwogg2JVYeZpkNlr7BpvWTcHO59RCjCFb0azLwXSgE1 Xghdp1s+N2k8lLt/iGSna91KbFWuJHU+c7XwIICxj5sxJ6e7IeNkdKBGCqmzgyh8qA r5tBsDYN0Osi0lu6JDzMO0q3UUBdfboL3jx4mXZc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 22 Jun 2020 07:38:12 +0300 Message-Id: <20200622043812.16989-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: add support for planar YUV422 and YUV420 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: Mon, 22 Jun 2020 04:38:41 -0000 From: David Plowman These formats can be helpful when downstream applications or libraries support them natively (avoiding a costly conversion). Signed-off-by: David Plowman Signed-off-by: Laurent Pinchart Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Kieran Bingham --- Changes since v1: - Rebase on top of formats rework - Fix number of planes in formats descriptions --- src/libcamera/formats.cpp | 14 ++++++++++++++ src/libcamera/formats.yaml | 5 +++++ src/libcamera/v4l2_pixelformat.cpp | 2 ++ src/v4l2/v4l2_camera_proxy.cpp | 4 +++- 4 files changed, 24 insertions(+), 1 deletion(-) David, could you please test this and provide a Tested-by tag (and Reviewed-by too if possible) ? diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 97e986786cc8..c0b53ce7cc97 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -270,6 +270,20 @@ const std::map pixelFormatInfo{ .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, } }, + { formats::YUV420, { + .format = PixelFormat(formats::YUV420), + .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV420), + .bitsPerPixel = 12, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = false, + } }, + { formats::YUV422, { + .format = PixelFormat(formats::YUV422), + .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV422P), + .bitsPerPixel = 16, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = false, + } }, /* Greyscale formats. */ { formats::R8, { diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml index a6841c618f93..ce06dbc41aa1 100644 --- a/src/libcamera/formats.yaml +++ b/src/libcamera/formats.yaml @@ -53,6 +53,11 @@ formats: - NV42: fourcc: DRM_FORMAT_NV42 + - YUV420: + fourcc: DRM_FORMAT_YUV420 + - YUV422: + fourcc: DRM_FORMAT_YUV422 + - MJPEG: fourcc: DRM_FORMAT_MJPEG diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp index 741f6c2646bc..6745d17d4926 100644 --- a/src/libcamera/v4l2_pixelformat.cpp +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -63,6 +63,8 @@ const std::map vpf2pf{ { V4L2PixelFormat(V4L2_PIX_FMT_NV61), formats::NV61 }, { V4L2PixelFormat(V4L2_PIX_FMT_NV12), formats::NV12 }, { V4L2PixelFormat(V4L2_PIX_FMT_NV21), formats::NV21 }, + { V4L2PixelFormat(V4L2_PIX_FMT_YUV420), formats::YUV420 }, + { V4L2PixelFormat(V4L2_PIX_FMT_YUV422P), formats::YUV422 }, /* Greyscale formats. */ { V4L2PixelFormat(V4L2_PIX_FMT_GREY), formats::R8 }, diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index bf47aa7ee633..86b87e379b98 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -560,7 +560,7 @@ struct PixelFormatInfo { namespace { -static const std::array pixelFormatInfo = {{ +static const std::array pixelFormatInfo = {{ /* RGB formats. */ { formats::RGB888, V4L2_PIX_FMT_BGR24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, { formats::BGR888, V4L2_PIX_FMT_RGB24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, @@ -577,6 +577,8 @@ static const std::array pixelFormatInfo = {{ { formats::NV61, V4L2_PIX_FMT_NV61, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, { formats::NV24, V4L2_PIX_FMT_NV24, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} }, { formats::NV42, V4L2_PIX_FMT_NV42, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} }, + { formats::YUV420, V4L2_PIX_FMT_YUV420, 3, {{ { 8, 1, 1 }, { 8, 2, 2 }, { 8, 2, 2 } }} }, + { formats::YUV422, V4L2_PIX_FMT_YUV422P, 3, {{ { 8, 1, 1 }, { 8, 2, 1 }, { 8, 2, 1 } }} }, /* Compressed formats. */ /* * \todo Get a better image size estimate for MJPEG, via