From patchwork Tue Sep 29 16:40:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 9869 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 BA482C3B5B for ; Tue, 29 Sep 2020 16:40:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7B2706221F; Tue, 29 Sep 2020 18:40:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lVa87LLF"; dkim-atps=neutral Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D68A62211 for ; Tue, 29 Sep 2020 18:40:11 +0200 (CEST) Received: by mail-wr1-x433.google.com with SMTP id z4so6185050wrr.4 for ; Tue, 29 Sep 2020 09:40:11 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=WDoEdN80X2fj4rhVFmRDdDnGzuHzhrvAaQt+7lJP83w=; b=lVa87LLFzTT3HPK4FkFoSCyIEaruvxMSXDxHwJtkjOLaxeJCYlQUQvHusA7pPL8ux7 XWDrGD2lyAfkA/Vvw+TOqwFLuuCbDPZTI3HOeyBZVJWVw9Hesgdpr5s7gDEHx3xukfcx B3ixrabf6y7s62Me6ccSb2f1nDY5oAZTtlJovPKd1RPC0afU6Bo1CfPB09QD/qzehyEj DPfZ8UOs8CayPRT3TQ7mvYMPdkCAu/VoW5h8gtHvsos4NuqVWeRyKxEwrUez1aN8FXat uQssRMgIptZalmCaTs5QcK6/4Bq9ECSIQHIXRw59DsndYGGRBwcYu1mGJd0FcKzVthIj ftEQ== 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:mime-version:content-transfer-encoding; bh=WDoEdN80X2fj4rhVFmRDdDnGzuHzhrvAaQt+7lJP83w=; b=S8z4uikHr2T4HVl3WotA5uHq8SPTunD8TM+ZVb0iUfMDE1eNLXwp8vQEp+JtppDyiQ pdnfP/EOqualEQ7xG3jb6raDoVAGwNq+icjp+zALnMg5UexpQDvE4lWnNfVZztQF/hre hB5uB13gcviW7O5Wj0carrvVrFGrnaHCJ5WFts2KmjYgv4WjGRiy9EeCpPJYKZpVj41k DXY0+jjguGjBu9Vtld6J/x4XdJXD8voI3SHWaULCcCngP9KtrMd73VABnKF0C5xsk8H2 hNl1I6mEV9GTQxsCGn9Z3aEPsssjdMwdsRB2n0XkV0Qc3IyajhR9s7Bg1HyZLJ/gLTuU dmyQ== X-Gm-Message-State: AOAM533k9yxY6dYkOR9olf9gwMFj71brmF1Dci1OgxF7ZnM1RHM3nr2D k+5VnGIoioW3/8DQ2iMLU82+xWshdVQJEg== X-Google-Smtp-Source: ABdhPJxM2mGdRI1BAW944mzbsluGJJkR14rX+QpPl4SooH1dm/3//qoleV6SmWGApK8bVdAeUEcuUA== X-Received: by 2002:a5d:5404:: with SMTP id g4mr5099203wrv.134.1601397610412; Tue, 29 Sep 2020 09:40:10 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id q12sm6977393wrs.48.2020.09.29.09.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 09:40:09 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Sep 2020 17:40:00 +0100 Message-Id: <20200929164000.15429-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200929164000.15429-1-david.plowman@raspberrypi.com> References: <20200929164000.15429-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 6/6] cam: Add command line option to test IspCrop control 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This allows the user to request digital zoom by adding, for example, "-z 0.25,0.25,0.5,0.5" which would give a 2x zoom, still centred in the middle of the image. Signed-off-by: David Plowman --- src/cam/capture.cpp | 25 +++++++++++++++++++++++-- src/cam/capture.h | 2 +- src/cam/main.cpp | 3 +++ src/cam/main.h | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index 5510c009..3b50c591 100644 --- a/src/cam/capture.cpp +++ b/src/cam/capture.cpp @@ -10,6 +10,9 @@ #include #include +#include +#include + #include "capture.h" #include "main.h" @@ -58,7 +61,7 @@ int Capture::run(const OptionsParser::Options &options) FrameBufferAllocator *allocator = new FrameBufferAllocator(camera_); - ret = capture(allocator); + ret = capture(allocator, options); if (options.isSet(OptFile)) { delete writer_; @@ -70,7 +73,7 @@ int Capture::run(const OptionsParser::Options &options) return ret; } -int Capture::capture(FrameBufferAllocator *allocator) +int Capture::capture(FrameBufferAllocator *allocator, const OptionsParser::Options &options) { int ret; @@ -120,6 +123,24 @@ int Capture::capture(FrameBufferAllocator *allocator) requests.push_back(request); } + /* Set up digital zoom if it was requested on the command line. */ + if (options.isSet(OptZoom)) { + std::string zoom = options[OptZoom].toString(); + float x, y, width, height; + + if (sscanf(zoom.c_str(), "%f,%f,%f,%f", &x, &y, &width, &height) == 4) { + Size sensorArea = camera_->properties().get(properties::SensorOutputSize); + Rectangle crop(x * sensorArea.width, + y * sensorArea.height, + width * sensorArea.width, + height * sensorArea.height); + + requests.front()->controls().set(controls::IspCrop, crop); + } else { + std::cout << "Invalid zoom values - ignoring" << std::endl; + } + } + ret = camera_->start(); if (ret) { std::cout << "Failed to start capture" << std::endl; diff --git a/src/cam/capture.h b/src/cam/capture.h index 0aebdac9..52806164 100644 --- a/src/cam/capture.h +++ b/src/cam/capture.h @@ -29,7 +29,7 @@ public: int run(const OptionsParser::Options &options); private: - int capture(libcamera::FrameBufferAllocator *allocator); + int capture(libcamera::FrameBufferAllocator *allocator, const OptionsParser::Options &options); void requestComplete(libcamera::Request *request); diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 244720b4..b871d049 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -201,6 +201,9 @@ int CamApp::parseOptions(int argc, char *argv[]) parser.addOption(OptStrictFormats, OptionNone, "Do not allow requested stream format(s) to be adjusted", "strict-formats"); + parser.addOption(OptZoom, OptionString, + "Zoom in on the image portion described by the x,y,width,height rectangle (fractions of the maximum FOV) e.g. 0.25,0.25,0.5,0.5", + "zoom", ArgumentRequired, "zoom"); options_ = parser.parse(argc, argv); if (!options_.valid()) diff --git a/src/cam/main.h b/src/cam/main.h index ea8dfd33..a1fd899f 100644 --- a/src/cam/main.h +++ b/src/cam/main.h @@ -17,6 +17,7 @@ enum { OptListProperties = 'p', OptMonitor = 'm', OptStream = 's', + OptZoom = 'z', OptListControls = 256, OptStrictFormats = 257, };