/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/signals/callback.h>
#include <string.h>
+// INTERNAL HEADERS
+#include <dali-toolkit/internal/image-loader/async-image-loader-impl.h>
+
namespace Dali
{
namespace Toolkit
{
namespace Internal
{
-typedef unsigned char PixelBuffer;
-
Texture ImageAtlas::PackToAtlas(const std::vector<PixelData>& pixelData, Dali::Vector<Vector4>& textureRects)
{
// Record each block size
// Apply the half pixel correction to avoid the color bleeding between neighbour blocks
textureRects[index].x = (static_cast<float>(packPositionX) + 0.5f) / atlasWidth; // left
- textureRects[index].y = (static_cast<float>(packPositionY) + 0.5f) / atlasHeight; // right
+ textureRects[index].y = (static_cast<float>(packPositionY) + 0.5f) / atlasHeight; // top
textureRects[index].z = (static_cast<float>(packPositionX + pixelData[index].GetWidth()) - 0.5f) / atlasWidth; // right
textureRects[index].w = (static_cast<float>(packPositionY + pixelData[index].GetHeight()) - 0.5f) / atlasHeight; // bottom
}
}
bool ImageAtlas::Upload(Vector4& textureRect,
- const std::string& url,
+ const VisualUrl& url,
ImageDimensions size,
FittingMode::Type fittingMode,
bool orientationCorrection,
ImageDimensions zero;
if(size == zero) // image size not provided
{
- dimensions = Dali::GetClosestImageSize(url);
+ dimensions = Dali::GetClosestImageSize(url.GetUrl());
if(dimensions == zero) // Fail to read the image & broken image file exists
{
if(!mBrokenImageUrl.empty())
}
}
- unsigned int packPositionX = 0;
- unsigned int packPositionY = 0;
+ uint32_t packPositionX = 0;
+ uint32_t packPositionY = 0;
if(mPacker.Pack(dimensions.GetWidth(), dimensions.GetHeight(), packPositionX, packPositionY))
{
- unsigned short loadId = mAsyncLoader.Load(url, size, fittingMode, SamplingMode::BOX_THEN_LINEAR, orientationCorrection);
+ uint32_t loadId = GetImplementation(mAsyncLoader).Load(url, size, fittingMode, SamplingMode::BOX_THEN_LINEAR, orientationCorrection, DevelAsyncImageLoader::PreMultiplyOnLoad::OFF, false);
mLoadingTaskInfoContainer.PushBack(new LoadingTaskInfo(loadId, packPositionX, packPositionY, dimensions.GetWidth(), dimensions.GetHeight(), atlasUploadObserver));
// apply the half pixel correction
textureRect.x = (static_cast<float>(packPositionX) + 0.5f) / mWidth; // left
- textureRect.y = (static_cast<float>(packPositionY) + 0.5f) / mHeight; // right
+ textureRect.y = (static_cast<float>(packPositionY) + 0.5f) / mHeight; // top
textureRect.z = (static_cast<float>(packPositionX + dimensions.GetX()) - 0.5f) / mWidth; // right
textureRect.w = (static_cast<float>(packPositionY + dimensions.GetY()) - 0.5f) / mHeight; // bottom
return false;
}
+bool ImageAtlas::Upload(Vector4& textureRect,
+ const EncodedImageBuffer& encodedImageBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ bool orientationCorrection,
+ AtlasUploadObserver* atlasUploadObserver)
+{
+ ImageDimensions zero;
+ if(size == zero) // image size not provided
+ {
+ DALI_LOG_ERROR("Desired size is zero! We need to setup desired size for Atlas.\n");
+ // EncodedImageBuffer didn't support to get closest image size.
+ // Just draw broken image.
+ if(!mBrokenImageUrl.empty())
+ {
+ return Upload(textureRect, mBrokenImageUrl, mBrokenImageSize, FittingMode::DEFAULT, true, atlasUploadObserver);
+ }
+ else
+ {
+ textureRect = Vector4::ZERO;
+ return true;
+ }
+ }
+
+ uint32_t packPositionX = 0;
+ uint32_t packPositionY = 0;
+ if(mPacker.Pack(size.GetWidth(), size.GetHeight(), packPositionX, packPositionY))
+ {
+ uint32_t loadId = GetImplementation(mAsyncLoader).LoadEncodedImageBuffer(encodedImageBuffer, size, fittingMode, SamplingMode::BOX_THEN_LINEAR, orientationCorrection, DevelAsyncImageLoader::PreMultiplyOnLoad::OFF);
+ mLoadingTaskInfoContainer.PushBack(new LoadingTaskInfo(loadId, packPositionX, packPositionY, size.GetWidth(), size.GetHeight(), atlasUploadObserver));
+ // apply the half pixel correction
+ textureRect.x = (static_cast<float>(packPositionX) + 0.5f) / mWidth; // left
+ textureRect.y = (static_cast<float>(packPositionY) + 0.5f) / mHeight; // top
+ textureRect.z = (static_cast<float>(packPositionX + size.GetX()) - 0.5f) / mWidth; // right
+ textureRect.w = (static_cast<float>(packPositionY + size.GetY()) - 0.5f) / mHeight; // bottom
+
+ if(atlasUploadObserver)
+ {
+ // register to the observer,
+ // Not that a matching unregister call should be invoked in UploadToAtlas if the observer is still alive by then.
+ atlasUploadObserver->Register(*this);
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
bool ImageAtlas::Upload(Vector4& textureRect, PixelData pixelData)
{
- unsigned int packPositionX = 0;
- unsigned int packPositionY = 0;
+ uint32_t packPositionX = 0;
+ uint32_t packPositionY = 0;
if(mPacker.Pack(pixelData.GetWidth(), pixelData.GetHeight(), packPositionX, packPositionY))
{
mAtlas.Upload(pixelData, 0u, 0u, packPositionX, packPositionY, pixelData.GetWidth(), pixelData.GetHeight());
// apply the half pixel correction
textureRect.x = (static_cast<float>(packPositionX) + 0.5f) / mWidth; // left
- textureRect.y = (static_cast<float>(packPositionY) + 0.5f) / mHeight; // right
+ textureRect.y = (static_cast<float>(packPositionY) + 0.5f) / mHeight; // top
textureRect.z = (static_cast<float>(packPositionX + pixelData.GetWidth()) - 0.5f) / mWidth; // right
textureRect.w = (static_cast<float>(packPositionY + pixelData.GetHeight()) - 0.5f) / mHeight; // bottom
{
if(mLoadingTaskInfoContainer[0]->loadTaskId == id)
{
- Rect<unsigned int> packRect(mLoadingTaskInfoContainer[0]->packRect);
+ Rect<uint32_t> packRect(mLoadingTaskInfoContainer[0]->packRect);
if(!pixelData || (pixelData.GetWidth() == 0 && pixelData.GetHeight() == 0))
{
if(!mBrokenImageUrl.empty()) // replace with the broken image
}
}
-void ImageAtlas::UploadBrokenImage(const Rect<unsigned int>& area)
+void ImageAtlas::UploadBrokenImage(const Rect<uint32_t>& area)
{
Devel::PixelBuffer brokenBuffer = LoadImageFromFile(mBrokenImageUrl, ImageDimensions(area.width, area.height));
SizeType loadedWidth = brokenBuffer.GetWidth();