From patchwork Thu Apr 30 00:36:03 2020 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: 3618 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 F1C5660AF5 for ; Thu, 30 Apr 2020 02:36:37 +0200 (CEST) X-Halon-ID: 8773b20a-8a7a-11ea-89d0-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 8773b20a-8a7a-11ea-89d0-0050569116f7; Thu, 30 Apr 2020 02:35:45 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Apr 2020 02:36:03 +0200 Message-Id: <20200430003604.2423018-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200430003604.2423018-1-niklas.soderlund@ragnatech.se> References: <20200430003604.2423018-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC/PATCH 4/5] qcam: Remove QFileDialog from JPEG capture 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-List-Received-Date: Thu, 30 Apr 2020 00:36:38 -0000 Instead of popping up a dialog to enter a filename to save use the sequence number and the default output directory to generate a path. Signed-off-by: Niklas Söderlund --- src/qcam/main_window.cpp | 40 +++++++++++++++++++++++++++------------- src/qcam/main_window.h | 3 ++- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 470f78162cabffe5..f57aaf4a27e5f4ca 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -8,6 +8,7 @@ #include "main_window.h" #include +#include #include #include @@ -146,8 +147,7 @@ int MainWindow::createToolbars() action = toolbar_->addAction(QIcon::fromTheme("document-save-as", QIcon(":save.svg")), "Save As..."); - action->setShortcut(QKeySequence::SaveAs); - connect(action, &QAction::triggered, this, &MainWindow::saveImageAs); + connect(action, &QAction::triggered, this, &MainWindow::saveViewfinder); return 0; } @@ -509,18 +509,9 @@ void MainWindow::stopCapture() * Image Save */ -void MainWindow::saveImageAs() +void MainWindow::saveViewfinder() { - QImage image = viewfinder_->getCurrentImage(); - - QString filename = QFileDialog::getSaveFileName(this, "Save Image", defaultPath_, - "Image Files (*.png *.jpg *.jpeg)"); - if (filename.isEmpty()) - return; - - QImageWriter writer(filename); - writer.setQuality(95); - writer.write(image); + saveViewfinder_ = true; } /* ----------------------------------------------------------------------------- @@ -602,6 +593,29 @@ void MainWindow::processViewfinder(FrameBuffer *buffer) /* Render the frame on the viewfinder. */ viewfinder_->render(buffer, &mappedBuffers_[buffer]); + + /* Save viewfinder to file if requested. */ + if (saveViewfinder_) { + std::string filename = defaultPath_.toStdString() + "/picture-#.jpeg"; + size_t pos; + + pos = filename.find_first_of('#'); + if (pos != std::string::npos) { + std::stringstream ss; + ss << std::setw(6) << std::setfill('0') + << buffer->metadata().sequence; + filename.replace(pos, 1, ss.str()); + } + + qInfo() << "Saving viewfinder to" << filename.c_str(); + + QImage image = viewfinder_->getCurrentImage(); + QImageWriter writer(QString::fromUtf8(filename.c_str())); + writer.setQuality(95); + writer.write(image); + + saveViewfinder_ = false; + } } void MainWindow::queueRequest(FrameBuffer *buffer) diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 7b8a185511e17a8f..580bcac146fabe07 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -54,7 +54,7 @@ private Q_SLOTS: void switchCamera(int index); void toggleCapture(bool start); - void saveImageAs(); + void saveViewfinder(); void queueRequest(FrameBuffer *buffer); @@ -96,6 +96,7 @@ private: /* Capture state, buffers queue and statistics */ bool isCapturing_; + bool saveViewfinder_; Stream *vfStream_; Stream *rawStream_; std::map> freeBuffers_;