From patchwork Mon Oct 17 17:17:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17614 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C8B11BD16B for ; Mon, 17 Oct 2022 17:18:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7BE2262E0B; Mon, 17 Oct 2022 19:18:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666027081; bh=OB8Nx/5WhI+4P+Q7brDY0+UAXS+POsdPKzTcvVI9/kU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=2HuRobIt27rBsyCtBfedcP3YLYJBIN/NN4XxqzkVPwP4NC7AnmOy0pCBdyzL9DjeW qRJjmKYyfR+K76FRPLH8S7rb3pm0MOu1EvLE7XX226pe/VipNXsKD2xxSxXcKYu8aa Ykaf5Db1xnGtEhyCNjE/rVuTXRRyWd5jQYRaAjunvr1j0p5nzVEWVvez28QwkzdLNC jVo/5tfaLlozcWLltZXtKSDC2Dzj+Sbt5Rvb2n63V5lhMxsofEfJ8mjfSAw3uGbmMK B/zcGzpgsyIzpmmaSGgbeVljqZNU5ieESTn8l+0biDfnD0ldai3NKBKkKZtaK4AooG I3YeILQGlpMJA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AAEF562DEE for ; Mon, 17 Oct 2022 19:17:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Xi7dNPm5"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3BF0BCCF; Mon, 17 Oct 2022 19:17:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1666027077; bh=OB8Nx/5WhI+4P+Q7brDY0+UAXS+POsdPKzTcvVI9/kU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xi7dNPm54MDa/00mYhyKkQnGxUSQjy1J3X+v6qOHwPGbyXEwH+lJArSyyHxMeN5XV L4JlzUZKoHHdWp0Qpo/0An+GngE2s2KCI/3rWHp8QHTG3vluyYVByPKLtsTu+/1YAY GlUusnFIF4MmJz0Lo2d8HJW59zB4gOCsCWl+zJSs= To: libcamera-devel@lists.libcamera.org Date: Tue, 18 Oct 2022 02:17:40 +0900 Message-Id: <20221017171741.3803909-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221017171741.3803909-1-paul.elder@ideasonboard.com> References: <20221017171741.3803909-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] cam: file_sink: Add support for DNG output X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add support for outputting buffers in DNG format. It reuses the DNG writer that we had previously in qcam. Signed-off-by: Paul Elder --- src/cam/camera_session.cpp | 3 ++- src/cam/file_sink.cpp | 31 +++++++++++++++++++++++++------ src/cam/file_sink.h | 7 +++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp index 238186a3..2557f32d 100644 --- a/src/cam/camera_session.cpp +++ b/src/cam/camera_session.cpp @@ -208,7 +208,8 @@ int CameraSession::start() if (options_.isSet(OptFile)) { if (!options_[OptFile].toString().empty()) sink_ = std::make_unique(streamNames_, - options_[OptFile]); + options_[OptFile], + camera_.get()); else sink_ = std::make_unique(streamNames_); } diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp index 45213d4a..fabf163c 100644 --- a/src/cam/file_sink.cpp +++ b/src/cam/file_sink.cpp @@ -15,14 +15,15 @@ #include +#include "dng_writer.h" #include "file_sink.h" #include "image.h" using namespace libcamera; FileSink::FileSink(const std::map &streamNames, - const std::string &pattern) - : streamNames_(streamNames), pattern_(pattern) + const std::string &pattern, const libcamera::Camera *camera) + : streamNames_(streamNames), pattern_(pattern), camera_(camera) { } @@ -51,12 +52,13 @@ void FileSink::mapBuffer(FrameBuffer *buffer) bool FileSink::processRequest(Request *request) { for (auto [stream, buffer] : request->buffers()) - writeBuffer(stream, buffer); + writeBuffer(stream, buffer, request->metadata()); return true; } -void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer) +void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer, + [[maybe_unused]] const ControlList &metadata) { std::string filename; size_t pos; @@ -65,6 +67,10 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer) if (!pattern_.empty()) filename = pattern_; +#ifdef HAVE_TIFF + bool dng = filename.find(".dng", filename.size() - 4) != std::string::npos; +#endif /* HAVE_TIFF */ + if (filename.empty() || filename.back() == '/') filename += "frame-#.bin"; @@ -76,6 +82,21 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer) filename.replace(pos, 1, ss.str()); } + Image *image = mappedBuffers_[buffer].get(); + +#ifdef HAVE_TIFF + if (dng) { + ret = DNGWriter::write(filename.c_str(), camera_, + stream->configuration(), metadata, + buffer, image->data(0).data()); + if (ret < 0) + std::cerr << "failed to write DNG " << filename + << std::endl; + + return; + } +#endif /* HAVE_TIFF */ + fd = open(filename.c_str(), O_CREAT | O_WRONLY | (pos == std::string::npos ? O_APPEND : O_TRUNC), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); @@ -86,8 +107,6 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer) return; } - Image *image = mappedBuffers_[buffer].get(); - for (unsigned int i = 0; i < buffer->planes().size(); ++i) { const FrameMetadata::Plane &meta = buffer->metadata().planes()[i]; diff --git a/src/cam/file_sink.h b/src/cam/file_sink.h index 067736f5..e4838b37 100644 --- a/src/cam/file_sink.h +++ b/src/cam/file_sink.h @@ -21,7 +21,7 @@ class FileSink : public FrameSink { public: FileSink(const std::map &streamNames, - const std::string &pattern = ""); + const std::string &pattern = "", const libcamera::Camera *camera = nullptr); ~FileSink(); int configure(const libcamera::CameraConfiguration &config) override; @@ -32,9 +32,12 @@ public: private: void writeBuffer(const libcamera::Stream *stream, - libcamera::FrameBuffer *buffer); + libcamera::FrameBuffer *buffer, + const libcamera::ControlList &metadata); std::map streamNames_; std::string pattern_; std::map> mappedBuffers_; + + const libcamera::Camera *camera_; };