From patchwork Fri Sep 25 08:51:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 9827 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 64059C3B5E for ; Fri, 25 Sep 2020 08:51:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2DEE76303E; Fri, 25 Sep 2020 10:51:41 +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="Cb82YblN"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E49363043 for ; Fri, 25 Sep 2020 10:51:37 +0200 (CEST) Received: by mail-wm1-x335.google.com with SMTP id w2so2221739wmi.1 for ; Fri, 25 Sep 2020 01:51:37 -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=9KYLEfSfm9lWEFuKcyq5x/Li6dFc8LJrxWJSayBldfI=; b=Cb82YblNKMLHsJN7E+MsJO2HH5L4PwnOcJ7U6T6MBYzDfjJy4tqBjkVVr51YQoOhFz r38bL6xvUYPq6yza8IkA6dJu8uv09goGUg8g7cD1boMm+NnxKNyh4pgPs3Pv/fsLiJxe 42XwWPQyum60T5F4YJqHlJdnmDjO4c/zSO/PShcbDIkcKr5UAPninXc0aIAPlQv+CIrL M8GGRklycQomD+P9UKJ3vzI1sXodQLj/RyZDS30cWX7W2/7E3VhJbGv+kbGGGqLmS5+R x3Qk3XkAu5Yd0nB4OYulwcZ90KdsYu7thI8MvIxgw4IADFXimiVwvNSD3P0mXhAUSdn0 Vnzg== 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=9KYLEfSfm9lWEFuKcyq5x/Li6dFc8LJrxWJSayBldfI=; b=lvvLNLq+gUjgezfY697H0BunU9APC9yOKi7yPsFWHtjgbcmCDbyMbDf3pg4/Isj7gW 6nlfOyfv3UV/AmgNcxoQCWCMDwfsnsGyipOfc4mFZN+uTL71RsCVWvdTxSUdLPmZSHIj lmSWvKQ+1CFHOXbC2G6zYZgiJvuYM0vripYai+xPbQYHfkJ4kNCoJBH+OzKJpab/LfLb A7yKKRWHCodtmMiwEJ0taPqOXn82ff5SssVufkodhJalAL/EO57pD4fBIh2nPt6llaRL TxJr7L7V7uxTaAO2WaAnNEATd/1c2zav0HQDWmaEASKxlsZ1yx91bA5NuttcY6Dlysxb nUwA== X-Gm-Message-State: AOAM532VuLasblP9wG1s+0nG4KoWeMvyrG58WTj4R8sOaQdDfwSlg9ko UI8qHMQCPrxSXYr7sdXa8ATJL3C67A6XZQ== X-Google-Smtp-Source: ABdhPJyHeheRKX71RbD7I2gSCkSAyXoTs5oJaL1IC2UcFKL42FGNS0u/naPUhIH+ViwVC3ZRHDI65w== X-Received: by 2002:a1c:740c:: with SMTP id p12mr1939475wmc.176.1601023897113; Fri, 25 Sep 2020 01:51:37 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id n4sm2001383wrp.61.2020.09.25.01.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 01:51:36 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Sep 2020 09:51:27 +0100 Message-Id: <20200925085127.17214-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200925085127.17214-1-david.plowman@raspberrypi.com> References: <20200925085127.17214-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 Reviewed-by: Jacopo Mondi --- 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 5510c00..3b50c59 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 0aebdac..5280616 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 244720b..8f326d9 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, + "Specify digital zoom by supplying IspCrop control as x,y,width,height 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 ea8dfd3..a1fd899 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, };