[dali_2.1.29] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-loader / async-image-loader-impl.h
1 #ifndef DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H
2 #define DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/images/pixel-data.h>
22 #include <dali/public-api/object/base-object.h>
23
24 // INTERNAL INCLUDES
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>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35 class AsyncImageLoader : public BaseObject
36 {
37 public:
38   /**
39    * Constructor
40    */
41   AsyncImageLoader();
42
43   /**
44    * @copydoc Toolkit::AsyncImageLoader::New()
45    */
46   static IntrusivePtr<AsyncImageLoader> New();
47
48   /**
49    * @copydoc Toolkit::AsyncImageLoader::LoadAnimatedImage( Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
50    */
51   uint32_t LoadAnimatedImage(Dali::AnimatedImageLoading               animatedImageLoading,
52                              uint32_t                                 frameIndex,
53                              DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
54
55   /**
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
65    */
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,
72                 bool                                     loadPlanes);
73
74   /**
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
83    */
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);
90
91   /**
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
99    */
100   uint32_t ApplyMask(Devel::PixelBuffer                       pixelBuffer,
101                      Devel::PixelBuffer                       maskPixelBuffer,
102                      float                                    contentScale,
103                      bool                                     cropToMask,
104                      DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
105
106   /**
107    * @copydoc Toolkit::AsyncImageLoader::ImageLoadedSignal
108    */
109   Toolkit::AsyncImageLoader::ImageLoadedSignalType& ImageLoadedSignal();
110
111   /**
112    * @copydoc Toolkit::AsyncImageLoader::PixelBufferLoadedSignal
113    */
114   Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& PixelBufferLoadedSignal();
115
116   /**
117    * @copydoc Toolkit::AsyncImageLoader::Cancel
118    */
119   bool Cancel(uint32_t loadingTaskId);
120
121   /**
122    * @copydoc Toolkit::AsyncImageLoader::CancelAll
123    */
124   void CancelAll();
125
126   /**
127    * Process the completed loading task from the worker thread.
128    */
129   void ProcessLoadedImage();
130
131 protected:
132   /**
133    * Destructor
134    */
135   ~AsyncImageLoader() override;
136
137 private:
138   Toolkit::AsyncImageLoader::ImageLoadedSignalType            mLoadedSignal;
139   Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType mPixelBufferLoadedSignal;
140
141   ImageLoadThread mLoadThread;
142   uint32_t        mLoadTaskId;
143   bool            mIsLoadThreadStarted;
144 };
145
146 } // namespace Internal
147
148 inline const Internal::AsyncImageLoader& GetImplementation(const Toolkit::AsyncImageLoader& handle)
149 {
150   DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
151
152   const BaseObject& object = handle.GetBaseObject();
153
154   return static_cast<const Internal::AsyncImageLoader&>(object);
155 }
156
157 inline Internal::AsyncImageLoader& GetImplementation(Toolkit::AsyncImageLoader& handle)
158 {
159   DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
160
161   BaseObject& object = handle.GetBaseObject();
162
163   return static_cast<Internal::AsyncImageLoader&>(object);
164 }
165
166 } // namespace Toolkit
167
168 } // namespace Dali
169
170 #endif // DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H