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 animated image loading task.
71 * @param[in] asyncImageLoader The ayncImageLoader
72 * @param[in] animatedImageLoading The AnimatedImageLoading to load animated image
73 * @param[in] frameIndex The frame index of a frame to be loaded frame
74 * @param[in] dimensions The width and height to fit the loaded image to
75 * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
76 * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
77 * @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.
78 * @return The loading task id
80 uint32_t LoadAnimatedImage(Dali::AnimatedImageLoading animatedImageLoading,
82 Dali::ImageDimensions desiredSize,
83 Dali::FittingMode::Type fittingMode,
84 Dali::SamplingMode::Type samplingMode,
85 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
88 * @brief Starts an image loading task.
89 * @param[in] url The URL of the image file to load
90 * @param[in] dimensions The width and height to fit the loaded image to
91 * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
92 * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
93 * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
94 * @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.
95 * @param[in] loadPlanes true to load image planes or false to load bitmap image.
96 * @return The loading task id
98 uint32_t Load(const VisualUrl& url,
99 ImageDimensions dimensions,
100 FittingMode::Type fittingMode,
101 SamplingMode::Type samplingMode,
102 bool orientationCorrection,
103 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
107 * @brief Starts an image loading task by encoded image buffer.
108 * @param[in] encodedImageBuffer The encoded buffer of the image to load
109 * @param[in] dimensions The width and height to fit the loaded image to
110 * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
111 * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
112 * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
113 * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
114 * @return The loading task id
116 uint32_t LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer,
117 ImageDimensions dimensions,
118 FittingMode::Type fittingMode,
119 SamplingMode::Type samplingMode,
120 bool orientationCorrection,
121 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
124 * @brief Starts an mask applying task.
125 * @param[in] pixelBuffer of the to be masked image
126 * @param[in] maskPixelBuffer of the mask image
127 * @param[in] contentScale The factor to scale the content
128 * @param[in] cropToMask Whether to crop the content to the mask size
129 * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
130 * @return The loading task id
132 uint32_t ApplyMask(Devel::PixelBuffer pixelBuffer,
133 Devel::PixelBuffer maskPixelBuffer,
136 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
139 * @copydoc Toolkit::AsyncImageLoader::ImageLoadedSignal
141 Toolkit::AsyncImageLoader::ImageLoadedSignalType& ImageLoadedSignal();
144 * @copydoc Toolkit::AsyncImageLoader::PixelBufferLoadedSignal
146 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& PixelBufferLoadedSignal();
149 * @copydoc Toolkit::AsyncImageLoader::Cancel
151 bool Cancel(uint32_t loadingTaskId);
154 * @copydoc Toolkit::AsyncImageLoader::CancelAll
159 * Process the completed loading task from the worker thread.
161 void ProcessLoadedImage(LoadingTaskPtr task);
167 ~AsyncImageLoader() override;
171 * Remove already completed tasks
173 void RemoveCompletedTask();
176 Toolkit::AsyncImageLoader::ImageLoadedSignalType mLoadedSignal;
177 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType mPixelBufferLoadedSignal;
178 std::vector<AsyncImageLoadingInfo> mLoadingTasks;
179 std::vector<uint32_t> mCompletedTaskIds;
180 uint32_t mLoadTaskId;
183 } // namespace Internal
185 inline const Internal::AsyncImageLoader& GetImplementation(const Toolkit::AsyncImageLoader& handle)
187 DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
189 const BaseObject& object = handle.GetBaseObject();
191 return static_cast<const Internal::AsyncImageLoader&>(object);
194 inline Internal::AsyncImageLoader& GetImplementation(Toolkit::AsyncImageLoader& handle)
196 DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
198 BaseObject& object = handle.GetBaseObject();
200 return static_cast<Internal::AsyncImageLoader&>(object);
203 } // namespace Toolkit
207 #endif // DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H