mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-15 16:35:06 +03:00
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>
This commit is contained in:
parent
f0421988dc
commit
b053384ffa
4 changed files with 77 additions and 2 deletions
|
@ -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";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue