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/visuals/visual-url.h>
23 #include <dali/public-api/adaptor-framework/async-task-manager.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/encoded-image-buffer.h>
31 #include <dali/public-api/common/dali-vector.h>
32 #include <dali/public-api/images/image-operations.h>
33 #include <dali/public-api/object/ref-object.h>
34 #include <dali-toolkit/internal/texture-manager/texture-manager-type.h>
44 using LoadingTaskPtr = IntrusivePtr<LoadingTask>;
47 * The task of loading and packing an image into the atlas
49 class LoadingTask : public AsyncTask
54 * @param [in] id of the task
55 * @param [in] animatedImageLoading The AnimatedImageLoading to load animated image
56 * @param [in] frameIndex The frame index of a frame to be loaded frame
57 * @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.
58 * @param [in] callback The callback that is called when the operation is completed.
60 LoadingTask(uint32_t id,
61 Dali::AnimatedImageLoading animatedImageLoading,
63 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
64 CallbackBase* callback);
68 * @param [in] id of the task
69 * @param [in] url The URL of the image file to load.
70 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
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] orientationCorrection Reorient the image to respect any orientation metadata in its header.
74 * @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.
75 * @param [in] loadPlanes true to load image planes or false to load bitmap image.
76 * @param [in] callback The callback that is called when the operation is completed.
78 LoadingTask(uint32_t id,
80 ImageDimensions dimensions,
81 FittingMode::Type fittingMode,
82 SamplingMode::Type samplingMode,
83 bool orientationCorrection,
84 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
86 CallbackBase* callback);
90 * @param [in] id of the task
91 * @param [in] encodedImageBuffer The encoded buffer of the image to load.
92 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
93 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
94 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
95 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
96 * @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.
97 * @param [in] callback The callback that is called when the operation is completed.
99 LoadingTask(uint32_t id,
100 const EncodedImageBuffer& encodedImageBuffer,
101 ImageDimensions dimensions,
102 FittingMode::Type fittingMode,
103 SamplingMode::Type samplingMode,
104 bool orientationCorrection,
105 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
106 CallbackBase* callback);
110 * @param [in] id of the task
111 * @param [in] pixelBuffer of the to be masked image
112 * @param [in] maskPixelBuffer of the mask image
113 * @param [in] contentScale The factor to scale the content
114 * @param [in] cropToMask Whether to crop the content to the mask size
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.
116 * @param [in] callback The callback that is called when the operation is completed.
118 LoadingTask(uint32_t id,
119 Devel::PixelBuffer pixelBuffer,
120 Devel::PixelBuffer maskPixelBuffer,
123 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
124 CallbackBase* callback);
129 ~LoadingTask() override;
132 * Process the task accodring to the type
134 void Process() override;
137 * Whether the task is ready to process.
138 * @return True if the task is ready to process.
140 bool IsReady() override;
143 * @brief Set the Texture Id
146 void SetTextureId(TextureManagerType::TextureId id);
150 LoadingTask(const LoadingTask& queue);
153 LoadingTask& operator=(const LoadingTask& queue);
168 void MultiplyAlpha();
171 std::vector<Devel::PixelBuffer> pixelBuffers{}; ///< pixelBuffer handle after successful load
172 ///< or pixelBuffer to be masked image in the mask task
173 VisualUrl url; ///< url of the image to load
174 EncodedImageBuffer encodedImageBuffer; ///< encoded buffer of the image to load
175 uint32_t id; ///< The unique id associated with this task.
176 TextureManagerType::TextureId textureId; ///< textureId for loading
177 ImageDimensions dimensions; ///< dimensions to load
178 FittingMode::Type fittingMode; ///< fitting options
179 SamplingMode::Type samplingMode; ///< sampling options
180 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad; ///< if the image's color should be multiplied by it's alpha
182 Devel::PixelBuffer maskPixelBuffer; ///< pixelBuffer of mask image
183 float contentScale; ///< The factor to scale the content
184 Dali::AnimatedImageLoading animatedImageLoading;
187 bool orientationCorrection : 1; ///< if orientation correction is needed
188 bool isMaskTask : 1; ///< whether this task is for mask or not
189 bool cropToMask : 1; ///< Whether to crop the content to the mask size
190 bool loadPlanes : 1; ///< Whether to load image planes
191 bool isReady : 1; ///< Whether this task ready to run
194 } // namespace Internal
196 } // namespace Toolkit
200 #endif // DALI_TOOLKIT_IMAGE_LOAD_THREAD_H