Show a patch.

GET /api/1.1/patches/2832/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2832,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/2832/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2832/",
    "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": "<20200214001810.19302-8-kieran.bingham@ideasonboard.com>",
    "date": "2020-02-14T00:18:10",
    "name": "[libcamera-devel,v2,7/7] qcam: Provide save image functionality",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "0832a6cd189d61b6c897e47725d0ab5d7f1c0e81",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/1.1/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2832/mbox/",
    "series": [
        {
            "id": 673,
            "url": "https://patchwork.libcamera.org/api/1.1/series/673/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=673",
            "date": "2020-02-14T00:18:03",
            "name": "qcam: Provide an initial toolbar",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/673/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2832/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2832/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<kieran.bingham@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 14FDE61A2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Feb 2020 01:18:16 +0100 (CET)",
            "from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A5323504;\n\tFri, 14 Feb 2020 01:18:15 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1581639495;\n\tbh=EKTNFapm9xD4ofe37wUsen3sqcrcEp0sQRca5slKVno=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=L9yV2kmjQ0W+PekQzwPxDO/FIbMD9q/0uG615tso3yJiJZP8LgWjJ4g5sg1aMyzVL\n\tq7W3CnBqazzBCLz9uwEryFf/2I5XjD8y+0zQPGGfNSyNpoFBp2GJ9JY6ahdFGucz78\n\tGUIMLYpJD2zdlWflnc+EJyVsy6vwEiO+kcM4AgCQ=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "libcamera devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Fri, 14 Feb 2020 00:18:10 +0000",
        "Message-Id": "<20200214001810.19302-8-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20200214001810.19302-1-kieran.bingham@ideasonboard.com>",
        "References": "<20200214001810.19302-1-kieran.bingham@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 7/7] qcam: Provide save image\n\tfunctionality",
        "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": "Fri, 14 Feb 2020 00:18:17 -0000"
    },
    "content": "Implement a save image button on the toolbar which will take a current\nviewfinder image and present the user with a QFileDialog to allow them\nto choose where to save the image.\n\nUtilise the QImageWriter to perform the output task.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv2:\n - Rename save to saveAs\n - Add empty file check\n - Lock concurrent access to the ViewFinder image\n\n src/qcam/assets/feathericons/feathericons.qrc |  1 +\n src/qcam/main_window.cpp                      | 22 +++++++++++++++++++\n src/qcam/main_window.h                        |  1 +\n src/qcam/viewfinder.cpp                       | 11 ++++++++++\n src/qcam/viewfinder.h                         |  5 +++++\n 5 files changed, 40 insertions(+)",
    "diff": "diff --git a/src/qcam/assets/feathericons/feathericons.qrc b/src/qcam/assets/feathericons/feathericons.qrc\nindex b8e5c2266408..6ca3a846803c 100644\n--- a/src/qcam/assets/feathericons/feathericons.qrc\n+++ b/src/qcam/assets/feathericons/feathericons.qrc\n@@ -1,6 +1,7 @@\n <!DOCTYPE RCC><RCC version=\"1.0\">\n <qresource>\n <file>./play-circle.svg</file>\n+<file>./save.svg</file>\n <file>./stop-circle.svg</file>\n <file>./x-circle.svg</file>\n </qresource>\ndiff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex ec93e0177b41..8ee2a7d68c96 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -12,7 +12,10 @@\n \n #include <QComboBox>\n #include <QCoreApplication>\n+#include <QFileDialog>\n #include <QIcon>\n+#include <QImage>\n+#include <QImageWriter>\n #include <QInputDialog>\n #include <QTimer>\n #include <QToolBar>\n@@ -88,6 +91,9 @@ int MainWindow::createToolbars()\n \taction = toolbar_->addAction(QIcon(\":stop-circle.svg\"), \"stop\");\n \tconnect(action, &QAction::triggered, this, &MainWindow::stopCapture);\n \n+\taction = toolbar_->addAction(QIcon(\":save.svg\"), \"saveAs\");\n+\tconnect(action, &QAction::triggered, this, &MainWindow::saveImageAs);\n+\n \treturn 0;\n }\n \n@@ -339,6 +345,22 @@ void MainWindow::stopCapture()\n \tsetWindowTitle(title_);\n }\n \n+void MainWindow::saveImageAs()\n+{\n+\tQImage image = viewfinder_->getCurrentImage();\n+\n+\tQString filename = QFileDialog::getSaveFileName(this, \"Save Image\", \"\",\n+\t\t\t\t\t\t\t\"Image Files (*.png *.jpg *.jpeg)\");\n+\n+\tstd::cerr << \"Save image to \" << filename.toStdString() << std::endl;\n+\n+\tif (filename == \"\")\n+\t\treturn;\n+\n+\tQImageWriter writer(filename);\n+\twriter.write(image);\n+}\n+\n void MainWindow::requestComplete(Request *request)\n {\n \tif (request->status() == Request::RequestCancelled)\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex 27ceed611d59..dcc39d7de948 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -48,6 +48,7 @@ private Q_SLOTS:\n \n \tint startCapture();\n \tvoid stopCapture();\n+\tvoid saveImageAs();\n \n private:\n \tint createToolbars();\ndiff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp\nindex 6de284d1b782..211926e185d3 100644\n--- a/src/qcam/viewfinder.cpp\n+++ b/src/qcam/viewfinder.cpp\n@@ -6,6 +6,8 @@\n  */\n \n #include <QImage>\n+#include <QImageWriter>\n+#include <QMutexLocker>\n #include <QPainter>\n \n #include \"format_converter.h\"\n@@ -23,10 +25,19 @@ ViewFinder::~ViewFinder()\n \n void ViewFinder::display(const unsigned char *raw, size_t size)\n {\n+\tQMutexLocker locker(&mutex_);\n+\n \tconverter_.convert(raw, size, image_);\n \tupdate();\n }\n \n+QImage ViewFinder::getCurrentImage()\n+{\n+\tQMutexLocker locker(&mutex_);\n+\n+\treturn *image_;\n+}\n+\n int ViewFinder::setFormat(unsigned int format, unsigned int width,\n \t\t\t  unsigned int height)\n {\ndiff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h\nindex ef5fd45b264a..06e8034fce1d 100644\n--- a/src/qcam/viewfinder.h\n+++ b/src/qcam/viewfinder.h\n@@ -7,6 +7,7 @@\n #ifndef __QCAM_VIEWFINDER_H__\n #define __QCAM_VIEWFINDER_H__\n \n+#include <QMutex>\n #include <QWidget>\n \n #include \"format_converter.h\"\n@@ -23,6 +24,8 @@ public:\n \t\t      unsigned int height);\n \tvoid display(const unsigned char *rgb, size_t size);\n \n+\tQImage getCurrentImage();\n+\n protected:\n \tvoid paintEvent(QPaintEvent *) override;\n \tQSize sizeHint() const override;\n@@ -33,7 +36,9 @@ private:\n \tunsigned int height_;\n \n \tFormatConverter converter_;\n+\n \tQImage *image_;\n+\tQMutex mutex_; // Prevent concurrent access to image_\n };\n \n #endif /* __QCAM_VIEWFINDER__ */\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "7/7"
    ]
}