e74e30acd940e4d269a3007ba083c1fcb2dbfbbb
[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    * @brief Type of signal for LoadingFinished and Uploaded.
67    * @SINCE_1_0.0
68    */
69   typedef Signal< void (ResourceImage) > ResourceImageSignal;
70
71 public:
72
73   /**
74    * @brief Get the size of an image from disk.
75    *
76    * This function will read the header info from file on disk and is
77    * synchronous, so it should not be used repeatedly or in tight
78    * loops.
79    *
80    * @SINCE_1_0.0
81    * @param [in] url The URL of the image file.
82    * @return The width and height in pixels of the image.
83    */
84   static ImageDimensions GetImageSize( const std::string& url );
85
86   /**
87    * @brief Constructor which creates an empty ResourceImage object.
88    *
89    * Use ResourceImage::New(...) to create an initialised object.
90    * @SINCE_1_0.0
91    */
92   ResourceImage();
93
94   /**
95    * @brief Destructor
96    *
97    * This is non-virtual since derived Handle types must not contain data or virtual methods.
98    * @SINCE_1_0.0
99    */
100   ~ResourceImage();
101
102   /**
103    * @brief This copy constructor is required for (smart) pointer semantics.
104    *
105    * @SINCE_1_0.0
106    * @param [in] handle A reference to the copied handle
107    */
108   ResourceImage( const ResourceImage& handle );
109
110   /**
111    * @brief This assignment operator is required for (smart) pointer semantics.
112    *
113    * @SINCE_1_0.0
114    * @param [in] rhs  A reference to the copied handle
115    * @return A reference to this
116    */
117   ResourceImage& operator=( const ResourceImage& rhs );
118
119   /**
120    * @name ResourceImageFactoryFunctions
121    * Create ResourceImage object instances using these functions.
122    */
123   ///@{
124
125   /**
126    * @brief Create an initialised ResourceImage object.
127    *
128    * Uses defaults for all options.
129    *
130    * @sa Dali::FittingMode::Type Dali::SamplingMode::Type
131    * @SINCE_1_0.0
132    * @REMARK_INTERNET
133    * @param [in] url The URL of the image file to use.
134    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
135    * @return A handle to a newly allocated object
136    */
137   static ResourceImage New( const std::string& url, bool orientationCorrection = true );
138
139   /**
140    * @brief Create an initialised ResourceImage object.
141    *
142    * @SINCE_1_0.0
143    * @REMARK_INTERNET
144    * @param [in] url The URL of the image file to use.
145    * @param [in] size The width and height to fit the loaded image to.
146    * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
147    * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
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,
152                             ImageDimensions size,
153                             FittingMode::Type fittingMode = FittingMode::DEFAULT,
154                             SamplingMode::Type samplingMode = SamplingMode::DEFAULT,
155                             bool orientationCorrection = true );
156
157   ///@}
158
159   /**
160    * @brief Downcast a handle to ResourceImage handle.
161    *
162    * If handle points to a ResourceImage object the
163    * downcast produces valid handle. If not the returned handle is left uninitialized.
164    * @SINCE_1_0.0
165    * @param[in] handle Handle to an object
166    * @return Handle to a Image object or an uninitialized handle
167    */
168   static ResourceImage DownCast( BaseHandle handle );
169
170   /**
171    * @brief Query whether the image data has loaded.
172    *
173    * The asynchronous loading begins when the Image object is created.
174    * After the Image object is discarded, the image data will be released from memory.
175    * @SINCE_1_0.0
176    * @return The loading state, either Loading, Success or Failed.
177    */
178   LoadingState GetLoadingState() const;
179
180   /**
181    * @brief Returns the URL of the image.
182    *
183    * @SINCE_1_0.0
184    * @return The URL of the image file.
185    */
186   std::string GetUrl() const;
187
188   /**
189    * @brief Reload image from filesystem.
190    *
191    * The original set of image loading attributes (requested dimensions, scaling
192    * mode and filter mode) are used when requesting the image again.
193    * @SINCE_1_0.0
194    * @note If image is offstage and OnDemand policy is set, the reload request is
195    * ignored.
196    */
197   void Reload();
198
199 public: // Signals
200
201   /**
202    * @brief Emitted when the image data loads successfully, or when the loading fails.
203    *
204    * @SINCE_1_0.0
205    * @return A signal object to Connect() with.
206    */
207   ResourceImageSignal& LoadingFinishedSignal();
208
209 public: // Not intended for application developers
210
211   explicit DALI_INTERNAL ResourceImage( Internal::ResourceImage* );
212 };
213
214 /**
215  * @}
216  */
217 } // namespace Dali
218
219 #endif // __DALI_RESOURCE_IMAGE_H__