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