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