[dali_1.1.38] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / images / resource-image.h
1 #ifndef __DALI_RESOURCE_IMAGE_H__
2 #define __DALI_RESOURCE_IMAGE_H__
3
4 /*
5  * Copyright (c) 2015 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
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/loading-state.h>
26 #include <dali/public-api/images/image.h>
27 #include <dali/public-api/signals/dali-signal.h>
28 #include <dali/public-api/images/image-operations.h>
29
30 namespace Dali
31 {
32 /**
33  * @addtogroup dali_core_images
34  * @{
35  */
36
37 namespace Internal DALI_INTERNAL
38 {
39 class ResourceImage;
40 }
41
42 /**
43  * @brief ResourceImage is an image loaded using a URL
44  *
45  * <i>Customizing load requests</i>
46  *
47  * Size, scaling mode, filter mode, and orientation compensation can be set when requesting an image.
48  *
49  * <i>Reloading images</i>
50  *
51  * The same request used on creating the ResourceImage is re-issued when reloading images.
52  * If the file changed since the last load operation, this might result in a different resource.
53  * Reload only takes effect if the ResourceImage has already finished loading.
54  *
55  * Signals
56  * | %Signal Name         | Method                       |
57  * |----------------------|------------------------------|
58  * | imageLoadingFinished | @ref LoadingFinishedSignal() |
59  * @SINCE_1_0.0
60  */
61 class DALI_IMPORT_API ResourceImage : public Image
62 {
63 public:
64
65   /**
66    * @DEPRECATED_1_1.3. Image loading starts immediately in the frame when then ResourceImage object is created.
67    *
68    * @brief LoadPolicy controls the way images are loaded into memory.
69    * @SINCE_1_0.0
70    * @remarks This is an experimental feature and might not be supported in the next release.
71    * We do recommend not to use it.
72    */
73   enum LoadPolicy
74   {
75     IMMEDIATE, ///< Load image once it is created (default) @SINCE_1_0.0
76     ON_DEMAND  ///< Delay loading until the image is being used (a related actor is added to Stage) @SINCE_1_0.0
77   };
78
79   /**
80    * @brief Type of signal for LoadingFinished and Uploaded.
81    * @SINCE_1_0.0
82    */
83   typedef Signal< void (ResourceImage) > ResourceImageSignal;
84
85 public:
86
87   /**
88    * @brief Get the size of an image from disk.
89    *
90    * This function will read the header info from file on disk and is
91    * synchronous, so it should not be used repeatedly or in tight
92    * loops.
93    *
94    * @SINCE_1_0.0
95    * @param [in] url The URL of the image file.
96    * @return The width and height in pixels of the image.
97    */
98   static ImageDimensions GetImageSize( const std::string& url );
99
100   /**
101    * @brief Constructor which creates an empty ResourceImage object.
102    *
103    * Use ResourceImage::New(...) to create an initialised object.
104    * @SINCE_1_0.0
105    */
106   ResourceImage();
107
108   /**
109    * @brief Destructor
110    *
111    * This is non-virtual since derived Handle types must not contain data or virtual methods.
112    * @SINCE_1_0.0
113    */
114   ~ResourceImage();
115
116   /**
117    * @brief This copy constructor is required for (smart) pointer semantics.
118    *
119    * @SINCE_1_0.0
120    * @param [in] handle A reference to the copied handle
121    */
122   ResourceImage( const ResourceImage& handle );
123
124   /**
125    * @brief This assignment operator is required for (smart) pointer semantics.
126    *
127    * @SINCE_1_0.0
128    * @param [in] rhs  A reference to the copied handle
129    * @return A reference to this
130    */
131   ResourceImage& operator=( const ResourceImage& rhs );
132
133   /**
134    * @name ResourceImageFactoryFunctions
135    * Create ResourceImage object instances using these functions.
136    */
137   ///@{
138
139   /**
140    * @brief Create an initialised ResourceImage object.
141    *
142    * Uses defaults for all options.
143    *
144    * @sa Dali::FittingMode::Type Dali::SamplingMode::Type
145    * @SINCE_1_0.0
146    * @param [in] url The URL of the image file to use.
147    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
148    * @return A handle to a newly allocated object
149    */
150   static ResourceImage New( const std::string& url, bool orientationCorrection = true );
151
152   /**
153    * @DEPRECATED_1_1.3. Use New( const std::string& url ) instead.
154    *
155    * @brief Create an initialised ResourceImage object.
156    *
157    * @SINCE_1_0.0
158    * @param [in] url The URL of the image file to use.
159    * @param [in] loadPol    The LoadPolicy to apply when loading the image resource.
160    * @param [in] releasePol The ReleasePolicy to apply to Image.
161    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
162    * @return A handle to a newly allocated object
163    */
164   static ResourceImage New( const std::string& url, LoadPolicy loadPol, ReleasePolicy releasePol, bool orientationCorrection = true );
165
166   /**
167    * @brief Create an initialised ResourceImage object.
168    *
169    * @SINCE_1_0.0
170    * @param [in] url The URL of the image file to use.
171    * @param [in] size The width and height to fit the loaded image to.
172    * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
173    * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
174    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
175    * @return A handle to a newly allocated object
176    */
177   static ResourceImage New( const std::string& url,
178                             ImageDimensions size,
179                             FittingMode::Type fittingMode = FittingMode::DEFAULT,
180                             SamplingMode::Type samplingMode = SamplingMode::DEFAULT,
181                             bool orientationCorrection = true );
182
183   /**
184    * @DEPRECATED_1_1.3. Use New( const std::string& url, ImageDimensions size ) instead.
185    *
186    * @brief Create an initialised ResourceImage object.
187    *
188    * @SINCE_1_0.0
189    * @param [in] url The URL of the image file to use.
190    * @param [in] loadPol    The LoadPolicy to apply when loading the image resource.
191    * @param [in] releasePol The ReleasePolicy to apply to Image.
192    * @param [in] size The width and height to fit the loaded image to.
193    * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
194    * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
195    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
196    * @return A handle to a newly allocated object
197    */
198   static ResourceImage New( const std::string& url,
199                             LoadPolicy loadPol,
200                             ReleasePolicy releasePol,
201                             ImageDimensions size,
202                             FittingMode::Type fittingMode = FittingMode::DEFAULT,
203                             SamplingMode::Type samplingMode = SamplingMode::DEFAULT,
204                             bool orientationCorrection = true );
205
206   ///@}
207
208   /**
209    * @brief Downcast a handle to ResourceImage handle.
210    *
211    * If handle points to a ResourceImage object the
212    * downcast produces valid handle. If not the returned handle is left uninitialized.
213    * @SINCE_1_0.0
214    * @param[in] handle Handle to an object
215    * @return Handle to a Image object or an uninitialized handle
216    */
217   static ResourceImage DownCast( BaseHandle handle );
218
219   /**
220    * @DEPRECATED_1_1.3
221    *
222    * @brief Return load policy.
223    *
224    * @SINCE_1_0.0
225    * @remarks This is an experimental feature and might not be supported in the next release.
226    * We do recommend not to use it.
227    * @return Resource load policy
228    */
229   LoadPolicy GetLoadPolicy() const;
230
231   /**
232    * @brief Query whether the image data has loaded.
233    *
234    * The asynchronous loading begins when the Image object is created.
235    * After the Image object is discarded, the image data will be released from memory.
236    * @SINCE_1_0.0
237    * @return The loading state, either Loading, Success or Failed.
238    */
239   LoadingState GetLoadingState() const;
240
241   /**
242    * @brief Returns the URL of the image.
243    *
244    * @SINCE_1_0.0
245    * @return The URL of the image file.
246    */
247   std::string GetUrl() const;
248
249   /**
250    * @brief Reload image from filesystem.
251    *
252    * The original set of image loading attributes (requested dimensions, scaling
253    * mode and filter mode) are used when requesting the image again.
254    * @SINCE_1_0.0
255    * @note If image is offstage and OnDemand policy is set, the reload request is
256    * ignored.
257    */
258   void Reload();
259
260 public: // Signals
261
262   /**
263    * @brief Emitted when the image data loads successfully, or when the loading fails.
264    *
265    * @SINCE_1_0.0
266    * @return A signal object to Connect() with.
267    */
268   ResourceImageSignal& LoadingFinishedSignal();
269
270 public: // Not intended for application developers
271
272   explicit DALI_INTERNAL ResourceImage( Internal::ResourceImage* );
273 };
274
275 /**
276  * @}
277  */
278 } // namespace Dali
279
280 #endif // __DALI_RESOURCE_IMAGE_H__