1 #ifndef DALI_TOOLKIT_IMAGE_LOADING_TASK_H
2 #define DALI_TOOLKIT_IMAGE_LOADING_TASK_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-toolkit/devel-api/image-loader/async-image-loader-devel.h>
22 #include <dali-toolkit/internal/texture-manager/texture-manager-type.h>
23 #include <dali-toolkit/internal/visuals/visual-url.h>
24 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
25 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
26 #include <dali/devel-api/threading/conditional-wait.h>
27 #include <dali/devel-api/threading/mutex.h>
28 #include <dali/devel-api/threading/thread.h>
29 #include <dali/integration-api/adaptor-framework/log-factory-interface.h>
30 #include <dali/public-api/adaptor-framework/async-task-manager.h>
31 #include <dali/public-api/adaptor-framework/encoded-image-buffer.h>
32 #include <dali/public-api/common/dali-vector.h>
33 #include <dali/public-api/images/image-operations.h>
34 #include <dali/public-api/object/ref-object.h>
43 using LoadingTaskPtr = IntrusivePtr<LoadingTask>;
46 * The task of loading and packing an image into the atlas
48 class LoadingTask : public AsyncTask
53 * @param [in] id of the task
54 * @param [in] animatedImageLoading The AnimatedImageLoading to load animated image
55 * @param [in] frameIndex The frame index of a frame to be loaded frame
56 * @param [in] preMultiplyOnLoad ON if the image's 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.
57 * @param [in] callback The callback that is called when the operation is completed.
59 LoadingTask(uint32_t id,
60 Dali::AnimatedImageLoading animatedImageLoading,
62 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
63 CallbackBase* callback);
67 * @param [in] id of the task
68 * @param [in] animatedImageLoading The AnimatedImageLoading to load animated image
69 * @param [in] frameIndex The frame index of a frame to be loaded frame
70 * @param [in] dimensions The width and height to fit the loaded image to
71 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
72 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
73 * @param [in] preMultiplyOnLoad ON if the image's 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.
74 * @param [in] callback The callback that is called when the operation is completed.
76 LoadingTask(uint32_t id,
77 Dali::AnimatedImageLoading animatedImageLoading,
79 Dali::ImageDimensions dimensions,
80 Dali::FittingMode::Type fittingMode,
81 Dali::SamplingMode::Type samplingMode,
82 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
83 CallbackBase* callback);
87 * @param [in] id of the task
88 * @param [in] url The URL of the image file to load.
89 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
90 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
91 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
92 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
93 * @param [in] preMultiplyOnLoad ON if the image's 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.
94 * @param [in] loadPlanes true to load image planes or false to load bitmap image.
95 * @param [in] callback The callback that is called when the operation is completed.
97 LoadingTask(uint32_t id,
99 ImageDimensions dimensions,
100 FittingMode::Type fittingMode,
101 SamplingMode::Type samplingMode,
102 bool orientationCorrection,
103 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
105 CallbackBase* callback);
109 * @param [in] id of the task
110 * @param [in] encodedImageBuffer The encoded buffer of the image to load.
111 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
112 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
113 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
114 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
115 * @param [in] preMultiplyOnLoad ON if the image's 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.
116 * @param [in] callback The callback that is called when the operation is completed.
118 LoadingTask(uint32_t id,
119 const EncodedImageBuffer& encodedImageBuffer,
120 ImageDimensions dimensions,
121 FittingMode::Type fittingMode,
122 SamplingMode::Type samplingMode,
123 bool orientationCorrection,
124 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
125 CallbackBase* callback);
129 * @param [in] id of the task
130 * @param [in] pixelBuffer of the to be masked image
131 * @param [in] maskPixelBuffer of the mask image
132 * @param [in] contentScale The factor to scale the content
133 * @param [in] cropToMask Whether to crop the content to the mask size
134 * @param [in] preMultiplyOnLoad ON if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
135 * @param [in] callback The callback that is called when the operation is completed.
137 LoadingTask(uint32_t id,
138 Devel::PixelBuffer pixelBuffer,
139 Devel::PixelBuffer maskPixelBuffer,
142 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
143 CallbackBase* callback);
148 ~LoadingTask() override;
151 * Process the task accodring to the type
153 void Process() override;
156 * Whether the task is ready to process.
157 * @return True if the task is ready to process.
159 bool IsReady() override;
162 * @brief Set the Texture Id
165 void SetTextureId(TextureManagerType::TextureId id);
169 LoadingTask(const LoadingTask& queue);
172 LoadingTask& operator=(const LoadingTask& queue);
187 void MultiplyAlpha();
190 std::vector<Devel::PixelBuffer> pixelBuffers{}; ///< pixelBuffer handle after successful load
191 ///< or pixelBuffer to be masked image in the mask task
192 VisualUrl url; ///< url of the image to load
193 EncodedImageBuffer encodedImageBuffer; ///< encoded buffer of the image to load
194 uint32_t id; ///< The unique id associated with this task.
195 TextureManagerType::TextureId textureId; ///< textureId for loading
196 ImageDimensions dimensions; ///< dimensions to load
197 FittingMode::Type fittingMode; ///< fitting options
198 SamplingMode::Type samplingMode; ///< sampling options
199 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad; ///< if the image's color should be multiplied by it's alpha
201 Devel::PixelBuffer maskPixelBuffer; ///< pixelBuffer of mask image
202 float contentScale; ///< The factor to scale the content
203 Dali::AnimatedImageLoading animatedImageLoading;
206 bool orientationCorrection : 1; ///< if orientation correction is needed
207 bool isMaskTask : 1; ///< whether this task is for mask or not
208 bool cropToMask : 1; ///< Whether to crop the content to the mask size
209 bool loadPlanes : 1; ///< Whether to load image planes
210 bool isReady : 1; ///< Whether this task ready to run
213 } // namespace Internal
215 } // namespace Toolkit
219 #endif // DALI_TOOLKIT_IMAGE_LOAD_THREAD_H