2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "loading-task.h"
22 #include <dali/devel-api/adaptor-framework/image-loading.h>
23 #include <dali/devel-api/adaptor-framework/thread-settings.h>
24 #include <dali/integration-api/adaptor-framework/adaptor.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/adaptor-framework/encoded-image-buffer.h>
34 LoadingTask::LoadingTask(uint32_t id, Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad, CallbackBase* callback)
35 : AsyncTask(callback),
39 textureId(TextureManagerType::INVALID_TEXTURE_ID),
43 preMultiplyOnLoad(preMultiplyOnLoad),
46 animatedImageLoading(animatedImageLoading),
47 frameIndex(frameIndex),
48 orientationCorrection(),
56 LoadingTask::LoadingTask(uint32_t id, const VisualUrl& url, ImageDimensions dimensions, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad, bool loadPlanes, CallbackBase* callback)
57 : AsyncTask(callback),
61 textureId(TextureManagerType::INVALID_TEXTURE_ID),
62 dimensions(dimensions),
63 fittingMode(fittingMode),
64 samplingMode(samplingMode),
65 preMultiplyOnLoad(preMultiplyOnLoad),
68 animatedImageLoading(),
70 orientationCorrection(orientationCorrection),
73 loadPlanes(loadPlanes),
78 LoadingTask::LoadingTask(uint32_t id, const EncodedImageBuffer& encodedImageBuffer, ImageDimensions dimensions, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad, CallbackBase* callback)
79 : AsyncTask(callback),
81 encodedImageBuffer(encodedImageBuffer),
83 textureId(TextureManagerType::INVALID_TEXTURE_ID),
84 dimensions(dimensions),
85 fittingMode(fittingMode),
86 samplingMode(samplingMode),
87 preMultiplyOnLoad(preMultiplyOnLoad),
90 animatedImageLoading(),
92 orientationCorrection(orientationCorrection),
100 LoadingTask::LoadingTask(uint32_t id, Devel::PixelBuffer pixelBuffer, Devel::PixelBuffer maskPixelBuffer, float contentScale, bool cropToMask, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad, CallbackBase* callback)
101 : AsyncTask(callback),
103 encodedImageBuffer(),
105 textureId(TextureManagerType::INVALID_TEXTURE_ID),
109 preMultiplyOnLoad(preMultiplyOnLoad),
110 maskPixelBuffer(maskPixelBuffer),
111 contentScale(contentScale),
112 animatedImageLoading(),
114 orientationCorrection(),
116 cropToMask(cropToMask),
120 pixelBuffers.push_back(pixelBuffer);
123 LoadingTask::~LoadingTask()
127 void LoadingTask::Process()
142 bool LoadingTask::IsReady()
147 void LoadingTask::Load()
149 Devel::PixelBuffer pixelBuffer;
150 if(animatedImageLoading)
152 pixelBuffer = animatedImageLoading.LoadFrame(frameIndex);
154 else if(encodedImageBuffer)
156 pixelBuffer = Dali::LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), dimensions, fittingMode, samplingMode, orientationCorrection);
158 else if(url.IsValid() && url.IsLocalResource())
162 Dali::LoadImagePlanesFromFile(url.GetUrl(), pixelBuffers, dimensions, fittingMode, samplingMode, orientationCorrection);
166 pixelBuffer = Dali::LoadImageFromFile(url.GetUrl(), dimensions, fittingMode, samplingMode, orientationCorrection);
169 else if(url.IsValid())
171 pixelBuffer = Dali::DownloadImageSynchronously(url.GetUrl(), dimensions, fittingMode, samplingMode, orientationCorrection);
176 pixelBuffers.push_back(pixelBuffer);
179 if(pixelBuffers.empty())
181 DALI_LOG_ERROR("LoadingTask::Load: Loading is failed: %s\n", url.GetUrl().c_str());
185 void LoadingTask::ApplyMask()
187 if(!pixelBuffers.empty())
189 pixelBuffers[0].ApplyMask(maskPixelBuffer, contentScale, cropToMask);
193 void LoadingTask::MultiplyAlpha()
195 if(!pixelBuffers.empty() && Pixel::HasAlpha(pixelBuffers[0].GetPixelFormat()))
197 if(preMultiplyOnLoad == DevelAsyncImageLoader::PreMultiplyOnLoad::ON)
199 pixelBuffers[0].MultiplyColorByAlpha();
204 void LoadingTask::SetTextureId(TextureManagerType::TextureId id)
209 } // namespace Internal
211 } // namespace Toolkit