{"id":2792,"url":"https://patchwork.libcamera.org/api/1.1/patches/2792/?format=json","web_url":"https://patchwork.libcamera.org/patch/2792/","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":"<20200206150504.24204-7-kieran.bingham@ideasonboard.com>","date":"2020-02-06T15:05:04","name":"[libcamera-devel,6/6] qcam: Provide save image functionality","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e575ee9018fc9e9caeab5b48ba8551d283bc76cd","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2792/mbox/","series":[{"id":663,"url":"https://patchwork.libcamera.org/api/1.1/series/663/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=663","date":"2020-02-06T15:04:58","name":"qcam: Provide an initial toolbar","version":1,"mbox":"https://patchwork.libcamera.org/series/663/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2792/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2792/checks/","tags":{},"headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AADE760902\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Feb 2020 16:05:11 +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 5784EB7D;\n\tThu,  6 Feb 2020 16:05:11 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1581001511;\n\tbh=PtmplQqhe0wEuklPc8Jw/+DcHL1p5yhct/6PJlwZ0PY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=DbE95t+YDa1mXtoFhsk5u637OdWjqJAtUhBt7GVoxkpsXPJWiopmJYOXxkMaJIsvN\n\tt50JPbRrIeC0esDnRApg1hMFNDbRmBbLtN5ed8THkE+c/Vy0h9QknsnEvSPRj5jmzR\n\t4hFl0rWKqYv+o44xc0lhxfNQcp/OqZuP3Cc8Q4fA=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Date":"Thu,  6 Feb 2020 15:05:04 +0000","Message-Id":"<20200206150504.24204-7-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20200206150504.24204-1-kieran.bingham@ideasonboard.com>","References":"<20200206150504.24204-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 6/6] qcam: Provide save image functionality","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, 06 Feb 2020 15:05:12 -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 src/qcam/main_window.cpp | 22 ++++++++++++++++++++++\n src/qcam/main_window.h   |  1 +\n src/qcam/viewfinder.cpp  |  7 +++++++\n src/qcam/viewfinder.h    |  2 ++\n 4 files changed, 32 insertions(+)","diff":"diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 0ae4c60b8699..0e994b1e9197 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -11,7 +11,10 @@\n #include <sys/mman.h>\n \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@@ -89,6 +92,9 @@ int MainWindow::createToolbars(CameraManager *cm)\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\"), \"save\");\n+\tconnect(action, &QAction::triggered, this, &MainWindow::saveImage);\n+\n \treturn 0;\n }\n \n@@ -339,6 +345,22 @@ void MainWindow::stopCapture()\n \tsetWindowTitle(title_);\n }\n \n+void MainWindow::saveImage()\n+{\n+\t/* Take a lock to prevent updating the backed image, copy,\n+\t * then ask where to save with lock released */\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 jpeg to \" << filename.toStdString() << std::endl;\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 b0bf16dd2a09..fc85b6a46491 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 saveImage();\n \n private:\n \tint createToolbars(CameraManager *cm);\ndiff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp\nindex 6de284d1b782..3fa4a326c342 100644\n--- a/src/qcam/viewfinder.cpp\n+++ b/src/qcam/viewfinder.cpp\n@@ -6,6 +6,7 @@\n  */\n \n #include <QImage>\n+#include <QImageWriter>\n #include <QPainter>\n \n #include \"format_converter.h\"\n@@ -27,6 +28,12 @@ void ViewFinder::display(const unsigned char *raw, size_t size)\n \tupdate();\n }\n \n+QImage ViewFinder::getCurrentImage()\n+{\n+\t/* Ideally need to lock, return/copy, then unlock... Can a scoped lock work? */\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..1da79d3e67aa 100644\n--- a/src/qcam/viewfinder.h\n+++ b/src/qcam/viewfinder.h\n@@ -23,6 +23,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","prefixes":["libcamera-devel","6/6"]}