[libcamera-devel] [PATCH 4/5] thumbnailer: Change the type of thumbnail to MappedBuffer
Hirokazu Honda
hiroh at chromium.org
Tue Aug 31 08:34:37 CEST 2021
Thumbnailer uses the std::vector<unsigned char> for the created
thumbnail. The created thumbnail is NV12. It should rather be
deal with MappedBuffer interface.
Signed-off-by: Hirokazu Honda <hiroh at chromium.org>
---
src/android/jpeg/post_processor_jpeg.cpp | 12 ++++++++----
src/android/jpeg/thumbnailer.cpp | 12 +++++++-----
src/android/jpeg/thumbnailer.h | 6 +++++-
3 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp
index 3160a784..6eefce0f 100644
--- a/src/android/jpeg/post_processor_jpeg.cpp
+++ b/src/android/jpeg/post_processor_jpeg.cpp
@@ -56,7 +56,7 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,
std::vector<unsigned char> *thumbnail)
{
/* Stores the raw scaled-down thumbnail bytes. */
- std::vector<unsigned char> rawThumbnail;
+ std::unique_ptr<MappedBuffer> rawThumbnail;
thumbnailer_.createThumbnail(source, targetSize, &rawThumbnail);
@@ -65,14 +65,18 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,
thCfg.pixelFormat = thumbnailer_.pixelFormat();
int ret = thumbnailEncoder_.configure(thCfg);
- if (!rawThumbnail.empty() && !ret) {
+ if (!rawThumbnail && !ret) {
/*
* \todo Avoid value-initialization of all elements of the
* vector.
*/
- thumbnail->resize(rawThumbnail.size());
+ size_t bufferSize = 0;
+ for (const auto &plane : rawThumbnail->planes())
+ bufferSize += plane.size();
+ thumbnail->resize(bufferSize);
- int jpeg_size = thumbnailEncoder_.encode(rawThumbnail,
+ libcamera::Span rawThumbnailData(rawThumbnail->planes()[0].data(), bufferSize);
+ int jpeg_size = thumbnailEncoder_.encode(rawThumbnailData,
*thumbnail, {}, quality);
thumbnail->resize(jpeg_size);
diff --git a/src/android/jpeg/thumbnailer.cpp b/src/android/jpeg/thumbnailer.cpp
index fe2c4969..f88cda10 100644
--- a/src/android/jpeg/thumbnailer.cpp
+++ b/src/android/jpeg/thumbnailer.cpp
@@ -39,7 +39,7 @@ void Thumbnailer::configure(const Size &sourceSize, PixelFormat pixelFormat)
void Thumbnailer::createThumbnail(const FrameBuffer &source,
const Size &targetSize,
- std::vector<unsigned char> *destination)
+ std::unique_ptr<libcamera::MappedBuffer> *dest)
{
MappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);
if (!frame.isValid()) {
@@ -67,10 +67,12 @@ void Thumbnailer::createThumbnail(const FrameBuffer &source,
unsigned char *srcCb, *srcCr;
unsigned char *dstY, *srcY;
- size_t dstSize = (th * tw) + ((th / 2) * tw);
- destination->resize(dstSize);
- unsigned char *dst = destination->data();
- unsigned char *dstC = dst + th * tw;
+ *dest = std::make_unique<MappedVectorBuffer>(
+ std::vector<std::vector<uint8_t>>{
+ std::vector<uint8_t>(th * tw),
+ std::vector<uint8_t>((th / 2) * tw) });
+ unsigned char *dst = (*dest)->planes()[0].data();
+ unsigned char *dstC = (*dest)->planes()[1].data();
for (unsigned int y = 0; y < th; y += 2) {
unsigned int sourceY = (sh * y + th / 2) / th;
diff --git a/src/android/jpeg/thumbnailer.h b/src/android/jpeg/thumbnailer.h
index 4d086c49..8b007f1e 100644
--- a/src/android/jpeg/thumbnailer.h
+++ b/src/android/jpeg/thumbnailer.h
@@ -7,11 +7,15 @@
#ifndef __ANDROID_JPEG_THUMBNAILER_H__
#define __ANDROID_JPEG_THUMBNAILER_H__
+#include <memory>
+
#include <libcamera/framebuffer.h>
#include <libcamera/geometry.h>
#include "libcamera/internal/formats.h"
+#include "libcamera/internal/mapped_framebuffer.h"
+
class Thumbnailer
{
public:
@@ -21,7 +25,7 @@ public:
libcamera::PixelFormat pixelFormat);
void createThumbnail(const libcamera::FrameBuffer &source,
const libcamera::Size &targetSize,
- std::vector<unsigned char> *dest);
+ std::unique_ptr<libcamera::MappedBuffer> *dest);
const libcamera::PixelFormat &pixelFormat() const { return pixelFormat_; }
private:
--
2.33.0.259.gc128427fd7-goog
More information about the libcamera-devel
mailing list