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