From patchwork Tue May 28 18:16:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 1327 X-Patchwork-Delegate: niklas.soderlund@ragnatech.se Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4253A600EA for ; Tue, 28 May 2019 20:17:14 +0200 (CEST) X-Halon-ID: c48af6ee-8174-11e9-8601-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from wyvern.fractalia.es (unknown [195.77.54.83]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id c48af6ee-8174-11e9-8601-0050569116f7; Tue, 28 May 2019 20:17:02 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 28 May 2019 20:16:54 +0200 Message-Id: <20190528181654.10649-1-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] qcam: Allow user to select pixel format and resolution X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 May 2019 18:17:14 -0000 Allow users to select pixel format and resolution from two selection dialogues. Ideally the dialog should be turned into a toolbar with an additional start/stop stream button, but this allows us to demonstrate the selection interface for now. Signed-off-by: Niklas Söderlund --- src/qcam/main_window.cpp | 64 ++++++++++++++++++++++++++++++++++++++-- src/qcam/main_window.h | 1 + 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 16b123132dd96cbe..20a87bbf9a8a2514 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -93,11 +93,71 @@ int MainWindow::openCamera() return 0; } -int MainWindow::startCapture() +int MainWindow::selectFormat() { - int ret; + QStringList list; + QString name; + bool result; config_ = camera_->generateConfiguration({ StreamRole::VideoRecording }); + + StreamConfiguration &cfg = config_->at(0); + + const std::vector &pixelformats = cfg.formats().pixelformats(); + if (pixelformats.size()) { + for (unsigned int pixelformat : pixelformats) + list.append(QString::fromStdString(std::to_string(pixelformat))); + + name = QInputDialog::getItem(this, "Select pixel format", + "Pixel format:", list, 0, + false, &result); + if (!result) + return -EINVAL; + + cfg.pixelFormat = pixelformats.at(list.indexOf(name)); + } + + const std::vector &sizes = cfg.formats().sizes(cfg.pixelFormat); + if (sizes.size()) { + list.clear(); + for (const Size &size : sizes) + list.append(QString::fromStdString(size.toString())); + + name = QInputDialog::getItem(this, "Select resolution", + "Resolution:", list, 0, + false, &result); + if (!result) + return -EINVAL; + + cfg.size = sizes.at(list.indexOf(name)); + } + + std::cout << "Trying to use stream configuration" << cfg.toString() << std::endl; + return 0; + + switch (config_->validate()) { + case CameraConfiguration::Valid: + break; + case CameraConfiguration::Adjusted: + std::cout << "Camera configuration adjusted" << std::endl; + break; + case CameraConfiguration::Invalid: + std::cout << "Camera configuration invalid" << std::endl; + config_.reset(); + return -EINVAL; + } + + return 0; +} + +int MainWindow::startCapture() +{ + int ret; + + ret = selectFormat(); + if (ret) + return ret; + ret = camera_->configure(config_.get()); if (ret < 0) { std::cout << "Failed to configure camera" << std::endl; diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index fe565cbcb4603d9d..43d2d3e3894fb444 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -34,6 +34,7 @@ public: private: int openCamera(); + int selectFormat(); int startCapture(); void stopCapture();