summaryrefslogtreecommitdiff
path: root/src/apps/cam
diff options
context:
space:
mode:
authorMilan Zamazal <mzamazal@redhat.com>2024-03-22 20:50:32 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-03-28 03:11:59 +0200
commit666f17affcad23118e110909331b499411b57562 (patch)
tree1f46cd8839d090767fe6501b6db0d7a5d79ce88c /src/apps/cam
parent48f3a25d7c5f6f4b2eef590c79d8eeaef32014d2 (diff)
apps: cam: Add support for PPM output format
When file output is requested from cam app, it simply dumps the processed data and it must be converted to a readable image format manually. Let's add support for PPM output file format to make files produced by cam directly readable by image display and processing software. For now, only BGR888 output format, which is the simplest one to use, is supported but nothing prevents adding support for other output formats if needed. Nevertheless, they would typically need byte reordering or other conversions for PPM file format. It may be better to find a way to dump the image data in other output formats directly using some of the already existing file formats or raw file format converters. Signed-off-by: Milan Zamazal <mzamazal@redhat.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/apps/cam')
-rw-r--r--src/apps/cam/file_sink.cpp11
-rw-r--r--src/apps/cam/main.cpp2
2 files changed, 13 insertions, 0 deletions
diff --git a/src/apps/cam/file_sink.cpp b/src/apps/cam/file_sink.cpp
index dca350c4..906b50e6 100644
--- a/src/apps/cam/file_sink.cpp
+++ b/src/apps/cam/file_sink.cpp
@@ -17,6 +17,7 @@
#include "../common/dng_writer.h"
#include "../common/image.h"
+#include "../common/ppm_writer.h"
#include "file_sink.h"
@@ -76,6 +77,7 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer,
#ifdef HAVE_TIFF
bool dng = filename.find(".dng", filename.size() - 4) != std::string::npos;
#endif /* HAVE_TIFF */
+ bool ppm = filename.find(".ppm", filename.size() - 4) != std::string::npos;
if (filename.empty() || filename.back() == '/')
filename += "frame-#.bin";
@@ -102,6 +104,15 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer,
return;
}
#endif /* HAVE_TIFF */
+ if (ppm) {
+ ret = PPMWriter::write(filename.c_str(), stream->configuration(),
+ image->data(0));
+ if (ret < 0)
+ std::cerr << "failed to write PPM file `" << filename
+ << "'" << std::endl;
+
+ return;
+ }
fd = open(filename.c_str(), O_CREAT | O_WRONLY |
(pos == std::string::npos ? O_APPEND : O_TRUNC),
diff --git a/src/apps/cam/main.cpp b/src/apps/cam/main.cpp
index 179cc376..1aabee01 100644
--- a/src/apps/cam/main.cpp
+++ b/src/apps/cam/main.cpp
@@ -154,6 +154,8 @@ int CamApp::parseOptions(int argc, char *argv[])
"If the file name ends with '.dng', then the frame will be written to\n"
"the output file(s) in DNG format.\n"
#endif
+ "If the file name ends with '.ppm', then the frame will be written to\n"
+ "the output file(s) in PPM format.\n"
"The default file name is 'frame-#.bin'.",
"file", ArgumentOptional, "filename", false,
OptCamera);