From 5de02e443f0c283fd7e6bf628a77a894d660f5d9 Mon Sep 17 00:00:00 2001 From: seungho baek Date: Tue, 17 Jan 2023 15:18:22 +0900 Subject: [PATCH] Support to load an image from uint8_t* encoded buffer. Change-Id: I0252773ef6c9ad62e552c05697cdd39507bd892e Signed-off-by: seungho baek --- dali/devel-api/adaptor-framework/image-loading.cpp | 24 ++++++++++++++++++++++ dali/devel-api/adaptor-framework/image-loading.h | 22 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/dali/devel-api/adaptor-framework/image-loading.cpp b/dali/devel-api/adaptor-framework/image-loading.cpp index 794d8ad..a552b61 100644 --- a/dali/devel-api/adaptor-framework/image-loading.cpp +++ b/dali/devel-api/adaptor-framework/image-loading.cpp @@ -87,6 +87,30 @@ Devel::PixelBuffer LoadImageFromBuffer(const Dali::Vector& buffer, Imag return Dali::Devel::PixelBuffer(); } +Devel::PixelBuffer LoadImageFromBuffer(uint8_t* buffer, size_t bufferSize, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection) +{ + if(buffer == nullptr) + { + DALI_LOG_ERROR("buffer is empty!\n"); + return Dali::Devel::PixelBuffer(); + } + Integration::BitmapResourceType resourceType(size, fittingMode, samplingMode, orientationCorrection); + + Internal::Platform::FileReader fileReader(buffer, bufferSize); + FILE* const fp = fileReader.GetFile(); + if(fp != NULL) + { + Dali::Devel::PixelBuffer bitmap; + // Make path as empty string. Path information just for file format hint. + bool success = TizenPlatform::ImageLoader::ConvertStreamToBitmap(resourceType, std::string(""), fp, bitmap); + if(success && bitmap) + { + return bitmap; + } + } + return Dali::Devel::PixelBuffer(); +} + ImageDimensions GetClosestImageSize(const std::string& filename, ImageDimensions size, FittingMode::Type fittingMode, diff --git a/dali/devel-api/adaptor-framework/image-loading.h b/dali/devel-api/adaptor-framework/image-loading.h index 53e07df..365b38d 100644 --- a/dali/devel-api/adaptor-framework/image-loading.h +++ b/dali/devel-api/adaptor-framework/image-loading.h @@ -88,6 +88,28 @@ DALI_ADAPTOR_API Devel::PixelBuffer LoadImageFromBuffer( bool orientationCorrection = true); /** + * @brief Load an image synchronously from encoded buffer. + * + * @note This method is thread safe, i.e. can be called from any thread. + * + * @param [in] buffer The encoded buffer of the image to load. + * The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream + * @param [in] bufferSize Size of the encoded buffer. + * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image + * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter. + * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size. + * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header. + * @return handle to the loaded PixelBuffer object or an empty handle in case loading failed. + */ +DALI_ADAPTOR_API Devel::PixelBuffer LoadImageFromBuffer( + uint8_t* buffer, + size_t bufferSize, + ImageDimensions size = ImageDimensions(0, 0), + FittingMode::Type fittingMode = FittingMode::DEFAULT, + SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR, + bool orientationCorrection = true); + +/** * @brief Determine the size of an image that LoadImageFromFile will provide when * given the same image loading parameters. * -- 2.7.4