[dali_2.3.20] 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) 2021 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    * @copydoc Toolkit::AsyncImageLoader::Load( const std::string&, ImageDimensions, FittingMode::Type, SamplingMode::Type, bool , DevelAsyncImageLoader::PreMultiplyOnLoad )
57    */
58   uint32_t Load(const VisualUrl&                         url,
59                 ImageDimensions                          dimensions,
60                 FittingMode::Type                        fittingMode,
61                 SamplingMode::Type                       samplingMode,
62                 bool                                     orientationCorrection,
63                 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
64
65   /**
66    * @brief Starts an image loading task by encoded image buffer.
67    * @param[in] encodedImageBuffer The encoded buffer of the image to load
68    * @param[in] dimensions The width and height to fit the loaded image to
69    * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
70    * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
71    * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
72    * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
73    * @return The loading task id
74    */
75   uint32_t LoadEncodedImageBuffer(const EncodedImageBuffer&                encodedImageBuffer,
76                                   ImageDimensions                          dimensions,
77                                   FittingMode::Type                        fittingMode,
78                                   SamplingMode::Type                       samplingMode,
79                                   bool                                     orientationCorrection,
80                                   DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
81
82   /**
83    * @brief Starts an mask applying task.
84    * @param[in] pixelBuffer of the to be masked image
85    * @param[in] maskPixelBuffer of the mask image
86    * @param[in] contentScale The factor to scale the content
87    * @param[in] cropToMask Whether to crop the content to the mask size
88    * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
89    * @return The loading task id
90    */
91   uint32_t ApplyMask(Devel::PixelBuffer                       pixelBuffer,
92                      Devel::PixelBuffer                       maskPixelBuffer,
93                      float                                    contentScale,
94                      bool                                     cropToMask,
95                      DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
96
97   /**
98    * @copydoc Toolkit::AsyncImageLoader::ImageLoadedSignal
99    */
100   Toolkit::AsyncImageLoader::ImageLoadedSignalType& ImageLoadedSignal();
101
102   /**
103    * @copydoc Toolkit::AsyncImageLoader::PixelBufferLoadedSignal
104    */
105   Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& PixelBufferLoadedSignal();
106
107   /**
108    * @copydoc Toolkit::AsyncImageLoader::Cancel
109    */
110   bool Cancel(uint32_t loadingTaskId);
111
112   /**
113    * @copydoc Toolkit::AsyncImageLoader::CancelAll
114    */
115   void CancelAll();
116
117   /**
118    * Process the completed loading task from the worker thread.
119    */
120   void ProcessLoadedImage();
121
122 protected:
123   /**
124    * Destructor
125    */
126   ~AsyncImageLoader() override;
127
128 private:
129   Toolkit::AsyncImageLoader::ImageLoadedSignalType            mLoadedSignal;
130   Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType mPixelBufferLoadedSignal;
131
132   ImageLoadThread mLoadThread;
133   uint32_t        mLoadTaskId;
134   bool            mIsLoadThreadStarted;
135 };
136
137 } // namespace Internal
138
139 inline const Internal::AsyncImageLoader& GetImplementation(const Toolkit::AsyncImageLoader& handle)
140 {
141   DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
142
143   const BaseObject& object = handle.GetBaseObject();
144
145   return static_cast<const Internal::AsyncImageLoader&>(object);
146 }
147
148 inline Internal::AsyncImageLoader& GetImplementation(Toolkit::AsyncImageLoader& handle)
149 {
150   DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
151
152   BaseObject& object = handle.GetBaseObject();
153
154   return static_cast<Internal::AsyncImageLoader&>(object);
155 }
156
157 } // namespace Toolkit
158
159 } // namespace Dali
160
161 #endif // DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_H