From patchwork Fri Oct 13 09:10:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19145 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 E56D4C3272 for ; Fri, 13 Oct 2023 09:10:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F04006297B; Fri, 13 Oct 2023 11:10:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697188210; bh=qdCBY8SGQ31vCCWq4/C0U1NCCZPPOQGHETH43bN3tSE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Nw5F2gGQht6EX0rVwTf8FpQBKqbLA6zyVzJUE7RnsI0jL2TmZg8uYZgzZCQkaStBP xd6eUndKc6JMOMIocNQGxWmMQIfZj2bl2Pj/xD/NzfwHyCUCP6BYHaSiLS0WcDehjc 3P0VBI6dW2lv0mhXh9ZTFsWHQhuYCFGPfSgcPjC394SfiENTRrlX9uhgtUg5QPIVzu YSwnkWCO0gk+YNpmOOlX5jy70PPl4aRCQIzIewnApPV5AjSPwYsSceJiOTOWMiSI+M +WPHHC6hOWNmP9n24/YcY3UN6f6l978RxszTQI3Bjmv/7R/leZPp30rAIq4Me5uFAp ZkhcJ49E9QYJw== 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 4B1C36295F for ; Fri, 13 Oct 2023 11:10:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Bat718g3"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-32003aae100so1987977f8f.0 for ; Fri, 13 Oct 2023 02:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1697188206; x=1697793006; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G0eki5a9qXNrnvqCWIms+tfm0M23ES+9LJBeasDRMdQ=; b=Bat718g3gcWSr9JwG96azlb3Tj6Xh3Q75t1blU0nFYso5Jd8h0naCnqffA7vEixSzY rqeBePfyF/qMf/sqtXERwMiaYaioKzsufbneDN3gKZot+MuEydNQs3Gnwl28UtjLAsfy /JYfijYtg9o67qRF6YVyQ3+lcYMNku5rQJT/CBGPfWf8mt550ZqPZtAarPg3ZYTNnmeV kJIlCnPUd/FDfu9CgjBzjeR99FCnPdGJnoIzU4UXXkdayjA1N4p/zxJcjuhMtFTzUN0q XQuY5zkBOY6Vbg+r1Lqhg+FiCyHlt7X24n6UcN6Z1mas9n7YmSSc0XmClqd6f2SEcK8s mmJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697188206; x=1697793006; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G0eki5a9qXNrnvqCWIms+tfm0M23ES+9LJBeasDRMdQ=; b=X/ZPP3VdBXDllsjY6aGwDVAnphZNxPAlRHFFNaibpuFSSFJR2cVqRiCYLbNTRBMk8N WbWdQkVwQZPrEb3w3KumYv49Re8C7LrPTLBjQACz4PIFcWlCsZ+aPQwoA+PkBumBGUbO D+2maDQnDXhbhX0bGcLESJ/mlTju9T3zDkRqC1nK0XIjYIja/UfgutRxm5oMe6IpN+0z PnxewYsAI5xxUBcHCr/ELsiMRv6ZrmUP7fvfoXv4fdOky9sgwBNm/yi9pSycsn9cazBs rAPrIchm/jHW/dH+UZPt1UglCEWkBj7zYqHEjwldw/exf3VkEeW3IDbPnkwMRlJV9A9s iqfQ== X-Gm-Message-State: AOJu0Yyc3UjvWc/I1bNRRZgpZyYkbmMC94nU3inZRn9utH2dodl4GrPG SN9giyknkT2sfpR+qswNYNyvUmIPsZRowQil7lF1qw== X-Google-Smtp-Source: AGHT+IEAxm3Q10n4S3cm/MUaHKX6bEz2DLIVdmkrfuGN2XvhzfLQipbCauQybcV46EykUB/kAfiqsA== X-Received: by 2002:adf:a388:0:b0:32d:8872:aac6 with SMTP id l8-20020adfa388000000b0032d8872aac6mr5932675wrb.31.1697188206545; Fri, 13 Oct 2023 02:10:06 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id v15-20020a5d43cf000000b003233b554e6esm20482082wrr.85.2023.10.13.02.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 02:10:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Oct 2023 10:10:03 +0100 Message-Id: <20231013091003.2571-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231013074841.16972-15-naush@raspberrypi.com> References: <20231013074841.16972-15-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] pipeline: rpi: Move flip handling validation code 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Move the handling of Bayer order changes due to flips to run before platformValidate(). This removes the need for this code to be split between platformValidate() and validate() as it is right now. Also add some validation to ensure the vc4 pipeline handler only supports CSI2 packing or no packing. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 43 +++++++++++++------ src/libcamera/pipeline/rpi/vc4/vc4.cpp | 15 ++++--- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 825eae80d014..7c88b87e0608 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -231,16 +231,12 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() } } - /* Do any platform specific fixups. */ - status = data_->platformValidate(this); - if (status == Invalid) - return Invalid; - - /* Further fixups on the RAW streams. */ + /* Start with some initial generic RAW stream adjustments. */ for (auto &raw : rawStreams_) { - int ret = raw.dev->tryFormat(&raw.format); - if (ret) - return Invalid; + StreamConfiguration *rawStream = raw.cfg; + + /* Adjust the RAW stream to match the computed sensor format. */ + BayerFormat sensorBayer = BayerFormat::fromMbusCode(sensorFormat_.mbus_code); /* * Some sensors change their Bayer order when they are h-flipped @@ -249,12 +245,33 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * Note how we must fetch the "native" (i.e. untransformed) Bayer * order, because the sensor may currently be flipped! */ - BayerFormat bayer = BayerFormat::fromPixelFormat(raw.cfg->pixelFormat); if (data_->flipsAlterBayerOrder_) { - bayer.order = data_->nativeBayerOrder_; - bayer = bayer.transform(combinedTransform_); + sensorBayer.order = data_->nativeBayerOrder_; + sensorBayer = sensorBayer.transform(combinedTransform_); + } + + /* Apply the sensor adjusted Bayer order to the user request. */ + BayerFormat cfgBayer = BayerFormat::fromPixelFormat(rawStream->pixelFormat); + cfgBayer.order = sensorBayer.order; + + if (rawStream->pixelFormat != cfgBayer.toPixelFormat()) { + rawStream->pixelFormat = cfgBayer.toPixelFormat(); + status = Adjusted; } - raw.cfg->pixelFormat = bayer.toPixelFormat(); + } + + /* Do any platform specific fixups. */ + Status st = data_->platformValidate(this); + if (st == Invalid) + return Invalid; + else if (st == Adjusted) + status = Adjusted; + + /* Further fixups on the RAW streams. */ + for (auto &raw : rawStreams_) { + int ret = raw.dev->tryFormat(&raw.format); + if (ret) + return Invalid; if (RPi::PipelineHandlerBase::updateStreamConfig(raw.cfg, raw.format)) status = Adjusted; diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 233473e2fe2b..425ab9ae6ea5 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -409,16 +409,17 @@ CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfig /* Adjust the RAW stream to match the computed sensor format. */ StreamConfiguration *rawStream = rawStreams[0].cfg; - BayerFormat rawBayer = BayerFormat::fromMbusCode(rpiConfig->sensorFormat_.mbus_code); + BayerFormat rawBayer = BayerFormat::fromPixelFormat(rawStream->pixelFormat); - /* Handle flips to make sure to match the RAW stream format. */ - if (flipsAlterBayerOrder_) - rawBayer = rawBayer.transform(rpiConfig->combinedTransform_); + /* Apply the sensor bitdepth. */ + rawBayer.bitDepth = BayerFormat::fromMbusCode(rpiConfig->sensorFormat_.mbus_code).bitDepth; - /* Apply the user requested packing. */ - rawBayer.packing = BayerFormat::fromPixelFormat(rawStream->pixelFormat).packing; - PixelFormat rawFormat = rawBayer.toPixelFormat(); + /* Default to CSI2 packing if the user request is unsupported. */ + if (rawBayer.packing != BayerFormat::Packing::CSI2 && + rawBayer.packing != BayerFormat::Packing::None) + rawBayer.packing = BayerFormat::Packing::CSI2; + PixelFormat rawFormat = rawBayer.toPixelFormat(); if (rawStream->pixelFormat != rawFormat || rawStream->size != rpiConfig->sensorFormat_.size) { rawStream->pixelFormat = rawFormat;