From patchwork Wed Jun 17 16:44:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 4073 Return-Path: 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 D81F8603BF for ; Wed, 17 Jun 2020 18:44:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="WmdUalhU"; dkim-atps=neutral Received: by mail-wr1-x431.google.com with SMTP id c3so3033459wru.12 for ; Wed, 17 Jun 2020 09:44:47 -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:mime-version :content-transfer-encoding; bh=cemhbHAyQVJNGl5fy0sG9uWFtdvlcyoqKp6xMOB8roM=; b=WmdUalhUPZFw7SPbpre+kH+T3TPoxCardRL111PoPItCqlSpOI2P4Mobe8xM0B2BUO lGdbjA2USLE86Z+pb7e17cJO+od7imGre41c8OTB9pXv8Y34DhMnlUtNcI8URiHsQCAu T3NAaIV6yN88DGzDYS7tjVDz7U5DpLlFL6dzfsiY1i0v4iXDb84WppooG7T+BiwFmv/K 4f19dskV07njkG3JCzwb04MKEf3YYP+MC3vIDWokgwlk5R3IaYmfxRAvPT72DCiQgr89 Te8PX0NoOtVUpCoUPe38tNrNv1HdeO87Ogubo4PYEx5CnJlvjvYhT8ooq9jr2RVIW06e udtA== 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:mime-version :content-transfer-encoding; bh=cemhbHAyQVJNGl5fy0sG9uWFtdvlcyoqKp6xMOB8roM=; b=UdZjyblxcH1cskQ8JkEhJL2E6dpVji4vb2Af4rSL236yqlWbekjvSIsIohoJK/vDOh pLBl+xKoTqRZ0WtieQN5rV7RuAKOw/XON2KtbVfK4KO9nuaaY4RITTLJ5tNan95BFSIp KDVb+39+lI/IU4jgft+1j0aLVlq7yTpznwIalp/ZO8x8EpXybU5DxeLqTkUENoU/dHUY M3DlcCFGaJHOLn8wy0BcxEmPa13iZ2PnNjU5tYSngRDKRtFu9tWLb0/EvYB5ZZIVYPg8 sSm2wcJBeZW7GBnyruoA1TKWhn2ZvxyyKdcwA+PYEeeUrVZW+W5CoOO9rZIPVSX7TzVg zcIQ== X-Gm-Message-State: AOAM53390ummriYHHlhEgc4vQ/l7vFHVTguvDtHCrGc9HWYFoiSuWId6 zhpM29ENK5Dxp0zniIPiIvsZyAmupSA= X-Google-Smtp-Source: ABdhPJwFZACQ787rA0R+g2e+ZNLv7B/BzjsSv7TH/McoHT9mW5/qUFADh2UJqhtWsWyuOnlat0S5SQ== X-Received: by 2002:adf:fa89:: with SMTP id h9mr165499wrr.120.1592412287114; Wed, 17 Jun 2020 09:44:47 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id e5sm184300wrw.19.2020.06.17.09.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2020 09:44:46 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 17 Jun 2020 17:44:42 +0100 Message-Id: <20200617164442.2643-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] 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: Wed, 17 Jun 2020 16:44:48 -0000 These formats can be helpful when downstream applications or libraries support them natively (avoiding a costly conversion). Signed-off-by: David Plowman --- src/libcamera/formats.cpp | 14 ++++++++++++++ src/libcamera/v4l2_pixelformat.cpp | 2 ++ src/v4l2/v4l2_camera_proxy.cpp | 2 ++ 3 files changed, 18 insertions(+) diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 2ac3b41..dcd1dcf 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -268,6 +268,20 @@ const std::map pixelFormatInfo{ .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, } }, + { PixelFormat(DRM_FORMAT_YUV422), { + .format = PixelFormat(DRM_FORMAT_YUV422), + .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV422P), + .bitsPerPixel = 16, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = false, + } }, + { PixelFormat(DRM_FORMAT_YUV420), { + .format = PixelFormat(DRM_FORMAT_YUV420), + .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV420), + .bitsPerPixel = 12, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = false, + } }, /* Greyscale formats. */ { PixelFormat(DRM_FORMAT_R8), { diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp index 94fae47..01778c0 100644 --- a/src/libcamera/v4l2_pixelformat.cpp +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -64,6 +64,8 @@ const std::map vpf2pf{ { V4L2PixelFormat(V4L2_PIX_FMT_NV61), PixelFormat(DRM_FORMAT_NV61) }, { V4L2PixelFormat(V4L2_PIX_FMT_NV12), PixelFormat(DRM_FORMAT_NV12) }, { V4L2PixelFormat(V4L2_PIX_FMT_NV21), PixelFormat(DRM_FORMAT_NV21) }, + { V4L2PixelFormat(V4L2_PIX_FMT_YUV422P), PixelFormat(DRM_FORMAT_YUV422) }, + { V4L2PixelFormat(V4L2_PIX_FMT_YUV420), PixelFormat(DRM_FORMAT_YUV420) }, /* Greyscale formats. */ { V4L2PixelFormat(V4L2_PIX_FMT_GREY), PixelFormat(DRM_FORMAT_R8) }, diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index d7f14e6..a54d47e 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -576,6 +576,8 @@ static const std::array pixelFormatInfo = {{ { PixelFormat(DRM_FORMAT_NV61), V4L2_PIX_FMT_NV61, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, { PixelFormat(DRM_FORMAT_NV24), V4L2_PIX_FMT_NV24, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} }, { PixelFormat(DRM_FORMAT_NV42), V4L2_PIX_FMT_NV42, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} }, + { PixelFormat(DRM_FORMAT_YUV422), V4L2_PIX_FMT_YUV422P, 2, {{ { 8, 1, 1 }, { 8, 2, 1 }, { 8, 2, 1 } }} }, + { PixelFormat(DRM_FORMAT_YUV420), V4L2_PIX_FMT_YUV420, 2, {{ { 8, 1, 1 }, { 8, 2, 2 }, { 8, 2, 2 } }} }, /* Compressed formats. */ /* * \todo Get a better image size estimate for MJPEG, via