android: exif: Fix thumbnail buffer lifetime
Previously the thumbnail buffer is destructed before even being used in Exif. This patch moves the buffer into class Exif, so that the developer won't need to worry about its lifetime. Signed-off-by: Harvey Yang <chenghaoyang@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
This commit is contained in:
committed by
Umang Jain
parent
5646849b59
commit
74794de987
@@ -430,16 +430,13 @@ void Exif::setOrientation(int orientation)
|
||||
setShort(EXIF_IFD_0, EXIF_TAG_ORIENTATION, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* The thumbnail data should remain valid until the Exif object is destroyed.
|
||||
* Failing to do so, might result in no thumbnail data being set even after a
|
||||
* call to Exif::setThumbnail().
|
||||
*/
|
||||
void Exif::setThumbnail(Span<const unsigned char> thumbnail,
|
||||
void Exif::setThumbnail(std::vector<unsigned char> &&thumbnail,
|
||||
Compression compression)
|
||||
{
|
||||
data_->data = const_cast<unsigned char *>(thumbnail.data());
|
||||
data_->size = thumbnail.size();
|
||||
thumbnailData_ = std::move(thumbnail);
|
||||
|
||||
data_->data = thumbnailData_.data();
|
||||
data_->size = thumbnailData_.size();
|
||||
|
||||
setShort(EXIF_IFD_0, EXIF_TAG_COMPRESSION, compression);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libexif/exif-data.h>
|
||||
|
||||
@@ -60,7 +61,7 @@ public:
|
||||
|
||||
void setOrientation(int orientation);
|
||||
void setSize(const libcamera::Size &size);
|
||||
void setThumbnail(libcamera::Span<const unsigned char> thumbnail,
|
||||
void setThumbnail(std::vector<unsigned char> &&thumbnail,
|
||||
Compression compression);
|
||||
void setTimestamp(time_t timestamp, std::chrono::milliseconds msec);
|
||||
|
||||
@@ -106,4 +107,6 @@ private:
|
||||
|
||||
unsigned char *exifData_;
|
||||
unsigned int size_;
|
||||
|
||||
std::vector<unsigned char> thumbnailData_;
|
||||
};
|
||||
|
||||
@@ -166,7 +166,7 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu
|
||||
std::vector<unsigned char> thumbnail;
|
||||
generateThumbnail(source, thumbnailSize, quality, &thumbnail);
|
||||
if (!thumbnail.empty())
|
||||
exif.setThumbnail(thumbnail, Exif::Compression::JPEG);
|
||||
exif.setThumbnail(std::move(thumbnail), Exif::Compression::JPEG);
|
||||
}
|
||||
|
||||
resultMetadata->addEntry(ANDROID_JPEG_THUMBNAIL_SIZE, data, 2);
|
||||
|
||||
Reference in New Issue
Block a user