[libcamera-devel,v1,2/3,DNI] jpeg/thumbnailer: write thumbnail to file

Message ID 20201002103416.53623-3-email@uajain.com
State Superseded
Headers show
Series
  • Basic NV12 image thumbnailer
Related show

Commit Message

Umang Jain Oct. 2, 2020, 10:34 a.m. UTC
Signed-off-by: Umang Jain <email@uajain.com>
---
 src/android/jpeg/thumbnailer.cpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Patch

diff --git a/src/android/jpeg/thumbnailer.cpp b/src/android/jpeg/thumbnailer.cpp
index d706ea6..d1dbdaf 100644
--- a/src/android/jpeg/thumbnailer.cpp
+++ b/src/android/jpeg/thumbnailer.cpp
@@ -34,6 +34,22 @@  void Thumbnailer::configure(const Size &sourceSize, PixelFormat pixelFormat)
 	validConfiguration_ = true;
 }
 
+static std::string datetime()
+{
+	time_t rawtime;
+	struct tm *timeinfo;
+	char buffer[80];
+	static unsigned int milliseconds = 0;
+
+	time(&rawtime);
+	timeinfo = localtime(&rawtime);
+
+	strftime(buffer, 80, "%d-%m-%Y.%H-%M-%S.", timeinfo);
+
+	/* milliseconds is just a fast hack to ensure unique filenames */
+	return std::string(buffer) + std::to_string(milliseconds++);
+}
+
 /* Compute a thumbnail size with same aspect ratio as source. */
 void Thumbnailer::computeThumbnailSize()
 {
@@ -99,6 +115,12 @@  int Thumbnailer::scaleBuffer(const FrameBuffer *source, Span<uint8_t> &dest)
 		}
 	}
 
+	/* Helper code: Write the output pixels to a file so we can inspect */
+	File file("/tmp/" + datetime() + ".raw");
+	int32_t ret = file.open(File::WriteOnly);
+	ret = file.write({ destination, dstSize });
+	LOG(Thumbnailer, Info) << "Wrote " << ret << " bytes: " << targetSize_.width << "x" << targetSize_.height;
+
 	/* Write scaled pixels to dest */
 	dest = { destination, dstSize };