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/image-load-thread.h>
27 #include <dali-toolkit/public-api/image-loader/async-image-loader.h>
35 class AsyncImageLoader : public BaseObject
44 * @copydoc Toolkit::AsyncImageLoader::New()
46 static IntrusivePtr<AsyncImageLoader> New();
49 * @copydoc Toolkit::AsyncImageLoader::LoadAnimatedImage( Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
51 uint32_t LoadAnimatedImage(Dali::AnimatedImageLoading animatedImageLoading,
53 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
56 * @brief Starts an image loading task.
57 * @param[in] url The URL of the image file to load
58 * @param[in] dimensions The width and height to fit the loaded image to
59 * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
60 * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
61 * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
62 * @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.
63 * @param[in] loadPlanes true to load image planes or false to load bitmap image.
64 * @return The loading task id
66 uint32_t Load(const VisualUrl& url,
67 ImageDimensions dimensions,
68 FittingMode::Type fittingMode,
69 SamplingMode::Type samplingMode,
70 bool orientationCorrection,
71 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
75 * @brief Starts an image loading task by encoded image buffer.
76 * @param[in] encodedImageBuffer The encoded buffer of the image to load
77 * @param[in] dimensions The width and height to fit the loaded image to
78 * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
79 * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
80 * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
81 * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
82 * @return The loading task id
84 uint32_t LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer,
85 ImageDimensions dimensions,
86 FittingMode::Type fittingMode,
87 SamplingMode::Type samplingMode,
88 bool orientationCorrection,
89 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
92 * @brief Starts an mask applying task.
93 * @param[in] pixelBuffer of the to be masked image
94 * @param[in] maskPixelBuffer of the mask image
95 * @param[in] contentScale The factor to scale the content
96 * @param[in] cropToMask Whether to crop the content to the mask size
97 * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
98 * @return The loading task id
100 uint32_t ApplyMask(Devel::PixelBuffer pixelBuffer,
101 Devel::PixelBuffer maskPixelBuffer,
104 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
107 * @copydoc Toolkit::AsyncImageLoader::ImageLoadedSignal
109 Toolkit::AsyncImageLoader::ImageLoadedSignalType& ImageLoadedSignal();
112 * @copydoc Toolkit::AsyncImageLoader::PixelBufferLoadedSignal
114 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& PixelBufferLoadedSignal();
117 * @copydoc Toolkit::AsyncImageLoader::Cancel
119 bool Cancel(uint32_t loadingTaskId);
122 * @copydoc Toolkit::AsyncImageLoader::CancelAll
127 * Process the completed loading task from the worker thread.
129 void ProcessLoadedImage();
135 ~AsyncImageLoader() override;
138 Toolkit::AsyncImageLoader::ImageLoadedSignalType mLoadedSignal;
139 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType mPixelBufferLoadedSignal;
141 ImageLoadThread mLoadThread;
142 uint32_t mLoadTaskId;
143 bool mIsLoadThreadStarted;
146 } // namespace Internal
148 inline const Internal::AsyncImageLoader& GetImplementation(const Toolkit::AsyncImageLoader& handle)
150 DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
152 const BaseObject& object = handle.GetBaseObject();
154 return static_cast<const Internal::AsyncImageLoader&>(object);
157 inline Internal::AsyncImageLoader& GetImplementation(Toolkit::AsyncImageLoader& handle)
159 DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
161 BaseObject& object = handle.GetBaseObject();
163 return static_cast<Internal::AsyncImageLoader&>(object);
166 } // namespace Toolkit
170 #endif // DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H