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