1 #ifndef DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H
2 #define DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali/public-api/images/pixel-data.h>
22 #include <dali/public-api/object/base-object.h>
25 #include <dali-toolkit/devel-api/image-loader/async-image-loader-devel.h>
26 #include <dali-toolkit/internal/image-loader/loading-task.h>
27 #include <dali-toolkit/public-api/image-loader/async-image-loader.h>
35 using LoadingTaskPtr = IntrusivePtr<LoadingTask>;
37 struct AsyncImageLoadingInfo
39 AsyncImageLoadingInfo(LoadingTaskPtr loadingTask,std::uint32_t loadId)
40 : loadingTask(loadingTask),
45 LoadingTaskPtr loadingTask;
49 class AsyncImageLoader : public BaseObject, public ConnectionTracker
58 * @copydoc Toolkit::AsyncImageLoader::New()
60 static IntrusivePtr<AsyncImageLoader> New();
63 * @copydoc Toolkit::AsyncImageLoader::LoadAnimatedImage( Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
65 uint32_t LoadAnimatedImage(Dali::AnimatedImageLoading animatedImageLoading,
67 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
70 * @brief Starts an image loading task.
71 * @param[in] url The URL of the image file to load
72 * @param[in] dimensions The width and height to fit the loaded image to
73 * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
74 * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
75 * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
76 * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
77 * @param[in] loadPlanes true to load image planes or false to load bitmap image.
78 * @return The loading task id
80 uint32_t Load(const VisualUrl& url,
81 ImageDimensions dimensions,
82 FittingMode::Type fittingMode,
83 SamplingMode::Type samplingMode,
84 bool orientationCorrection,
85 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
89 * @brief Starts an image loading task by encoded image buffer.
90 * @param[in] encodedImageBuffer The encoded buffer of the image to load
91 * @param[in] dimensions The width and height to fit the loaded image to
92 * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
93 * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
94 * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
95 * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
96 * @return The loading task id
98 uint32_t LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer,
99 ImageDimensions dimensions,
100 FittingMode::Type fittingMode,
101 SamplingMode::Type samplingMode,
102 bool orientationCorrection,
103 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
106 * @brief Starts an mask applying task.
107 * @param[in] pixelBuffer of the to be masked image
108 * @param[in] maskPixelBuffer of the mask image
109 * @param[in] contentScale The factor to scale the content
110 * @param[in] cropToMask Whether to crop the content to the mask size
111 * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
112 * @return The loading task id
114 uint32_t ApplyMask(Devel::PixelBuffer pixelBuffer,
115 Devel::PixelBuffer maskPixelBuffer,
118 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
121 * @copydoc Toolkit::AsyncImageLoader::ImageLoadedSignal
123 Toolkit::AsyncImageLoader::ImageLoadedSignalType& ImageLoadedSignal();
126 * @copydoc Toolkit::AsyncImageLoader::PixelBufferLoadedSignal
128 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& PixelBufferLoadedSignal();
131 * @copydoc Toolkit::AsyncImageLoader::Cancel
133 bool Cancel(uint32_t loadingTaskId);
136 * @copydoc Toolkit::AsyncImageLoader::CancelAll
141 * Process the completed loading task from the worker thread.
143 void ProcessLoadedImage(LoadingTaskPtr task);
149 ~AsyncImageLoader() override;
153 * Remove already completed tasks
155 void RemoveCompletedTask();
158 Toolkit::AsyncImageLoader::ImageLoadedSignalType mLoadedSignal;
159 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType mPixelBufferLoadedSignal;
160 std::vector<AsyncImageLoadingInfo> mLoadingTasks;
161 std::vector<uint32_t> mCompletedTaskIds;
162 uint32_t mLoadTaskId;
165 } // namespace Internal
167 inline const Internal::AsyncImageLoader& GetImplementation(const Toolkit::AsyncImageLoader& handle)
169 DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
171 const BaseObject& object = handle.GetBaseObject();
173 return static_cast<const Internal::AsyncImageLoader&>(object);
176 inline Internal::AsyncImageLoader& GetImplementation(Toolkit::AsyncImageLoader& handle)
178 DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
180 BaseObject& object = handle.GetBaseObject();
182 return static_cast<Internal::AsyncImageLoader&>(object);
185 } // namespace Toolkit
189 #endif // DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H