[{"id":4689,"web_url":"https://patchwork.libcamera.org/comment/4689/","msgid":"<20200430193457.GV5856@pendragon.ideasonboard.com>","date":"2020-04-30T19:34:57","subject":"Re: [libcamera-devel] [RFC/PATCH 4/5] qcam: Remove QFileDialog from\n\tJPEG capture","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Thu, Apr 30, 2020 at 02:36:03AM +0200, Niklas Söderlund wrote:\n> Instead of popping up a dialog to enter a filename to save use the\n> sequence number and the default output directory to generate a path.\n\nI think we should keep the current save option and add a quick save for\nthis.\n\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/qcam/main_window.cpp | 40 +++++++++++++++++++++++++++-------------\n>  src/qcam/main_window.h   |  3 ++-\n>  2 files changed, 29 insertions(+), 14 deletions(-)\n> \n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index 470f78162cabffe5..f57aaf4a27e5f4ca 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -8,6 +8,7 @@\n>  #include \"main_window.h\"\n>  \n>  #include <iomanip>\n> +#include <sstream>\n>  #include <string>\n>  #include <sys/mman.h>\n>  \n> @@ -146,8 +147,7 @@ int MainWindow::createToolbars()\n>  \taction = toolbar_->addAction(QIcon::fromTheme(\"document-save-as\",\n>  \t\t\t\t\t\t      QIcon(\":save.svg\")),\n>  \t\t\t\t     \"Save As...\");\n> -\taction->setShortcut(QKeySequence::SaveAs);\n> -\tconnect(action, &QAction::triggered, this, &MainWindow::saveImageAs);\n> +\tconnect(action, &QAction::triggered, this, &MainWindow::saveViewfinder);\n>  \n>  \treturn 0;\n>  }\n> @@ -509,18 +509,9 @@ void MainWindow::stopCapture()\n>   * Image Save\n>   */\n>  \n> -void MainWindow::saveImageAs()\n> +void MainWindow::saveViewfinder()\n>  {\n> -\tQImage image = viewfinder_->getCurrentImage();\n> -\n> -\tQString filename = QFileDialog::getSaveFileName(this, \"Save Image\", defaultPath_,\n> -\t\t\t\t\t\t\t\"Image Files (*.png *.jpg *.jpeg)\");\n> -\tif (filename.isEmpty())\n> -\t\treturn;\n> -\n> -\tQImageWriter writer(filename);\n> -\twriter.setQuality(95);\n> -\twriter.write(image);\n> +\tsaveViewfinder_ = true;\n\nYou'll need to set saveViewFinder_ to false in stopCapture() I think.\nThere could also be other concurrent operations that I haven't thought\nabout.\n\n>  }\n>  \n>  /* -----------------------------------------------------------------------------\n> @@ -602,6 +593,29 @@ void MainWindow::processViewfinder(FrameBuffer *buffer)\n>  \n>  \t/* Render the frame on the viewfinder. */\n>  \tviewfinder_->render(buffer, &mappedBuffers_[buffer]);\n> +\n> +\t/* Save viewfinder to file if requested. */\n> +\tif (saveViewfinder_) {\n> +\t\tstd::string filename = defaultPath_.toStdString() + \"/picture-#.jpeg\";\n\ns/jpeg/jpg/\n\nNote that Qt can also save to other formats, such as PNG. Removing the\nfile save dialog we're losing this capability.\n\n> +\t\tsize_t pos;\n> +\n> +\t\tpos = filename.find_first_of('#');\n> +\t\tif (pos != std::string::npos) {\n> +\t\t\tstd::stringstream ss;\n> +\t\t\tss << std::setw(6) << std::setfill('0')\n> +\t\t\t   << buffer->metadata().sequence;\n> +\t\t\tfilename.replace(pos, 1, ss.str());\n> +\t\t}\n> +\n> +\t\tqInfo() << \"Saving viewfinder to\" << filename.c_str();\n\nUse QString instead of std:string, and you can do\n\n\t\tQString filename(\"%1/picture-%2.jpg\");\n\t\tfilename = filename.arg(defaultPath_)\n\t\t\t\t   .arg(buffer->metadata().sequence, 6, 10,\n\t\t\t\t        QLatin1Char('0'));\n\n(and you can drop <sstream>)\n\n> +\n> +\t\tQImage image = viewfinder_->getCurrentImage();\n> +\t\tQImageWriter writer(QString::fromUtf8(filename.c_str()));\n> +\t\twriter.setQuality(95);\n> +\t\twriter.write(image);\n> +\n> +\t\tsaveViewfinder_ = false;\n> +\t}\n\nWith this you're adding a delay when taking a snapshot :-S\n\n>  }\n>  \n>  void MainWindow::queueRequest(FrameBuffer *buffer)\n> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> index 7b8a185511e17a8f..580bcac146fabe07 100644\n> --- a/src/qcam/main_window.h\n> +++ b/src/qcam/main_window.h\n> @@ -54,7 +54,7 @@ private Q_SLOTS:\n>  \tvoid switchCamera(int index);\n>  \tvoid toggleCapture(bool start);\n>  \n> -\tvoid saveImageAs();\n> +\tvoid saveViewfinder();\n>  \n>  \tvoid queueRequest(FrameBuffer *buffer);\n>  \n> @@ -96,6 +96,7 @@ private:\n>  \n>  \t/* Capture state, buffers queue and statistics */\n>  \tbool isCapturing_;\n> +\tbool saveViewfinder_;\n>  \tStream *vfStream_;\n>  \tStream *rawStream_;\n>  \tstd::map<Stream *, QQueue<FrameBuffer *>> freeBuffers_;","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B6445613A8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 21:34:59 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 339FC72C;\n\tThu, 30 Apr 2020 21:34:59 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"eETpt7tx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588275299;\n\tbh=T3thuypAvqWbqjCijCVZwCVdss65aAZGcdVlQtZaIjI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=eETpt7tx8CeN3lDf0a43cWUND5x3TVsZAQn2/KgrShG06KoLdTkO/cgtKjw8vq51u\n\tzK1d5vknFYl1qWH4WHH4C28dwy6giyjUrjfp5Ih4dRMiTo9eBf4vrNSH8zT0VM6jfk\n\tDCaHyGb+uxMqWE4bYJm090u9SJM+26fAW2ETAVsw=","Date":"Thu, 30 Apr 2020 22:34:57 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200430193457.GV5856@pendragon.ideasonboard.com>","References":"<20200430003604.2423018-1-niklas.soderlund@ragnatech.se>\n\t<20200430003604.2423018-5-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200430003604.2423018-5-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [RFC/PATCH 4/5] qcam: Remove QFileDialog from\n\tJPEG capture","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 30 Apr 2020 19:34:59 -0000"}}]