Patch Detail
Show a patch.
GET /api/1.1/patches/3619/?format=api
{ "id": 3619, "url": "https://patchwork.libcamera.org/api/1.1/patches/3619/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3619/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200430003604.2423018-6-niklas.soderlund@ragnatech.se>", "date": "2020-04-30T00:36:04", "name": "[libcamera-devel,RFC/PATCH,5/5] qcam: Add RAW capture support", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "2c2ea0ac5a63be2334ad12ca042686e0fd77309b", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3619/mbox/", "series": [ { "id": 855, "url": "https://patchwork.libcamera.org/api/1.1/series/855/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=855", "date": "2020-04-30T00:36:00", "name": "qcam: Add RAW capture support", "version": 1, "mbox": "https://patchwork.libcamera.org/series/855/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3619/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3619/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 A11A7613C1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 02:36:38 +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 87c5111f-8a7a-11ea-89d0-0050569116f7;\n\tThu, 30 Apr 2020 02:35:45 +0200 (CEST)" ], "X-Halon-ID": "87c5111f-8a7a-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": "Thu, 30 Apr 2020 02:36:04 +0200", "Message-Id": "<20200430003604.2423018-6-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", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC/PATCH 5/5] 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": "Thu, 30 Apr 2020 00:36:40 -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>\n---\n src/qcam/assets/feathericons/feathericons.qrc | 1 +\n src/qcam/main_window.cpp | 94 ++++++++++++++++++-\n src/qcam/main_window.h | 4 +\n 3 files changed, 98 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 f57aaf4a27e5f4ca..535fa53d6705a1a9 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -7,10 +7,13 @@\n \n #include \"main_window.h\"\n \n+#include <fcntl.h>\n #include <iomanip>\n #include <sstream>\n #include <string>\n #include <sys/mman.h>\n+#include <sys/stat.h>\n+#include <unistd.h>\n \n #include <QComboBox>\n #include <QCoreApplication>\n@@ -49,7 +52,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: options_(options), cm_(cm), allocator_(nullptr), isCapturing_(false),\n+\t captureRaw_(false)\n {\n \tint ret;\n \n@@ -149,6 +153,14 @@ int MainWindow::createToolbars()\n \t\t\t\t \"Save As...\");\n \tconnect(action, &QAction::triggered, this, &MainWindow::saveViewfinder);\n \n+\t/* Save Raw action. */\n+\taction = toolbar_->addAction(QIcon::fromTheme(\"document-save-as\",\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::saveRaw);\n+\tsaveRaw_ = action;\n+\n \treturn 0;\n }\n \n@@ -369,6 +381,9 @@ int MainWindow::startCapture()\n \n \tadjustSize();\n \n+\t/* Configure the raw capture button. */\n+\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 +489,7 @@ void MainWindow::stopCapture()\n \t\treturn;\n \n \tviewfinder_->stop();\n+\tsaveRaw_->setEnabled(false);\n \n \tint ret = camera_->stop();\n \tif (ret)\n@@ -514,6 +530,11 @@ void MainWindow::saveViewfinder()\n \tsaveViewfinder_ = true;\n }\n \n+void MainWindow::saveRaw()\n+{\n+\tcaptureRaw_ = true;\n+}\n+\n /* -----------------------------------------------------------------------------\n * Request Completion Handling\n */\n@@ -558,6 +579,9 @@ void MainWindow::processCapture()\n \t\tif (buffers.count(vfStream_))\n \t\t\tprocessViewfinder(buffers[vfStream_]);\n \n+\t\tif (buffers.count(rawStream_))\n+\t\t\tprocessRaw(buffers[rawStream_]);\n+\n \t\t/*\n \t\t * Return buffers so they can be reused. No processing involving\n \t\t * a buffer can happen after they are returned to the free list.\n@@ -618,6 +642,61 @@ void MainWindow::processViewfinder(FrameBuffer *buffer)\n \t}\n }\n \n+void MainWindow::processRaw(FrameBuffer *raw)\n+{\n+\t/* TODO: Should write a DNG file instead of a .raw and .jpeg file. */\n+\n+\tunsigned int seq = raw->metadata().sequence;\n+\tstd::string filename;\n+\tint fd, ret = 0;\n+\tsize_t pos;\n+\n+\t/* Write .raw */\n+\tfilename = defaultPath_.toStdString() + \"/raw-#.raw\";\n+\tpos = filename.find_first_of('#');\n+\tif (pos != std::string::npos) {\n+\t\tstd::stringstream ss;\n+\t\tss << std::setw(6) << std::setfill('0') << seq;\n+\t\tfilename.replace(pos, 1, ss.str());\n+\t}\n+\tqInfo() << \"Saving\" << filename.c_str();\n+\n+\tfd = open(filename.c_str(), O_CREAT | O_WRONLY |\n+\t\t (pos == std::string::npos ? O_APPEND : O_TRUNC),\n+\t\t S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);\n+\tif (fd == -1) {\n+\t\tqWarning() << \"Failed to open raw output file\";\n+\t\treturn;\n+\t}\n+\n+\tconst MappedBuffer &info = mappedBuffers_[raw];\n+\tret = ::write(fd, info.memory, info.size);\n+\tif (ret < 0) {\n+\t\tret = -errno;\n+\t\tqWarning() << \"write error: \" << strerror(-ret);\n+\t} else if (ret != (int)info.size) {\n+\t\tqWarning() << \"write error: only \" << ret\n+\t\t\t << \" bytes written instead of \" << info.size;\n+\t}\n+\n+\t::close(fd);\n+\n+\t/* Write scaled thumbnail .jpeg */\n+\tfilename = defaultPath_.toStdString() + \"/raw-#.jpeg\";\n+\tpos = filename.find_first_of('#');\n+\tif (pos != std::string::npos) {\n+\t\tstd::stringstream ss;\n+\t\tss << std::setw(6) << std::setfill('0') << seq;\n+\t\tfilename.replace(pos, 1, ss.str());\n+\t}\n+\tqInfo() << \"Saving\" << filename.c_str();\n+\n+\tQImage image = viewfinder_->getCurrentImage().scaledToHeight(640);\n+\tQImageWriter writer(QString::fromUtf8(filename.c_str()));\n+\twriter.setQuality(95);\n+\twriter.write(image);\n+}\n+\n void MainWindow::queueRequest(FrameBuffer *buffer)\n {\n \tRequest *request = camera_->createRequest();\n@@ -628,5 +707,18 @@ void MainWindow::queueRequest(FrameBuffer *buffer)\n \n \trequest->addBuffer(vfStream_, buffer);\n \n+\tif (captureRaw_) {\n+\t\tQMutexLocker locker(&mutex_);\n+\n+\t\tif (freeBuffers_[rawStream_].isEmpty()) {\n+\t\t\tqWarning() << \"Raw stream buffer empty\";\n+\t\t\treturn;\n+\t\t}\n+\n+\t\trequest->addBuffer(rawStream_,\n+\t\t\t\t freeBuffers_[rawStream_].dequeue());\n+\t\tcaptureRaw_ = false;\n+\t}\n+\n \tcamera_->queueRequest(request);\n }\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex 580bcac146fabe07..37a1d95351e144e0 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -55,6 +55,7 @@ private Q_SLOTS:\n \tvoid toggleCapture(bool start);\n \n \tvoid saveViewfinder();\n+\tvoid saveRaw();\n \n \tvoid queueRequest(FrameBuffer *buffer);\n \n@@ -70,10 +71,12 @@ private:\n \tvoid requestComplete(Request *request);\n \tvoid processCapture();\n \tvoid processViewfinder(FrameBuffer *buffer);\n+\tvoid processRaw(FrameBuffer *raw);\n \n \t/* UI elements */\n \tQToolBar *toolbar_;\n \tQAction *startStopAction_;\n+\tQAction *saveRaw_;\n \tViewFinder *viewfinder_;\n \n \tQIcon iconPlay_;\n@@ -97,6 +100,7 @@ private:\n \t/* Capture state, buffers queue and statistics */\n \tbool isCapturing_;\n \tbool saveViewfinder_;\n+\tbool captureRaw_;\n \tStream *vfStream_;\n \tStream *rawStream_;\n \tstd::map<Stream *, QQueue<FrameBuffer *>> freeBuffers_;\n", "prefixes": [ "libcamera-devel", "RFC/PATCH", "5/5" ] }