[libcamera-devel] [PATCH] qcam: Allow user to select pixel format and resolution
Niklas Söderlund
niklas.soderlund at ragnatech.se
Tue May 28 20:16:54 CEST 2019
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 <niklas.soderlund at ragnatech.se>
---
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<unsigned int> &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<Size> &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();
--
2.21.0
More information about the libcamera-devel
mailing list