From patchwork Fri Sep 15 07:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 19009 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 AF1BABD160 for ; Fri, 15 Sep 2023 07:57:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C01FC62927; Fri, 15 Sep 2023 09:57:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694764652; bh=0hHduLXnGmQRUinzMw3HA8Pdweuxi4OWV720ADh/2cI=; h=Date:References:In-Reply-To:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=R5CzMKXxImhKZbpAYgZ9dcXkn/ytdf1NciRSuUqCYppLvC4Y7ZLsulZY98jk/+fWy fap9m/1qFFQIbSlJkyYfe5NBZwBnvPl6ImdCu4ohmESsyIJwXo09pFDL4Jb2JstbcN kCATv5K3TBW5CVRKAlGXmlUEsMg7rwoA349WbamsIEdKcsxDXFarfURSC0AyrWOWvY Mr09XCoaYZPx7S3R57kvlyL15lX2ilEploI8xhemSQLjF2WnTZH0zQFjD2IuSGEjqs Xk4G2OzUWzqPsNgWjqmy637IJ+5ZTp0tg3Y90kgf1og/n6Lm2Vmh4+ttjSf6fsIb// 8H1/iwMtI7b5Q== Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D1CF16291A for ; Fri, 15 Sep 2023 09:57:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="Pg6kyn7C"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-313e742a787so1181775f8f.1 for ; Fri, 15 Sep 2023 00:57:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1694764649; x=1695369449; darn=lists.libcamera.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=b/wOgWma/1S7FO6/zEXOhIIMNxsMj5cc2vXJjrkX00w=; b=Pg6kyn7Cu+8gSvX8VjPyGujWhHvyg+Lz6l3UG0OB7wWFA0jSl5cYewawwZmFsxWC5h 08OEPYl4uNeFxwxosNKbk0FQ1sjOhSR4szh2wzETbiqFw3QJ677IAfof2TvEbLRx3A3T CklEP0b+0zgjgRfCfBllWV0y384FTIA+FLhf2MwE18uhfRlk3KlrOKWIEfHnn8tsmZL/ Ddq1FuilEnJBNkaMtLks+IQq94ZcrNVdP3A1k3wzPSkfgYLDMijPlPbkWwEy9nk5TDiG hxA3noYonXXQM/uoWUSX55iic0G0au9TH+CmjQL/tz/GiAJ2XbgRW2QqUiGTPi/B6Qqm q1Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694764649; x=1695369449; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b/wOgWma/1S7FO6/zEXOhIIMNxsMj5cc2vXJjrkX00w=; b=uYXqoyPtJgTdMGsnwl4QN73uaXdSAPWfuQA3UTVuWMxiK7sUIJ90cahbhq49Hp7G7Z qXINxzoIddvfNtFs5fFw5qavST65KYBhs4VmYEN3H+t7yPKCEM6jBJcmqf+9dD59vWNZ EVKHhjp9cTuJ+F/Byh2aIgsVg/FWetZvWUTuZCnscS9pnTUAVgWwex2zW12Irc+Mt5fZ QpludYYxdz2Q7/qiJhn9LyKCtwKOFX0l3sFSgIIklLr/hiDQ8Cxk6eYqlE33SVdJtHtp +uMjVJpL3Ja3gFnxKvoliM4YNRyZmTXAYZsrx/g4kcOi/V5mvX/btMTOPv7BnorAk+dw AMIQ== X-Gm-Message-State: AOJu0Ywy2uaumUakvp7MbVDiJoN5fOSGn1UVLvGBNTbxCpdDbiMbb9AN 3qtki7r4E3tpOSgpzZlZpBwczQ== X-Google-Smtp-Source: AGHT+IHyYHYC0JnSqUmB2Q5e6L82bCm/r40Bkes++y72PayEMp/FFHAFkQBpVTJ/83t2PsndqIeu2w== X-Received: by 2002:adf:fc42:0:b0:31f:d8be:a313 with SMTP id e2-20020adffc42000000b0031fd8bea313mr599172wrs.5.1694764649474; Fri, 15 Sep 2023 00:57:29 -0700 (PDT) Received: from [192.168.1.20] ([2a01:cb19:8704:be00:4f55:bd9d:611a:6c8e]) by smtp.gmail.com with ESMTPSA id m2-20020a056000174200b0031fe9a47a87sm2506942wrf.112.2023.09.15.00.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 00:57:29 -0700 (PDT) Date: Fri, 15 Sep 2023 09:57:27 +0200 MIME-Version: 1.0 Message-Id: <20230915-libyuv-convert-v1-3-1e5bcf68adac@baylibre.com> References: <20230915-libyuv-convert-v1-0-1e5bcf68adac@baylibre.com> In-Reply-To: <20230915-libyuv-convert-v1-0-1e5bcf68adac@baylibre.com> To: libcamera-devel@lists.libcamera.org X-Mailer: b4 0.12.4-dev-6aa5d Subject: [libcamera-devel] [PATCH RFC 3/7] android: yuv: prepare support for other pixel 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-Patchwork-Original-From: Mattijs Korpershoek via libcamera-devel From: Mattijs Korpershoek Reply-To: Mattijs Korpershoek Cc: Guillaume La Roque Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" PostProcessorYuv assumes that both source and destination pixel formats will always be formats::NV12. This might change in the future, for example when doing pixel format conversion via libyuv. Add the necessary plumbing so that other formats can be added easily in the future. Also increase plane number to 3, since some YUV format [1] are fully planar (and thus have 3 planes). [1] https://docs.kernel.org/userspace-api/media/v4l/pixfmt-yuv-planar.html#fully-planar-yuv-formats Signed-off-by: Mattijs Korpershoek Reviewed-by: Jacopo Mondi --- src/android/yuv/post_processor_yuv.cpp | 26 +++++++++++++++----------- src/android/yuv/post_processor_yuv.h | 12 ++++++++---- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp index d58090db14ee..734bb85b7351 100644 --- a/src/android/yuv/post_processor_yuv.cpp +++ b/src/android/yuv/post_processor_yuv.cpp @@ -90,18 +90,18 @@ void PostProcessorYuv::process(Camera3RequestDescriptor::StreamBuffer *streamBuf bool PostProcessorYuv::isValidBuffers(const FrameBuffer &source, const CameraBuffer &destination) const { - if (source.planes().size() != 2) { + if (source.planes().size() != sourceNumPlanes_) { LOG(YUV, Error) << "Invalid number of source planes: " << source.planes().size(); return false; } - if (destination.numPlanes() != 2) { + if (destination.numPlanes() != destinationNumPlanes_) { LOG(YUV, Error) << "Invalid number of destination planes: " << destination.numPlanes(); return false; } - for (unsigned int i = 0; i < 2; i++) { + for (unsigned int i = 0; i < sourceNumPlanes_; i++) { if (source.planes()[i].length < sourceLength_[i]) { LOG(YUV, Error) << "The source planes lengths are too small, " @@ -112,7 +112,7 @@ bool PostProcessorYuv::isValidBuffers(const FrameBuffer &source, return false; } } - for (unsigned int i = 0; i < 2; i++) { + for (unsigned int i = 0; i < destinationNumPlanes_; i++) { if (destination.plane(i).size() < destinationLength_[i]) { LOG(YUV, Error) << "The destination planes lengths are too small, " @@ -132,18 +132,22 @@ void PostProcessorYuv::calculateLengths(const StreamConfiguration &inCfg, { sourceSize_ = inCfg.size; destinationSize_ = outCfg.size; + sourceFormat_ = inCfg.pixelFormat; + destinationFormat_ = outCfg.pixelFormat; - const PixelFormatInfo &sourceInfo = PixelFormatInfo::info(formats::NV12); - for (unsigned int i = 0; i < 2; i++) { + const PixelFormatInfo &sourceInfo = PixelFormatInfo::info(sourceFormat_); + sourceNumPlanes_ = sourceInfo.numPlanes(); + for (unsigned int i = 0; i < sourceInfo.numPlanes(); i++) { sourceStride_[i] = inCfg.stride; sourceLength_[i] = sourceInfo.planeSize(sourceSize_.height, i, sourceStride_[i]); } - const PixelFormatInfo &destinationInfo = PixelFormatInfo::info(formats::NV12); - for (unsigned int i = 0; i < 2; i++) { - destinationStride_[i] = sourceInfo.stride(destinationSize_.width, i, 1); - destinationLength_[i] = sourceInfo.planeSize(destinationSize_.height, i, - destinationStride_[i]); + const PixelFormatInfo &destinationInfo = PixelFormatInfo::info(destinationFormat_); + destinationNumPlanes_ = destinationInfo.numPlanes(); + for (unsigned int i = 0; i < destinationInfo.numPlanes(); i++) { + destinationStride_[i] = destinationInfo.stride(destinationSize_.width, i, 1); + destinationLength_[i] = destinationInfo.planeSize(destinationSize_.height, i, + destinationStride_[i]); } } diff --git a/src/android/yuv/post_processor_yuv.h b/src/android/yuv/post_processor_yuv.h index a7ac17c564b6..bfe35f46c6dc 100644 --- a/src/android/yuv/post_processor_yuv.h +++ b/src/android/yuv/post_processor_yuv.h @@ -28,8 +28,12 @@ private: libcamera::Size sourceSize_; libcamera::Size destinationSize_; - unsigned int sourceLength_[2] = {}; - unsigned int destinationLength_[2] = {}; - unsigned int sourceStride_[2] = {}; - unsigned int destinationStride_[2] = {}; + libcamera::PixelFormat sourceFormat_; + libcamera::PixelFormat destinationFormat_; + unsigned int sourceLength_[3] = {}; + unsigned int destinationLength_[3] = {}; + unsigned int sourceStride_[3] = {}; + unsigned int destinationStride_[3] = {}; + unsigned int sourceNumPlanes_; + unsigned int destinationNumPlanes_; };