{"id":3664,"url":"https://patchwork.libcamera.org/api/1.1/patches/3664/?format=json","web_url":"https://patchwork.libcamera.org/patch/3664/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200502121356.1045727-4-niklas.soderlund@ragnatech.se>","date":"2020-05-02T12:13:56","name":"[libcamera-devel,v4,3/3] qcam: Add RAW capture support","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"de2e4a03cd756cb052ed7e6dddf56831910f26e4","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3664/mbox/","series":[{"id":870,"url":"https://patchwork.libcamera.org/api/1.1/series/870/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=870","date":"2020-05-02T12:13:53","name":"qcam: Add RAW capture support","version":4,"mbox":"https://patchwork.libcamera.org/series/870/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3664/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3664/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 01F386149A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  2 May 2020 14:14:07 +0200 (CEST)","from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de\n\t[79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 692ec53e-8c6e-11ea-89d0-0050569116f7;\n\tSat, 02 May 2020 14:14:03 +0200 (CEST)"],"X-Halon-ID":"692ec53e-8c6e-11ea-89d0-0050569116f7","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat,  2 May 2020 14:13:56 +0200","Message-Id":"<20200502121356.1045727-4-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.26.2","In-Reply-To":"<20200502121356.1045727-1-niklas.soderlund@ragnatech.se>","References":"<20200502121356.1045727-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 3/3] qcam: Add RAW capture support","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":"Sat, 02 May 2020 12:14:08 -0000"},"content":"Add a toolbar button that captures RAW data to disk. The button is only\nenabled if the camera is configured to provide a raw stream to the\napplication.\n\nOnly when the capture action is triggered will a request with a raw\nbuffer be queued to the camera.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n* Changes since v2\n- Use a file dialog\n- Make DNG optional depending on libtiff\n\n* Changes since v3\n- Use HAVE_DNG\n- Rework MainWindow::queueRequest() to reduce code cover by lock.\n---\n src/qcam/assets/feathericons/feathericons.qrc |  1 +\n src/qcam/main_window.cpp                      | 68 ++++++++++++++++++-\n src/qcam/main_window.h                        |  4 ++\n 3 files changed, 72 insertions(+), 1 deletion(-)","diff":"diff --git a/src/qcam/assets/feathericons/feathericons.qrc b/src/qcam/assets/feathericons/feathericons.qrc\nindex c4eb7a0be6884373..fc8213928ece70ea 100644\n--- a/src/qcam/assets/feathericons/feathericons.qrc\n+++ b/src/qcam/assets/feathericons/feathericons.qrc\n@@ -1,5 +1,6 @@\n <!DOCTYPE RCC><RCC version=\"1.0\">\n <qresource>\n+<file>./aperture.svg</file>\n <file>./camera-off.svg</file>\n <file>./play-circle.svg</file>\n <file>./save.svg</file>\ndiff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 0bd9f3583ea4f6d4..8720c6c61f401c14 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -27,6 +27,8 @@\n #include <libcamera/camera_manager.h>\n #include <libcamera/version.h>\n \n+#include \"dng_writer.h\"\n+\n using namespace libcamera;\n \n /**\n@@ -48,7 +50,8 @@ public:\n };\n \n MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n-\t: options_(options), cm_(cm), allocator_(nullptr), isCapturing_(false)\n+\t: saveRaw_(nullptr), options_(options), cm_(cm), allocator_(nullptr),\n+\t  isCapturing_(false), captureRaw_(false)\n {\n \tint ret;\n \n@@ -144,6 +147,16 @@ int MainWindow::createToolbars()\n \taction->setShortcut(QKeySequence::SaveAs);\n \tconnect(action, &QAction::triggered, this, &MainWindow::saveImageAs);\n \n+#ifdef HAVE_DNG\n+\t/* Save Raw action. */\n+\taction = toolbar_->addAction(QIcon::fromTheme(\"camera-photo\",\n+\t\t\t\t\t\t      QIcon(\":aperture.svg\")),\n+\t\t\t\t     \"Save Raw\");\n+\taction->setEnabled(false);\n+\tconnect(action, &QAction::triggered, this, &MainWindow::captureRaw);\n+\tsaveRaw_ = action;\n+#endif\n+\n \treturn 0;\n }\n \n@@ -369,6 +382,10 @@ int MainWindow::startCapture()\n \n \tadjustSize();\n \n+\t/* Configure the raw capture button. */\n+\tif (saveRaw_)\n+\t\tsaveRaw_->setEnabled(config_->size() == 2);\n+\n \t/* Allocate and map buffers. */\n \tallocator_ = new FrameBufferAllocator(camera_);\n \tfor (StreamConfiguration &config : *config_) {\n@@ -474,6 +491,9 @@ void MainWindow::stopCapture()\n \t\treturn;\n \n \tviewfinder_->stop();\n+\tif (saveRaw_)\n+\t\tsaveRaw_->setEnabled(false);\n+\tcaptureRaw_ = false;\n \n \tint ret = camera_->stop();\n \tif (ret)\n@@ -524,6 +544,32 @@ void MainWindow::saveImageAs()\n \twriter.write(image);\n }\n \n+void MainWindow::captureRaw()\n+{\n+\tcaptureRaw_ = true;\n+}\n+\n+void MainWindow::processRaw(FrameBuffer *buffer)\n+{\n+#ifdef HAVE_DNG\n+\tQString defaultPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);\n+\tQString filename = QFileDialog::getSaveFileName(this, \"Save DNG\", defaultPath,\n+\t\t\t\t\t\t\t\"DNG Files (*.dng)\");\n+\n+\tif (!filename.isEmpty()) {\n+\t\tconst MappedBuffer &mapped = mappedBuffers_[buffer];\n+\t\tDNGWriter::write(filename.toStdString().c_str(), camera_.get(),\n+\t\t\t\t rawStream_->configuration(), buffer,\n+\t\t\t\t mapped.memory);\n+\t}\n+#endif\n+\n+\t{\n+\t\tQMutexLocker locker(&mutex_);\n+\t\tfreeBuffers_[rawStream_].enqueue(buffer);\n+\t}\n+}\n+\n /* -----------------------------------------------------------------------------\n  * Request Completion Handling\n  */\n@@ -566,6 +612,9 @@ void MainWindow::processCapture()\n \t/* Process buffers. */\n \tif (buffers.count(vfStream_))\n \t\tprocessViewfinder(buffers[vfStream_]);\n+\n+\tif (buffers.count(rawStream_))\n+\t\tprocessRaw(buffers[rawStream_]);\n }\n \n void MainWindow::processViewfinder(FrameBuffer *buffer)\n@@ -598,5 +647,22 @@ void MainWindow::queueRequest(FrameBuffer *buffer)\n \n \trequest->addBuffer(vfStream_, buffer);\n \n+\tif (captureRaw_) {\n+\t\tFrameBuffer *buffer = nullptr;\n+\n+\t\t{\n+\t\t\tQMutexLocker locker(&mutex_);\n+\t\t\tif (!freeBuffers_[rawStream_].isEmpty())\n+\t\t\t\tbuffer = freeBuffers_[rawStream_].dequeue();\n+\t\t}\n+\n+\t\tif (buffer) {\n+\t\t\trequest->addBuffer(rawStream_, buffer);\n+\t\t\tcaptureRaw_ = false;\n+\t\t} else {\n+\t\t\tqWarning() << \"No free buffer available for RAW capture\";\n+\t\t}\n+\t}\n+\n \tcamera_->queueRequest(request);\n }\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex 4856ecc10729159c..295ecc537e9d45bf 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -55,6 +55,8 @@ private Q_SLOTS:\n \tvoid toggleCapture(bool start);\n \n \tvoid saveImageAs();\n+\tvoid captureRaw();\n+\tvoid processRaw(FrameBuffer *buffer);\n \n \tvoid queueRequest(FrameBuffer *buffer);\n \n@@ -75,6 +77,7 @@ private:\n \tQToolBar *toolbar_;\n \tQAction *startStopAction_;\n \tQComboBox *cameraCombo_;\n+\tQAction *saveRaw_;\n \tViewFinder *viewfinder_;\n \n \tQIcon iconPlay_;\n@@ -96,6 +99,7 @@ private:\n \n \t/* Capture state, buffers queue and statistics */\n \tbool isCapturing_;\n+\tbool captureRaw_;\n \tStream *vfStream_;\n \tStream *rawStream_;\n \tstd::map<Stream *, QQueue<FrameBuffer *>> freeBuffers_;\n","prefixes":["libcamera-devel","v4","3/3"]}