diff options
author | sunghyun kim <scholb.kim@samsung.com> | 2024-02-05 10:37:45 +0900 |
---|---|---|
committer | sunghyun kim <scholb.kim@samsung.com> | 2024-02-21 16:36:01 +0900 |
commit | d7c6af4027df0a113f8faf62cbceb8a7157dc208 (patch) | |
tree | 113c9ba8795d740e20b627e67731e91e2a5e6bd8 | |
parent | aea464f1af37aaabeeb29d844d131942e4aa9ea4 (diff) | |
download | dali-adaptor-d7c6af4027df0a113f8faf62cbceb8a7157dc208.tar.gz dali-adaptor-d7c6af4027df0a113f8faf62cbceb8a7157dc208.tar.bz2 dali-adaptor-d7c6af4027df0a113f8faf62cbceb8a7157dc208.zip |
Decoding webp using desired size
webp provides decoding option with provided size.
with this options, dali don't need to scaling buffer after decoding.
Change-Id: I63bb47ec29cb3950687b1814839674ca32c4cb62
-rw-r--r-- | dali/internal/imaging/common/animated-image-loading-impl.h | 5 | ||||
-rw-r--r-- | dali/internal/imaging/common/gif-loading.cpp | 2 | ||||
-rw-r--r-- | dali/internal/imaging/common/gif-loading.h | 2 | ||||
-rw-r--r-- | dali/internal/imaging/common/webp-loading.cpp | 71 | ||||
-rw-r--r-- | dali/internal/imaging/common/webp-loading.h | 2 |
5 files changed, 66 insertions, 16 deletions
diff --git a/dali/internal/imaging/common/animated-image-loading-impl.h b/dali/internal/imaging/common/animated-image-loading-impl.h index a240b1d58..a15005339 100644 --- a/dali/internal/imaging/common/animated-image-loading-impl.h +++ b/dali/internal/imaging/common/animated-image-loading-impl.h @@ -82,7 +82,7 @@ public: Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode) { - Dali::Devel::PixelBuffer pixelBuffer = LoadFrame(frameIndex); + Dali::Devel::PixelBuffer pixelBuffer = LoadFrame(frameIndex, size); return Dali::Internal::Platform::ApplyAttributesToBitmap(pixelBuffer, size, fittingMode, samplingMode); } @@ -119,9 +119,10 @@ private: * * @note This function will load the entire animated image into memory if not already loaded. * @param[in] frameIndex The frame index to load. + * @param[in] size The width and height to fit the loaded image to. * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle. */ - virtual Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex) = 0; + virtual Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex, ImageDimensions size = ImageDimensions()) = 0; }; } // namespace Adaptor diff --git a/dali/internal/imaging/common/gif-loading.cpp b/dali/internal/imaging/common/gif-loading.cpp index 7c04fc242..37d810913 100644 --- a/dali/internal/imaging/common/gif-loading.cpp +++ b/dali/internal/imaging/common/gif-loading.cpp @@ -1576,7 +1576,7 @@ GifLoading::~GifLoading() delete mImpl; } -Dali::Devel::PixelBuffer GifLoading::LoadFrame(uint32_t frameIndex) +Dali::Devel::PixelBuffer GifLoading::LoadFrame(uint32_t frameIndex, ImageDimensions desiredSize) { int error; Dali::Devel::PixelBuffer pixelBuffer; diff --git a/dali/internal/imaging/common/gif-loading.h b/dali/internal/imaging/common/gif-loading.h index 2de8ead50..dbc564ad6 100644 --- a/dali/internal/imaging/common/gif-loading.h +++ b/dali/internal/imaging/common/gif-loading.h @@ -75,7 +75,7 @@ public: * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle. */ - Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex) override; + Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex, ImageDimensions size) override; /** * @brief Get the size of a gif image. diff --git a/dali/internal/imaging/common/webp-loading.cpp b/dali/internal/imaging/common/webp-loading.cpp index 1903d2c42..0dd3c853e 100644 --- a/dali/internal/imaging/common/webp-loading.cpp +++ b/dali/internal/imaging/common/webp-loading.cpp @@ -307,7 +307,7 @@ WebPLoading::~WebPLoading() delete mImpl; } -Dali::Devel::PixelBuffer WebPLoading::LoadFrame(uint32_t frameIndex) +Dali::Devel::PixelBuffer WebPLoading::LoadFrame(uint32_t frameIndex, ImageDimensions desiredSize) { Dali::Devel::PixelBuffer pixelBuffer; @@ -334,22 +334,71 @@ Dali::Devel::PixelBuffer WebPLoading::LoadFrame(uint32_t frameIndex) { uint32_t channelNumber = (features.has_alpha) ? 4 : 3; uint8_t* frameBuffer = nullptr; - if(channelNumber == 4) + + if(desiredSize.GetWidth() > 0 && desiredSize.GetHeight() > 0) { - frameBuffer = WebPDecodeRGBA(mImpl->mBuffer, mImpl->mBufferSize, &width, &height); + const int desiredWidth = desiredSize.GetWidth(); + const int desiredHeight = desiredSize.GetHeight(); + + WebPDecoderConfig config; + if(!DALI_LIKELY(WebPInitDecoderConfig(&config))) + { + DALI_LOG_ERROR("WebPInitDecoderConfig is failed"); + return pixelBuffer; + } + + // Apply config for scaling + config.options.use_scaling = 1; + config.options.scaled_width = desiredWidth; + config.options.scaled_height = desiredHeight; + + if(channelNumber == 4) + { + config.output.colorspace = MODE_RGBA; + } + else + { + config.output.colorspace = MODE_RGB; + } + + if(WebPDecode(mImpl->mBuffer, mImpl->mBufferSize, &config) == VP8_STATUS_OK) + { + frameBuffer = config.output.u.RGBA.rgba; + } + else + { + DALI_LOG_ERROR("Webp Decoding with scaled size is failed \n"); + } + + if(frameBuffer != nullptr) + { + Pixel::Format pixelFormat = (channelNumber == 4) ? Pixel::RGBA8888 : Pixel::RGB888; + int32_t bufferSize = desiredWidth * desiredHeight * Dali::Pixel::GetBytesPerPixel(pixelFormat); + pixelBuffer = Dali::Devel::PixelBuffer::New(desiredWidth, desiredHeight, pixelFormat); + memcpy(pixelBuffer.GetBuffer(), frameBuffer, bufferSize); + } + + WebPFreeDecBuffer(&config.output); } else { - frameBuffer = WebPDecodeRGB(mImpl->mBuffer, mImpl->mBufferSize, &width, &height); - } + if(channelNumber == 4) + { + frameBuffer = WebPDecodeRGBA(mImpl->mBuffer, mImpl->mBufferSize, &width, &height); + } + else + { + frameBuffer = WebPDecodeRGB(mImpl->mBuffer, mImpl->mBufferSize, &width, &height); + } - if(frameBuffer != nullptr) - { - Pixel::Format pixelFormat = (channelNumber == 4) ? Pixel::RGBA8888 : Pixel::RGB888; - int32_t bufferSize = width * height * Dali::Pixel::GetBytesPerPixel(pixelFormat); - Internal::Adaptor::PixelBufferPtr internal = + if(frameBuffer != nullptr) + { + Pixel::Format pixelFormat = (channelNumber == 4) ? Pixel::RGBA8888 : Pixel::RGB888; + int32_t bufferSize = width * height * Dali::Pixel::GetBytesPerPixel(pixelFormat); + Internal::Adaptor::PixelBufferPtr internal = Internal::Adaptor::PixelBuffer::New(frameBuffer, bufferSize, width, height, width, pixelFormat); - pixelBuffer = Devel::PixelBuffer(internal.Get()); + pixelBuffer = Devel::PixelBuffer(internal.Get()); + } } } } diff --git a/dali/internal/imaging/common/webp-loading.h b/dali/internal/imaging/common/webp-loading.h index 5a232fbfc..74eed611f 100644 --- a/dali/internal/imaging/common/webp-loading.h +++ b/dali/internal/imaging/common/webp-loading.h @@ -92,7 +92,7 @@ public: * @param[in] frameIndex The frame counter to load. Will usually be the next frame. * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle. */ - Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex) override; + Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex, ImageDimensions size) override; /** * @brief Get the size of a webp image. |