summaryrefslogtreecommitdiff
path: root/src/android/jpeg/post_processor_jpeg.cpp
diff options
context:
space:
mode:
authorUmang Jain <email@uajain.com>2020-10-28 02:54:47 +0530
committerKieran Bingham <kieran.bingham@ideasonboard.com>2020-10-28 15:52:51 +0000
commitb053384ffab467ed016019bbcf8121a6f9e48fed (patch)
treea2e1910dcdf2bd9fd6d24c21325971842d38916d /src/android/jpeg/post_processor_jpeg.cpp
parentf0421988dc7d91fbd221e2282f839cb51e1a3f8c (diff)
android: jpeg: post_processor_jpeg: Embed thumbnail into Exif metadata
Embed a Jpeg-encoded thumbnail into Exif metadata using the Thumbnailer class that got introduced. Introduce a helper function in Exif class for setting the thumbnail data. Signed-off-by: Umang Jain <email@uajain.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> [Kieran: Add todo comment, and Compression enum] Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/android/jpeg/post_processor_jpeg.cpp')
-rw-r--r--src/android/jpeg/post_processor_jpeg.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp
index 93acfe52..b9b9dc00 100644
--- a/src/android/jpeg/post_processor_jpeg.cpp
+++ b/src/android/jpeg/post_processor_jpeg.cpp
@@ -39,11 +39,45 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg,
}
streamSize_ = outCfg.size;
+
+ thumbnailer_.configure(inCfg.size, inCfg.pixelFormat);
+ StreamConfiguration thCfg = inCfg;
+ thCfg.size = thumbnailer_.size();
+ if (thumbnailEncoder_.configure(thCfg) != 0) {
+ LOG(JPEG, Error) << "Failed to configure thumbnail encoder";
+ return -EINVAL;
+ }
+
encoder_ = std::make_unique<EncoderLibJpeg>();
return encoder_->configure(inCfg);
}
+void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,
+ std::vector<unsigned char> *thumbnail)
+{
+ /* Stores the raw scaled-down thumbnail bytes. */
+ std::vector<unsigned char> rawThumbnail;
+
+ thumbnailer_.createThumbnail(source, &rawThumbnail);
+
+ if (!rawThumbnail.empty()) {
+ /*
+ * \todo Avoid value-initialization of all elements of the
+ * vector.
+ */
+ thumbnail->resize(rawThumbnail.size());
+
+ int jpeg_size = thumbnailEncoder_.encode(rawThumbnail,
+ *thumbnail, {});
+ thumbnail->resize(jpeg_size);
+
+ LOG(JPEG, Debug)
+ << "Thumbnail compress returned "
+ << jpeg_size << " bytes";
+ }
+}
+
int PostProcessorJpeg::process(const FrameBuffer &source,
Span<uint8_t> destination,
CameraMetadata *metadata)
@@ -64,6 +98,12 @@ int PostProcessorJpeg::process(const FrameBuffer &source,
* second, it is good enough.
*/
exif.setTimestamp(std::time(nullptr));
+
+ std::vector<unsigned char> thumbnail;
+ generateThumbnail(source, &thumbnail);
+ if (!thumbnail.empty())
+ exif.setThumbnail(thumbnail, Exif::Compression::JPEG);
+
if (exif.generate() != 0)
LOG(JPEG, Error) << "Failed to generate valid EXIF data";